From nobody Sat Jul 25 18:54:01 2026 Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (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 7342C427FB5 for ; Tue, 14 Jul 2026 21:56:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784066179; cv=none; b=KnvT4FsXyUk/3JET5mxSY5injGrTEbARQsYVnBAp/Ct4TzyvWRQHJZV6BzPnotGaeSMkXU4N1kkQkN0okEjwDHhG53HaD7HJpmHtZZclJaiaqHCRQF1nFJg0F7xkfw7EdGpovsBJZTlHM00eeFz1tbURJe0hs+sJerjFp4vOtck= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1784066179; c=relaxed/simple; bh=/AfF9I8r9L88QBqEXJ+knjHCrOUZXwHF9Mjcs14h22w=; h=From:To:Cc:Subject:Date:Message-ID:MIME-Version; b=a2TQYlYGfbTdq2rZTxo55Fcca0GVJhy3k8APML9E5D/np7neZ5b3YtDn6n6SpyoLVsn/BTboJkj2HdpsP1mwMoJh3OAf2apMOuJIn1qEaOkFxuMsQSCGAn04HE2hPkPJpaQxm8vmTmr6uvAsYRdCdCOv1OqppSX1xhJzhjR07Gg= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=asu.edu; spf=pass smtp.mailfrom=asu.edu; dkim=pass (2048-bit key) header.d=asu.edu header.i=@asu.edu header.b=DREa4cm1; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=asu.edu Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=asu.edu Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=asu.edu header.i=@asu.edu header.b="DREa4cm1" Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-2ce98cb8165so15007595ad.1 for ; Tue, 14 Jul 2026 14:56:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=asu.edu; s=google; t=1784066177; x=1784670977; 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:content-type; bh=a3bMWS4b6GGm8PZgGzkoAOMcuJeTSNNgmOihDM66PlI=; b=DREa4cm1m9Ylo7pKIQDsuRve4bsUFOEFus+ELhJDsYeTdBv4ZmbfoFXRBZntrl0Sff oRKEmy3QGgnHQangciwzBVKJEi2lKt0raXk3YAvj2hfzG2NnCwO26KGdMiTQvaPr0WHN Wl1TGVZGSyBpkc7XcZlKDCQbzEa1kpT9dKWJ1Hemcp32RnmRZXRTKGlVMvmICJwjJ8F2 e3TC/E87pg5MrDKBrZSs9wsf/pWZtf6mOvoReIJvM2WO4y3Jg+XrxfXV1KZOyqUc8mpU J2pgaVRDfNLZwUY68Ogm0U3xsXQWYGqIGu6ycGM9cJ+hymr0oJixMJ+UlrF6ZbHK5YS3 c2Aw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1784066177; x=1784670977; 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:content-type; bh=a3bMWS4b6GGm8PZgGzkoAOMcuJeTSNNgmOihDM66PlI=; b=Yy2nDarVvUCaPG+q61bvCkAdJ7Y3i+yKmNGR1UvZw2eJuHdLDnzKif6dW1RUjl+T1W UDTWaEVVjwNzGifVrGrSp8Iwoh8IPAi8mPp5WaSmLx12+R1Mg1xvUAVTIbv3jVAwlgNG mqOJQlbZBtCin28uf3G7nxMMwUZLEt53pOgxnnyVR9uc6CPCDkCJzNzCgSW3KNFIIYUI mMFRHr8j2AxgDiSa4AW380dmW2R5I1684QhSJxrWR79nZuSdarrBDnWnQRBX4BlZBPo0 GkCydtp6AE+nh0WnYUhhcMdesy3s4DGo35gmgXdauG7jQsNi5RloEAxN66sGAi5fY3WZ Bqaw== X-Forwarded-Encrypted: i=1; AHgh+RobM36lm1/ou9XgzVZtL0USeSjdRUlVSCrtiZDm3Aj+R3it5wd1mzrLGKXkds0rlMy25DbUvHvij8ovL+8=@vger.kernel.org X-Gm-Message-State: AOJu0YxId2wUYsHQHCnDYt43Vjsb09Ih/fWWpiC36Ci/fJgr/NksTpwb nY1xszGFFr6KtmyZuY6pw899YSdhejPMuhg00vE9LCdB5qb9Z4KPAnJOAsTY2wq5rA== X-Gm-Gg: AfdE7cljCVrEoh7XeIe3taWuyYx/zkQksZx9WetudOjJLRJ1H3ckH9AQkzomVVgKbzL XsYY4+MHKvTYgLkmLdKsSiXkbhx2WuIKWMcyGlbW6WuqIp/JtS6GbkPx0PGiC46O2waqPX0e4nL WY5xmSI4XgdoDhHfQddolPW80i5E1nU8T8ktXuFrcOaHR0agcNVnl3WwK0WTSKwMUvO6n5huqjX vXETPMwxXen004PGF/XrHl6HdjdicGzNbqZPxaN6CqkXw6aEoVD5D1dPmjcWDenN7IT2sDnehZu DYkYDgn0wIK/eUI9sGroP2H8vc4Ec6RFJ9+8ThnVeSIuFXMgY1UCq8Y9kyiwY8MikFsubjAnSMU sPIZG5s3iyJb0qH2VgUMc/UDMcIsXkBqoFonkbZr1/zT4Gs2n9Lf8ljfhyktVw3RCgo9+2ARoR5 UXDQk5i2s= X-Received: by 2002:a17:903:298e:b0:2c9:97a7:3283 with SMTP id d9443c01a7336-2cea187c0d0mr144303245ad.23.1784066176736; Tue, 14 Jul 2026 14:56:16 -0700 (PDT) Received: from p1.. ([2607:fb91:153f:24b:150b:bb6f:1d25:f03e]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-2ccc9bf77e4sm122119835ad.22.2026.07.14.14.56.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 14 Jul 2026 14:56:16 -0700 (PDT) From: Xiang Mei To: Carlos Maiolino Cc: "Darrick J . Wong" , linux-xfs@vger.kernel.org, linux-kernel@vger.kernel.org, bestswngs@gmail.com, Xiang Mei , stable@vger.kernel.org, Christoph Hellwig Subject: [PATCH v2] xfs: fix off-by-one in rtrefcount btree root level validation Date: Tue, 14 Jul 2026 14:56:12 -0700 Message-ID: <20260714215612.1528518-1-xmei5@asu.edu> 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" xfs_rtrefcountbt_compute_maxlevels() sets mp->m_rtrefc_maxlevels =3D min(d_maxlevels, r_maxlevels) + 1; where the trailing "+ 1" already accounts for the inode-root level, so the deepest valid on-disk root level is m_rtrefc_maxlevels - 1 and a cursor must satisfy bc_nlevels <=3D bc_maxlevels (=3D m_rtrefc_maxlevels). The two on-disk validation paths, xfs_rtrefcountbt_verify() and xfs_iformat_rtrefcount(), check the root level with ">" instead of ">=3D", = so a crafted rtreflink (metadir + realtime + reflink) image whose /rtgroups/N.refcount inode has bb_level =3D=3D m_rtrefc_maxlevels is accept= ed on mount. xfs_rtrefcountbt_init_cursor() then sets bc_nlevels =3D bb_level + 1, exceeding bc_maxlevels by one. Since the xfs_rtrefcountbt_cur slab object is sized for exactly bc_maxlevels entries, the first btree op on such a cursor indexes bc_levels[m_rtrefc_maxlevels] past the end of the object. This is reached by the first rtrefcount cursor built after mount, via log/CoW recovery (xfs_reflink_recover_cow() during xfs_mountfs()) or an FS_IOC_GETFSMAP over the realtime device. Reject a root level equal to m_rtrefc_maxlevels, matching the ">=3D" form already used by the sibling data-device refcount/rmap verifiers and the in-memory rtrmap verifier. BUG: KASAN: slab-out-of-bounds in xfs_btree_lookup (fs/xfs/libxfs/xfs_btr= ee.c:2101) Write of size 2 at addr ffff888018391658 by task exploit/144 xfs_btree_lookup (fs/xfs/libxfs/xfs_btree.c:2101) xfs_btree_query_range (fs/xfs/libxfs/xfs_btree.c:5308) xfs_refcount_recover_cow_leftovers (fs/xfs/libxfs/xfs_refcount.c:2113) xfs_reflink_recover_cow (fs/xfs/xfs_reflink.c:1085) xlog_recover_finish (fs/xfs/xfs_log_recover.c:3551) xfs_mountfs (fs/xfs/xfs_mount.c:1158) xfs_fs_fill_super (fs/xfs/xfs_super.c:1940) get_tree_bdev_flags (fs/super.c:1634) vfs_get_tree (fs/super.c:1694) path_mount (fs/namespace.c:4161) __x64_sys_mount (fs/namespace.c:4367) entry_SYSCALL_64_after_hwframe (arch/x86/entry/entry_64.S:121) The buggy address belongs to the cache xfs_rtrefcountbt_cur of size 216 The buggy address is located 8 bytes to the right of allocated 216-byte region [ffff888018391578, ffff888018391650) Kernel panic - not syncing: Fatal exception Cc: # v6.14 Fixes: 9abe03a0e4f978 ("xfs: introduce realtime refcount btree ondisk defin= itions") Reported-by: Weiming Shi Assisted-by: Claude:claude-opus-4-8 Signed-off-by: Xiang Mei Reviewed-by: "Darrick J. Wong" Reviewed-by: Christoph Hellwig --- fs/xfs/libxfs/xfs_rtrefcount_btree.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/fs/xfs/libxfs/xfs_rtrefcount_btree.c b/fs/xfs/libxfs/xfs_rtref= count_btree.c index f27b80a199ba..22acc1411aac 100644 --- a/fs/xfs/libxfs/xfs_rtrefcount_btree.c +++ b/fs/xfs/libxfs/xfs_rtrefcount_btree.c @@ -201,7 +201,7 @@ xfs_rtrefcountbt_verify( if (fa) return fa; level =3D be16_to_cpu(block->bb_level); - if (level > mp->m_rtrefc_maxlevels) + if (level >=3D mp->m_rtrefc_maxlevels) return __this_address; =20 return xfs_btree_fsblock_verify(bp, mp->m_rtrefc_mxr[level !=3D 0]); @@ -651,7 +651,7 @@ xfs_iformat_rtrefcount( numrecs =3D be16_to_cpu(dfp->bb_numrecs); level =3D be16_to_cpu(dfp->bb_level); =20 - if (level > mp->m_rtrefc_maxlevels || + if (level >=3D mp->m_rtrefc_maxlevels || xfs_rtrefcount_droot_space_calc(level, numrecs) > dsize) { xfs_inode_mark_sick(ip, XFS_SICK_INO_CORE); return -EFSCORRUPTED; --=20 2.43.0