[PATCH] fuse: use current creds for backing files

zhaoguohan@kylinos.cn posted 1 patch 1 month ago
fs/fuse/backing.c | 2 +-
fs/fuse/fuse_i.h  | 2 +-
2 files changed, 2 insertions(+), 2 deletions(-)
[PATCH] fuse: use current creds for backing files
Posted by zhaoguohan@kylinos.cn 1 month ago
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
Re: [PATCH] fuse: use current creds for backing files
Posted by Miklos Szeredi 1 month ago
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
Re: [PATCH] fuse: use current creds for backing files
Posted by Christian Brauner 1 month ago
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