[PATCH v1] proc: limit schedstate node write operation

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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@xxxxxxx>
---
 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




[Index of Archives]     [Linux Ext4 Filesystem]     [Union Filesystem]     [Filesystem Testing]     [Ceph Users]     [Ecryptfs]     [NTFS 3]     [AutoFS]     [Kernel Newbies]     [Share Photos]     [Security]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux Cachefs]     [Reiser Filesystem]     [Linux RAID]     [NTFS 3]     [Samba]     [Device Mapper]     [CEPH Development]

  Powered by Linux