From nobody Sun Feb 8 02:20:46 2026 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 41F4030DEB2 for ; Sun, 4 Jan 2026 13:35:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.179 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767533715; cv=none; b=NzCKLX6XDl7UzyIx65wALVxUExFG5vVU7QIyIQLKLPRDDfnzwr8QkN7TXnmncMaXA7cAEelqwvDNvGLwsIpxTHIW6rMYLkndJOXAV9VstLdRdiSAgeBHnFR9/efRw6UHt33xaw+Qzp6vIFLTKvGgEqs4pR1JtbDxZMP5XLL3ZNw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767533715; c=relaxed/simple; bh=gsITpUOGdQDLvCVOzdeUMZ3zpJsx1qlz2qHxo5nVveo=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Lkp1e/QYiRk//WA8D/q7WbLDPJ8fQ0goB6iriC4NWmIBtUdbjl/vRuhHSrgI8fBKQStHMNBwxkM1cYl6YiO08RkgWmCOLEIexF622P5tay0JBrFWkpgobAVadlvR89aE+xfIE0cgOkrRG5fE5Cb8vIT6xFzyYTKnVUbkl41tpL0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=BK5kpBEB; arc=none smtp.client-ip=209.85.214.179 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="BK5kpBEB" Received: by mail-pl1-f179.google.com with SMTP id d9443c01a7336-2a102494058so5257505ad.0 for ; Sun, 04 Jan 2026 05:35:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767533713; x=1768138513; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=2BBSlS/sUmpDgECm0JFuorFD0hPkfViLXKE80/Mz72E=; b=BK5kpBEBpoz3lYeFjFeGUBI9OiMsetsTVKjmpOrV2OkedBzudM7O5at/HqqH3i1sMZ p6sf91D2t6oBa7crS2cqRO31+BbPcKyQNJg8WQRTT+65mLYY6AFBng+J4C/HMLakGflt +07kiNG5wI0dPpA1R9jcDaUsdq5nQmbxFYiPYW1isTXcGSXGEiaObABG4PHoRc+Eljmh j1jSs1mw8OafffH5jiMVHVP0xa+BIUUOv/myiB12RgypRqx+65r3D07PDNcBvrE+1kTQ CH46D/lpGfCM9Jht56hROJHLe3F/Z5cXnQA/DheTDsgmgv5zf9OSv4hST4AInR2BJOAM LHgg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767533713; x=1768138513; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-gg:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=2BBSlS/sUmpDgECm0JFuorFD0hPkfViLXKE80/Mz72E=; b=r5RewsqIeP2sBwrS8QJt7/hfV0mrrgsEPIHCkSkY9cSzgfkM6UdttkSdg2bXJJ13TP +b17v4kZDh7XhA5oQt+SRI91I+scEVL5bc87/TJNv+pJPiVTWECJbb9S/raqy1DPaqO1 YPVDFZk8D52KtLKgWUOCLMpynbJ7N3sirsWB9b/unvnhkO6KHobvWqCOExJSn5U7EYR6 f2pbISgBEsSlfUzmCGGyAsfBSck45/88Ipj3bjH4xgFE0EXMaOJu4F7F9L3h3ELGarOU Otr6KogJJsepwKZv4/t3Nk/bHaJkbf7jYcT0J7ZgbjqmV2U5wQAPfrjPUm/nqV/QPpei kYpQ== X-Forwarded-Encrypted: i=1; AJvYcCX54VRCSM/8TiPZgXbeTBU+AjvFzc1niJIKvOSyRwOuf8+SMR8ptB8RIWYjy4YNcFYNdIh0rQKSQQJzZNc=@vger.kernel.org X-Gm-Message-State: AOJu0Yx+hR1L71NPrnq2u1Mc+AsvKQmpDl+fVM/NLB3SFrRdyUWshSmx o9ShBHj5qDiaHSjwAgl2OO4THWXVdolA5jaHnAheT8JV+kdmdl3q3SRo4H8vfg== X-Gm-Gg: AY/fxX6TSuhPABZno7qhaNhzc0bCrgXHg9KrbR25TO5xld8vI+M6sxgWBptrH6l60xR eplEMGyzxz9QOmQw3YWmEzDohO3dRqlolGHeGnTEhb67EkL49pgGtYnavYuTMxaDkIIld0EcKCW 2Mj5ELUSCx+KnAPbjwQ7Yfxnk0QiUr6uBYmoxuvZkfJtEwpducMtxIRAsfErxiAX2rqG6X4zaAw VyBki49sFfx4z+zTGMRFl+xWEerPj7HuB/ugW3pR/oxJDosBQ0TuXeDZkvIAQAmb51bFzWGWW5A VMvLEniJdDLgd9S8bcs8JMTNNOrFtF4FHJCqA1XaXW489Pn3dj3CrkeX42RfU78A6sS7MbV6WbI IZt/hGuheqSbQT3Q2P1zJ5IEthUqgN2zFJKMklJyUWokIxhivUpA9mn+MpHsha2LJRPILwCSKHr dSSNkHmypfb41wJaq2dJibRelfrS62V121Hw0ABgZzZVnVCPFFU0sked5fAafzowKP2uk= X-Google-Smtp-Source: AGHT+IGIlOvMhqWcVXHVVnRdmo2BxUI7PrzIbxyarhVVyfVzGIbsKISoPxKEzukQ5jH+92p+2N1zcw== X-Received: by 2002:a17:903:1984:b0:2a0:d0ae:454d with SMTP id d9443c01a7336-2a3c09b7ae4mr40296305ad.22.1767533713379; Sun, 04 Jan 2026 05:35:13 -0800 (PST) Received: from deepanshu-kernel-hacker.. ([2405:201:682f:389d:3d5d:94a5:a074:8109]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a2f3d4d36esm429756545ad.63.2026.01.04.05.35.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 04 Jan 2026 05:35:12 -0800 (PST) From: Deepanshu Kartikey To: mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com Cc: ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, Deepanshu Kartikey , syzbot+7960178e777909060224@syzkaller.appspotmail.com Subject: [PATCH v2] ocfs2: add check for free bits before allocation in ocfs2_move_extent() Date: Sun, 4 Jan 2026 19:05:04 +0530 Message-ID: <20260104133504.14810-1-kartikey406@gmail.com> X-Mailer: git-send-email 2.43.0 Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Add a check to verify the group descriptor has enough free bits before attempting allocation in ocfs2_move_extent(). This prevents a kernel BUG_ON crash in ocfs2_block_group_set_bits() when the move_extents ioctl is called on a crafted or corrupted filesystem. The existing validation in ocfs2_validate_gd_self() only checks static metadata consistency (bg_free_bits_count <=3D bg_bits) when the descriptor is first read from disk. However, during move_extents operations, multiple allocations can exhaust the free bits count below the requested allocation size, triggering BUG_ON(le16_to_cpu(bg->bg_free_bits_count) < num_bits). The debug trace shows the issue clearly: - Block group 32 validated with bg_free_bits_count=3D427 - Repeated allocations decreased count: 427 -> 171 -> 43 -> ... -> 1 - Final request for 2 bits with only 1 available triggers BUG_ON By adding an early check in ocfs2_move_extent() right after ocfs2_find_victim_alloc_group(), we return -ENOSPC gracefully instead of crashing the kernel. This also avoids unnecessary work in ocfs2_probe_alloc_group() and __ocfs2_move_extent() when the allocation will fail. Reported-by: syzbot+7960178e777909060224@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3D7960178e777909060224 Link: https://lore.kernel.org/all/20251231115801.293726-1-kartikey406@gmail= .com/T/ [v1] Signed-off-by: Deepanshu Kartikey Reviewed-by: Joseph Qi --- v2: - Fixed missing '<' in commit message (Joseph) - Moved check right after ocfs2_find_victim_alloc_group() to fail early and avoid unnecessary work (Joseph) --- fs/ocfs2/move_extents.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c index 99637e34d9da..c037fb34b1e3 100644 --- a/fs/ocfs2/move_extents.c +++ b/fs/ocfs2/move_extents.c @@ -662,6 +662,12 @@ static int ocfs2_move_extent(struct ocfs2_move_extents= _context *context, goto out_commit; } =20 + gd =3D (struct ocfs2_group_desc *)gd_bh->b_data; + if (le16_to_cpu(gd->bg_free_bits_count) < len) { + ret =3D -ENOSPC; + goto out_commit; + } + /* * probe the victim cluster group to find a proper * region to fit wanted movement, it even will perform @@ -682,7 +688,6 @@ static int ocfs2_move_extent(struct ocfs2_move_extents_= context *context, goto out_commit; } =20 - gd =3D (struct ocfs2_group_desc *)gd_bh->b_data; ret =3D ocfs2_alloc_dinode_update_counts(gb_inode, handle, gb_bh, len, le16_to_cpu(gd->bg_chain)); if (ret) { --=20 2.43.0