aboutsummaryrefslogtreecommitdiffstats
path: root/fs/proc
diff options
context:
space:
mode:
authorEric W. Biederman <ebiederm@xmission.com>2008-02-08 07:18:33 -0500
committerLinus Torvalds <torvalds@woody.linux-foundation.org>2008-02-08 12:22:24 -0500
commitdf5f8314ca30d6a76735748e5ba4ca9809c0f434 (patch)
treee0a6157b1666a320e69586a81c77a3fe83b36a2a /fs/proc
parenta56d3fc74c0178c5f41c48315604d62cff4e746d (diff)
proc: seqfile convert proc_pid_status to properly handle pid namespaces
Currently we possibly lookup the pid in the wrong pid namespace. So seq_file convert proc_pid_status which ensures the proper pid namespaces is passed in. [akpm@linux-foundation.org: coding-style fixes] [akpm@linux-foundation.org: build fix] [akpm@linux-foundation.org: another build fix] [akpm@linux-foundation.org: s390 build fix] [akpm@linux-foundation.org: fix task_name() output] [akpm@linux-foundation.org: fix nommu build] Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Cc: Andrew Morgan <morgan@kernel.org> Cc: Serge Hallyn <serue@us.ibm.com> Cc: Cedric Le Goater <clg@fr.ibm.com> Cc: Pavel Emelyanov <xemul@openvz.org> Cc: Martin Schwidefsky <schwidefsky@de.ibm.com> Cc: Heiko Carstens <heiko.carstens@de.ibm.com> Cc: Paul Menage <menage@google.com> Cc: Paul Jackson <pj@sgi.com> Cc: David Rientjes <rientjes@google.com> Signed-off-by: Andrew Morton <akpm@linux-foundation.org> Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'fs/proc')
-rw-r--r--fs/proc/array.c128
-rw-r--r--fs/proc/base.c4
-rw-r--r--fs/proc/internal.h3
-rw-r--r--fs/proc/task_mmu.c6
-rw-r--r--fs/proc/task_nommu.c5
5 files changed, 72 insertions, 74 deletions
diff --git a/fs/proc/array.c b/fs/proc/array.c
index 5540e9575c6d..07d6c4853fe8 100644
--- a/fs/proc/array.c
+++ b/fs/proc/array.c
@@ -89,18 +89,21 @@
89do { memcpy(buffer, string, strlen(string)); \ 89do { memcpy(buffer, string, strlen(string)); \
90 buffer += strlen(string); } while (0) 90 buffer += strlen(string); } while (0)
91 91
92static inline char *task_name(struct task_struct *p, char *buf) 92static inline void task_name(struct seq_file *m, struct task_struct *p)
93{ 93{
94 int i; 94 int i;
95 char *buf, *end;
95 char *name; 96 char *name;
96 char tcomm[sizeof(p->comm)]; 97 char tcomm[sizeof(p->comm)];
97 98
98 get_task_comm(tcomm, p); 99 get_task_comm(tcomm, p);
99 100
100 ADDBUF(buf, "Name:\t"); 101 seq_printf(m, "Name:\t");
102 end = m->buf + m->size;
103 buf = m->buf + m->count;
101 name = tcomm; 104 name = tcomm;
102 i = sizeof(tcomm); 105 i = sizeof(tcomm);
103 do { 106 while (i && (buf < end)) {
104 unsigned char c = *name; 107 unsigned char c = *name;
105 name++; 108 name++;
106 i--; 109 i--;
@@ -108,20 +111,21 @@ static inline char *task_name(struct task_struct *p, char *buf)
108 if (!c) 111 if (!c)
109 break; 112 break;
110 if (c == '\\') { 113 if (c == '\\') {
111 buf[1] = c; 114 buf++;
112 buf += 2; 115 if (buf < end)
116 *buf++ = c;
113 continue; 117 continue;
114 } 118 }
115 if (c == '\n') { 119 if (c == '\n') {
116 buf[0] = '\\'; 120 *buf++ = '\\';
117 buf[1] = 'n'; 121 if (buf < end)
118 buf += 2; 122 *buf++ = 'n';
119 continue; 123 continue;
120 } 124 }
121 buf++; 125 buf++;
122 } while (i); 126 }
123 *buf = '\n'; 127 m->count = buf - m->buf;
124 return buf+1; 128 seq_printf(m, "\n");
125} 129}
126 130
127/* 131/*
@@ -152,21 +156,20 @@ static inline const char *get_task_state(struct task_struct *tsk)
152 return *p; 156 return *p;
153} 157}
154 158
155static inline char *task_state(struct task_struct *p, char *buffer) 159static inline void task_state(struct seq_file *m, struct pid_namespace *ns,
160 struct pid *pid, struct task_struct *p)
156{ 161{
157 struct group_info *group_info; 162 struct group_info *group_info;
158 int g; 163 int g;
159 struct fdtable *fdt = NULL; 164 struct fdtable *fdt = NULL;
160 struct pid_namespace *ns;
161 pid_t ppid, tpid; 165 pid_t ppid, tpid;
162 166
163 ns = current->nsproxy->pid_ns;
164 rcu_read_lock(); 167 rcu_read_lock();
165 ppid = pid_alive(p) ? 168 ppid = pid_alive(p) ?
166 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0; 169 task_tgid_nr_ns(rcu_dereference(p->real_parent), ns) : 0;
167 tpid = pid_alive(p) && p->ptrace ? 170 tpid = pid_alive(p) && p->ptrace ?
168 task_pid_nr_ns(rcu_dereference(p->parent), ns) : 0; 171 task_pid_nr_ns(rcu_dereference(p->parent), ns) : 0;
169 buffer += sprintf(buffer, 172 seq_printf(m,
170 "State:\t%s\n" 173 "State:\t%s\n"
171 "Tgid:\t%d\n" 174 "Tgid:\t%d\n"
172 "Pid:\t%d\n" 175 "Pid:\t%d\n"
@@ -176,7 +179,7 @@ static inline char *task_state(struct task_struct *p, char *buffer)
176 "Gid:\t%d\t%d\t%d\t%d\n", 179 "Gid:\t%d\t%d\t%d\t%d\n",
177 get_task_state(p), 180 get_task_state(p),
178 task_tgid_nr_ns(p, ns), 181 task_tgid_nr_ns(p, ns),
179 task_pid_nr_ns(p, ns), 182 pid_nr_ns(pid, ns),
180 ppid, tpid, 183 ppid, tpid,
181 p->uid, p->euid, p->suid, p->fsuid, 184 p->uid, p->euid, p->suid, p->fsuid,
182 p->gid, p->egid, p->sgid, p->fsgid); 185 p->gid, p->egid, p->sgid, p->fsgid);
@@ -184,7 +187,7 @@ static inline char *task_state(struct task_struct *p, char *buffer)
184 task_lock(p); 187 task_lock(p);
185 if (p->files) 188 if (p->files)
186 fdt = files_fdtable(p->files); 189 fdt = files_fdtable(p->files);
187 buffer += sprintf(buffer, 190 seq_printf(m,
188 "FDSize:\t%d\n" 191 "FDSize:\t%d\n"
189 "Groups:\t", 192 "Groups:\t",
190 fdt ? fdt->max_fds : 0); 193 fdt ? fdt->max_fds : 0);
@@ -195,20 +198,18 @@ static inline char *task_state(struct task_struct *p, char *buffer)
195 task_unlock(p); 198 task_unlock(p);
196 199
197 for (g = 0; g < min(group_info->ngroups, NGROUPS_SMALL); g++) 200 for (g = 0; g < min(group_info->ngroups, NGROUPS_SMALL); g++)
198 buffer += sprintf(buffer, "%d ", GROUP_AT(group_info, g)); 201 seq_printf(m, "%d ", GROUP_AT(group_info, g));
199 put_group_info(group_info); 202 put_group_info(group_info);
200 203
201 buffer += sprintf(buffer, "\n"); 204 seq_printf(m, "\n");
202 return buffer;
203} 205}
204 206
205static char *render_sigset_t(const char *header, sigset_t *set, char *buffer) 207static void render_sigset_t(struct seq_file *m, const char *header,
208 sigset_t *set)
206{ 209{
207 int i, len; 210 int i;
208 211
209 len = strlen(header); 212 seq_printf(m, "%s", header);
210 memcpy(buffer, header, len);
211 buffer += len;
212 213
213 i = _NSIG; 214 i = _NSIG;
214 do { 215 do {
@@ -219,12 +220,10 @@ static char *render_sigset_t(const char *header, sigset_t *set, char *buffer)
219 if (sigismember(set, i+2)) x |= 2; 220 if (sigismember(set, i+2)) x |= 2;
220 if (sigismember(set, i+3)) x |= 4; 221 if (sigismember(set, i+3)) x |= 4;
221 if (sigismember(set, i+4)) x |= 8; 222 if (sigismember(set, i+4)) x |= 8;
222 *buffer++ = (x < 10 ? '0' : 'a' - 10) + x; 223 seq_printf(m, "%x", x);
223 } while (i >= 4); 224 } while (i >= 4);
224 225
225 *buffer++ = '\n'; 226 seq_printf(m, "\n");
226 *buffer = 0;
227 return buffer;
228} 227}
229 228
230static void collect_sigign_sigcatch(struct task_struct *p, sigset_t *ign, 229static void collect_sigign_sigcatch(struct task_struct *p, sigset_t *ign,
@@ -242,7 +241,7 @@ static void collect_sigign_sigcatch(struct task_struct *p, sigset_t *ign,
242 } 241 }
243} 242}
244 243
245static inline char *task_sig(struct task_struct *p, char *buffer) 244static inline void task_sig(struct seq_file *m, struct task_struct *p)
246{ 245{
247 unsigned long flags; 246 unsigned long flags;
248 sigset_t pending, shpending, blocked, ignored, caught; 247 sigset_t pending, shpending, blocked, ignored, caught;
@@ -269,67 +268,66 @@ static inline char *task_sig(struct task_struct *p, char *buffer)
269 } 268 }
270 rcu_read_unlock(); 269 rcu_read_unlock();
271 270
272 buffer += sprintf(buffer, "Threads:\t%d\n", num_threads); 271 seq_printf(m, "Threads:\t%d\n", num_threads);
273 buffer += sprintf(buffer, "SigQ:\t%lu/%lu\n", qsize, qlim); 272 seq_printf(m, "SigQ:\t%lu/%lu\n", qsize, qlim);
274 273
275 /* render them all */ 274 /* render them all */
276 buffer = render_sigset_t("SigPnd:\t", &pending, buffer); 275 render_sigset_t(m, "SigPnd:\t", &pending);
277 buffer = render_sigset_t("ShdPnd:\t", &shpending, buffer); 276 render_sigset_t(m, "ShdPnd:\t", &shpending);
278 buffer = render_sigset_t("SigBlk:\t", &blocked, buffer); 277 render_sigset_t(m, "SigBlk:\t", &blocked);
279 buffer = render_sigset_t("SigIgn:\t", &ignored, buffer); 278 render_sigset_t(m, "SigIgn:\t", &ignored);
280 buffer = render_sigset_t("SigCgt:\t", &caught, buffer); 279 render_sigset_t(m, "SigCgt:\t", &caught);
281
282 return buffer;
283} 280}
284 281
285static char *render_cap_t(const char *header, kernel_cap_t *a, char *buffer) 282static void render_cap_t(struct seq_file *m, const char *header,
283 kernel_cap_t *a)
286{ 284{
287 unsigned __capi; 285 unsigned __capi;
288 286
289 buffer += sprintf(buffer, "%s", header); 287 seq_printf(m, "%s", header);
290 CAP_FOR_EACH_U32(__capi) { 288 CAP_FOR_EACH_U32(__capi) {
291 buffer += sprintf(buffer, "%08x", 289 seq_printf(m, "%08x",
292 a->cap[(_LINUX_CAPABILITY_U32S-1) - __capi]); 290 a->cap[(_LINUX_CAPABILITY_U32S-1) - __capi]);
293 } 291 }
294 return buffer + sprintf(buffer, "\n"); 292 seq_printf(m, "\n");
295} 293}
296 294
297static inline char *task_cap(struct task_struct *p, char *buffer) 295static inline void task_cap(struct seq_file *m, struct task_struct *p)
298{ 296{
299 buffer = render_cap_t("CapInh:\t", &p->cap_inheritable, buffer); 297 render_cap_t(m, "CapInh:\t", &p->cap_inheritable);
300 buffer = render_cap_t("CapPrm:\t", &p->cap_permitted, buffer); 298 render_cap_t(m, "CapPrm:\t", &p->cap_permitted);
301 return render_cap_t("CapEff:\t", &p->cap_effective, buffer); 299 render_cap_t(m, "CapEff:\t", &p->cap_effective);
302} 300}
303 301
304static inline char *task_context_switch_counts(struct task_struct *p, 302static inline void task_context_switch_counts(struct seq_file *m,
305 char *buffer) 303 struct task_struct *p)
306{ 304{
307 return buffer + sprintf(buffer, "voluntary_ctxt_switches:\t%lu\n" 305 seq_printf(m, "voluntary_ctxt_switches:\t%lu\n"
308 "nonvoluntary_ctxt_switches:\t%lu\n", 306 "nonvoluntary_ctxt_switches:\t%lu\n",
309 p->nvcsw, 307 p->nvcsw,
310 p->nivcsw); 308 p->nivcsw);
311} 309}
312 310
313int proc_pid_status(struct task_struct *task, char *buffer) 311int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
312 struct pid *pid, struct task_struct *task)
314{ 313{
315 char *orig = buffer;
316 struct mm_struct *mm = get_task_mm(task); 314 struct mm_struct *mm = get_task_mm(task);
317 315
318 buffer = task_name(task, buffer); 316 task_name(m, task);
319 buffer = task_state(task, buffer); 317 task_state(m, ns, pid, task);
320 318
321 if (mm) { 319 if (mm) {
322 buffer = task_mem(mm, buffer); 320 task_mem(m, mm);
323 mmput(mm); 321 mmput(mm);
324 } 322 }
325 buffer = task_sig(task, buffer); 323 task_sig(m, task);
326 buffer = task_cap(task, buffer); 324 task_cap(m, task);
327 buffer = cpuset_task_status_allowed(task, buffer); 325 cpuset_task_status_allowed(m, task);
328#if defined(CONFIG_S390) 326#if defined(CONFIG_S390)
329 buffer = task_show_regs(task, buffer); 327 task_show_regs(m, task);
330#endif 328#endif
331 buffer = task_context_switch_counts(task, buffer); 329 task_context_switch_counts(m, task);
332 return buffer - orig; 330 return 0;
333} 331}
334 332
335/* 333/*
diff --git a/fs/proc/base.c b/fs/proc/base.c
index 9c3e548a6754..8a19a8a1a3e6 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -2274,7 +2274,7 @@ static const struct pid_entry tgid_base_stuff[] = {
2274 DIR("fdinfo", S_IRUSR|S_IXUSR, fdinfo), 2274 DIR("fdinfo", S_IRUSR|S_IXUSR, fdinfo),
2275 REG("environ", S_IRUSR, environ), 2275 REG("environ", S_IRUSR, environ),
2276 INF("auxv", S_IRUSR, pid_auxv), 2276 INF("auxv", S_IRUSR, pid_auxv),
2277 INF("status", S_IRUGO, pid_status), 2277 ONE("status", S_IRUGO, pid_status),
2278 INF("limits", S_IRUSR, pid_limits), 2278 INF("limits", S_IRUSR, pid_limits),
2279#ifdef CONFIG_SCHED_DEBUG 2279#ifdef CONFIG_SCHED_DEBUG
2280 REG("sched", S_IRUGO|S_IWUSR, pid_sched), 2280 REG("sched", S_IRUGO|S_IWUSR, pid_sched),
@@ -2605,7 +2605,7 @@ static const struct pid_entry tid_base_stuff[] = {
2605 DIR("fdinfo", S_IRUSR|S_IXUSR, fdinfo), 2605 DIR("fdinfo", S_IRUSR|S_IXUSR, fdinfo),
2606 REG("environ", S_IRUSR, environ), 2606 REG("environ", S_IRUSR, environ),
2607 INF("auxv", S_IRUSR, pid_auxv), 2607 INF("auxv", S_IRUSR, pid_auxv),
2608 INF("status", S_IRUGO, pid_status), 2608 ONE("status", S_IRUGO, pid_status),
2609 INF("limits", S_IRUSR, pid_limits), 2609 INF("limits", S_IRUSR, pid_limits),
2610#ifdef CONFIG_SCHED_DEBUG 2610#ifdef CONFIG_SCHED_DEBUG
2611 REG("sched", S_IRUGO|S_IWUSR, pid_sched), 2611 REG("sched", S_IRUGO|S_IWUSR, pid_sched),
diff --git a/fs/proc/internal.h b/fs/proc/internal.h
index 45bdbfc704e7..ea496ffeabe7 100644
--- a/fs/proc/internal.h
+++ b/fs/proc/internal.h
@@ -53,7 +53,8 @@ extern int proc_tid_stat(struct seq_file *m, struct pid_namespace *ns,
53 struct pid *pid, struct task_struct *task); 53 struct pid *pid, struct task_struct *task);
54extern int proc_tgid_stat(struct seq_file *m, struct pid_namespace *ns, 54extern int proc_tgid_stat(struct seq_file *m, struct pid_namespace *ns,
55 struct pid *pid, struct task_struct *task); 55 struct pid *pid, struct task_struct *task);
56extern int proc_pid_status(struct task_struct *, char *); 56extern int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
57 struct pid *pid, struct task_struct *task);
57extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns, 58extern int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
58 struct pid *pid, struct task_struct *task); 59 struct pid *pid, struct task_struct *task);
59extern loff_t mem_lseek(struct file *file, loff_t offset, int orig); 60extern loff_t mem_lseek(struct file *file, loff_t offset, int orig);
diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
index 38338ed98cc6..a34c440f8d25 100644
--- a/fs/proc/task_mmu.c
+++ b/fs/proc/task_mmu.c
@@ -9,13 +9,14 @@
9#include <linux/mempolicy.h> 9#include <linux/mempolicy.h>
10#include <linux/swap.h> 10#include <linux/swap.h>
11#include <linux/swapops.h> 11#include <linux/swapops.h>
12#include <linux/seq_file.h>
12 13
13#include <asm/elf.h> 14#include <asm/elf.h>
14#include <asm/uaccess.h> 15#include <asm/uaccess.h>
15#include <asm/tlbflush.h> 16#include <asm/tlbflush.h>
16#include "internal.h" 17#include "internal.h"
17 18
18char *task_mem(struct mm_struct *mm, char *buffer) 19void task_mem(struct seq_file *m, struct mm_struct *mm)
19{ 20{
20 unsigned long data, text, lib; 21 unsigned long data, text, lib;
21 unsigned long hiwater_vm, total_vm, hiwater_rss, total_rss; 22 unsigned long hiwater_vm, total_vm, hiwater_rss, total_rss;
@@ -37,7 +38,7 @@ char *task_mem(struct mm_struct *mm, char *buffer)
37 data = mm->total_vm - mm->shared_vm - mm->stack_vm; 38 data = mm->total_vm - mm->shared_vm - mm->stack_vm;
38 text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) >> 10; 39 text = (PAGE_ALIGN(mm->end_code) - (mm->start_code & PAGE_MASK)) >> 10;
39 lib = (mm->exec_vm << (PAGE_SHIFT-10)) - text; 40 lib = (mm->exec_vm << (PAGE_SHIFT-10)) - text;
40 buffer += sprintf(buffer, 41 seq_printf(m,
41 "VmPeak:\t%8lu kB\n" 42 "VmPeak:\t%8lu kB\n"
42 "VmSize:\t%8lu kB\n" 43 "VmSize:\t%8lu kB\n"
43 "VmLck:\t%8lu kB\n" 44 "VmLck:\t%8lu kB\n"
@@ -56,7 +57,6 @@ char *task_mem(struct mm_struct *mm, char *buffer)
56 data << (PAGE_SHIFT-10), 57 data << (PAGE_SHIFT-10),
57 mm->stack_vm << (PAGE_SHIFT-10), text, lib, 58 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
58 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10); 59 (PTRS_PER_PTE*sizeof(pte_t)*mm->nr_ptes) >> 10);
59 return buffer;
60} 60}
61 61
62unsigned long task_vsize(struct mm_struct *mm) 62unsigned long task_vsize(struct mm_struct *mm)
diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
index 1932c2ca3457..cee0231c6cec 100644
--- a/fs/proc/task_nommu.c
+++ b/fs/proc/task_nommu.c
@@ -12,7 +12,7 @@
12 * each process that owns it. Non-shared memory is counted 12 * each process that owns it. Non-shared memory is counted
13 * accurately. 13 * accurately.
14 */ 14 */
15char *task_mem(struct mm_struct *mm, char *buffer) 15void task_mem(struct seq_file *m, struct mm_struct *mm)
16{ 16{
17 struct vm_list_struct *vml; 17 struct vm_list_struct *vml;
18 unsigned long bytes = 0, sbytes = 0, slack = 0; 18 unsigned long bytes = 0, sbytes = 0, slack = 0;
@@ -58,14 +58,13 @@ char *task_mem(struct mm_struct *mm, char *buffer)
58 58
59 bytes += kobjsize(current); /* includes kernel stack */ 59 bytes += kobjsize(current); /* includes kernel stack */
60 60
61 buffer += sprintf(buffer, 61 seq_printf(m,
62 "Mem:\t%8lu bytes\n" 62 "Mem:\t%8lu bytes\n"
63 "Slack:\t%8lu bytes\n" 63 "Slack:\t%8lu bytes\n"
64 "Shared:\t%8lu bytes\n", 64 "Shared:\t%8lu bytes\n",
65 bytes, slack, sbytes); 65 bytes, slack, sbytes);
66 66
67 up_read(&mm->mmap_sem); 67 up_read(&mm->mmap_sem);
68 return buffer;
69} 68}
70 69
71unsigned long task_vsize(struct mm_struct *mm) 70unsigned long task_vsize(struct mm_struct *mm)