From nobody Sun Jun 21 00:13:37 2026 Received: from mail-pg1-f174.google.com (mail-pg1-f174.google.com [209.85.215.174]) (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 069061DF27F for ; Thu, 9 Apr 2026 06:03:14 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.174 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775714597; cv=none; b=IlR5YyV4BslH/9JOWZN305vZJ20nAvits2DoDnOiMLCSCU+fFfGjCJq+BR62mcnFuuJGY9htDSZwRzSkJ9kxRj8hYLiJv7gNCJTImb4hWfCdNQncOIK7L2+OtUzJlArVQo0IAYOv2QOk0yEWLyT0i9ReboHjSY5kSCZ34RgJyAg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1775714597; c=relaxed/simple; bh=dS4TVawFWrExnqEmCepp3a6SmkFo/dyHQqphFHd35Ns=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=bya29QWD5VEvOIubxJ4OpculZXzFgbzwMOBUWVt2PYwS3MAhhXl/MMFTLhM1N7Catt7jMVxGrdG5/C6gjghztr5xkU1w62c6SLFciKzz7LdD58M1D7te0aNhA6TDYwWLXSHIjkSj0f3udwOkr3Z4N90e/eOvLIPdQNmtR2x4to8= 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=sCJNeTKM; arc=none smtp.client-ip=209.85.215.174 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="sCJNeTKM" Received: by mail-pg1-f174.google.com with SMTP id 41be03b00d2f7-c76bc3e8de3so277733a12.2 for ; Wed, 08 Apr 2026 23:03:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1775714594; x=1776319394; 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=tSaOv0azjmSiOgE4UMcdS1bwbJhCj8e5gx9KHNU+W2Y=; b=sCJNeTKMA/80sFoZUMD1h0qJKGldK/F4hbD4RVedfcrYiq6K5WNT3xAz2yWoT6txOg TxLiABWqPRuX0AhzjhM8swnMxhHxUy2QSr4oEpFfSEGHoM4ncUEYVjrblMtMrlLW93I/ QOqFumwBs5z2DrfM+hJBSF/JkxyvIFD7rakVuRs9u3UfxFU/MqlEz2LSjgXJB+DSr5yS ZNpSb/HxB0py2H4LEAk4oTpD6GaNPf5GGfFY1XinZycqX4+Ua01OvBhn5ABYBQ56eq1R QoqtL6crhtrEEFSz1vDFs22qmviJmZpgZnIrXNrYkJbLaFXql4WCqbwo6+gQGjv6vL0Z biwQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1775714594; x=1776319394; 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=tSaOv0azjmSiOgE4UMcdS1bwbJhCj8e5gx9KHNU+W2Y=; b=AeFUS6O3TYUoVhBcy3S1b2RCFjroh4ZcPK6E2E28GwBAlaqOb6OW2bML7rVrAqv/e0 STnp4kVHQEm1sAN9ZJC1Ye+k9AkPqQFW1PNHlaaFfEhG98fufJD8zd3necwZXKjRGWEc lF6pDmFUhRjb99NeSY0fJ9cmQaPnvwcKYduGiuYzi/NoyDPDO4uWVjH/4aQppnB1R3Dx 8O76Orno81OVPcqt3FN8wEZjgXfLTJjlqiuW4EtarIK5mVlhnznzEA/4N7bv09PmVTJV 8sEP38n/yghbpvwqCgPbDwr++mrO0AjIRKFDjRoxE8WrddKY0ACIn0jDTMlH/bija5Ex 74RA== X-Forwarded-Encrypted: i=1; AJvYcCVvWwrdTa+V9OuqGjtsH5eS1mOS23ZSWl7W/bFdzaqs4DAgA/WQiZYK9PH1zuOHHoxjGEfhTEjpmCAGaYg=@vger.kernel.org X-Gm-Message-State: AOJu0YwejyI/QkrtagWlE3pwvGXvi+mGbraR2696X2vrXdh9Y8v3LRyP XXihCVmooSix7GeF7hwBYCoMk7ocOdn0dU/uwaQCFae32R/T6dzwG1L3 X-Gm-Gg: AeBDieu3XWewQO+7HRGkKaJ7OidZxB5ZwQRKmKRJriOLwsmq/CPOEQcZPclo043kWdv Lpo50KAxNc1/g/USXFPE/eu/drVlN5/zV2X60BkLYUcjN4SAYbPra9cmrq3Wzf9In3CILpPA5Iy nmE+hYl6dNo1KH8cRn8U2QL9iZ9/2UlGY5RkwvES5XxGQmyS1GieCmE2k5Kt/lwtqf1aHLFy1Lf ILEog6x1vNUjuwMTaHNyKCF/RQq8GJdCULfdfq8Wx9MFHwS9fwsdtmzjKGxKQlm69NElXbYnmcA VK3YGzvono+qyYDAmK2z3QPbYR+CoZ/H5Cn+wC1oR8jIBUaSfcPYE3r7PxeuEaDcyfJ/FLxYx5W uN2bdzp7m1rptFKP6PuJDteJ/a7dXBVvfBnZXj9p3YAOCFGERgI7CRh9jMWvPLDDZCtMAhFeDit nUJKHXLO79BuNQfySHm73yq9/Kacu2fX9RSfHR7m/ahIaQuIEnCgEv9zxSrxOiQyL3m14tkQ== X-Received: by 2002:a05:6a00:178e:b0:827:455b:86b1 with SMTP id d2e1a72fcca58-82d0db693cemr23797880b3a.28.1775714594051; Wed, 08 Apr 2026 23:03:14 -0700 (PDT) Received: from kernel-fuzz.. ([138.199.21.245]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-82cf9c68273sm27975827b3a.41.2026.04.08.23.03.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Apr 2026 23:03:13 -0700 (PDT) From: ZhengYuan Huang To: mark@fasheh.com, jlbec@evilplan.org, joseph.qi@linux.alibaba.com Cc: ocfs2-devel@lists.linux.dev, linux-kernel@vger.kernel.org, baijiaju1990@gmail.com, r33s3n6@gmail.com, zzzccc427@gmail.com, ZhengYuan Huang Subject: [PATCH] ocfs2: validate bg_bits during freefrag scan Date: Thu, 9 Apr 2026 14:02:41 +0800 Message-ID: <20260409060241.3344855-1-gality369@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" [BUG] A crafted filesystem can trigger an out-of-bounds bitmap walk when OCFS2_IOC_INFO is issued with OCFS2_INFO_FL_NON_COHERENT. BUG: KASAN: use-after-free in instrument_atomic_read include/linux/instrume= nted.h:68 [inline] BUG: KASAN: use-after-free in _test_bit include/asm-generic/bitops/instrume= nted-non-atomic.h:141 [inline] BUG: KASAN: use-after-free in test_bit_le include/asm-generic/bitops/le.h:2= 1 [inline] BUG: KASAN: use-after-free in ocfs2_info_freefrag_scan_chain fs/ocfs2/ioctl= .c:495 [inline] BUG: KASAN: use-after-free in ocfs2_info_freefrag_scan_bitmap fs/ocfs2/ioct= l.c:588 [inline] BUG: KASAN: use-after-free in ocfs2_info_handle_freefrag fs/ocfs2/ioctl.c:6= 62 [inline] BUG: KASAN: use-after-free in ocfs2_info_handle_request+0x1c66/0x3370 fs/oc= fs2/ioctl.c:754 Read of size 8 at addr ffff888031bce000 by task syz.0.636/1435 Call Trace: __dump_stack lib/dump_stack.c:94 [inline] dump_stack_lvl+0xbe/0x130 lib/dump_stack.c:120 print_address_description mm/kasan/report.c:378 [inline] print_report+0xd1/0x650 mm/kasan/report.c:482 kasan_report+0xfb/0x140 mm/kasan/report.c:595 check_region_inline mm/kasan/generic.c:186 [inline] kasan_check_range+0x11c/0x200 mm/kasan/generic.c:200 __kasan_check_read+0x11/0x20 mm/kasan/shadow.c:31 instrument_atomic_read include/linux/instrumented.h:68 [inline] _test_bit include/asm-generic/bitops/instrumented-non-atomic.h:141 [inline] test_bit_le include/asm-generic/bitops/le.h:21 [inline] ocfs2_info_freefrag_scan_chain fs/ocfs2/ioctl.c:495 [inline] ocfs2_info_freefrag_scan_bitmap fs/ocfs2/ioctl.c:588 [inline] ocfs2_info_handle_freefrag fs/ocfs2/ioctl.c:662 [inline] ocfs2_info_handle_request+0x1c66/0x3370 fs/ocfs2/ioctl.c:754 ocfs2_info_handle+0x18d/0x2a0 fs/ocfs2/ioctl.c:828 ocfs2_ioctl+0x632/0x6e0 fs/ocfs2/ioctl.c:913 vfs_ioctl fs/ioctl.c:51 [inline] __do_sys_ioctl fs/ioctl.c:597 [inline] __se_sys_ioctl fs/ioctl.c:583 [inline] __x64_sys_ioctl+0x197/0x1e0 fs/ioctl.c:583 ... [CAUSE] ocfs2_info_freefrag_scan_chain() uses on-disk bg_bits directly as the bitmap scan limit. The coherent path reads group descriptors through ocfs2_read_group_descriptor(), which enforces bg_bits <=3D bg_size * 8. The non-coherent path uses ocfs2_read_blocks_sync() instead and skips that validation, so an impossible bg_bits value can drive the bitmap walk past the end of the block. [FIX] Check bg_bits against the actual bitmap capacity before scanning the group bitmap and fail the ioctl with -EIO if the descriptor is impossible. This keeps the coherent path unchanged and gives the non-coherent path the same bound needed to avoid walking beyond the buffer. Signed-off-by: ZhengYuan Huang --- fs/ocfs2/ioctl.c | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/fs/ocfs2/ioctl.c b/fs/ocfs2/ioctl.c index b6864602814c..a341a599e440 100644 --- a/fs/ocfs2/ioctl.c +++ b/fs/ocfs2/ioctl.c @@ -441,7 +441,7 @@ static int ocfs2_info_freefrag_scan_chain(struct ocfs2_= super *osb, struct buffer_head *bh =3D NULL; struct ocfs2_group_desc *bg =3D NULL; =20 - unsigned int max_bits, num_clusters; + unsigned int max_bits, max_bitmap_bits, num_clusters; unsigned int offset =3D 0, cluster, chunk; unsigned int chunk_free, last_chunksize =3D 0; =20 @@ -474,11 +474,27 @@ static int ocfs2_info_freefrag_scan_chain(struct ocfs= 2_super *osb, } =20 bg =3D (struct ocfs2_group_desc *)bh->b_data; + max_bits =3D le16_to_cpu(bg->bg_bits); + max_bitmap_bits =3D 8U * le16_to_cpu(bg->bg_size); + + /* + * Non-coherent scans read raw blocks and do not get the + * bg_bits <=3D bg_size * 8 validation from + * ocfs2_read_group_descriptor(). + */ + if (max_bits > max_bitmap_bits) { + mlog(ML_ERROR, + "Group desc #%llu has %u bits but bitmap holds %u\n", + (unsigned long long)blkno, + max_bits, + max_bitmap_bits); + status =3D -EIO; + goto bail; + } =20 if (!le16_to_cpu(bg->bg_free_bits_count)) continue; =20 - max_bits =3D le16_to_cpu(bg->bg_bits); offset =3D 0; =20 for (chunk =3D 0; chunk < chunks_in_group; chunk++) { --=20 2.43.0