From patchwork Mon Mar 20 02:47:38 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13180689 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9E9F6C6FD1F for ; Mon, 20 Mar 2023 02:47:52 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 8739F900004; Sun, 19 Mar 2023 22:47:51 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 7FD90900003; Sun, 19 Mar 2023 22:47:51 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 69E4F900004; Sun, 19 Mar 2023 22:47:51 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0014.hostedemail.com [216.40.44.14]) by kanga.kvack.org (Postfix) with ESMTP id 54A08900002 for ; Sun, 19 Mar 2023 22:47:51 -0400 (EDT) Received: from smtpin19.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 18F1F1C5F0F for ; Mon, 20 Mar 2023 02:47:51 +0000 (UTC) X-FDA: 80587741542.19.CEFD1A0 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf04.hostedemail.com (Postfix) with ESMTP id 8C68D4000E for ; Mon, 20 Mar 2023 02:47:48 +0000 (UTC) Authentication-Results: imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=mawupeng1@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679280469; a=rsa-sha256; cv=none; b=2j0sMiiYYak5Fw+5kzGg3hTXBbESIdd9ROBeA/B2IZ+iFlWGApVpGmxedo82A1ZBvdoVjO bsR6Y1XnyJ0kSUNoEBCjr1zifoi+2vX8cWGTYOysselkPsl6rAcYhjQr0rN1yD03Yi5FTJ wdHPRIyfkKvjiPhVVBBpeZ2rwFKTYR4= ARC-Authentication-Results: i=1; imf04.hostedemail.com; dkim=none; spf=pass (imf04.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=mawupeng1@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679280469; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=xrR6Vz5OJ69Puj4GdEzkMxibWO2+u+Xn2wcSgiONoa0=; b=Q7O5j9EpzuyVh2T/jwrXY++MHDoLNzx3QQOcRBrn66S3kQInUCHCHEgy5OrnzhCZmG0dkP D7T1XqCV8+GR1r31FCNQuEkmaed3ri+P5OGrulILxPY5XqoJVPfqbK8MF/pSuifZ5gVypa DhHGCXvPuRNTeApi6Nvf1SZnnEnVMyw= Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.57]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4PfzbZ2WnGz17MLK; Mon, 20 Mar 2023 10:44:42 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by dggpemm500014.china.huawei.com (7.185.36.153) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2507.21; Mon, 20 Mar 2023 10:47:45 +0800 From: Wupeng Ma To: CC: , , , , , Subject: [PATCH v4 3/4] mm/mempolicy: return EINVAL if len overflows for mbind Date: Mon, 20 Mar 2023 10:47:38 +0800 Message-ID: <20230320024739.224850-4-mawupeng1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230320024739.224850-1-mawupeng1@huawei.com> References: <20230320024739.224850-1-mawupeng1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Queue-Id: 8C68D4000E X-Rspamd-Server: rspam01 X-Stat-Signature: cwnq7y8iex8iqukk71yghubbrw3eded3 X-HE-Tag: 1679280468-609923 X-HE-Meta: U2FsdGVkX184Z2mxMV5xGYXaIWuAeXoLZuq0THyGz4+ghMNTJ8F1yC07S/RhTvt+0w7XNTOdRuaFb/apOl+OXZrprOZgM4/AkvE2tW/5Rs89yAftGKusbCCjxT2cc7JVNfnGqlg3gNx8FQlUiZlFcQk3JEWW/0/ZP30kH5/Wj3SexyXT2Xy38Oq6VjQJ80J6sBGKMuSiX15FSyFsDN755mSZqL2NRaPAStPD84Jtk4HZxt+HekHiK4ai4rQCUvNBcf458Ofs8EoALIC0KKC7a4Jnmxdu7alnnqX+/b1vs8+RwmSBbJh49KAFS1ueEyK8f7YTQ/c1psnRmKxDgra+8vnPiahEkv5KXg+DGiKZkA9qedI2J2U5NoHgbO56vPWhNem6Uw3K2DuWj47LM1NSNSdDEGwWruNJSh/lWRvSlPtyhudVeVqDDzwveqbvzw2QB99ghtrD1eyIIakkw7/RwlYhF8oG6UdULZ4gh6PstCM4tFRLH1K5W2Y80ejKzx0Am+Hc65+m+1u7t2LFeOMBV0xLVpBEGp37TT1luMoywTpYRInG9N8QkX4oYF10Wifn576oVCBI8PDeheScHiW1zIKkIyvEC7tQTar72RUK6i28BvFBpsBB3jBEBQdccifZ3rznWTieyKVydbmcCXFYkAuI1uMX4enxl9IccEQIobP8SZ90sfYF8ael0AH7ruwYMC+oxMNAtijbWla/WnXZ/6blvZAGNhqW19aGegEpxMJSjxsxAeiEpqvbdRjuOmfS4RtpoXX0NghBq8L6ETtBakhmRb8HVLoWuCV7sJpb42X+xAEdyEya7TyYqJ6nuXVjlfXXpCsCTrn1YM6vbQ/TJ245GhQW7kcQ5pquIIpHMS95ODa08kxOtCB8qqLjXgUF+BRtYS72DNP6npoCY/hyh+RKiAJJzHKTVipPx3Xs8BkWCzMKAwXFinVZGMT0iZYG5XA1gsMmjjFlH5hFfMv UfJuTtTN u+CvQkq4vvxC6DHh60hzIv5ndCMIBqE0gscwjnHKVqrvxYO/Edkg+MZdiMQ+dAT8zHgF+BI0riqVduUXg1Tnhl5MH8K3wOuvRDUWD9DkVFw0tc4RCk1gGrkqKCuR2UpPIWIPs22TRfToaNl8yq5gqGiRbPEKFEEz4/+Zk X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: From: Ma Wupeng Return -EINVAL if len overflows for mbind. Signed-off-by: Ma Wupeng --- mm/mempolicy.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 3a68998adc3a..6b1c45021e48 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1259,6 +1259,7 @@ static long do_mbind(unsigned long start, unsigned long len, nodemask_t *nmask, unsigned long flags) { struct mm_struct *mm = current->mm; + unsigned long old_len = len; struct mempolicy *new; unsigned long end; int err; @@ -1279,7 +1280,7 @@ static long do_mbind(unsigned long start, unsigned long len, len = PAGE_ALIGN(len); end = start + len; - if (end < start) + if (end < start || (old_len != 0 && len == 0)) return -EINVAL; if (end == start) return 0;