All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] pid: fix uninitialized retval in alloc_pid()
@ 2020-03-11  3:21 John Hubbard
  2020-03-11  3:30 ` Christian Brauner
  0 siblings, 1 reply; 3+ messages in thread
From: John Hubbard @ 2020-03-11  3:21 UTC (permalink / raw)
  To: Stephen Rothwell, Christian Brauner; +Cc: Linux Next, LKML, John Hubbard

Commit 8deb24dcb89cb ("pid: make ENOMEM return value more obvious")
left the return value uninitialized in one error case. The justification
for the above commit included a statement that retval is "initialized on
ever[y] failure path in the loop". However, that is not quite good
enough because there is an earlier case that is before the loop. And
also, it's more maintenance and merge-safe to initialize it once at the
top, as evidenced by this build warning that we now have.

Therefore, restore the top-level initialization of retval.

Also move the descriptive comment up, and remove the now-redundant
later initialization of retval.

Fixes: 8deb24dcb89cb ("pid: make ENOMEM return value more obvious")
Cc: Christian Brauner <christian.brauner@ubuntu.com>
Signed-off-by: John Hubbard <jhubbard@nvidia.com>
---
 kernel/pid.c | 21 ++++++++++-----------
 1 file changed, 10 insertions(+), 11 deletions(-)

diff --git a/kernel/pid.c b/kernel/pid.c
index ff6cd6786d10..49bf6dd32de4 100644
--- a/kernel/pid.c
+++ b/kernel/pid.c
@@ -162,7 +162,16 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
 	int i, nr;
 	struct pid_namespace *tmp;
 	struct upid *upid;
-	int retval;
+
+	/*
+	 * ENOMEM is not the most obvious choice especially for the case
+	 * where the child subreaper has already exited and the pid
+	 * namespace denies the creation of any new processes. But ENOMEM
+	 * is what we have exposed to userspace for a long time and it is
+	 * documented behavior for pid namespaces. So we can't easily
+	 * change it even if there were an error code better suited.
+	 */
+	int retval = -ENOMEM;
 
 	/*
 	 * set_tid_size contains the size of the set_tid array. Starting at
@@ -244,16 +253,6 @@ struct pid *alloc_pid(struct pid_namespace *ns, pid_t *set_tid,
 		tmp = tmp->parent;
 	}
 
-	/*
-	 * ENOMEM is not the most obvious choice especially for the case
-	 * where the child subreaper has already exited and the pid
-	 * namespace denies the creation of any new processes. But ENOMEM
-	 * is what we have exposed to userspace for a long time and it is
-	 * documented behavior for pid namespaces. So we can't easily
-	 * change it even if there were an error code better suited.
-	 */
-	retval = -ENOMEM;
-
 	get_pid_ns(ns);
 	refcount_set(&pid->count, 1);
 	for (type = 0; type < PIDTYPE_MAX; ++type)

base-commit: 134546626849cd6852d6d4bf8f207b5fbc54261b
-- 
2.25.1


^ permalink raw reply related	[flat|nested] 3+ messages in thread

* Re: [PATCH] pid: fix uninitialized retval in alloc_pid()
  2020-03-11  3:21 [PATCH] pid: fix uninitialized retval in alloc_pid() John Hubbard
@ 2020-03-11  3:30 ` Christian Brauner
  2020-03-11  3:33   ` John Hubbard
  0 siblings, 1 reply; 3+ messages in thread
From: Christian Brauner @ 2020-03-11  3:30 UTC (permalink / raw)
  To: John Hubbard; +Cc: Stephen Rothwell, Linux Next, LKML

On Tue, Mar 10, 2020 at 08:21:53PM -0700, John Hubbard wrote:
> Commit 8deb24dcb89cb ("pid: make ENOMEM return value more obvious")
> left the return value uninitialized in one error case. The justification
> for the above commit included a statement that retval is "initialized on
> ever[y] failure path in the loop". However, that is not quite good
> enough because there is an earlier case that is before the loop. And
> also, it's more maintenance and merge-safe to initialize it once at the
> top, as evidenced by this build warning that we now have.
> 
> Therefore, restore the top-level initialization of retval.
> 
> Also move the descriptive comment up, and remove the now-redundant
> later initialization of retval.
> 
> Fixes: 8deb24dcb89cb ("pid: make ENOMEM return value more obvious")
> Cc: Christian Brauner <christian.brauner@ubuntu.com>
> Signed-off-by: John Hubbard <jhubbard@nvidia.com>

Thanks. I already have a fixed-up version in my tree after Stephen
reported it earlier today:
https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/commit/?h=fixes&id=10dab84caf400f2f5f8b010ebb0c7c4272ec5093

(Fwiw, we can't just move the it back up. It needs to be set after the
loop too because it can be set to EPERM before. See
https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/commit/?h=fixes&id=b26ebfe12f34f372cf041c6f801fa49c3fb382c5
for the motiviation for the comment.)

Christian

^ permalink raw reply	[flat|nested] 3+ messages in thread

* Re: [PATCH] pid: fix uninitialized retval in alloc_pid()
  2020-03-11  3:30 ` Christian Brauner
@ 2020-03-11  3:33   ` John Hubbard
  0 siblings, 0 replies; 3+ messages in thread
From: John Hubbard @ 2020-03-11  3:33 UTC (permalink / raw)
  To: Christian Brauner; +Cc: Stephen Rothwell, Linux Next, LKML

On 3/10/20 8:30 PM, Christian Brauner wrote:
> On Tue, Mar 10, 2020 at 08:21:53PM -0700, John Hubbard wrote:
>> Commit 8deb24dcb89cb ("pid: make ENOMEM return value more obvious")
>> left the return value uninitialized in one error case. The justification
>> for the above commit included a statement that retval is "initialized on
>> ever[y] failure path in the loop". However, that is not quite good
>> enough because there is an earlier case that is before the loop. And
>> also, it's more maintenance and merge-safe to initialize it once at the
>> top, as evidenced by this build warning that we now have.
>>
>> Therefore, restore the top-level initialization of retval.
>>
>> Also move the descriptive comment up, and remove the now-redundant
>> later initialization of retval.
>>
>> Fixes: 8deb24dcb89cb ("pid: make ENOMEM return value more obvious")
>> Cc: Christian Brauner <christian.brauner@ubuntu.com>
>> Signed-off-by: John Hubbard <jhubbard@nvidia.com>
> 
> Thanks. I already have a fixed-up version in my tree after Stephen
> reported it earlier today:
> https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/commit/?h=fixes&id=10dab84caf400f2f5f8b010ebb0c7c4272ec5093
> 
> (Fwiw, we can't just move the it back up. It needs to be set after the
> loop too because it can be set to EPERM before. See


OK, yes. Sounds good.

thanks,
-- 
John Hubbard
NVIDIA

> https://git.kernel.org/pub/scm/linux/kernel/git/brauner/linux.git/commit/?h=fixes&id=b26ebfe12f34f372cf041c6f801fa49c3fb382c5
> for the motiviation for the comment.)
> 
> Christian
> 

^ permalink raw reply	[flat|nested] 3+ messages in thread

end of thread, other threads:[~2020-03-11  3:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-03-11  3:21 [PATCH] pid: fix uninitialized retval in alloc_pid() John Hubbard
2020-03-11  3:30 ` Christian Brauner
2020-03-11  3:33   ` John Hubbard

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.