linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] wait.2: Add ESRCH for when pid == INT_MIN
@ 2021-07-08 10:08 Richard Palethorpe
  2021-07-10 18:15 ` Alejandro Colomar (man-pages)
  2021-07-12 16:11 ` Jakub Wilk
  0 siblings, 2 replies; 4+ messages in thread
From: Richard Palethorpe @ 2021-07-08 10:08 UTC (permalink / raw)
  To: linux-man; +Cc: Richard Palethorpe, Alejandro Colomar, Michael Kerrisk

Please see upstream commit:

 commit dd83c161fbcc5d8be637ab159c0de015cbff5ba4
 Author: zhongjiang <zhongjiang@huawei.com>
 Date:   Mon Jul 10 15:53:01 2017 -0700

     kernel/exit.c: avoid undefined behaviour when calling wait4()

It avoids negating INT_MIN by returning early with ESRCH.

Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>
---
 man2/wait.2 | 9 +++++++++
 1 file changed, 9 insertions(+)

diff --git a/man2/wait.2 b/man2/wait.2
index 5ae955b3f..63d872ee6 100644
--- a/man2/wait.2
+++ b/man2/wait.2
@@ -455,6 +455,15 @@ was caught; see
 The
 .I options
 argument was invalid.
+.TP
+.B ESRCH
+(for
+.BR wait ()
+or
+.BR waitpid ())
+.I pid
+is equal to
+.I INT_MIN
 .SH CONFORMING TO
 SVr4, 4.3BSD, POSIX.1-2001.
 .SH NOTES
-- 
2.31.1


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

* Re: [PATCH] wait.2: Add ESRCH for when pid == INT_MIN
  2021-07-08 10:08 [PATCH] wait.2: Add ESRCH for when pid == INT_MIN Richard Palethorpe
@ 2021-07-10 18:15 ` Alejandro Colomar (man-pages)
  2021-07-12 16:11 ` Jakub Wilk
  1 sibling, 0 replies; 4+ messages in thread
From: Alejandro Colomar (man-pages) @ 2021-07-10 18:15 UTC (permalink / raw)
  To: Richard Palethorpe; +Cc: Michael Kerrisk, linux-man

Hello Richard,

On 7/8/21 12:08 PM, Richard Palethorpe wrote:
> Please see upstream commit:
> 
>  commit dd83c161fbcc5d8be637ab159c0de015cbff5ba4
>  Author: zhongjiang <zhongjiang@huawei.com>
>  Date:   Mon Jul 10 15:53:01 2017 -0700
> 
>      kernel/exit.c: avoid undefined behaviour when calling wait4()
> 
> It avoids negating INT_MIN by returning early with ESRCH.
> 
> Signed-off-by: Richard Palethorpe <rpalethorpe@suse.com>

Patch applied.

Thanks,

Alex

> ---
>  man2/wait.2 | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/man2/wait.2 b/man2/wait.2
> index 5ae955b3f..63d872ee6 100644
> --- a/man2/wait.2
> +++ b/man2/wait.2
> @@ -455,6 +455,15 @@ was caught; see
>  The
>  .I options
>  argument was invalid.
> +.TP
> +.B ESRCH
> +(for
> +.BR wait ()
> +or
> +.BR waitpid ())
> +.I pid
> +is equal to
> +.I INT_MIN
>  .SH CONFORMING TO
>  SVr4, 4.3BSD, POSIX.1-2001.
>  .SH NOTES
> 

-- 
Alejandro Colomar
Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/
http://www.alejandro-colomar.es/

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

* Re: [PATCH] wait.2: Add ESRCH for when pid == INT_MIN
  2021-07-08 10:08 [PATCH] wait.2: Add ESRCH for when pid == INT_MIN Richard Palethorpe
  2021-07-10 18:15 ` Alejandro Colomar (man-pages)
@ 2021-07-12 16:11 ` Jakub Wilk
  2021-07-13  7:37   ` Richard Palethorpe
  1 sibling, 1 reply; 4+ messages in thread
From: Jakub Wilk @ 2021-07-12 16:11 UTC (permalink / raw)
  To: Richard Palethorpe; +Cc: linux-man, Alejandro Colomar, Michael Kerrisk

* Richard Palethorpe <rpalethorpe@suse.com>, 2021-07-08, 11:08:
>Please see upstream commit:
>
> commit dd83c161fbcc5d8be637ab159c0de015cbff5ba4
> Author: zhongjiang <zhongjiang@huawei.com>
> Date:   Mon Jul 10 15:53:01 2017 -0700
>
>     kernel/exit.c: avoid undefined behaviour when calling wait4()
>
>It avoids negating INT_MIN by returning early with ESRCH.

That sounds like a bug in the kernel, though?

POSIX says the error should be ECHILD if "the process group specified by 
pid does not exist".

-- 
Jakub Wilk

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

* Re: [PATCH] wait.2: Add ESRCH for when pid == INT_MIN
  2021-07-12 16:11 ` Jakub Wilk
@ 2021-07-13  7:37   ` Richard Palethorpe
  0 siblings, 0 replies; 4+ messages in thread
From: Richard Palethorpe @ 2021-07-13  7:37 UTC (permalink / raw)
  To: Jakub Wilk; +Cc: linux-man, Alejandro Colomar, Michael Kerrisk

Hello Jakub,

Jakub Wilk <jwilk@jwilk.net> writes:

> * Richard Palethorpe <rpalethorpe@suse.com>, 2021-07-08, 11:08:
>>Please see upstream commit:
>>
>> commit dd83c161fbcc5d8be637ab159c0de015cbff5ba4
>> Author: zhongjiang <zhongjiang@huawei.com>
>> Date:   Mon Jul 10 15:53:01 2017 -0700
>>
>>     kernel/exit.c: avoid undefined behaviour when calling wait4()
>>
>>It avoids negating INT_MIN by returning early with ESRCH.
>
> That sounds like a bug in the kernel, though?
>
> POSIX says the error should be ECHILD if "the process group specified
> by pid does not exist".

The absolute value of INT_MIN is undefined or "not representable" in
two's complement. So I think this can reasonably be considered undefined
behaviour and the kernel can do what it wants.

Also, as the error code is different, we can detect if the fix has been
applied without UBSAN enabled (unlike a similar fix in kill).

OTOH, I would have probably used ECHILD for consistency. However it is
done now and has been in use for some years.

-- 
Thank you,
Richard.

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

end of thread, other threads:[~2021-07-13  7:37 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-08 10:08 [PATCH] wait.2: Add ESRCH for when pid == INT_MIN Richard Palethorpe
2021-07-10 18:15 ` Alejandro Colomar (man-pages)
2021-07-12 16:11 ` Jakub Wilk
2021-07-13  7:37   ` Richard Palethorpe

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).