procfs: /proc/pid/comm fixes
cover procfs: /proc/pid/comm fixes
These two patches are preparation for extending TASK_COMM_LEN above current 16-byte limit.
Michał Mirosław (2):
procfs: signal /proc/pid/comm write truncation
procfs: let userspace find out max /proc/pid/comm length
fs/proc/base.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-)
Signature · 1 line
2.11.0
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 <[email protected]>
--- fs/proc/base.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/proc/base.c +10 -1
@@ -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; }
Signature · 1 line
2.11.0
PATCH 2/2 procfs: let userspace find out max /proc/pid/comm length
In reply to Michał MirosławAbuse 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 <[email protected]>
--- fs/proc/base.c | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-)
fs/proc/base.c +10 -1
@@ -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, };
Signature · 1 line
2.11.0