From patchwork Mon Mar 20 02:47:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13180691 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 91F52C7619A for ; Mon, 20 Mar 2023 02:47:55 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 568C6900005; Sun, 19 Mar 2023 22:47:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 518CD900003; Sun, 19 Mar 2023 22:47:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 4060A900005; Sun, 19 Mar 2023 22:47:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0015.hostedemail.com [216.40.44.15]) by kanga.kvack.org (Postfix) with ESMTP id 31CCD900003 for ; Sun, 19 Mar 2023 22:47:52 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id C1C8516054B for ; Mon, 20 Mar 2023 02:47:51 +0000 (UTC) X-FDA: 80587741542.13.AA6CE5C Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf10.hostedemail.com (Postfix) with ESMTP id 92139C0019 for ; Mon, 20 Mar 2023 02:47:49 +0000 (UTC) Authentication-Results: imf10.hostedemail.com; dkim=none; spf=pass (imf10.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=1679280470; 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=w42+SfSejOEvP90T6yloGYrurgPK1m3W+HVg6+rZo80=; b=AKbvmeLUKYTr4Ha9oAXoIJiGLjLXnpIS4+Xiz066O8xDHpZAixopShX6/fbPaBcSrTLVqM s0+G2F6mbZrEuhcP9oNbshe1mQScCw3QhSpLxTZfP46gkUemKAqyjrM01M47nPaaTBQdWX DI/ThavApJTM0BWIVg+fAIIToSEZAoM= ARC-Authentication-Results: i=1; imf10.hostedemail.com; dkim=none; spf=pass (imf10.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=1679280470; a=rsa-sha256; cv=none; b=5KJtPmjBiesja0DYFJOxtCmQxrsxGrFtcS/hDLxn7Lw7oHGOB2JQXDYMR5fl/l4wWpWjin eJfCuF+oZGroC2xq4rXXuScGyzC4bg88ART4mOMxZn7welAxHgeusxgDpl68Q1qmmxDtEv +/ui5fBwFxbGPaRVFyftjUi2MO/9QXg= Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4PfzbY6VtPz17MLF; Mon, 20 Mar 2023 10:44:41 +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:44 +0800 From: Wupeng Ma To: CC: , , , , , Subject: [PATCH v4 2/4] mm/mempolicy: return EINVAL for if len overflows for set_mempolicy_home_node Date: Mon, 20 Mar 2023 10:47:37 +0800 Message-ID: <20230320024739.224850-3-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-Server: rspam03 X-Stat-Signature: yxsmbg597ifx349wsyf1r77ceyof5awa X-Rspamd-Queue-Id: 92139C0019 X-HE-Tag: 1679280469-259001 X-HE-Meta: U2FsdGVkX18HoScugt43Leg5KfYK1hWKiccM91fHsTGg3qB+4Na8SSkvGeWuqbfsh7VVOgX0ffUOtrrP5jz6eCLSCr+s1Y4M8jyJ3nh5eP6BZB3syX8c+pQt4N4AVBEs/lwOa93x3HlDC8hjKPiv0y5wbhkFP5TjWNCQRAiVlsZhtKRm2SnH47hvBRuKwtnAFMRloHHDz5wwpLE68UpmNxA131qaQXauT1dKPFAggcvvKb3UBJ5shjqYY5lxIsKunPWDiODu9usc6fvoVo9f1cLWDscLEgvtk8abzEz/Y6vhj4KekZULUZojgwdYxg+4SjwetGdrvQ06lTSJH83UCTLauOoaskDCt10QaazsbQrdRYlCNP8XN4HMvof9P6IgA8IgfzNCTOIstiF/OUwGzG/kBBLhDTjYhycWvAdG3yKscwhoHRvPkCoKCMnKp9h8boQskY4OuL3v3m2t5BaZxfftyBAEdE9VJa+fQKNI5n7HP2pbHmWz+x+6dwwgpt9A4dLvaqlghkM1GH1pwe/24AZXvPQ/G1kEFuFt9LU6x570soa6R8CEbFpYPzIcin+DZ6fKMBpePG2d5qH/zYvgA1+D7nS7qEhSGSvlDL/CfosiI0SAT+9U2WNgv4ivZ21fOUMaefqkHyBSwfGzEzLTBd9B2EljM+SmtPYCOyVtAhWZD4izqiNxAqRtRTJXcR46/rf5oaFOtbAqMtl8TRh/j3UWUMgCxH4JbbBn6T5ILIpFggAi6rZhmLkKncanIGZcGjq9wQa6PZ4NapCgvdNE1SHkLXuOrvUNWA2XIs5msLL84Mr4hC8kKS6W3GsVUk4P6Ss1Nn173YY0dMvbXsk8rTaqUxNPLEFWU7dcaZyKdWlj2pxCeTc3IMrsyMVSCa4F0btdCvnZ7hmiHmuQjpBIh+nJ1/thzx5Rz89DlYi2WhUMuRffz+X+YUuDDq67ZUPqcmE4GAdzABVpmRegBlM vNGbOHuS cTh/h2wrxVMWZpjGlld0OZs7EbfzwMoeQvPoX23F0Hsx6guJbqOk1NX4p5dPufDbL/502OvDsMarMdEp/ZYyJDaWNZgPc5hf0aGnjQS+60hucY1cWMJyFtn8ydthMpkqGLN5lv4K8be2gHV1+aXNitRK5EMP/tbswLu0ykHGp2gLXHhLdrHzUeC1oGt0YsSgYNmcRZS5+fEeHA1g= 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 set_mempolicy_home_node. 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 a256a241fd1d..3a68998adc3a 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1489,6 +1489,7 @@ SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, le unsigned long, home_node, unsigned long, flags) { struct mm_struct *mm = current->mm; + unsigned long old_len = len; struct vm_area_struct *vma; struct mempolicy *new, *old; unsigned long vmstart; @@ -1516,7 +1517,7 @@ SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, le 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;