From: Junwen Wu <wudaemon@163.com>
To: akpm@linux-foundation.org, keescook@chromium.org,
adobriyan@gmail.com, fweimer@redhat.com, ddiss@suse.de
Cc: linux-kernel@vger.kernel.org, linux-fsdevel@vger.kernel.org,
Junwen Wu <wudaemon@163.com>
Subject: [PATCH v1] proc: limit schedstate node write operation
Date: Sat, 23 Apr 2022 02:31:04 +0000 [thread overview]
Message-ID: <20220423023104.153004-1-wudaemon@163.com> (raw)
Whatever value is written to /proc/$pid/sched, a task's schedstate data
will reset.In some cases, schedstate will drop by accident. We restrict
writing a certain value to this node before the data is reset.
Signed-off-by: Junwen Wu <wudaemon@163.com>
---
fs/proc/base.c | 18 +++++++++++++-----
1 file changed, 13 insertions(+), 5 deletions(-)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index d654ce7150fd..6bb2677659ce 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1459,13 +1459,21 @@ sched_write(struct file *file, const char __user *buf,
{
struct inode *inode = file_inode(file);
struct task_struct *p;
+ char ubuf[5];
- p = get_proc_task(inode);
- if (!p)
- return -ESRCH;
- proc_sched_set_task(p);
+ memset(ubuf, 0, sizeof(ubuf));
+ if (count > 5)
+ count = 0;
+ if (copy_from_user(ubuf, buf, count))
+ return -EFAULT;
+ if (strcmp(ubuf, "reset") == 0) {
+ p = get_proc_task(inode);
+ if (!p)
+ return -ESRCH;
+ proc_sched_set_task(p);
- put_task_struct(p);
+ put_task_struct(p);
+ }
return count;
}
--
2.25.1
next reply other threads:[~2022-04-23 2:34 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-04-23 2:31 Junwen Wu [this message]
2022-04-23 3:05 ` [PATCH v1] proc: limit schedstate node write operation Matthew Wilcox
2022-04-24 19:23 ` Matthew Wilcox
2022-04-30 13:48 ` Junwen Wu
2022-04-23 4:26 ` kernel test robot
2022-04-24 15:23 ` Junwen Wu
2022-04-24 15:27 ` Junwen Wu
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=20220423023104.153004-1-wudaemon@163.com \
--to=wudaemon@163.com \
--cc=adobriyan@gmail.com \
--cc=akpm@linux-foundation.org \
--cc=ddiss@suse.de \
--cc=fweimer@redhat.com \
--cc=keescook@chromium.org \
--cc=linux-fsdevel@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
/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;
as well as URLs for NNTP newsgroup(s).