From patchwork Tue Mar 21 07:40:32 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13182342 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 966D6C761A6 for ; Tue, 21 Mar 2023 07:40:51 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 2F52B6B007B; Tue, 21 Mar 2023 03:40:49 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 1F3176B0081; 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 D754C6B007B; Tue, 21 Mar 2023 03:40:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0010.hostedemail.com [216.40.44.10]) by kanga.kvack.org (Postfix) with ESMTP id C4BF96B0078 for ; Tue, 21 Mar 2023 03:40:48 -0400 (EDT) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 9175E1C6CAC for ; Tue, 21 Mar 2023 07:40:48 +0000 (UTC) X-FDA: 80592108576.23.632F6C1 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf02.hostedemail.com (Postfix) with ESMTP id 4038080005 for ; Tue, 21 Mar 2023 07:40:45 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.187 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=1679384446; 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=ifVVFs5bwlnPk8NflEfbMhrEG7oBpaPnYOyIHSPKgkE=; b=4wAT03I0wIM9lEl7jzhjIJjcOH4bFzeBZ2R7OkFvnDz50HoovC0vTurdybD9Sybe8e5ZJN 6NLdsowAwfakMFPx5L0d5+Rq9m/rNJz+zeDt9MP3cJbd4fk5osXpCwBTwsiHfgDhZINot+ wSq/X4JybUgM0b+a0nAziK3x4FS8PQw= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; spf=pass (imf02.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.187 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=1679384446; a=rsa-sha256; cv=none; b=fPxRezvZ/CJcg0VuEKs0WGIUtsgDR6+96RODWKByrwZw84/nZ58Ro253YQVK5EXtOPgr5f tBiwfDEOo3uwqnnFPLfMwk8iVDG4s54KjUNCLtnut7T2Roa9KSyBPMxlJYDqTNNmM+b+ck mf2IfndXKKjTaMH4vQ/kjcBoVweb0X8= Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Pgk325l0PznYR6; Tue, 21 Mar 2023 15:37:34 +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 1/4] mm/mlock: return EINVAL if len overflows for mlock/munlock Date: Tue, 21 Mar 2023 15:40:32 +0800 Message-ID: <20230321074035.1526157-2-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-Stat-Signature: 781po8hjyedqcydbikwz7nda8ews4t1q X-Rspam-User: X-Rspamd-Queue-Id: 4038080005 X-Rspamd-Server: rspam06 X-HE-Tag: 1679384445-563328 X-HE-Meta: U2FsdGVkX19wBlzRHnoED2+aUxrCfoKLA0UdRIGPeDJkgmd8G6bkjHnBzprqOxdgj9NCkoGKz8vlpEoy36JEYRdx0FNKbIvfPp3PUY8mWly2I6XUkeDHprVqr63c0S8YlnrVVmuit3jFRwe06n8eaYom40T2lfStQ6ZZZFP3Zmu+rYtBSC/5jHndqCBIyqo6Gk2W7E3Tj1J2IPyIVl0EtnEEhV9rHC0fDVRGjc2FHbGwxdy7ev/Z6355RkVXVaZUq+DzUxpFcISkmOkSOuEmav4XobVt5WKkUiTYEOkgQ1Pm12V2wnEeCUyacNgol0oXo+0bHEmeLtc+ATrYdfXOamVA2lBS2LiEUthKco0ZO3C6B9zilLuGjvWQ0NwjAbolytUie29Hg4cpZWEf483iOAoE4rwgdWuQK7aLeDjwhp52d6Eci7v9kN6xTrM+vWMYP7tK/WfU57zvf4UiCT34T3MOSVxM1VQ4H1cQHeehtW0EPcC2giiR5RVnWVG+yCUlmuf7C0eNA3ZYk5w5yr//Gju3XZunpMasYKYean/G0nqdRU1pI+hZhvNDc+RkwCnUkH87wCmh6IAo0U7BTOasMdZ/UsN1Vxc78Zldx47RT7yZhG2cb0iMek6w8Y04AhNMZB9NRDHaCRmTuWFAIJHTM0yopEBUKJkevwQfLApZAdiVhTjN8vWE3QV3GA2+FYnbCx1RaQ+cgIqtzkyjZw1Lig7jeoN33WZe4hWragcuStw9s4CWNyqz82roLIGLPecl5Q1JyV1ToQrYbxJSwFJHHFzfTL2zL2PGefXc4AgIrNMachiJ/0Llsau4tul6KHzLwoREmIHY2B3z4Wy/mKJR8GvS1BskzKWm83K79RRSsy+pUDeOMLZxPJSHj9PQOPrd757gzGmMD5bJePgiRIxkKXDwUGRy/C5Z9mSvmJN+PwYr0GTT7t38gBrBTGvhTZzHmgNEcK0fBPVSRbDJsnq oO2HlEp6 iURUdxCZIJ4lM8W0occkrI4bcSAqKtWa5p133hN4ojmA8M01Vam/kGAF9CSedjzOokoP06Q7VOIaL5UjWG9tESBvdLRyC6vLonX8S61U8Kf7uV7reeC1XqkoVMEEcK+TjodJKvZctaUSPGksAH4wckVRX+/055paVei7A 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 While testing mlock, we have a problem if the len of mlock is ULONG_MAX. The return value of mlock is zero. But nothing will be locked since the len in do_mlock overflows to zero due to the following code in mlock: len = PAGE_ALIGN(len + (offset_in_page(start))); The same problem happens in munlock. Add new check and return -EINVAL to fix this overflowing scenarios since they are absolutely wrong. Return 0 early to avoid burn a bunch of cpu cycles if len == 0. Signed-off-by: Ma Wupeng --- mm/mlock.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/mm/mlock.c b/mm/mlock.c index 617469fce96d..247ce396bb16 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -479,8 +479,6 @@ static int apply_vma_lock_flags(unsigned long start, size_t len, end = start + len; if (end < start) return -EINVAL; - if (end == start) - return 0; vma = vma_iter_load(&vmi); if (!vma) return -ENOMEM; @@ -574,7 +572,13 @@ static __must_check int do_mlock(unsigned long start, size_t len, vm_flags_t fla if (!can_do_mlock()) return -EPERM; + if (!len) + return 0; + len = PAGE_ALIGN(len + (offset_in_page(start))); + if (!len) + return -EINVAL; + start &= PAGE_MASK; lock_limit = rlimit(RLIMIT_MEMLOCK); @@ -634,7 +638,13 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len) start = untagged_addr(start); + if (!len) + return 0; + len = PAGE_ALIGN(len + (offset_in_page(start))); + if (!len) + return -EINVAL; + start &= PAGE_MASK; if (mmap_write_lock_killable(current->mm)) 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) { /* From patchwork Tue Mar 21 07:40:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13182344 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 6D1AAC7618D for ; Tue, 21 Mar 2023 07:40:54 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id BA14C6B007E; Tue, 21 Mar 2023 03:40:50 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id AB6046B0080; Tue, 21 Mar 2023 03:40:50 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 955E36B0081; Tue, 21 Mar 2023 03:40:50 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 803716B007E for ; Tue, 21 Mar 2023 03:40:50 -0400 (EDT) Received: from smtpin12.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay06.hostedemail.com (Postfix) with ESMTP id 46E4EAC306 for ; Tue, 21 Mar 2023 07:40:50 +0000 (UTC) X-FDA: 80592108660.12.D0D8383 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf13.hostedemail.com (Postfix) with ESMTP id 0F0CF20005 for ; Tue, 21 Mar 2023 07:40:47 +0000 (UTC) Authentication-Results: imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=mawupeng1@huawei.com ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1679384448; 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=LZoH2w5s6OPqiVIbWtngsm1X7CcIHW5TjC17/SGlsQg=; b=FsyEZUmzWYx8E/D8G8Tj79JiWLiJLIIdRLu8dT9DxsMCJIvR0z/tjnvyqV4nEBOY5F5b1j VQD9a8oFSNSOEwCVmsJ6ltaZjtiq33VzwJQI18HMz7aZqOGRgisT740GXkjprOD6viS2Ao sRR14uIAJEY/zqkyZjJxXFQ7EK1iHSE= ARC-Authentication-Results: i=1; imf13.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf13.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.188 as permitted sender) smtp.mailfrom=mawupeng1@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679384448; a=rsa-sha256; cv=none; b=EhXqunbPIRg2gSSLZYTNtDgIWdpAa4FbsAtcOsMecuAauBQi+X1HeB/r8ZxCfFOYcWAV9A XnEw8Q8rjL5SHnnTKxh9WkPOKCKFPy++RyxSwlWzae9Yq+vDKc58FgJnd1hjmDyearsY89 SdZVnHTRbeKy5uCEl9X3AqHC1ovORlA= Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.57]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4Pgk411GCCzKsdc; Tue, 21 Mar 2023 15:38:25 +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 3/4] mm/mempolicy: return EINVAL if len overflows for mbind Date: Tue, 21 Mar 2023 15:40:34 +0800 Message-ID: <20230321074035.1526157-4-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-Rspamd-Queue-Id: 0F0CF20005 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: 19h3roqy4q3b5geysgiixnokibtufuq9 X-HE-Tag: 1679384447-749064 X-HE-Meta: U2FsdGVkX1+lWtZuXtmr58jsp9LFcSz9cBlTdaQiezmeieT769NAWMXsRuJ2UZTqJD7MYyICOmH5QCgRBxUu/D3z7l5t80XCieKqDWycarba68+xqmCoazRE7X72HeNRXeaqVcOGiq/88vtGQQ7qtFTxPwcL7cW1gxqoixZOWMCrI16Fd88oVdw7iL8n0yl66stWLU6GSHvOpvECC8460niw5H9tkOt5HgHmynVQTRtpJ1pn4/bYPu4hvBvrhBI+Gcj2EvxPn8uDYuCbYBoh+m8ze0v5sea/fDgLxam60+Oa4uAYvmP5iSJQo+yat+zxSsj2b3IOh28q4RrGFB8aIhR90RHm05niNOeehEDaev6S5Q1Vzam5vg6Yk3mtBoei6BKN1JuNQHVMbePzYPAZBWb8ZWiOrU1glE6t9RhxQ2fOnhhIxMKUKQFHMoBSh1QChfrDRf4aJJcWvSZlAMuV7r06Jtaon36jU1koPqPRsTrrxvSn3pQXfkk/I3mhyC5uczAsKnAC7MgHhtF9NmX6ShmE1vug+K7UgZRIbbUU+77p9fyTIsgQ4N9El/lDUibH9RdT//3xWoiTzQAJbH1kl95fIezpIxGonqaRvaZ76n5n+PSFjF+9g/X2QEQaXJaOVAPSVpeZOkcQI2lYV4JftrgWDDd2g0Zmw41d2eo4jjSedlQfjNUPJV8Qt3zR/HkOCWH3Cj4+EnXwSWI8ikFNhYmVXPQho0cgu1YMP+ti7vNebpsDU8WotJak+hhbQh0U3xaswNY0r2imwwXs0PX7sCpKS4sGInrIu6J2phRceI7glpf1jIJjujEbuEQha7Kw8c89Kq5w7HGpegIkDIRTsOqXzGkVVmyZx0djF5GF8bqtsjk4N0N2Hhp16zqVZSdlPD3sSUJ9JF6+RXbP5cES2kCH+Dq0inCHoyNeoetwEJgI11SufeCCrKBdfcTBgfqXMH46zgD8jstUdtxqECZ 4L4FXybC ujbvpM6YxpfouvgLsaj0u7L7apc3omNEaYNgGywkxArz7SlI8f9Iuxzj9T9eBM89akC4YuTmVyP60egH8J7x/oYCbb3Iinth6BR7lF5gmFRJRnYvPdrYy9gzyowIMk9udP319Ph9gOx2qWF+99cKHY1599bMbLpJZ1/1E 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 mbind. 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 0a596c6cbed9..134fdc1f6c87 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1276,13 +1276,16 @@ static long do_mbind(unsigned long start, unsigned long len, if (mode == MPOL_DEFAULT) flags &= ~MPOL_MF_STRICT; + 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; new = mpol_new(mode, mode_flags, nmask); if (IS_ERR(new)) From patchwork Tue Mar 21 07:40:35 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13182341 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 CAE45C6FD1D for ; Tue, 21 Mar 2023 07:40:49 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D88F76B0078; Tue, 21 Mar 2023 03:40:48 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id CFE8C6B007E; 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 B78006B007D; Tue, 21 Mar 2023 03:40:48 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0011.hostedemail.com [216.40.44.11]) by kanga.kvack.org (Postfix) with ESMTP id A85EC6B0078 for ; Tue, 21 Mar 2023 03:40:48 -0400 (EDT) Received: from smtpin30.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 680311A1259 for ; Tue, 21 Mar 2023 07:40:48 +0000 (UTC) X-FDA: 80592108576.30.05D8847 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf06.hostedemail.com (Postfix) with ESMTP id 4106018000A for ; Tue, 21 Mar 2023 07:40:44 +0000 (UTC) Authentication-Results: imf06.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf06.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=mawupeng1@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=DILtil9sUTcMprPNjXAc27/NnwwI86Xvi8O8VeB6SPg=; b=G7HLa8apFBx/og7u69vKbAgzAea+uop+1T/Y8GXm/jQ5LTWV6wsZlL8UqgV6eo/tv6dhtJ Mp9teAmBYq1G/+4Bw8mndzY9k0OgIRNtbeoOPcbaF0d1ESS6ZBRhUNLxc8qcppJmLX1aK/ kJXkFdpchQB2pNLHDbPoEM3xNGSh3CA= ARC-Authentication-Results: i=1; imf06.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf06.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=mawupeng1@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1679384445; a=rsa-sha256; cv=none; b=xX2krdbnNBPnJFBGZEYGLRtx8os5cIpAiCQXEjOX8T8O6dlx/3kC08/1q7gCAqI/zZDMbt GzbrQNA1dKggV1MisVFt3KoLuXJ7qjZ8P1CaLuJ/ahqjqf+9yiQJT9L7SFVpPyL0zXoNnn G2640j7/Blvi8WPXb4Jwm4CijlBosBE= Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4Pgk5T6CpMzrVn4; Tue, 21 Mar 2023 15:39: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; Tue, 21 Mar 2023 15:40:41 +0800 From: Wupeng Ma To: , CC: , , , , Subject: [PATCH v5 4/4] mm/msync: return ENOMEM if len overflows for msync Date: Tue, 21 Mar 2023 15:40:35 +0800 Message-ID: <20230321074035.1526157-5-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: rspam04 X-Rspamd-Queue-Id: 4106018000A X-Stat-Signature: oombdbxtdh57r86ysq688dbx4bak6phh X-HE-Tag: 1679384444-247679 X-HE-Meta: U2FsdGVkX18XkzVSFJfye7A+9aap0lGBcbCHrSpaYKxcQh6EvTlPNowLhyDi0/4PD+uq8r0BmKEFsGOmWOl6hlG96KExoXz4F9L8Dl6ElWtogveIxvzvFMMXkj+bvIXT3pgdLsBeAPy48ta6TPwBMKzpzEaUFxMWsxtkmSk/2HSeI+PvifbNeMvWBphA/pmQQEq9PBDP59GohrFRhq09v9OVmfOWHXOPE6e5He7KJk1b8K46S4pZQJbTVcjXK1L/iLgIplCIW3bYiEfsX+g4hQQb71sIISm2tnIY/E3mXziOCaGCbYozlQOsYpqWiSxnua81vtaOx5vQUUNJ2j8hoeeTBgIg3+G9jRn+Ip1IPe6ZqqIJTf4BN+8f2+EiifKq2sR4Sfk8zs0HtAF02I6txH9FpQrz0UouU8EJHww2ZA29liFKZ37htqopsBA342Qru08RZtyDWObtM5n1ThTGwK19e7A6nGbD5aOphxiF98lOERU3zEYLbe2wXfmYCOxSGctQdJAsTX23mnr//yEHp4jh+phFG6tjUJNMIEs1DY3dqYJA9Jb5w/1puqP2LK7yEBVw3VT2dQZ+UEh7Yx6wGTJY2imcOtv1g771o5+hmSKymk1JbrKxRvyBuAfUr4GNOPoigZYcLeAUAZOMrqzCB24y9eUb+pPSkLvrerFkvT08rFDW0L+9M/QZi+hid6nsSWUFVc3LSDXCGQARgf7O9NyRg15IYPVUfxn4usoEg5h7stBAV3/aqNbK6m3wYkTjFzRJm/rQOhd3CWz/qCupd8gtVxyhZkBpIaJg/VtYzpapnmhOS+qaDhAXnhEs78w3MM7BG+Ohw8yxBpOFusgR0vANQBjPNv5UwCcIAJd6tnJ2DJHNNqfk4ndxM2hmDkmPnzgXwln/oILkaBosicdp3JMyM1SHcnYAZ01SI6M9B9zDl0OCCW7IqvoqR93hkJxvdD9TB60iLn/ZDluGvg+ gk3VTt4x dBeCmDrpVBzkyQA0G6/+sY9Nb/ffzGLDwYo0XG8SkB3gChz+hEMyMpVcWyppPGv/L45zVN2mEuLa761TbBKwNSj2Ma3O1k5FL3MxJCgVTbISPZAixgIeKL5j8vEi7f3/5cj6OWvWj2qU/pfgMn2Wdwpz4wcKnLzzO1f3F 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 -ENOMEM if len overflows for msync. Signed-off-by: Ma Wupeng --- mm/msync.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/mm/msync.c b/mm/msync.c index ac4c9bfea2e7..3104c97d70d3 100644 --- a/mm/msync.c +++ b/mm/msync.c @@ -46,13 +46,16 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags) if ((flags & MS_ASYNC) && (flags & MS_SYNC)) goto out; error = -ENOMEM; + if (!len) + return 0; + len = (len + ~PAGE_MASK) & PAGE_MASK; + if (!len) + goto out; + end = start + len; if (end < start) goto out; - error = 0; - if (end == start) - goto out; /* * If the interval [start,end) covers some unmapped address ranges, * just ignore them, but return -ENOMEM at the end. Besides, if the