mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH] xfs: fix out-of-bounds cursor access from rtrmap level off-by-one
@ 2026-10-09 11:45 Henry Martin
  2026-10-09 12:04 ` Carlos Maiolino
  0 siblings, 1 reply; 2+ messages in thread
From: Henry Martin @ 2026-10-09 11:45 UTC (permalink / raw)
  To: Darrick J . Wong, Carlos Maiolino
  Cc: linux-xfs, linux-kernel, Henry Martin, stable

m_rtrmap_maxlevels includes the inode root level, so a valid on-disk
bb_level is strictly less than m_rtrmap_maxlevels.  Both
xfs_rtrmapbt_verify() and xfs_iformat_rtrmap() compare with ">"
instead of ">=", letting a forged block with level == maxlevels pass
validation.  The cursor is then sized for maxlevels entries while
bc_nlevels is set to level + 1, so the generic btree code indexes one
element past bc_levels[] - an out-of-bounds read/write on the cursor
allocation.

xfs_rtrmapbt_mem_verify() in the same file (from commit
4a61f12eb1195 "xfs: create a shadow rmap btree during realtime rmap
repair") already uses ">=".

This vulnerability was discovered by Tencent CodeBuddy Security.

Cc: stable@vger.kernel.org
Fixes: fc6856c6ff086 ("xfs: introduce realtime rmap btree ondisk definitions")
Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
---
 fs/xfs/libxfs/xfs_rtrmap_btree.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.c b/fs/xfs/libxfs/xfs_rtrmap_btree.c
index a15e460a1ec7..6833c924a383 100644
--- a/fs/xfs/libxfs/xfs_rtrmap_btree.c
+++ b/fs/xfs/libxfs/xfs_rtrmap_btree.c
@@ -256,7 +256,7 @@ xfs_rtrmapbt_verify(
 	if (fa)
 		return fa;
 	level = be16_to_cpu(block->bb_level);
-	if (level > mp->m_rtrmap_maxlevels)
+	if (level >= mp->m_rtrmap_maxlevels)
 		return __this_address;

 	return xfs_btree_fsblock_verify(bp, mp->m_rtrmap_mxr[level != 0]);
@@ -888,7 +888,7 @@ xfs_iformat_rtrmap(
 	numrecs = be16_to_cpu(dfp->bb_numrecs);
 	level = be16_to_cpu(dfp->bb_level);

-	if (level > mp->m_rtrmap_maxlevels ||
+	if (level >= mp->m_rtrmap_maxlevels ||
 	    xfs_rtrmap_droot_space_calc(level, numrecs) > dsize) {
 		xfs_inode_mark_sick(ip, XFS_SICK_INO_CORE);
 		return -EFSCORRUPTED;
--
2.43.7


^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [PATCH] xfs: fix out-of-bounds cursor access from rtrmap level off-by-one
  2026-10-09 11:45 [PATCH] xfs: fix out-of-bounds cursor access from rtrmap level off-by-one Henry Martin
@ 2026-10-09 12:04 ` Carlos Maiolino
  0 siblings, 0 replies; 2+ messages in thread
From: Carlos Maiolino @ 2026-10-09 12:04 UTC (permalink / raw)
  To: Henry Martin; +Cc: Darrick J . Wong, linux-xfs, linux-kernel, stable

On Fri, Oct 09, 2026 at 07:45:03PM +0800, Henry Martin wrote:
> m_rtrmap_maxlevels includes the inode root level, so a valid on-disk
> bb_level is strictly less than m_rtrmap_maxlevels.  Both
> xfs_rtrmapbt_verify() and xfs_iformat_rtrmap() compare with ">"
> instead of ">=", letting a forged block with level == maxlevels pass
> validation.

So you need a maliciously crafted filesystem image and enough privileges
to be able to mount it.

> The cursor is then sized for maxlevels entries while
> bc_nlevels is set to level + 1, so the generic btree code indexes one
> element past bc_levels[] - an out-of-bounds read/write on the cursor
> allocation.
> 
> xfs_rtrmapbt_mem_verify() in the same file (from commit
> 4a61f12eb1195 "xfs: create a shadow rmap btree during realtime rmap
> repair") already uses ">=".
> 
> This vulnerability was discovered by Tencent CodeBuddy Security.

What is the "vulnerability" you are claiming here? How can this be
exploited? For what you described, it requires a crafted filesystem
image, which should require a privileged user to mount, so while this is
a bug, calling it a vulnerability is a big stretch.
So, giving you claimed it to be a vulnerability, how can it be
exploited by a non-privileged user? Where is the reproducer? You can
even share it off-list if you prefer.

> 
> Cc: stable@vger.kernel.org
> Fixes: fc6856c6ff086 ("xfs: introduce realtime rmap btree ondisk definitions")
> Signed-off-by: Henry Martin <bsdhenrymartin@gmail.com>
> ---
>  fs/xfs/libxfs/xfs_rtrmap_btree.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/xfs/libxfs/xfs_rtrmap_btree.c b/fs/xfs/libxfs/xfs_rtrmap_btree.c
> index a15e460a1ec7..6833c924a383 100644
> --- a/fs/xfs/libxfs/xfs_rtrmap_btree.c
> +++ b/fs/xfs/libxfs/xfs_rtrmap_btree.c
> @@ -256,7 +256,7 @@ xfs_rtrmapbt_verify(
>  	if (fa)
>  		return fa;
>  	level = be16_to_cpu(block->bb_level);
> -	if (level > mp->m_rtrmap_maxlevels)
> +	if (level >= mp->m_rtrmap_maxlevels)
>  		return __this_address;
> 
>  	return xfs_btree_fsblock_verify(bp, mp->m_rtrmap_mxr[level != 0]);
> @@ -888,7 +888,7 @@ xfs_iformat_rtrmap(
>  	numrecs = be16_to_cpu(dfp->bb_numrecs);
>  	level = be16_to_cpu(dfp->bb_level);
> 
> -	if (level > mp->m_rtrmap_maxlevels ||
> +	if (level >= mp->m_rtrmap_maxlevels ||
>  	    xfs_rtrmap_droot_space_calc(level, numrecs) > dsize) {
>  		xfs_inode_mark_sick(ip, XFS_SICK_INO_CORE);
>  		return -EFSCORRUPTED;
> --
> 2.43.7
> 
> 

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-10-09 12:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-10-09 11:45 [PATCH] xfs: fix out-of-bounds cursor access from rtrmap level off-by-one Henry Martin
2026-10-09 12:04 ` Carlos Maiolino

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®