Skip to content

Commit 2f82913

Browse files
xiongzhongjiangZhengShunQian
authored andcommitted
kernel/exit.c: avoid undefined behaviour when calling wait4()
commit dd83c16 upstream. wait4(-2147483648, 0x20, 0, 0xdd0000) triggers: UBSAN: Undefined behaviour in kernel/exit.c:1651:9 The related calltrace is as follows: negation of -2147483648 cannot be represented in type 'int': CPU: 9 PID: 16482 Comm: zj Tainted: G B ---- ------- 3.10.0-327.53.58.71.x86_64+ #66 Hardware name: Huawei Technologies Co., Ltd. Tecal RH2285 /BC11BTSA , BIOS CTSAV036 04/27/2011 Call Trace: dump_stack+0x19/0x1b ubsan_epilogue+0xd/0x50 __ubsan_handle_negate_overflow+0x109/0x14e SyS_wait4+0x1cb/0x1e0 system_call_fastpath+0x16/0x1b Exclude the overflow to avoid the UBSAN warning. Link: http://lkml.kernel.org/r/[email protected] Signed-off-by: zhongjiang <[email protected]> Cc: Oleg Nesterov <[email protected]> Cc: David Rientjes <[email protected]> Cc: Aneesh Kumar K.V <[email protected]> Cc: Kirill A. Shutemov <[email protected]> Cc: Xishi Qiu <[email protected]> Signed-off-by: Andrew Morton <[email protected]> Signed-off-by: Linus Torvalds <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent ed1f87f commit 2f82913

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

kernel/exit.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1619,6 +1619,10 @@ SYSCALL_DEFINE4(wait4, pid_t, upid, int __user *, stat_addr,
16191619
__WNOTHREAD|__WCLONE|__WALL))
16201620
return -EINVAL;
16211621

1622+
/* -INT_MIN is not defined */
1623+
if (upid == INT_MIN)
1624+
return -ESRCH;
1625+
16221626
if (upid == -1)
16231627
type = PIDTYPE_MAX;
16241628
else if (upid < 0) {

0 commit comments

Comments
 (0)