Received: by 2002:ac0:a594:0:0:0:0:0 with SMTP id m20-v6csp2053900imm; Thu, 24 May 2018 05:09:03 -0700 (PDT) X-Google-Smtp-Source: AB8JxZrp0t7KqSKpoZJG/qUxMqfLyNNttVGzbd6IT+U1/3o3hm2ligMyXj/1zDKT4LoHHjViR4KF X-Received: by 2002:a63:4281:: with SMTP id p123-v6mr4711209pga.144.1527163743600; Thu, 24 May 2018 05:09:03 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1527163743; cv=none; d=google.com; s=arc-20160816; b=UhUFgML+KHLs4IVtk222yp32pRcAt+E8jf29fXFbk577k6sXTYaNCDKuVLmorW0og+ WDgjSuIFJSgw2+QzvqHWOhvlCK/QrT6sdchSnCEcnpN1p/am77tKgFgqlWgESZvquR+U isIavq8C+AiadD5qP33dAYg4HMDR00NCgXSkalMFCEexgxARP+mm5eb009BTHDb7/x9d m8+/MN5jJdPO6rxWY71H0JjSY8pIs2gn37GlyUjFrmyLYxmdufPYSWSxO5nUFAq1Tjhj YRt/aClZt5UBghss74F5Mh0MCOfVsRWWX4LeXbQtv3S+MFQybsPEEXP9+x0bYeR8V4KN EH2A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :in-reply-to:message-id:date:subject:cc:to:from:dkim-signature :arc-authentication-results; bh=SoTpalWWio3yWzx9QuRiqJ20rTXX7ShQh1S7NX7qfmg=; b=u+RzV/w7VfUQZUSq8x7KivcoO8XA5Yq22F+FQY7Ug2AINB3LYD/HSYpRv4gOUM7IBI r9pppj/FTYJgd/pV383whYb27tRvFiGjK9ozLjkTEtkvm2pB1qjgywev2pVrUECgHAGz sbXnMkOhsVcPoKj7ta7eGgiXzGYyMb6GDt4auUUA4mfMubR00UDQw5+o2Et+zGuFqXTy vQumqz7C2JFGv7yeyIW91oNpllJ/KRFJFBQkIYF+nz8gmoPtwmg6DXAphL27olZoxK1U yWhxoXTuU+9TegmfG37ZwGH0C9RmouBhQDpa6E+HGjPQpv5kvCWAzHfYcYAe3P4xhCF4 +hTg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ROy5MLc0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id n14-v6si16538940pgu.688.2018.05.24.05.08.48; Thu, 24 May 2018 05:09:03 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=ROy5MLc0; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S969633AbeEXMGq (ORCPT + 99 others); Thu, 24 May 2018 08:06:46 -0400 Received: from mail.kernel.org ([198.145.29.99]:55344 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S966562AbeEXJn7 (ORCPT ); Thu, 24 May 2018 05:43:59 -0400 Received: from localhost (LFbn-1-12247-202.w90-92.abo.wanadoo.fr [90.92.61.202]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 34AC5208B5; Thu, 24 May 2018 09:43:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1527155038; bh=GK0VRnRPF/lBjs2Itr/tLfgRZKaI7pXZ+x3PCrleRss=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ROy5MLc0iwLIwBtBPGy5ssQrLxI2z0579z4GfrPEL/Dg52Zqtk3t9pj56RnQz1FJM G70GaENQXK+nWNB2qKifv1cTmeD/xGCrBveiAuYojoeVw5rPDtaPAU56zTzAS8uSOO 0tR3MQ6l9DqxRiTNqwfUyoe3YO4Uy+6hkXf51LoA= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, zhongjiang , Oleg Nesterov , David Rientjes , "Aneesh Kumar K.V" , "Kirill A. Shutemov" , Xishi Qiu , Andrew Morton , Linus Torvalds Subject: [PATCH 4.4 32/92] kernel/exit.c: avoid undefined behaviour when calling wait4() Date: Thu, 24 May 2018 11:38:09 +0200 Message-Id: <20180524093202.008627270@linuxfoundation.org> X-Mailer: git-send-email 2.17.0 In-Reply-To: <20180524093159.286472249@linuxfoundation.org> References: <20180524093159.286472249@linuxfoundation.org> User-Agent: quilt/0.65 X-stable: review MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 4.4-stable review patch. If anyone has any objections, please let me know. ------------------ From: zhongjiang commit dd83c161fbcc5d8be637ab159c0de015cbff5ba4 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/1497264618-20212-1-git-send-email-zhongjiang@huawei.com Signed-off-by: zhongjiang Cc: Oleg Nesterov Cc: David Rientjes Cc: Aneesh Kumar K.V Cc: Kirill A. Shutemov Cc: Xishi Qiu Signed-off-by: Andrew Morton Signed-off-by: Linus Torvalds Signed-off-by: Greg Kroah-Hartman --- kernel/exit.c | 4 ++++ 1 file changed, 4 insertions(+) --- a/kernel/exit.c +++ b/kernel/exit.c @@ -1608,6 +1608,10 @@ SYSCALL_DEFINE4(wait4, pid_t, upid, int __WNOTHREAD|__WCLONE|__WALL)) return -EINVAL; + /* -INT_MIN is not defined */ + if (upid == INT_MIN) + return -ESRCH; + if (upid == -1) type = PIDTYPE_MAX; else if (upid < 0) {