All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v1] proc: limit schedstate node write operation
@ 2022-04-23  2:31 Junwen Wu
  2022-04-24 15:23   ` Junwen Wu
                   ` (2 more replies)
  0 siblings, 3 replies; 8+ messages in thread
From: Junwen Wu @ 2022-04-23  2:31 UTC (permalink / raw)
  To: akpm, keescook, adobriyan, fweimer, ddiss
  Cc: linux-kernel, linux-fsdevel, Junwen Wu

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


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2022-04-30 13:49 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-04-23  2:31 [PATCH v1] proc: limit schedstate node write operation Junwen Wu
2022-04-23  3:05 ` Matthew Wilcox
2022-04-24 15:23   ` Junwen Wu
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:27   ` Junwen Wu
2022-04-24 15:27 ` Junwen Wu

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.