Skip to content

Commit 6e1d1c1

Browse files
committed
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 <amir73il@gmail.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent b688171 commit 6e1d1c1

1 file changed

Lines changed: 2 additions & 4 deletions

File tree

fs/backing-file.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -331,7 +331,6 @@ EXPORT_SYMBOL_GPL(backing_file_splice_write);
331331
int backing_file_mmap(struct file *file, struct vm_area_struct *vma,
332332
struct backing_file_ctx *ctx)
333333
{
334-
const struct cred *old_cred;
335334
struct file *user_file = vma->vm_file;
336335
int ret;
337336

@@ -343,9 +342,8 @@ int backing_file_mmap(struct file *file, struct vm_area_struct *vma,
343342

344343
vma_set_file(vma, file);
345344

346-
old_cred = override_creds(ctx->cred);
347-
ret = vfs_mmap(vma->vm_file, vma);
348-
revert_creds(old_cred);
345+
scoped_with_creds(ctx->cred)
346+
ret = vfs_mmap(vma->vm_file, vma);
349347

350348
if (ctx->accessed)
351349
ctx->accessed(user_file);

0 commit comments

Comments
 (0)