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@xxxxxxxxxxxx> --- 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 ce3465479447..3a3b566443e5 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -1526,8 +1526,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); @@ -1541,6 +1547,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.19.2