Skip to contentSkip to conversation

proc: check permissions earlier for /proc/*/wchan

PATCH In review Alexey Dobriyan 1 participant 1 message Feb 17, 2018 Proc filesystem

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 proc: check permissions earlier for /proc/*/wchan

get_wchan() accesses stack page before permissions are checked, let's not play this game.

---

 fs/proc/base.c |   13 ++++++++-----
 1 file changed, 8 insertions(+), 5 deletions(-)
fs/proc/base.c +8 -5
@@ -391,14 +391,17 @@ static int proc_pid_wchan(struct seq_file *m, struct pid_namespace *ns,
 	unsigned long wchan;
 	char symname[KSYM_NAME_LEN];
 
-	wchan = get_wchan(task);
+	if (!ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS))
+		goto print0;
 
-	if (wchan && ptrace_may_access(task, PTRACE_MODE_READ_FSCREDS)
-			&& !lookup_symbol_name(wchan, symname))
+	wchan = get_wchan(task);
+	if (wchan && !lookup_symbol_name(wchan, symname)) {
 		seq_printf(m, "%s", symname);
-	else
-		seq_putc(m, '0');
+		return 0;
+	}
 
+print0:
+	seq_putc(m, '0');
 	return 0;
 }
 #endif /* CONFIG_KALLSYMS */