linux/kernel
David Meybohm 4c5640cb5f [PATCH] preempt race in getppid
With CONFIG_PREEMPT && !CONFIG_SMP, it's possible for sys_getppid to
return a bogus value if the parent's task_struct gets reallocated after
current->group_leader->real_parent is read:

        asmlinkage long sys_getppid(void)
        {
                int pid;
                struct task_struct *me = current;
                struct task_struct *parent;

                parent = me->group_leader->real_parent;
RACE HERE =>    for (;;) {
                        pid = parent->tgid;
        #ifdef CONFIG_SMP
        {
                        struct task_struct *old = parent;

                        /*
                         * Make sure we read the pid before re-reading the
                         * parent pointer:
                         */
                        smp_rmb();
                        parent = me->group_leader->real_parent;
                        if (old != parent)
                                continue;
        }
        #endif
                        break;
                }
                return pid;
        }

If the process gets preempted at the indicated point, the parent process
can go ahead and call exit() and then get wait()'d on to reap its
task_struct. When the preempted process gets resumed, it will not do any
further checks of the parent pointer on !CONFIG_SMP: it will read the
bad pid and return.

So, the same algorithm used when SMP is enabled should be used when
preempt is enabled, which will recheck ->real_parent in this case.

Signed-off-by: David Meybohm <dmeybohmlkml@bellsouth.net>
Signed-off-by: Andrew Morton <akpm@osdl.org>
Signed-off-by: Linus Torvalds <torvalds@osdl.org>
2005-08-23 11:44:29 -07:00
..
irq [PATCH] irqpoll 2005-06-28 21:20:35 -07:00
power [PATCH] Address BUG: using smp_processor_id() in preemptible [00000001] code 2005-07-27 16:25:50 -07:00
acct.c
audit.c
auditsc.c
capability.c [PATCH] kernel/capability.c: add kerneldoc 2005-07-27 16:26:06 -07:00
compat.c
configs.c
cpu.c
cpuset.c [PATCH] cpuset release ABBA deadlock fix 2005-08-09 12:08:22 -07:00
crash_dump.c [PATCH] kernel/crash_dump.c: add kerneldoc 2005-07-27 16:26:06 -07:00
dma.c
exec_domain.c
exit.c [PATCH] revert "timer exit cleanup" 2005-08-04 16:57:49 -07:00
extable.c
fork.c [PATCH] lower VM_DONTCOPY total_vm 2005-07-12 16:00:58 -07:00
futex.c
intermodule.c
itimer.c [PATCH] itimer fixes 2005-07-27 16:25:51 -07:00
kallsyms.c
Kconfig.hz
Kconfig.preempt [PATCH] sched: voluntary kernel preemption 2005-06-25 16:24:45 -07:00
kexec.c [PATCH] kexec: fix sparse warnings 2005-06-28 14:53:40 -07:00
kfifo.c
kmod.c
kprobes.c [PATCH] kprobes: fix namespace problem and sparc64 build 2005-07-05 19:19:00 -07:00
ksysfs.c [PATCH] Kdump: Export crash notes section address through sysfs 2005-06-25 16:24:51 -07:00
kthread.c
Makefile [PATCH] kdump: Routines for copying dump pages 2005-06-25 16:24:53 -07:00
module.c [PATCH] Module per-cpu alignment cannot always be met 2005-08-01 21:38:01 -07:00
panic.c [PATCH] Call emergency_reboot from panic 2005-07-26 14:35:43 -07:00
params.c
pid.c
posix-cpu-timers.c
posix-timers.c [PATCH] revert "timer exit cleanup" 2005-08-04 16:57:49 -07:00
printk.c
profile.c [PATCH] mostly_read data section 2005-07-07 18:23:46 -07:00
ptrace.c
rcupdate.c
resource.c [PATCH] Use ALIGN to remove duplicate code 2005-06-25 16:25:02 -07:00
sched.c [PATCH] Make RLIMIT_NICE ranges consistent with getpriority(2) 2005-08-18 12:53:58 -07:00
seccomp.c
signal.c [PATCH] NPTL signal delivery deadlock fix 2005-08-17 12:52:04 -07:00
softirq.c [PATCH] revert bogus softirq changes 2005-07-30 10:49:59 -07:00
spinlock.c
stop_machine.c
sys_ni.c [PATCH] remove sys_set_zone_reclaim() 2005-08-01 10:03:56 -07:00
sys.c [PATCH] Remove suspend() calls from shutdown path 2005-08-04 08:20:47 -07:00
sysctl.c [PATCH] s390: spin lock retry 2005-07-27 16:26:04 -07:00
time.c [PATCH] clean up inline static vs static inline 2005-07-27 16:26:20 -07:00
timer.c [PATCH] preempt race in getppid 2005-08-23 11:44:29 -07:00
uid16.c
user.c [PATCH] inotify 2005-07-12 20:38:38 -07:00
wait.c
workqueue.c [PATCH] remove name length check in a workqueue 2005-08-10 11:55:19 -07:00