smack: reject relabel-self writes from io_uring workers
Subsystems (3)
PATCH 1/1 smack: reject relabel-self writes from io_uring workers
smk_write_relabel_self() calls commit_creds() on current. When the write is issued through io_uring it runs on an io-wq worker, and io_uring override_creds()es the submitter's creds when they differ from the worker's. commit_creds() then trips BUG_ON(task->cred != task->real_cred):
kernel BUG at kernel/cred.c:376!
commit_creds
smk_write_relabel_self
loop_rw_iter
io_write
io_wq_submit_work
io_worker_handle_work
io_wq_worker
Even without the override, committing creds on a worker would relabel the worker rather than the submitting task. Refuse the write from PF_IO_WORKER context.
---
Reproduced under QEMU (x86, v7.3-rc3 + 00834fcb20d0) with a small io_uring
program: async IORING_OP_WRITE to /sys/fs/smackfs/relabel-self to spawn the worker, a direct write() to change the submitter's creds, then a second async write. Before: BUG at kernel/cred.c:376. After: the write fails with -EOPNOTSUPP and the program completes.
security/smack/smackfs.c | 4 ++++ 1 file changed, 4 insertions(+)
security/smack/smackfs.c +4 -0
@@ -2678,6 +2678,10 @@ static ssize_t smk_write_relabel_self(struct file *file, const char __user *buf,if (!smack_privileged (CAP_MAC_ADMIN ))return -EPERM ; +/* commit_creds() must act on the caller, not an io_uring worker. */ +if (current->flags &PF_IO_WORKER ) +return -EOPNOTSUPP ; +/* * No partial write. * Enough data must be present.
Signature · 1 line
2.43.0
[email protected]
AI reviewSashiko has reviewed this patch and found no issues. It looks great!
Quoted 18 lines
smk_write_relabel_self()callscommit_creds()on current. When the write is issued throughio_uringit runs on an io-wq worker, andio_uringoverride_creds()es the submitter's creds when they differ from the worker's.commit_creds()then tripsBUG_ON(task->cred != task->real_cred):kernel BUG at
kernel/cred.c:376!
commit_creds
smk_write_relabel_self
loop_rw_iter
io_write
io_wq_submit_work
io_worker_handle_work
io_wq_workerEven without the override, committing creds on a worker would relabel the worker rather than the submitting task. Refuse the write from
PF_IO_WORKERcontext.
Quoted 5 lines
Fixes 38416e53936e ("Smack: limited capability for changing process label")Reported-by [email protected]Signed-off-by Nguyen Ngoc Thang <[email protected]>
Sashiko has reviewed this patch and found no issues. It looks great!
Signature · 1 line
Sashiko AI review · https://sashiko.dev/#/patchset/[email protected]?part=1
Quoted 18 lines · Nguyen Ngoc Thang
smk_write_relabel_self()callscommit_creds()on current. When the write is issued throughio_uringit runs on an io-wq worker, andio_uringoverride_creds()es the submitter's creds when they differ from the worker's.commit_creds()then tripsBUG_ON(task->cred != task->real_cred):kernel BUG at
kernel/cred.c:376!
commit_creds
smk_write_relabel_self
loop_rw_iter
io_write
io_wq_submit_work
io_worker_handle_work
io_wq_workerEven without the override, committing creds on a worker would relabel the worker rather than the submitting task. Refuse the write from
PF_IO_WORKERcontext.
Quoted 5 lines
Fixes 38416e53936e ("Smack: limited capability for changing process label")Reported-by [email protected]Signed-off-by Nguyen Ngoc Thang <[email protected]>
Applied to smack-next. Thank you.
Quoted 25 lines
---
Reproduced under QEMU (x86, v7.3-rc3 +00834fcb20d0) with a smallio_uring
program: asyncIORING_OP_WRITEto/sys/fs/smackfs/relabel-selfto spawn the worker, a directwrite()to change the submitter's creds, then a second async write. Before: BUG atkernel/cred.c:376. After: the write fails with-EOPNOTSUPPand the program completes.security/smack/smackfs.c | 4 ++++ 1 file changed, 4 insertions(+)security/smack/smackfs.c +4
-0@@ -2678,6 +2678,10 @@ static ssize_t smk_write_relabel_self(struct file *file, const char __user *buf,if (!smack_privileged (CAP_MAC_ADMIN ))return -EPERM ; +/* commit_creds() must act on the caller, not an io_uring worker. */ +if (current->flags &PF_IO_WORKER ) +return -EOPNOTSUPP ; +/* * No partial write. * Enough data must be present.