Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > linux.kernel > #1724511

[PATCH 1/2] procfs: signal /proc/pid/comm write truncation

From Michał Mirosław <mirq-linux@rere.qmqm.pl>
Newsgroups linux.kernel
Subject [PATCH 1/2] procfs: signal /proc/pid/comm write truncation
Date 2017-08-31 21:20 +0200
Message-ID <ukDap-1iX-9@gated-at.bofh.it> (permalink)
References <ukDap-1iX-5@gated-at.bofh.it>
Organization linux.* mail to news gateway

Show all headers | View raw


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

Back to linux.kernel | Previous | Next | Find similar | Unroll thread


Thread

[PATCH 1/2] procfs: signal /proc/pid/comm write truncation Michał Mirosław <mirq-linux@rere.qmqm.pl> - 2017-08-31 21:20 +0200

csiph-web