From patchwork Tue Mar 21 07:40:33 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13182340 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 D4365C74A5B for ; Tue, 21 Mar 2023 07:40:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 33D856B0075; Tue, 21 Mar 2023 03:40:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 2C4F16B0078; Tue, 21 Mar 2023 03:40:48 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 1652C6B007B; Tue, 21 Mar 2023 03:40:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0017.hostedemail.com [216.40.44.17]) by kanga.kvack.org (Postfix) with ESMTP id 041416B0075 for ; Tue, 21 Mar 2023 03:40:48 -0400 (EDT) Received: from smtpin02.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id C51C7A111B for ; Tue, 21 Mar 2023 07:40:47 +0000 (UTC) X-FDA: 80592108534.02.216C009 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf14.hostedemail.com (Postfix) with ESMTP id EAFA2100008 for ; Tue, 21 Mar 2023 07:40:44 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.188 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=1679384445; 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=tZ/kR2wcz7OzwxjqgLo3MSm3QJMSybjvIWPNSXSCM9E=; b=k8nnZPDVD/QOR4yDHZH75s9YTO0/hk9wbfSF1/DJ99XnfKPrX686eHMY8oVK4hHUj9riky Sq3HZ/wK+H8ECfsgXAvqLzjCpJoeRPEL7TWxymJGy+YRSKR8LA8awyN9iQJeQSs2InBQss k94ImPWUlA4hGnJF/oRfb2nS0sTsJuQ= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; spf=pass (imf14.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.188 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=1679384445; a=rsa-sha256; cv=none; b=HH2VHUs9bVmugOYPzw9GqtDUvqbetByZpmZEkGVnty6Ru00l+97BBi4O7Jfc6TQrI+1LdR PV7ZWsR2cjVYaQlA3OV1Oz1e2woW6OiZwmkBG+1vgcUjk22JsYmbVPgqOKx58FtAeNxpI6 78iX/tYuEtsdEfpo/2nyAZHxsVhTVME= Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.53]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Pgk4051K4zKsPT; Tue, 21 Mar 2023 15:38:24 +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; Tue, 21 Mar 2023 15:40:40 +0800 From: Wupeng Ma To: , CC: , , , , Subject: [PATCH v5 2/4] mm/mempolicy: return EINVAL for if len overflows for set_mempolicy_home_node Date: Tue, 21 Mar 2023 15:40:33 +0800 Message-ID: <20230321074035.1526157-3-mawupeng1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230321074035.1526157-1-mawupeng1@huawei.com> References: <20230321074035.1526157-1-mawupeng1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam03 X-Stat-Signature: mmtxe3i4e85scmbb971ya75j38bm88at X-Rspamd-Queue-Id: EAFA2100008 X-HE-Tag: 1679384444-933718 X-HE-Meta: U2FsdGVkX199aOzT0YmKyqYL0Qc1AUh4QNjaxp1vG5ynHkQe9AzcnEMBdng4qAjl1eZ1aRxynoSYD9nReBNf1PjWsEvB/ptgpO8DPavFNNfX6Tif1yJ2YyhYxeNs/hOuLimnbWTYhi3vs3fK2Ki8DKiM7tKht7oLeXVcwDcaCr8iGKRAC/CP55OeiejR7gFmwHFphI+5H6XwVeNJK8pifty9zHzVNBE+GglAxzlK7q0gVmqq1I5w25yE6f9MLolQy6Xt54gCOh3Qt8L6BOEnrqKuszrI/m4KZOMQ57NSw7hAjJqw9r6wAAJSGRgWtjtYbu3pxuolcaHpcAQt3F7KYrOlMAyEoUs0sLEWSJwiOfC/tA/m6Y4SqeVgImnud3vDPkPCe3jO8oZE+OxeiGr3PQieRq44gJ5cZW04y6aERVEz2rr5IcnQFP+iknzN10Ws5LP35fgnMQsyixUhNCURfs6s3NS4uJnxbSYztDx7Mx4/AK4KHsa31AkDam0x1rgOYjI/ZqsXBG+r5e3BtkqkIH5GPRX/UqmerlMjorYRCuGo2JeizdG5mUC2dkrJsGb5Su3HzqNOGzld75U+/kPlWsX9YLlFE7esIUBYtUd0NyHyhRvJt89XhsvcXV5eRMaVAUmwR/bw+IOl4V2tkdREhXPOSJJk43v4OGM1q5u4eiVxOyHzU2k5L7yX6qy1oqVbHAbCvZJk429xz6kX30rQruSfuQwbDAXDfaHmksdjQa+CNTDpjAK75K2ajEe691TjjZrFy0xDjT/guLuDXsn9z6LKtxf5EhYOfrLHz7HzDlCrAwj8X1DCkUXlCIuetkbvmG+zcNGNeQm7jLNPg4XEOAwX1jo/rp4pPp3MBfPomKYlrHtH4hDHp8f0JTE1Fc/IZ6IReh+WgU+KGLVfBVTy6RdkoAiEurd1NZtA6gSEd56U16+mr7Db7syLiXoQhSfk9ZOJtqSNDvmF+bBgfpX ZEmBMPsp jZe18f/H5Ws7JOWEsSkJ7XAUglOmIjXf0WxBrwNMERstQZTIsWhqk+0am4mPtqQ1FtVfZtNBHgh3UJWEf0s4eZrTUKoQD8BZGmakb8HLN1tFEu5m2aJjlkfNLPCQXfIvDf7DVdv3mxFfcrr0F6lkba+9E/2aTRPxijPnKpjcubWX1wIXLZZc6tKYugLclo+SkP/0k7vSlpB4dAqVlbhSId5TZIQ== 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 Check and return 0 if len == 0 at the beginning of the function. Return -EINVAL if len overflows for set_mempolicy_home_node. Signed-off-by: Ma Wupeng --- mm/mempolicy.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index a256a241fd1d..0a596c6cbed9 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1513,13 +1513,16 @@ SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, le if (home_node >= MAX_NUMNODES || !node_online(home_node)) return -EINVAL; + if (!len) + return 0; + len = PAGE_ALIGN(len); - end = start + len; + if (!len) + return -EINVAL; + end = start + len; if (end < start) return -EINVAL; - if (end == start) - return 0; mmap_write_lock(mm); for_each_vma_range(vmi, vma, end) { /*