* [PATCH v2] pid: Fix error return value in some cases
@ 2020-03-06 17:23 minyard
2020-03-07 11:00 ` Christian Brauner
0 siblings, 1 reply; 4+ messages in thread
From: minyard @ 2020-03-06 17:23 UTC (permalink / raw)
To: linux-kernel
Cc: Corey Minyard, stable, Adrian Reber, Christian Brauner,
Oleg Nesterov, Dmitry Safonov, Andrei Vagin
From: Corey Minyard <cminyard@mvista.com>
Recent changes to alloc_pid() allow the pid number to be specified on
the command line. If set_tid_size is set, then the code scanning the
levels will hard-set retval to -EPERM, overriding it's previous -ENOMEM
value.
After the code scanning the levels, there are error returns that do not
set retval, assuming it is still set to -ENOMEM.
So set retval back to -ENOMEM after scanning the levels.
Fixes: 49cb2fc42ce4 "fork: extend clone3() to support setting a PID"
Signed-off-by: Corey Minyard <cminyard@mvista.com>
Cc: <stable@vger.kernel.org> # 5.5
Cc: Adrian Reber <areber@redhat.com>
Cc: Christian Brauner <christian.brauner@ubuntu.com>
Cc: Oleg Nesterov <oleg@redhat.com>
Cc: Dmitry Safonov <0x7f454c46@gmail.com>
Cc: Andrei Vagin <avagin@gmail.com>
---
Changes from v1:
Just set retval to -ENOMEM before the gotos that would use it.
I do think that the second instance:
if (!(ns->pid_allocated & PIDNS_ADDING))
goto out_unlock;
is returning the wrong error value, but that's probably not a big
deal, and if it was fixed would probably need to be a separate change.
In the first instance, the error return values are almost all -ENOMEM,
anyway.
kernel/pid.c | 2 ++
1 file changed, 2 insertions(+)
diff --git a/kernel/pid.c b/kernel/pid.c
index 0f4ecb57214c..19645b25b77c 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -247,6 +247,8 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
tmp = tmp->parent;
}
+ retval = -ENOMEM;
+
if (unlikely(is_child_reaper(pid))) {
if (pid_ns_prepare_proc(ns))
goto out_free;
--
2.17.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH v2] pid: Fix error return value in some cases
2020-03-06 17:23 [PATCH v2] pid: Fix error return value in some cases minyard
@ 2020-03-07 11:00 ` Christian Brauner
2020-03-07 13:11 ` Corey Minyard
0 siblings, 1 reply; 4+ messages in thread
From: Christian Brauner @ 2020-03-07 11:00 UTC (permalink / raw)
To: minyard
Cc: linux-kernel, Corey Minyard, stable, Adrian Reber, Oleg Nesterov,
Dmitry Safonov, Andrei Vagin
On Fri, Mar 06, 2020 at 11:23:14AM -0600, minyard@acm.org wrote:
> From: Corey Minyard <cminyard@mvista.com>
>
> Recent changes to alloc_pid() allow the pid number to be specified on
> the command line. If set_tid_size is set, then the code scanning the
> levels will hard-set retval to -EPERM, overriding it's previous -ENOMEM
> value.
>
> After the code scanning the levels, there are error returns that do not
> set retval, assuming it is still set to -ENOMEM.
>
> So set retval back to -ENOMEM after scanning the levels.
>
> Fixes: 49cb2fc42ce4 "fork: extend clone3() to support setting a PID"
> Signed-off-by: Corey Minyard <cminyard@mvista.com>
> Cc: <stable@vger.kernel.org> # 5.5
> Cc: Adrian Reber <areber@redhat.com>
> Cc: Christian Brauner <christian.brauner@ubuntu.com>
> Cc: Oleg Nesterov <oleg@redhat.com>
> Cc: Dmitry Safonov <0x7f454c46@gmail.com>
> Cc: Andrei Vagin <avagin@gmail.com>
Thanks! I've pulled the patch now and applied.
I think that restores the old behavior. If you don't mind, I'll add a
comment on top of it saying something like:
"ENOMEM is not the most obvious choice but it's the what we've been
exposing to userspace for a long time and it's also documented
behavior. So we can't easily change it to something more sensible."
Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] pid: Fix error return value in some cases
2020-03-07 11:00 ` Christian Brauner
@ 2020-03-07 13:11 ` Corey Minyard
2020-03-08 17:07 ` Christian Brauner
0 siblings, 1 reply; 4+ messages in thread
From: Corey Minyard @ 2020-03-07 13:11 UTC (permalink / raw)
To: Christian Brauner
Cc: minyard, linux-kernel, stable, Adrian Reber, Oleg Nesterov,
Dmitry Safonov, Andrei Vagin
On Sat, Mar 07, 2020 at 12:00:07PM +0100, Christian Brauner wrote:
> On Fri, Mar 06, 2020 at 11:23:14AM -0600, minyard@acm.org wrote:
> > From: Corey Minyard <cminyard@mvista.com>
> >
> > Recent changes to alloc_pid() allow the pid number to be specified on
> > the command line. If set_tid_size is set, then the code scanning the
> > levels will hard-set retval to -EPERM, overriding it's previous -ENOMEM
> > value.
> >
> > After the code scanning the levels, there are error returns that do not
> > set retval, assuming it is still set to -ENOMEM.
> >
> > So set retval back to -ENOMEM after scanning the levels.
> >
> > Fixes: 49cb2fc42ce4 "fork: extend clone3() to support setting a PID"
> > Signed-off-by: Corey Minyard <cminyard@mvista.com>
> > Cc: <stable@vger.kernel.org> # 5.5
> > Cc: Adrian Reber <areber@redhat.com>
> > Cc: Christian Brauner <christian.brauner@ubuntu.com>
> > Cc: Oleg Nesterov <oleg@redhat.com>
> > Cc: Dmitry Safonov <0x7f454c46@gmail.com>
> > Cc: Andrei Vagin <avagin@gmail.com>
>
> Thanks! I've pulled the patch now and applied.
>
> I think that restores the old behavior. If you don't mind, I'll add a
> comment on top of it saying something like:
> "ENOMEM is not the most obvious choice but it's the what we've been
> exposing to userspace for a long time and it's also documented
> behavior. So we can't easily change it to something more sensible."
That's great. I was just looking through the code for another reason
and noticed the issue. Every little thing counts for quality.
-corey
>
> Acked-by: Christian Brauner <christian.brauner@ubuntu.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH v2] pid: Fix error return value in some cases
2020-03-07 13:11 ` Corey Minyard
@ 2020-03-08 17:07 ` Christian Brauner
0 siblings, 0 replies; 4+ messages in thread
From: Christian Brauner @ 2020-03-08 17:07 UTC (permalink / raw)
To: Corey Minyard
Cc: minyard, linux-kernel, stable, Adrian Reber, Oleg Nesterov,
Dmitry Safonov, Andrei Vagin
On Sat, Mar 07, 2020 at 07:11:36AM -0600, Corey Minyard wrote:
> On Sat, Mar 07, 2020 at 12:00:07PM +0100, Christian Brauner wrote:
> > On Fri, Mar 06, 2020 at 11:23:14AM -0600, minyard@acm.org wrote:
> > > From: Corey Minyard <cminyard@mvista.com>
> > >
> > > Recent changes to alloc_pid() allow the pid number to be specified on
> > > the command line. If set_tid_size is set, then the code scanning the
> > > levels will hard-set retval to -EPERM, overriding it's previous -ENOMEM
> > > value.
> > >
> > > After the code scanning the levels, there are error returns that do not
> > > set retval, assuming it is still set to -ENOMEM.
> > >
> > > So set retval back to -ENOMEM after scanning the levels.
> > >
> > > Fixes: 49cb2fc42ce4 "fork: extend clone3() to support setting a PID"
> > > Signed-off-by: Corey Minyard <cminyard@mvista.com>
> > > Cc: <stable@vger.kernel.org> # 5.5
> > > Cc: Adrian Reber <areber@redhat.com>
> > > Cc: Christian Brauner <christian.brauner@ubuntu.com>
> > > Cc: Oleg Nesterov <oleg@redhat.com>
> > > Cc: Dmitry Safonov <0x7f454c46@gmail.com>
> > > Cc: Andrei Vagin <avagin@gmail.com>
> >
> > Thanks! I've pulled the patch now and applied.
Applied as:
https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/commit/?h=fixes&id=b26ebfe12f34f372cf041c6f801fa49c3fb382c5
Should show up in -next around Monday and I'll target it for rc6. Should
then be backported to v5.5 rather soon!
Thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-03-08 17:07 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2020-03-06 17:23 [PATCH v2] pid: Fix error return value in some cases minyard
2020-03-07 11:00 ` Christian Brauner
2020-03-07 13:11 ` Corey Minyard
2020-03-08 17:07 ` Christian Brauner
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).