From: Stefan Metzmacher <[email protected]>
To: [email protected]
Cc: Stefan Metzmacher <[email protected]>
Subject: [RFC PATCH 08/10] fs/proc: protect /proc/<pid>/[task/<tid>]/comm for PF_IO_WORKER
Date: Mon, 15 Mar 2021 18:01:46 +0100 [thread overview]
Message-ID: <97ad63bef490139bb4996e75dea408af1e78fa47.1615826736.git.metze@samba.org> (raw)
In-Reply-To: <[email protected]>
Signed-off-by: Stefan Metzmacher <[email protected]>
---
fs/proc/base.c | 15 +++++++++++----
1 file changed, 11 insertions(+), 4 deletions(-)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 6e04278de582..7177e92790c4 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1665,6 +1665,7 @@ static ssize_t comm_write(struct file *file, const char __user *buf,
size_t count, loff_t *offset)
{
struct inode *inode = file_inode(file);
+ bool is_same_tgroup = false;
struct task_struct *p;
char buffer[TASK_COMM_LEN];
const size_t maxlen = sizeof(buffer) - 1;
@@ -1677,7 +1678,10 @@ static ssize_t comm_write(struct file *file, const char __user *buf,
if (!p)
return -ESRCH;
- if (same_thread_group(current, p))
+ if (!(p->flags & PF_IO_WORKER))
+ is_same_tgroup = same_thread_group(current, p);
+
+ if (is_same_tgroup)
set_task_comm(p, buffer);
else
count = -EINVAL;
@@ -1822,7 +1826,7 @@ void task_dump_owner(struct task_struct *task, umode_t mode,
kuid_t uid;
kgid_t gid;
- if (unlikely(task->flags & PF_KTHREAD)) {
+ if (unlikely(task->flags & (PF_KTHREAD | PF_IO_WORKER))) {
*ruid = GLOBAL_ROOT_UID;
*rgid = GLOBAL_ROOT_GID;
return;
@@ -3478,19 +3482,22 @@ int proc_pid_readdir(struct file *file, struct dir_context *ctx)
static int proc_tid_comm_permission(struct user_namespace *mnt_userns,
struct inode *inode, int mask)
{
- bool is_same_tgroup;
+ bool is_same_tgroup = false;
struct task_struct *task;
task = get_proc_task(inode);
if (!task)
return -ESRCH;
- is_same_tgroup = same_thread_group(current, task);
+ if (!(task->flags & PF_IO_WORKER))
+ is_same_tgroup = same_thread_group(current, task);
put_task_struct(task);
if (likely(is_same_tgroup && !(mask & MAY_EXEC))) {
/* This file (/proc/<pid>/task/<tid>/comm) can always be
* read or written by the members of the corresponding
* thread group.
+ *
+ * But we exclude PF_IO_WORKER kernel threads.
*/
return 0;
}
--
2.25.1
next prev parent reply other threads:[~2021-03-15 17:04 UTC|newest]
Thread overview: 27+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-03-19 23:27 Problems with io_threads Stefan Metzmacher
2021-03-15 17:01 ` [RFC PATCH 00/10] Complete setup before calling wake_up_new_task() and improve task->comm Stefan Metzmacher
2021-03-15 17:01 ` [RFC PATCH 01/10] kernel: always initialize task->pf_io_worker to NULL Stefan Metzmacher
2021-03-15 17:01 ` [RFC PATCH 02/10] io_uring: io_sq_thread() no longer needs to reset current->pf_io_worker Stefan Metzmacher
2021-03-15 17:01 ` [RFC PATCH 03/10] io-wq: call set_task_comm() before wake_up_new_task() Stefan Metzmacher
2021-03-15 17:01 ` [RFC PATCH 04/10] io_uring: complete sq_thread setup before calling wake_up_new_task() Stefan Metzmacher
2021-03-15 17:01 ` [RFC PATCH 05/10] io-wq: protect against future set_task_comm() overflows Stefan Metzmacher
2021-03-15 17:01 ` [RFC PATCH 06/10] io_uring: " Stefan Metzmacher
2021-03-15 17:01 ` [RFC PATCH 07/10] fs/proc: hide PF_IO_WORKER in get_task_cmdline() Stefan Metzmacher
2021-03-15 17:01 ` Stefan Metzmacher [this message]
2021-03-15 17:01 ` [RFC PATCH 09/10] io-wq: add io_wq_worker_comm() helper function for dynamic proc_task_comm() generation Stefan Metzmacher
2021-03-15 17:01 ` [RFC PATCH 10/10] fs/proc: make use of io_wq_worker_comm() for PF_IO_WORKER threads Stefan Metzmacher
2021-03-17 22:42 ` [RFC PATCH 00/10] Complete setup before calling wake_up_new_task() and improve task->comm Jens Axboe
2021-03-17 23:06 ` Stefan Metzmacher
2021-03-17 23:26 ` Jens Axboe
2021-03-20 0:00 ` [PATCH v2 0/5] " Stefan Metzmacher
2021-03-20 0:00 ` [PATCH v2 1/5] kernel: always initialize task->pf_io_worker to NULL Stefan Metzmacher
2021-03-20 0:00 ` [PATCH v2 2/5] io_uring: io_sq_thread() no longer needs to reset current->pf_io_worker Stefan Metzmacher
2021-03-20 0:00 ` [PATCH v2 3/5] io-wq: call set_task_comm() before wake_up_new_task() Stefan Metzmacher
2021-03-20 0:00 ` [PATCH v2 4/5] io_uring: complete sq_thread setup before calling wake_up_new_task() Stefan Metzmacher
2021-03-20 0:00 ` [PATCH v2 5/5] fs/proc: hide PF_IO_WORKER in get_task_cmdline() Stefan Metzmacher
2021-03-20 1:24 ` [PATCH v2 0/5] Complete setup before calling wake_up_new_task() and improve task->comm Jens Axboe
2021-03-20 19:22 ` Stefan Metzmacher
2021-03-20 22:39 ` Jens Axboe
2021-03-19 23:46 ` Problems with io_threads Jens Axboe
2021-03-20 0:25 ` Stefan Metzmacher
2021-03-20 1:20 ` Jens Axboe
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=97ad63bef490139bb4996e75dea408af1e78fa47.1615826736.git.metze@samba.org \
[email protected] \
[email protected] \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox