* [PATCH 1/2] procfs: signal /proc/pid/comm write truncation
2017-08-31 19:12 [PATCH 0/2] procfs: /proc/pid/comm fixes Michał Mirosław
@ 2017-08-31 19:12 ` Michał Mirosław
2017-08-31 19:12 ` [PATCH 2/2] procfs: let userspace find out max /proc/pid/comm length Michał Mirosław
1 sibling, 0 replies; 3+ messages in thread
From: Michał Mirosław @ 2017-08-31 19:12 UTC (permalink / raw)
To: Andrew Morton, Alexey Dobriyan, Ingo Molnar, Michal Hocko,
John Stultz, Eric W. Biederman, Al Viro
Cc: linux-kernel
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
^ permalink raw reply related [flat|nested] 3+ messages in thread
* [PATCH 2/2] procfs: let userspace find out max /proc/pid/comm length
2017-08-31 19:12 [PATCH 0/2] procfs: /proc/pid/comm fixes Michał Mirosław
2017-08-31 19:12 ` [PATCH 1/2] procfs: signal /proc/pid/comm write truncation Michał Mirosław
@ 2017-08-31 19:12 ` Michał Mirosław
1 sibling, 0 replies; 3+ messages in thread
From: Michał Mirosław @ 2017-08-31 19:12 UTC (permalink / raw)
To: Andrew Morton, Alexey Dobriyan, Ingo Molnar, Michal Hocko,
John Stultz, Eric W. Biederman, Al Viro
Cc: linux-kernel
Abuse llseek(SEEK_END) to return max /proc/pid/comm length.
This is needed for pthread_getname_np to be able to return ERANGE
without modifying thread's name.
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 7238a64751e4..48089f087a8e 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1542,11 +1542,20 @@ static int comm_open(struct inode *inode, struct file *filp)
return single_open(filp, comm_show, inode);
}
+static loff_t comm_lseek(struct file *file, loff_t offset, int whence)
+{
+ /* SEEK_END for seq_files normally gets -EINVAL */
+ if (whence == SEEK_END && offset == 0)
+ return TASK_COMM_LEN - 1;
+
+ return seq_lseek(file, offset, whence);
+}
+
static const struct file_operations proc_pid_set_comm_operations = {
.open = comm_open,
.read = seq_read,
.write = comm_write,
- .llseek = seq_lseek,
+ .llseek = comm_lseek,
.release = single_release,
};
--
2.11.0
^ permalink raw reply related [flat|nested] 3+ messages in thread