Linux filesystem development
 help / color / mirror / Atom feed
* [PATCH] fuse: use current creds for backing files
@ 2026-05-10 14:54 zhaoguohan
  2026-05-11 13:55 ` Christian Brauner
                   ` (2 more replies)
  0 siblings, 3 replies; 4+ messages in thread
From: zhaoguohan @ 2026-05-10 14:54 UTC (permalink / raw)
  To: Miklos Szeredi; +Cc: linux-fsdevel, linux-kernel

From: GuoHan Zhao <zhaoguohan@kylinos.cn>

FUSE backing files only need a stable snapshot of the current credentials
for later backing-file I/O. prepare_creds() allocates a mutable copy and
can fail, but this code never modifies or commits the result.

Use get_current_cred() instead and store it as a const pointer. This
matches the rest of the backing-file helpers and avoids an unnecessary
allocation and failure path.

Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>
---
 fs/fuse/backing.c | 2 +-
 fs/fuse/fuse_i.h  | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)

diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c
index d95dfa48483f..8efb43b17c4d 100644
--- a/fs/fuse/backing.c
+++ b/fs/fuse/backing.c
@@ -118,7 +118,7 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
 		goto out_fput;
 
 	fb->file = file;
-	fb->cred = prepare_creds();
+	fb->cred = get_current_cred();
 	refcount_set(&fb->count, 1);
 
 	res = fuse_backing_id_alloc(fc, fb);
diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
index 17423d4e3cfa..36041e405bf8 100644
--- a/fs/fuse/fuse_i.h
+++ b/fs/fuse/fuse_i.h
@@ -106,7 +106,7 @@ struct fuse_submount_lookup {
 /** Container for data related to mapping to backing file */
 struct fuse_backing {
 	struct file *file;
-	struct cred *cred;
+	const struct cred *cred;
 
 	/** refcount */
 	refcount_t count;
-- 
2.43.0

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

* Re: [PATCH] fuse: use current creds for backing files
  2026-05-10 14:54 [PATCH] fuse: use current creds for backing files zhaoguohan
@ 2026-05-11 13:55 ` Christian Brauner
  2026-05-11 20:52 ` Amir Goldstein
  2026-05-12  6:22 ` Miklos Szeredi
  2 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2026-05-11 13:55 UTC (permalink / raw)
  To: zhaoguohan; +Cc: Miklos Szeredi, linux-fsdevel, linux-kernel

On Sun, May 10, 2026 at 10:54:37PM +0800, zhaoguohan@kylinos.cn wrote:
> From: GuoHan Zhao <zhaoguohan@kylinos.cn>
> 
> FUSE backing files only need a stable snapshot of the current credentials
> for later backing-file I/O. prepare_creds() allocates a mutable copy and
> can fail, but this code never modifies or commits the result.
> 
> Use get_current_cred() instead and store it as a const pointer. This
> matches the rest of the backing-file helpers and avoids an unnecessary
> allocation and failure path.
> 
> Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>
> ---

Seems reasonable,
Acked-by: Christian Brauner <brauner@kernel.org>

>  fs/fuse/backing.c | 2 +-
>  fs/fuse/fuse_i.h  | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c
> index d95dfa48483f..8efb43b17c4d 100644
> --- a/fs/fuse/backing.c
> +++ b/fs/fuse/backing.c
> @@ -118,7 +118,7 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
>  		goto out_fput;
>  
>  	fb->file = file;
> -	fb->cred = prepare_creds();
> +	fb->cred = get_current_cred();
>  	refcount_set(&fb->count, 1);
>  
>  	res = fuse_backing_id_alloc(fc, fb);
> diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
> index 17423d4e3cfa..36041e405bf8 100644
> --- a/fs/fuse/fuse_i.h
> +++ b/fs/fuse/fuse_i.h
> @@ -106,7 +106,7 @@ struct fuse_submount_lookup {
>  /** Container for data related to mapping to backing file */
>  struct fuse_backing {
>  	struct file *file;
> -	struct cred *cred;
> +	const struct cred *cred;
>  
>  	/** refcount */
>  	refcount_t count;
> -- 
> 2.43.0

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

* Re: [PATCH] fuse: use current creds for backing files
  2026-05-10 14:54 [PATCH] fuse: use current creds for backing files zhaoguohan
  2026-05-11 13:55 ` Christian Brauner
@ 2026-05-11 20:52 ` Amir Goldstein
  2026-05-12  6:22 ` Miklos Szeredi
  2 siblings, 0 replies; 4+ messages in thread
From: Amir Goldstein @ 2026-05-11 20:52 UTC (permalink / raw)
  To: zhaoguohan; +Cc: Miklos Szeredi, linux-fsdevel, fuse-devel

On Sun, May 10, 2026 at 10:54:37PM +0800, zhaoguohan@kylinos.cn wrote:
> From: GuoHan Zhao <zhaoguohan@kylinos.cn>
> 
> FUSE backing files only need a stable snapshot of the current credentials
> for later backing-file I/O. prepare_creds() allocates a mutable copy and
> can fail, but this code never modifies or commits the result.
> 
> Use get_current_cred() instead and store it as a const pointer. This
> matches the rest of the backing-file helpers and avoids an unnecessary
> allocation and failure path.
> 
> Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>

Reviewed-by: Amir Goldstein <amir73il@gmail.com>

> ---
>  fs/fuse/backing.c | 2 +-
>  fs/fuse/fuse_i.h  | 2 +-
>  2 files changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/fs/fuse/backing.c b/fs/fuse/backing.c
> index d95dfa48483f..8efb43b17c4d 100644
> --- a/fs/fuse/backing.c
> +++ b/fs/fuse/backing.c
> @@ -118,7 +118,7 @@ int fuse_backing_open(struct fuse_conn *fc, struct fuse_backing_map *map)
>  		goto out_fput;
>  
>  	fb->file = file;
> -	fb->cred = prepare_creds();
> +	fb->cred = get_current_cred();
>  	refcount_set(&fb->count, 1);
>  
>  	res = fuse_backing_id_alloc(fc, fb);
> diff --git a/fs/fuse/fuse_i.h b/fs/fuse/fuse_i.h
> index 17423d4e3cfa..36041e405bf8 100644
> --- a/fs/fuse/fuse_i.h
> +++ b/fs/fuse/fuse_i.h
> @@ -106,7 +106,7 @@ struct fuse_submount_lookup {
>  /** Container for data related to mapping to backing file */
>  struct fuse_backing {
>  	struct file *file;
> -	struct cred *cred;
> +	const struct cred *cred;
>  
>  	/** refcount */
>  	refcount_t count;
> -- 
> 2.43.0

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

* Re: [PATCH] fuse: use current creds for backing files
  2026-05-10 14:54 [PATCH] fuse: use current creds for backing files zhaoguohan
  2026-05-11 13:55 ` Christian Brauner
  2026-05-11 20:52 ` Amir Goldstein
@ 2026-05-12  6:22 ` Miklos Szeredi
  2 siblings, 0 replies; 4+ messages in thread
From: Miklos Szeredi @ 2026-05-12  6:22 UTC (permalink / raw)
  To: zhaoguohan; +Cc: linux-fsdevel, linux-kernel

On Sun, 10 May 2026 at 16:54, <zhaoguohan@kylinos.cn> wrote:
>
> From: GuoHan Zhao <zhaoguohan@kylinos.cn>
>
> FUSE backing files only need a stable snapshot of the current credentials
> for later backing-file I/O. prepare_creds() allocates a mutable copy and
> can fail, but this code never modifies or commits the result.
>
> Use get_current_cred() instead and store it as a const pointer. This
> matches the rest of the backing-file helpers and avoids an unnecessary
> allocation and failure path.
>
> Signed-off-by: GuoHan Zhao <zhaoguohan@kylinos.cn>

Applied, thanks.

Miklos

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

end of thread, other threads:[~2026-05-12  6:22 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-05-10 14:54 [PATCH] fuse: use current creds for backing files zhaoguohan
2026-05-11 13:55 ` Christian Brauner
2026-05-11 20:52 ` Amir Goldstein
2026-05-12  6:22 ` Miklos Szeredi

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