lkml.org 
[lkml]   [2017]   [Aug]   [31]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Date
From
Subject[PATCH 1/2] procfs: signal /proc/pid/comm write truncation
Keeps truncation working, but also signals to writing process
when that happens.

Fixes: 830e0fc967a7 ("fs, proc: truncate /proc/pid/comm writes to first TASK_COMM_LEN bytes")
Signed-off-by: Michał Mirosław <mirq-linux@rere.qmqm.pl>
---
fs/proc/base.c | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)

diff --git a/fs/proc/base.c b/fs/proc/base.c
index f1e1927ccd48..7238a64751e4 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1492,8 +1492,14 @@ static ssize_t comm_write(struct file *file, const char __user *buf,
char buffer[TASK_COMM_LEN];
const size_t maxlen = sizeof(buffer) - 1;

+ if (*offset)
+ return -ENOSPC;
+
+ if (count > maxlen)
+ count = maxlen;
+
memset(buffer, 0, sizeof(buffer));
- if (copy_from_user(buffer, buf, count > maxlen ? maxlen : count))
+ if (copy_from_user(buffer, buf, count))
return -EFAULT;

p = get_proc_task(inode);
@@ -1507,6 +1513,9 @@ static ssize_t comm_write(struct file *file, const char __user *buf,

put_task_struct(p);

+ if (count > 0)
+ *offset = count;
+
return count;
}

--
2.11.0
\
 
 \ /
  Last update: 2017-08-31 21:14    [W:0.028 / U:0.764 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site