Skip to contentSkip to conversation

proc/pid/cmdline: Handle invalid cmdline change failures correctly.

PATCH In review Timo Sirainen 2 participants 3 messages Oct 3, 2009 – Oct 16, 2009 Proc filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 proc/pid/cmdline: Handle invalid cmdline change failures correctly.

Handle access_process_vm() failures correctly in /proc/pid/cmdline. This bug might have leaked kernel memory to userspace.

---
 fs/proc/base.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
fs/proc/base.c +4 -3
index 837469a..f66cc4c 100644
@@ -252,7 +252,7 @@ struct mm_struct *mm_for_maps(struct task_struct *task)
 
 static int proc_pid_cmdline(struct task_struct *task, char * buffer)
 {
-	int res = 0;
+	int res = 0, res2;
 	unsigned int len;
 	struct mm_struct *mm = get_task_mm(task);
 	if (!mm)
@@ -277,8 +277,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
 			len = mm->env_end - mm->env_start;
 			if (len > PAGE_SIZE - res)
 				len = PAGE_SIZE - res;
-			res += access_process_vm(task, mm->env_start, buffer+res, len, 0);
-			res = strnlen(buffer, res);
+			res2 = access_process_vm(task, mm->env_start, buffer+res, len, 0);
+			if (res2 > 0)
+				res = strnlen(buffer, res + res2);
 		}
 	}
 out_mm:
Signature · 1 line
1.6.3.3
#1 lore raw
Quoted 3 lines · On Sat, 03 Oct 2009 00:07:12 -0400 Timo Sirainen <[email protected]> wrote:

Handle access_process_vm() failures correctly in /proc/pid/cmdline. This bug might have leaked kernel memory to userspace.

The changelog fails to describe the bug.

Quoted 18 lines
---
 fs/proc/base.c |    7 ++++---
 1 files changed, 4 insertions(+), 3 deletions(-)
fs/proc/base.c +1 -1
index 837469a..f66cc4c 100644
@@ -252,7 +252,7 @@ struct mm_struct *mm_for_maps(struct task_struct *task)
 
 static int proc_pid_cmdline(struct task_struct *task, char * buffer)
 {
-	int res = 0;
+	int res = 0, res2;
 	unsigned int len;
 	struct mm_struct *mm = get_task_mm(task);
 	if (!mm)

fs/proc/base.c static int proc_pid_cmdline(struct task_struct *task, char * buffer) · line 284

Quoted 10 lines
fs/proc/base.c +3 -2
@@ -277,8 +277,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
 			len = mm->env_end - mm->env_start;
 			if (len > PAGE_SIZE - res)
 				len = PAGE_SIZE - res;
-			res += access_process_vm(task, mm->env_start, buffer+res, len, 0);
-			res = strnlen(buffer, res);
+			res2 = access_process_vm(task, mm->env_start, buffer+res, len, 0);
+			if (res2 > 0)
+				res = strnlen(buffer, res + res2);
 		}
 	}

And I don't see what it is. afacit the current code is correct.

#2 lore raw
Quoted 8 lines · Andrew Morton
Quoted 3 lines · On Sat, 03 Oct 2009 00:07:12 -0400 Timo Sirainen <[email protected]> wrote:

Handle access_process_vm() failures correctly in /proc/pid/cmdline. This bug might have leaked kernel memory to userspace.

And I don't see what it is. afacit the current code is correct.

It is, sorry. Someone had mentioned access_process_vm() could fail by returning negative values and I didn't verify that myself before sending this "fix".