From f1a77e519e855566d291e0aa41558b50f66928f2 Mon Sep 17 00:00:00 2001 From: Olaf Kirch Date: Mon, 23 Aug 2004 21:42:57 -0700 Subject: [PATCH] [PATCH] /proc/PID/cmdline truncates arguments early We received a bug report that /proc/PID/cmdline only shows argv[0] if the total length of all arguments exceeds PAGE_SIZE. The problem is that proc_pid_cmdline checks for the presence of a NUL byte at the end of the args list, and assumes that the application did a setproctitle if there's any other character. OTOH proc_pid_cmdline will read just the first PAGE_SIZE worth of arguments at most, and if you have more arguments, it's quite likely that there won't be a NUL byte at offset PAGE_SIZE-1. The attached patch fixes this. Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds --- fs/proc/base.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/fs/proc/base.c b/fs/proc/base.c index e13183c988af6..a3614e9910aa5 100644 --- a/fs/proc/base.c +++ b/fs/proc/base.c @@ -352,7 +352,7 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer) // If the nul at the end of args has been overwritten, then // assume application is using setproctitle(3). - if (res > 0 && buffer[res-1] != '\0') { + if (res > 0 && buffer[res-1] != '\0' && len < PAGE_SIZE) { len = strnlen(buffer, res); if (len < res) { res = len; -- 2.53.0