public inbox for linux-xfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] xfs : Fix potential null pointer dereference in xfs_exchmaps_dir_to_sf()
@ 2025-11-25 14:22 Chelsy Ratnawat
  2025-11-25 17:04 ` Darrick J. Wong
  2025-12-03  6:21 ` Christoph Hellwig
  0 siblings, 2 replies; 4+ messages in thread
From: Chelsy Ratnawat @ 2025-11-25 14:22 UTC (permalink / raw)
  To: cem, djwong; +Cc: linux-xfs, Chelsy Ratnawat

xfs_dir3_block_read() can return a NULL buffer with no error, but
xfs_exchmaps_dir_to_sf() dereferences bp without checking it.
Fix this by adding a check for NULL and returning -EFSCORRUPTED if bp is
missing, since block-format directories must have a valid data block.

Signed-off-by: Chelsy Ratnawat <chelsyratnawat2001@gmail.com>
---
 fs/xfs/libxfs/xfs_exchmaps.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/fs/xfs/libxfs/xfs_exchmaps.c b/fs/xfs/libxfs/xfs_exchmaps.c
index 932ee4619e9e..e33a401d9766 100644
--- a/fs/xfs/libxfs/xfs_exchmaps.c
+++ b/fs/xfs/libxfs/xfs_exchmaps.c
@@ -475,6 +475,9 @@ xfs_exchmaps_dir_to_sf(
 	if (error)
 		return error;
 
+	if (!bp)
+		return -EFSCORRUPTED;
+
 	size = xfs_dir2_block_sfsize(xmi->xmi_ip2, bp->b_addr, &sfh);
 	if (size > xfs_inode_data_fork_size(xmi->xmi_ip2))
 		return 0;
-- 
2.47.3


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

* Re: [PATCH] xfs : Fix potential null pointer dereference in xfs_exchmaps_dir_to_sf()
  2025-11-25 14:22 [PATCH] xfs : Fix potential null pointer dereference in xfs_exchmaps_dir_to_sf() Chelsy Ratnawat
@ 2025-11-25 17:04 ` Darrick J. Wong
  2025-12-03  6:21 ` Christoph Hellwig
  1 sibling, 0 replies; 4+ messages in thread
From: Darrick J. Wong @ 2025-11-25 17:04 UTC (permalink / raw)
  To: Chelsy Ratnawat; +Cc: cem, linux-xfs

On Tue, Nov 25, 2025 at 06:22:05AM -0800, Chelsy Ratnawat wrote:
> xfs_dir3_block_read() can return a NULL buffer with no error, but
> xfs_exchmaps_dir_to_sf() dereferences bp without checking it.
> Fix this by adding a check for NULL and returning -EFSCORRUPTED if bp is
> missing, since block-format directories must have a valid data block.

How did you encounter this bug?  Did you hit it in production?  syzbot
report?  Something else?

Also, are there similar functions in xfs_exchmaps.c that suffer from the
same problem?

> Signed-off-by: Chelsy Ratnawat <chelsyratnawat2001@gmail.com>

Cc: <stable@vger.kernel.org> # v6.10
Fixes: da165fbde23b84 ("xfs: condense directories after a mapping exchange operation")

--D

> ---
>  fs/xfs/libxfs/xfs_exchmaps.c | 3 +++
>  1 file changed, 3 insertions(+)
> 
> diff --git a/fs/xfs/libxfs/xfs_exchmaps.c b/fs/xfs/libxfs/xfs_exchmaps.c
> index 932ee4619e9e..e33a401d9766 100644
> --- a/fs/xfs/libxfs/xfs_exchmaps.c
> +++ b/fs/xfs/libxfs/xfs_exchmaps.c
> @@ -475,6 +475,9 @@ xfs_exchmaps_dir_to_sf(
>  	if (error)
>  		return error;
>  
> +	if (!bp)
> +		return -EFSCORRUPTED;
> +
>  	size = xfs_dir2_block_sfsize(xmi->xmi_ip2, bp->b_addr, &sfh);
>  	if (size > xfs_inode_data_fork_size(xmi->xmi_ip2))
>  		return 0;
> -- 
> 2.47.3
> 

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

* Re: [PATCH] xfs : Fix potential null pointer dereference in xfs_exchmaps_dir_to_sf()
  2025-11-25 14:22 [PATCH] xfs : Fix potential null pointer dereference in xfs_exchmaps_dir_to_sf() Chelsy Ratnawat
  2025-11-25 17:04 ` Darrick J. Wong
@ 2025-12-03  6:21 ` Christoph Hellwig
  2025-12-03 10:32   ` Carlos Maiolino
  1 sibling, 1 reply; 4+ messages in thread
From: Christoph Hellwig @ 2025-12-03  6:21 UTC (permalink / raw)
  To: Chelsy Ratnawat; +Cc: cem, djwong, linux-xfs

On Tue, Nov 25, 2025 at 06:22:05AM -0800, Chelsy Ratnawat wrote:
> xfs_dir3_block_read() can return a NULL buffer with no error, but
> xfs_exchmaps_dir_to_sf() dereferences bp without checking it.
> Fix this by adding a check for NULL and returning -EFSCORRUPTED if bp is
> missing, since block-format directories must have a valid data block.

xfs_dir3_block_read is a thin wrapper around xfs_da_read_buf, which
like all the buffer functions should not return a NULL buffer unless
either an error occured, or the caller asked for read-ahead semantics,
which xfs_dir3_block_read never does.  It seems like it currently
could when an invalid mapping is passed in (see the invalid_mapping
case in xfs_dabuf_map).  I think we'd be much better off trying to
fix these inconsistencies than doctoring around them in the callers.


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

* Re: [PATCH] xfs : Fix potential null pointer dereference in xfs_exchmaps_dir_to_sf()
  2025-12-03  6:21 ` Christoph Hellwig
@ 2025-12-03 10:32   ` Carlos Maiolino
  0 siblings, 0 replies; 4+ messages in thread
From: Carlos Maiolino @ 2025-12-03 10:32 UTC (permalink / raw)
  To: Christoph Hellwig; +Cc: Chelsy Ratnawat, djwong, linux-xfs

On Tue, Dec 02, 2025 at 10:21:08PM -0800, Christoph Hellwig wrote:
> On Tue, Nov 25, 2025 at 06:22:05AM -0800, Chelsy Ratnawat wrote:
> > xfs_dir3_block_read() can return a NULL buffer with no error, but
> > xfs_exchmaps_dir_to_sf() dereferences bp without checking it.
> > Fix this by adding a check for NULL and returning -EFSCORRUPTED if bp is
> > missing, since block-format directories must have a valid data block.
> 
> xfs_dir3_block_read is a thin wrapper around xfs_da_read_buf, which
> like all the buffer functions should not return a NULL buffer unless
> either an error occured, or the caller asked for read-ahead semantics,
> which xfs_dir3_block_read never does.  It seems like it currently
> could when an invalid mapping is passed in (see the invalid_mapping
> case in xfs_dabuf_map).  I think we'd be much better off trying to
> fix these inconsistencies than doctoring around them in the callers.
> 

+1

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

end of thread, other threads:[~2025-12-03 10:32 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-11-25 14:22 [PATCH] xfs : Fix potential null pointer dereference in xfs_exchmaps_dir_to_sf() Chelsy Ratnawat
2025-11-25 17:04 ` Darrick J. Wong
2025-12-03  6:21 ` Christoph Hellwig
2025-12-03 10:32   ` Carlos Maiolino

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