[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <9b1b41ef58ad245de0e9bb89a66932e73ca55b04.1504206475.git.mirq-linux@rere.qmqm.pl>
Date: Thu, 31 Aug 2017 21:12:51 +0200
From: Michał Mirosław <mirq-linux@...e.qmqm.pl>
To: Andrew Morton <akpm@...ux-foundation.org>,
Alexey Dobriyan <adobriyan@...il.com>,
Ingo Molnar <mingo@...nel.org>, Michal Hocko <mhocko@...e.com>,
John Stultz <john.stultz@...aro.org>,
"Eric W. Biederman" <ebiederm@...ssion.com>,
Al Viro <viro@...iv.linux.org.uk>
Cc: linux-kernel@...r.kernel.org
Subject: [PATCH 2/2] procfs: let userspace find out max /proc/pid/comm length
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@...e.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
Powered by blists - more mailing lists