wait.2: Add ESRCH for when pid == INT_MIN
PATCH 1/1 wait.2: Add ESRCH for when pid == INT_MIN
Please see upstream commit:
commit dd83c161fbcc5d8be637ab159c0de015cbff5ba4
Author: zhongjiang <[email protected]>
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.
--- man2/wait.2 | 9 +++++++++ 1 file changed, 9 insertions(+)
man2/wait.2 +9 -0
@@ -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
Signature · 1 line
2.31.1
Hello Richard,
Quoted 11 lines · Richard Palethorpe
Please see upstream commit:
commit
dd83c161fbcc5d8be637ab159c0de015cbff5ba4
Author: zhongjiang <[email protected]>
Date: Mon Jul 10 15:53:01 2017 -0700
kernel/exit.c: avoid undefined behaviour when callingwait4()It avoids negating
INT_MINby returning early with ESRCH.Signed-off-by Richard Palethorpe <[email protected]>
Patch applied.
Thanks,
Alex
Quoted 25 lines
--- man2/wait.2 | 9 +++++++++ 1 file changed, 9 insertions(+)man2/wait.2 +9
-0@@ -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
Signature · 3 lines
Alejandro Colomar Linux man-pages comaintainer; https://www.kernel.org/doc/man-pages/ http://www.alejandro-colomar.es/
* Richard Palethorpe <[email protected]>, 2021-07-08, 11:08:
Quoted 9 lines
Please see upstream commit:
commit
dd83c161fbcc5d8be637ab159c0de015cbff5ba4Author: zhongjiang <[email protected]> Date: Mon Jul 10 15:53:01 2017 -0700
kernel/exit.c: avoid undefined behaviour when callingwait4()It avoids negating
INT_MINby 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".
Signature · 1 line
Jakub Wilk
Hello Jakub,
Quoted 7 lines · Jakub Wilk
* Richard Palethorpe <[email protected]>, 2021-07-08, 11:08:
Quoted 6 lines
Please see upstream commit:
commit
dd83c161fbcc5d8be637ab159c0de015cbff5ba4Author: zhongjiang <[email protected]> Date: Mon Jul 10 15:53:01 2017 -0700
Quoted 8 lines
Quoted 3 lines
kernel/exit.c: avoid undefined behaviour when callingwait4()It avoids negating
INT_MINby 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.
Signature · 2 lines
Thank you, Richard.