lkml.org 
[lkml]   [2022]   [Apr]   [22]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH v1] proc: limit schedstate node write operation
Date
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
\
 
 \ /
  Last update: 2022-04-23 04:34    [W:0.057 / U:0.348 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site