From nobody Mon Feb 9 00:43:12 2026 Received: from mail-pl1-f178.google.com (mail-pl1-f178.google.com [209.85.214.178]) (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 9F59F31960B for ; Wed, 31 Dec 2025 11:58:09 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.178 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767182291; cv=none; b=SbBomwPrxvfdaIF5fognFbXmfomxNe9fqPBGu8sNUB4T8bvidbfUBNn0J2UTymO5aZdAQVSNL3zA8YvuoJ+X5EqtZsZ/kV+VvkA8ii9BPNr2ywHAgy9qN3x6dY0fWsqheBw+TZbF9+L3ojf4u3SDFb6OfDrdS0bt2q6cooKsL3I= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1767182291; c=relaxed/simple; bh=k88tlWBQYYOEPRPsr7HVftPakb/hjG28OzQPctybQLM=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=Le650ERyu8SDYzDjm4uynLeI1xbADEwO+oGyV8aOXcvQ69abj5gPCqyinxRQi+EwZA8R/8dI7v35wB84pqUyi9jQvf2X6hYyqFSF9niuQTb8HUt/wiBxh50HRRiIq57vMUxku+/FiK/2hfGwRLdY4kase2WqrUQFT/bfMpKBNgg= 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=akyElrlz; arc=none smtp.client-ip=209.85.214.178 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="akyElrlz" Received: by mail-pl1-f178.google.com with SMTP id d9443c01a7336-2a0834769f0so105783075ad.2 for ; Wed, 31 Dec 2025 03:58:09 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1767182289; x=1767787089; 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=wz/+EK600urPKAZwKCkmBYjLyy6YfjogOlH1FKpFrF8=; b=akyElrlz5N5mLAlTy3T0XS3065UGLBexT8Ay4fg0MPoc263OBB0shLi20/lKH3Z52s hwLC2kDz2WuQFBKsuxqjIVz/obQCoU4pAOq2TBGjM4HYiV9EcvNnVImch7KpcWiVfMyz O6d13EZHNbyGJCOZM/hGUE4L6+xy2dGfqcKD/qvnnZW+Px1diDaE4WONU6j/6h8LWOqi mrU0XqL0RQA9DZ5qvZz2oE4oFFlt93lZ6lSInPz7fGF8iHuKq8Yyph1Gdwekkhge4AYj bB3WCD3z9LskASesJ0Wjyf+IbT/IOJ4AORE9meJ8WKVO4QB2BsECfwuyP1Ca6Akn8ZuT db8w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1767182289; x=1767787089; 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=wz/+EK600urPKAZwKCkmBYjLyy6YfjogOlH1FKpFrF8=; b=ADclfVGqKI6XTrxCUmW5eoaE0/4FkP9vmEddJBItN+6i/uxSIf94D3zijF9YyIIGpd rnSTXEF7TsWQE29PBA5HqllF0UDKGsRnUDjybROym/6DM7gGNl2WTfcMN2chq+EO9APN qa/2XnfO9V4c8+AHQewbg1B/2CV2ozN0GJpBpSzRTnaa0ZGoRh+dG+rWOFLWPGdBJANx LavIYkSp3N5FGLlBfdVTZ+54gBw06ic53bc/w23Wivb1c8m/BAivliro7Kf1qq9JQJhf DsuvqKcHcvRc1/Sbz5dbRwAZ6H7w+/QT4zQ6cnAhRwyz9DFxYxmFKFC9er/VGt+pSJ1T qHEw== X-Forwarded-Encrypted: i=1; AJvYcCUy5XV+nbg6WbUH+bcY3BSgf2bXa8SU16s7+MZF2+26iDjs6VCKrJ9gE9p2aLh8jE/kOABrlpdrQ2jk+Gw=@vger.kernel.org X-Gm-Message-State: AOJu0Yw68HbTpv65yWY8nZkJYnvCe4fsWx7s0LlmruXi3XXs47qNAMsT 4R4cAtK+FIWGvAJwB6m08LuZlp/jHxYoJGHQXbhdWVIYNIvjs11sI4YK X-Gm-Gg: AY/fxX7wBt7dM020iZ2GUem66am3JUavUE80FW1yWyj5Y0yty32kqAEC9qKzlKthHQ3 bUeNNTmQ6QOhk1CewLXLKDeuzT2Lfn2zYTVIRiqJgkn9VPPB7VHbE61+RZpOYnP0vLtYvEKdgSP REaVleTUeo8FL4xDkIkt2ulEhNhAhTsnp/WEJhqNeJmjCxWetrFX/rV2eFXrkzZFnN3bYZrf0Mi YQ2izApi3gsxB0XDNcqFVJJUfU+B7Q6XzNd1imMsWbutAhnltqhY6X/mz8Ao1mGFz/7xDT3VI33 A0/vxqX10bLBAQnT4e8ovHoI+uX/WUkfllLgoeBTJsYMwXIgTnPTtgMEiG3w/ZTZ3IuPzntRvDp 7OjiUzDE/Gw7flcaYrgr/0seUHJDNjDeXb2n9DVlInYytkp2mm7ItpiBEd9oYdOKDlvJV/R+yhg 5R7ikhu15NtFh0BAGHFdsx0UBvX4qtphWKfRhtKNKvyoQHcBYSObrYiAOSwc8A6iBNGS8uqmIc0 x60+w== X-Google-Smtp-Source: AGHT+IGziUsfUmQRaqOCxW6sieLIMR86pWG/brH0bc1pTwoC64rtPjrWcOpkzW3UzSVYaAAA4nYAog== X-Received: by 2002:a17:903:2ac5:b0:2a1:3ee7:cc7a with SMTP id d9443c01a7336-2a2f2223616mr342395905ad.17.1767182288787; Wed, 31 Dec 2025 03:58:08 -0800 (PST) Received: from deepanshu-kernel-hacker.. ([2405:201:682f:389d:8329:515d:5002:11e7]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2a2f3c66834sm319109045ad.9.2025.12.31.03.58.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 31 Dec 2025 03:58:08 -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] ocfs2: add check for free bits before allocation in ocfs2_move_extent() Date: Wed, 31 Dec 2025 17:28:01 +0530 Message-ID: <20251231115801.293726-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() before calling ocfs2_block_group_set_bits(), we return -ENOSPC gracefully instead of crashing the kernel. Reported-by: syzbot+7960178e777909060224@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=3D7960178e777909060224 Tested-by: syzbot+7960178e777909060224@syzkaller.appspotmail.com Signed-off-by: Deepanshu Kartikey --- fs/ocfs2/move_extents.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/fs/ocfs2/move_extents.c b/fs/ocfs2/move_extents.c index 99637e34d9da..2548a8908a1b 100644 --- a/fs/ocfs2/move_extents.c +++ b/fs/ocfs2/move_extents.c @@ -690,6 +690,11 @@ static int ocfs2_move_extent(struct ocfs2_move_extents= _context *context, goto out_commit; } =20 + if (le16_to_cpu(gd->bg_free_bits_count) < len) { + ret =3D -ENOSPC; + goto out_commit; + } + ret =3D ocfs2_block_group_set_bits(handle, gb_inode, gd, gd_bh, goal_bit, len, 0, 0); if (ret) { --=20 2.43.0