public inbox for linux-btrfs@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH v3] btrfs: fix a crash in the trace event btrfs_sync_file()
@ 2026-03-13 18:11 Goldwyn Rodrigues
  2026-03-13 18:56 ` Boris Burkov
  2026-03-18 11:20 ` David Sterba
  0 siblings, 2 replies; 3+ messages in thread
From: Goldwyn Rodrigues @ 2026-03-13 18:11 UTC (permalink / raw)
  To: linux-btrfs

If overlay is used on top of btrfs, dentry->d_sb translates to overlay's
super block and fsid assignment will lead to a crash.

Use file_inode(file)->i_sb to always get btrfs_sb.

Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
---
Changes since v2:
- Use of dget_parent() to get the parent of the inode
Changes since v1:
- Changed subject to include trace
- Use file_inode() to get inode pointer

 include/trace/events/btrfs.h | 11 +++++++----
 1 file changed, 7 insertions(+), 4 deletions(-)

diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h
index 125bdc166bfe..0864700f76e0 100644
--- a/include/trace/events/btrfs.h
+++ b/include/trace/events/btrfs.h
@@ -769,12 +769,15 @@ TRACE_EVENT(btrfs_sync_file,
 	),
 
 	TP_fast_assign(
-		const struct dentry *dentry = file->f_path.dentry;
-		const struct inode *inode = d_inode(dentry);
+		struct dentry *dentry = file_dentry(file);
+		struct inode *inode = file_inode(file);
+		struct dentry *parent = dget_parent(dentry);
+		struct inode *parent_inode = d_inode(parent);
 
-		TP_fast_assign_fsid(btrfs_sb(file->f_path.dentry->d_sb));
+		dput(parent);
+		TP_fast_assign_fsid(btrfs_sb(inode->i_sb));
 		__entry->ino		= btrfs_ino(BTRFS_I(inode));
-		__entry->parent		= btrfs_ino(BTRFS_I(d_inode(dentry->d_parent)));
+		__entry->parent		= btrfs_ino(BTRFS_I(parent_inode));
 		__entry->datasync	= datasync;
 		__entry->root_objectid	= btrfs_root_id(BTRFS_I(inode)->root);
 	),
-- 
2.53.0

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

* Re: [PATCH v3] btrfs: fix a crash in the trace event btrfs_sync_file()
  2026-03-13 18:11 [PATCH v3] btrfs: fix a crash in the trace event btrfs_sync_file() Goldwyn Rodrigues
@ 2026-03-13 18:56 ` Boris Burkov
  2026-03-18 11:20 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: Boris Burkov @ 2026-03-13 18:56 UTC (permalink / raw)
  To: Goldwyn Rodrigues; +Cc: linux-btrfs

On Fri, Mar 13, 2026 at 02:11:39PM -0400, Goldwyn Rodrigues wrote:
> If overlay is used on top of btrfs, dentry->d_sb translates to overlay's
> super block and fsid assignment will lead to a crash.
> 
> Use file_inode(file)->i_sb to always get btrfs_sb.
> 

Is there a relevant Fixes: commit here?

> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>

Reviewed-by: Boris Burkov <boris@bur.io>

> ---
> Changes since v2:
> - Use of dget_parent() to get the parent of the inode
> Changes since v1:
> - Changed subject to include trace
> - Use file_inode() to get inode pointer
> 
>  include/trace/events/btrfs.h | 11 +++++++----
>  1 file changed, 7 insertions(+), 4 deletions(-)
> 
> diff --git a/include/trace/events/btrfs.h b/include/trace/events/btrfs.h
> index 125bdc166bfe..0864700f76e0 100644
> --- a/include/trace/events/btrfs.h
> +++ b/include/trace/events/btrfs.h
> @@ -769,12 +769,15 @@ TRACE_EVENT(btrfs_sync_file,
>  	),
>  
>  	TP_fast_assign(
> -		const struct dentry *dentry = file->f_path.dentry;
> -		const struct inode *inode = d_inode(dentry);
> +		struct dentry *dentry = file_dentry(file);
> +		struct inode *inode = file_inode(file);
> +		struct dentry *parent = dget_parent(dentry);
> +		struct inode *parent_inode = d_inode(parent);
>  
> -		TP_fast_assign_fsid(btrfs_sb(file->f_path.dentry->d_sb));
> +		dput(parent);
> +		TP_fast_assign_fsid(btrfs_sb(inode->i_sb));
>  		__entry->ino		= btrfs_ino(BTRFS_I(inode));
> -		__entry->parent		= btrfs_ino(BTRFS_I(d_inode(dentry->d_parent)));
> +		__entry->parent		= btrfs_ino(BTRFS_I(parent_inode));
>  		__entry->datasync	= datasync;
>  		__entry->root_objectid	= btrfs_root_id(BTRFS_I(inode)->root);
>  	),
> -- 
> 2.53.0

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

* Re: [PATCH v3] btrfs: fix a crash in the trace event btrfs_sync_file()
  2026-03-13 18:11 [PATCH v3] btrfs: fix a crash in the trace event btrfs_sync_file() Goldwyn Rodrigues
  2026-03-13 18:56 ` Boris Burkov
@ 2026-03-18 11:20 ` David Sterba
  1 sibling, 0 replies; 3+ messages in thread
From: David Sterba @ 2026-03-18 11:20 UTC (permalink / raw)
  To: Goldwyn Rodrigues; +Cc: linux-btrfs

On Fri, Mar 13, 2026 at 02:11:39PM -0400, Goldwyn Rodrigues wrote:
> If overlay is used on top of btrfs, dentry->d_sb translates to overlay's
> super block and fsid assignment will lead to a crash.
> 
> Use file_inode(file)->i_sb to always get btrfs_sb.
> 
> Signed-off-by: Goldwyn Rodrigues <rgoldwyn@suse.com>
> ---
> Changes since v2:
> - Use of dget_parent() to get the parent of the inode
> Changes since v1:
> - Changed subject to include trace
> - Use file_inode() to get inode pointer

Added to for-next, thanks.

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

end of thread, other threads:[~2026-03-18 11:20 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-03-13 18:11 [PATCH v3] btrfs: fix a crash in the trace event btrfs_sync_file() Goldwyn Rodrigues
2026-03-13 18:56 ` Boris Burkov
2026-03-18 11:20 ` David Sterba

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