Skip to content

Commit b688171

Browse files
committed
backing-file: use credential guards for splice write
Use credential guards for scoped credential override with automatic restoration on scope exit. Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-6-a3e156839e7f@kernel.org Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent c3076d1 commit b688171

1 file changed

Lines changed: 5 additions & 6 deletions

File tree

fs/backing-file.c

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -303,7 +303,6 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe,
303303
size_t len, unsigned int flags,
304304
struct backing_file_ctx *ctx)
305305
{
306-
const struct cred *old_cred;
307306
ssize_t ret;
308307

309308
if (WARN_ON_ONCE(!(out->f_mode & FMODE_BACKING)))
@@ -316,11 +315,11 @@ ssize_t backing_file_splice_write(struct pipe_inode_info *pipe,
316315
if (ret)
317316
return ret;
318317

319-
old_cred = override_creds(ctx->cred);
320-
file_start_write(out);
321-
ret = out->f_op->splice_write(pipe, out, &iocb->ki_pos, len, flags);
322-
file_end_write(out);
323-
revert_creds(old_cred);
318+
scoped_with_creds(ctx->cred) {
319+
file_start_write(out);
320+
ret = out->f_op->splice_write(pipe, out, &iocb->ki_pos, len, flags);
321+
file_end_write(out);
322+
}
324323

325324
if (ctx->end_write)
326325
ctx->end_write(iocb, ret);

0 commit comments

Comments
 (0)