diff options
author | Eric W. Biederman <ebiederm@xmission.com> | 2008-02-08 07:18:33 -0500 |
---|---|---|
committer | Linus Torvalds <torvalds@woody.linux-foundation.org> | 2008-02-08 12:22:24 -0500 |
commit | df5f8314ca30d6a76735748e5ba4ca9809c0f434 (patch) | |
tree | e0a6157b1666a320e69586a81c77a3fe83b36a2a /fs/proc/array.c | |
parent | a56d3fc74c0178c5f41c48315604d62cff4e746d (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/array.c')
-rw-r--r-- | fs/proc/array.c | 128 |
1 files changed, 63 insertions, 65 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 @@ | |||
89 | do { memcpy(buffer, string, strlen(string)); \ | 89 | do { memcpy(buffer, string, strlen(string)); \ |
90 | buffer += strlen(string); } while (0) | 90 | buffer += strlen(string); } while (0) |
91 | 91 | ||
92 | static inline char *task_name(struct task_struct *p, char *buf) | 92 | static 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 | ||
155 | static inline char *task_state(struct task_struct *p, char *buffer) | 159 | static 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 | ||
205 | static char *render_sigset_t(const char *header, sigset_t *set, char *buffer) | 207 | static 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 | ||
230 | static void collect_sigign_sigcatch(struct task_struct *p, sigset_t *ign, | 229 | static 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 | ||
245 | static inline char *task_sig(struct task_struct *p, char *buffer) | 244 | static 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 | ||
285 | static char *render_cap_t(const char *header, kernel_cap_t *a, char *buffer) | 282 | static 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 | ||
297 | static inline char *task_cap(struct task_struct *p, char *buffer) | 295 | static 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 | ||
304 | static inline char *task_context_switch_counts(struct task_struct *p, | 302 | static 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 | ||
313 | int proc_pid_status(struct task_struct *task, char *buffer) | 311 | int 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 | /* |