From: Christian Brauner Date: Mon, 3 Nov 2025 11:26:55 +0000 (+0100) Subject: backing-file: use credential guards for mmap X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=6e1d1c1fa7b1a8d318ccb5f4f64b2a2b5803cf1c;p=thirdparty%2Flinux.git backing-file: use credential guards for mmap Use credential guards for scoped credential override with automatic restoration on scope exit. Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-7-a3e156839e7f@kernel.org Reviewed-by: Amir Goldstein Signed-off-by: Christian Brauner --- diff --git a/fs/backing-file.c b/fs/backing-file.c index 87ff918320c5..ea137be16331 100644 --- a/fs/backing-file.c +++ b/fs/backing-file.c @@ -331,7 +331,6 @@ EXPORT_SYMBOL_GPL(backing_file_splice_write); int backing_file_mmap(struct file *file, struct vm_area_struct *vma, struct backing_file_ctx *ctx) { - const struct cred *old_cred; struct file *user_file = vma->vm_file; int ret; @@ -343,9 +342,8 @@ int backing_file_mmap(struct file *file, struct vm_area_struct *vma, vma_set_file(vma, file); - old_cred = override_creds(ctx->cred); - ret = vfs_mmap(vma->vm_file, vma); - revert_creds(old_cred); + scoped_with_creds(ctx->cred) + ret = vfs_mmap(vma->vm_file, vma); if (ctx->accessed) ctx->accessed(user_file);