This is the mail archive of the
libc-alpha@sourceware.org
mailing list for the glibc project.
Re: [PATCH v1 1/1] waitid: Add support for waiting for the current process group
- From: Christian Brauner <christian dot brauner at ubuntu dot com>
- To: Oleg Nesterov <oleg at redhat dot com>
- Cc: linux-kernel at vger dot kernel dot org, libc-alpha at sourceware dot org, alistair23 at gmail dot com, ebiederm at xmission dot com, arnd at arndb dot de, dalias at libc dot org, torvalds at linux-foundation dot org, adhemerval dot zanella at linaro dot org, fweimer at redhat dot com, palmer at sifive dot com, macro at wdc dot com, zongbox at gmail dot com, akpm at linux-foundation dot org, viro at zeniv dot linux dot org dot uk, hpa at zytor dot com
- Date: Wed, 14 Aug 2019 14:45:51 +0200
- Subject: Re: [PATCH v1 1/1] waitid: Add support for waiting for the current process group
- References: <CAKmqyKMJPQAOKn11xepzAwXOd4e9dU0Cyz=A0T-uMEgUp5yJjA@mail.gmail.com> <20190814113822.9505-1-christian.brauner@ubuntu.com> <20190814113822.9505-2-christian.brauner@ubuntu.com> <20190814122909.GA11595@redhat.com>
On Wed, Aug 14, 2019 at 02:29:10PM +0200, Oleg Nesterov wrote:
> On 08/14, christian.brauner@ubuntu.com wrote:
> >
> > case P_PGID:
> > type = PIDTYPE_PGID;
> > - if (upid <= 0)
> > + if (upid < 0)
> > return -EINVAL;
> > +
> > + if (upid == 0)
> > + pid = get_pid(task_pgrp(current));
>
> this needs rcu lock or tasklist_lock, this can race with another thread
> doing sys_setpgid/setsid (see change_pid(PIDTYPE_PGID)).
Oh, I naively assumed task_pgrp() would take an rcu lock...
kernel/sys.c takes both, i.e.
rcu_read_lock();
write_lock_irq(&tasklist_lock);
though I think we should be fine with just rcu_read_lock(). setpgid()
indicates that it wants to check real_parent and needs the
write_lock_irq() because it might change behind its back which we don't
care about since we're not changing the pgrp.
Christian