Re: [PATCH] wait.2: Add ESRCH for when pid == INT_MIN
flat view
From: Richard Palethorpe <hidden>
Date: 2021-07-13 07:37:46
Hello Jakub, Jakub Wilk [off-list ref] writes:
* Richard Palethorpe [off-list ref], 2021-07-08, 11:08:quoted
Please see upstream commit: commit dd83c161fbcc5d8be637ab159c0de015cbff5ba4 Author: zhongjiang [off-list ref] 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.