Skip to content

Commit b66c7af

Browse files
committed
cgroup: use credential guards in cgroup_attach_permissions()
Use credential guards for scoped credential override with automatic restoration on scope exit. Link: https://patch.msgid.link/20251103-work-creds-guards-simple-v1-15-a3e156839e7f@kernel.org Reviewed-by: Amir Goldstein <amir73il@gmail.com> Signed-off-by: Christian Brauner <brauner@kernel.org>
1 parent 5db84ab commit b66c7af

1 file changed

Lines changed: 4 additions & 6 deletions

File tree

kernel/cgroup/cgroup.c

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5363,7 +5363,6 @@ static ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf,
53635363
struct cgroup_file_ctx *ctx = of->priv;
53645364
struct cgroup *src_cgrp, *dst_cgrp;
53655365
struct task_struct *task;
5366-
const struct cred *saved_cred;
53675366
ssize_t ret;
53685367
enum cgroup_attach_lock_mode lock_mode;
53695368

@@ -5386,11 +5385,10 @@ static ssize_t __cgroup_procs_write(struct kernfs_open_file *of, char *buf,
53865385
* permissions using the credentials from file open to protect against
53875386
* inherited fd attacks.
53885387
*/
5389-
saved_cred = override_creds(of->file->f_cred);
5390-
ret = cgroup_attach_permissions(src_cgrp, dst_cgrp,
5391-
of->file->f_path.dentry->d_sb,
5392-
threadgroup, ctx->ns);
5393-
revert_creds(saved_cred);
5388+
scoped_with_creds(of->file->f_cred)
5389+
ret = cgroup_attach_permissions(src_cgrp, dst_cgrp,
5390+
of->file->f_path.dentry->d_sb,
5391+
threadgroup, ctx->ns);
53945392
if (ret)
53955393
goto out_finish;
53965394

0 commit comments

Comments
 (0)