Commit f400e198b2ed26ce55b22a1412ded0896e7516ac
Committed by
Linus Torvalds
1 parent
959ed340f4
Exists in
master
and in
4 other branches
[PATCH] pidspace: is_init()
This is an updated version of Eric Biederman's is_init() patch. (http://lkml.org/lkml/2006/2/6/280). It applies cleanly to 2.6.18-rc3 and replaces a few more instances of ->pid == 1 with is_init(). Further, is_init() checks pid and thus removes dependency on Eric's other patches for now. Eric's original description: There are a lot of places in the kernel where we test for init because we give it special properties. Most significantly init must not die. This results in code all over the kernel test ->pid == 1. Introduce is_init to capture this case. With multiple pid spaces for all of the cases affected we are looking for only the first process on the system, not some other process that has pid == 1. Signed-off-by: Eric W. Biederman <ebiederm@xmission.com> Signed-off-by: Sukadev Bhattiprolu <sukadev@us.ibm.com> Cc: Dave Hansen <haveblue@us.ibm.com> Cc: Serge Hallyn <serue@us.ibm.com> Cc: Cedric Le Goater <clg@fr.ibm.com> Cc: <lxc-devel@lists.sourceforge.net> Acked-by: Paul Mackerras <paulus@samba.org> Signed-off-by: Andrew Morton <akpm@osdl.org> Signed-off-by: Linus Torvalds <torvalds@osdl.org>
Showing 29 changed files with 41 additions and 30 deletions Side-by-side Diff
- arch/alpha/mm/fault.c
- arch/arm/mm/fault.c
- arch/arm26/mm/fault.c
- arch/i386/lib/usercopy.c
- arch/i386/mm/fault.c
- arch/ia64/mm/fault.c
- arch/m32r/mm/fault.c
- arch/m68k/mm/fault.c
- arch/mips/mm/fault.c
- arch/powerpc/mm/fault.c
- arch/powerpc/platforms/pseries/ras.c
- arch/ppc/kernel/traps.c
- arch/ppc/mm/fault.c
- arch/s390/mm/fault.c
- arch/sh/mm/fault.c
- arch/sh64/mm/fault.c
- arch/um/kernel/trap.c
- arch/x86_64/mm/fault.c
- arch/xtensa/mm/fault.c
- drivers/char/sysrq.c
- include/linux/sched.h
- kernel/capability.c
- kernel/cpuset.c
- kernel/exit.c
- kernel/kexec.c
- kernel/ptrace.c
- kernel/sysctl.c
- mm/oom_kill.c
- security/commoncap.c
arch/alpha/mm/fault.c
... | ... | @@ -193,7 +193,7 @@ |
193 | 193 | /* We ran out of memory, or some other thing happened to us that |
194 | 194 | made us unable to handle the page fault gracefully. */ |
195 | 195 | out_of_memory: |
196 | - if (current->pid == 1) { | |
196 | + if (is_init(current)) { | |
197 | 197 | yield(); |
198 | 198 | down_read(&mm->mmap_sem); |
199 | 199 | goto survive; |
arch/arm/mm/fault.c
arch/arm26/mm/fault.c
arch/i386/lib/usercopy.c
... | ... | @@ -739,7 +739,7 @@ |
739 | 739 | retval = get_user_pages(current, current->mm, |
740 | 740 | (unsigned long )to, 1, 1, 0, &pg, NULL); |
741 | 741 | |
742 | - if (retval == -ENOMEM && current->pid == 1) { | |
742 | + if (retval == -ENOMEM && is_init(current)) { | |
743 | 743 | up_read(¤t->mm->mmap_sem); |
744 | 744 | blk_congestion_wait(WRITE, HZ/50); |
745 | 745 | goto survive; |
arch/i386/mm/fault.c
arch/ia64/mm/fault.c
arch/m32r/mm/fault.c
arch/m68k/mm/fault.c
arch/mips/mm/fault.c
arch/powerpc/mm/fault.c
arch/powerpc/platforms/pseries/ras.c
... | ... | @@ -337,7 +337,7 @@ |
337 | 337 | err->disposition == RTAS_DISP_NOT_RECOVERED && |
338 | 338 | err->target == RTAS_TARGET_MEMORY && |
339 | 339 | err->type == RTAS_TYPE_ECC_UNCORR && |
340 | - !(current->pid == 0 || current->pid == 1)) { | |
340 | + !(current->pid == 0 || is_init(current))) { | |
341 | 341 | /* Kill off a user process with an ECC error */ |
342 | 342 | printk(KERN_ERR "MCE: uncorrectable ecc error for pid %d\n", |
343 | 343 | current->pid); |
arch/ppc/kernel/traps.c
... | ... | @@ -119,7 +119,7 @@ |
119 | 119 | * generate the same exception over and over again and we get |
120 | 120 | * nowhere. Better to kill it and let the kernel panic. |
121 | 121 | */ |
122 | - if (current->pid == 1) { | |
122 | + if (is_init(current)) { | |
123 | 123 | __sighandler_t handler; |
124 | 124 | |
125 | 125 | spin_lock_irq(¤t->sighand->siglock); |
arch/ppc/mm/fault.c
arch/s390/mm/fault.c
arch/sh/mm/fault.c
arch/sh64/mm/fault.c
... | ... | @@ -277,7 +277,7 @@ |
277 | 277 | show_regs(regs); |
278 | 278 | #endif |
279 | 279 | } |
280 | - if (tsk->pid == 1) { | |
280 | + if (is_init(tsk)) { | |
281 | 281 | panic("INIT had user mode bad_area\n"); |
282 | 282 | } |
283 | 283 | tsk->thread.address = address; |
284 | 284 | |
... | ... | @@ -319,14 +319,14 @@ |
319 | 319 | * us unable to handle the page fault gracefully. |
320 | 320 | */ |
321 | 321 | out_of_memory: |
322 | - if (current->pid == 1) { | |
322 | + if (is_init(current)) { | |
323 | 323 | panic("INIT out of memory\n"); |
324 | 324 | yield(); |
325 | 325 | goto survive; |
326 | 326 | } |
327 | 327 | printk("fault:Out of memory\n"); |
328 | 328 | up_read(&mm->mmap_sem); |
329 | - if (current->pid == 1) { | |
329 | + if (is_init(current)) { | |
330 | 330 | yield(); |
331 | 331 | down_read(&mm->mmap_sem); |
332 | 332 | goto survive; |
arch/um/kernel/trap.c
arch/x86_64/mm/fault.c
... | ... | @@ -244,7 +244,7 @@ |
244 | 244 | |
245 | 245 | int unhandled_signal(struct task_struct *tsk, int sig) |
246 | 246 | { |
247 | - if (tsk->pid == 1) | |
247 | + if (is_init(tsk)) | |
248 | 248 | return 1; |
249 | 249 | if (tsk->ptrace & PT_PTRACED) |
250 | 250 | return 0; |
... | ... | @@ -580,7 +580,7 @@ |
580 | 580 | */ |
581 | 581 | out_of_memory: |
582 | 582 | up_read(&mm->mmap_sem); |
583 | - if (current->pid == 1) { | |
583 | + if (is_init(current)) { | |
584 | 584 | yield(); |
585 | 585 | goto again; |
586 | 586 | } |
arch/xtensa/mm/fault.c
drivers/char/sysrq.c
include/linux/sched.h
... | ... | @@ -1033,6 +1033,16 @@ |
1033 | 1033 | return p->pids[PIDTYPE_PID].pid != NULL; |
1034 | 1034 | } |
1035 | 1035 | |
1036 | +/** | |
1037 | + * is_init - check if a task structure is the first user space | |
1038 | + * task the kernel created. | |
1039 | + * @p: Task structure to be checked. | |
1040 | + */ | |
1041 | +static inline int is_init(struct task_struct *tsk) | |
1042 | +{ | |
1043 | + return tsk->pid == 1; | |
1044 | +} | |
1045 | + | |
1036 | 1046 | extern void free_task(struct task_struct *tsk); |
1037 | 1047 | #define get_task_struct(tsk) do { atomic_inc(&(tsk)->usage); } while(0) |
1038 | 1048 |
kernel/capability.c
kernel/cpuset.c
... | ... | @@ -240,7 +240,7 @@ |
240 | 240 | * A cpuset can only be deleted if both its 'count' of using tasks |
241 | 241 | * is zero, and its list of 'children' cpusets is empty. Since all |
242 | 242 | * tasks in the system use _some_ cpuset, and since there is always at |
243 | - * least one task in the system (init, pid == 1), therefore, top_cpuset | |
243 | + * least one task in the system (init), therefore, top_cpuset | |
244 | 244 | * always has either children cpusets and/or using tasks. So we don't |
245 | 245 | * need a special hack to ensure that top_cpuset cannot be deleted. |
246 | 246 | * |
kernel/exit.c
... | ... | @@ -219,7 +219,7 @@ |
219 | 219 | do_each_task_pid(pgrp, PIDTYPE_PGID, p) { |
220 | 220 | if (p == ignored_task |
221 | 221 | || p->exit_state |
222 | - || p->real_parent->pid == 1) | |
222 | + || is_init(p->real_parent)) | |
223 | 223 | continue; |
224 | 224 | if (process_group(p->real_parent) != pgrp |
225 | 225 | && p->real_parent->signal->session == p->signal->session) { |
kernel/kexec.c
kernel/ptrace.c
kernel/sysctl.c
mm/oom_kill.c
security/commoncap.c
... | ... | @@ -169,7 +169,7 @@ |
169 | 169 | /* For init, we want to retain the capabilities set |
170 | 170 | * in the init_task struct. Thus we skip the usual |
171 | 171 | * capability rules */ |
172 | - if (current->pid != 1) { | |
172 | + if (!is_init(current)) { | |
173 | 173 | current->cap_permitted = new_permitted; |
174 | 174 | current->cap_effective = |
175 | 175 | cap_intersect (new_permitted, bprm->cap_effective); |