[PATCH 1/2] procfs: signal /proc/pid/comm write truncation
From: MichaÅ MirosÅaw
Date: Thu Aug 31 2017 - 15:13:20 EST
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 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