From patchwork Sat Jan 28 06:32:26 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13119698 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 7F2E4C61DA4 for ; Sat, 28 Jan 2023 06:32:48 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 09F136B0074; Sat, 28 Jan 2023 01:32:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id E35A86B007D; Sat, 28 Jan 2023 01:32:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id B9DBA6B0074; Sat, 28 Jan 2023 01:32:46 -0500 (EST) 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 A4AF36B0073 for ; Sat, 28 Jan 2023 01:32:46 -0500 (EST) Received: from smtpin27.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay03.hostedemail.com (Postfix) with ESMTP id 61E53A024A for ; Sat, 28 Jan 2023 06:32:46 +0000 (UTC) X-FDA: 80403239532.27.07C3ABC Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf14.hostedemail.com (Postfix) with ESMTP id 9C00610000D for ; Sat, 28 Jan 2023 06:32:43 +0000 (UTC) Authentication-Results: imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.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=1674887564; 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=h6vKwVSyY7W55m4AzSw5Hc6HyhqCneigCqCcnvDYSf8=; b=wNmVmcEuvckTH/9kzHMnZ1zpx4UXiVY8IvqaTo6xJFsjWspYMSGsr2QtLDv8d1MeMt79HI +1BjPIWC4/0rTpN5hSOJMvZ11nrrpLfFxy7ll0oS7xcKwfEtAKS6oWjFXlXteV8s7tRCJp xQAGvOjIFncABnX4LAwxUwMOpypKNps= ARC-Authentication-Results: i=1; imf14.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf14.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=1674887564; a=rsa-sha256; cv=none; b=HOo7zUhTa+rOqKRyml0MKXF9zmI+opeNhlaTEIUtujYVEX/2zIUi4hjlZ2zEbTUM4v3TsE AZbQJcdj7LdS68c8LeC6KlElNkPEbJWNQfwh51EKWJXnLuyjDB5qmzNsaN2E3U4rmBCETA 9Y6qbvohhoQrhsXGMRFSJOIHI2kBNOw= Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4P3l1g6WJNzRrCW; Sat, 28 Jan 2023 14:30:31 +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.2375.34; Sat, 28 Jan 2023 14:32:38 +0800 From: Wupeng Ma To: CC: , , , , Subject: [PATCH v3 1/4] mm/mlock: return EINVAL if len overflows for mlock/munlock Date: Sat, 28 Jan 2023 14:32:26 +0800 Message-ID: <20230128063229.989058-2-mawupeng1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230128063229.989058-1-mawupeng1@huawei.com> References: <20230128063229.989058-1-mawupeng1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 9C00610000D X-Stat-Signature: 6ficxrak3c8ujpa6388mbtpofhn5z5ze X-Rspam-User: X-Rspamd-Server: rspam08 X-HE-Tag: 1674887563-503317 X-HE-Meta: U2FsdGVkX1+yXNehexG6uK9KixoVoPoCyR0BPwQqswLARzEJWXCKNt2jldvAXsPrWYmhgUwE/u7m+MoIxiHTylDEq1xX1DNbRkK4ie2hQyWofHrLoAaT3v5rWwNC7QK1GES3WeQLgI+g0HI5n6drSs9e46PzkjLCi3mAl9Jwlwx209SJuhs6L62ncUMTYUK0moVoQiUuuyqU7+AbNuKuKy8SwUGPRijU9oCB+QeNlupwC7NUgzBj6rOG2uGM8m00l0kYIs80/J7v5lj7jkDy8uFex+B5c36B1CVc4ddhbh1BY2Ql+ZwaG9dWUI1etDH0sCWVZzobziEmC7WMFsz65rzGK9h+Vl//6kSeNboFfg4XlQEwk7Fu0yGp6ZhjGcOv61GaANxzzZ5I0uZAMrLTh2Q90dOyYgchmm8wAndkRT80lJo082eBz4FADEDs6FHpM0oSfC1xOWuJIshl1/Q3+YrBH4tRfu2RN0panUl/Yadi+8IwEx46OLxCcwF9f07OpNQ3MJfrUentTojJ7CmMZ1Xyn1YwlGKu8zzRefgY7NEdTwK+aVojHrQXrCAgTcOGo962LI7pCdli+jGXl86mIS3e5ynM3vbvJ0yn2gqEYXBbeIRlP4T2f1dLEjN4J4Lt1pWgD8rzUeQa8yBLWHizgm/JecAk7pbmvuU6OCnu0uRQKrW8lqqxVudQZ4x2vxYvcWcMMG8WOxZoj+2eySaWHaPYgnXHfLrSsceypBl3JF2ptBL9gRLlTxAF76hr0Fzz4vYqEDrbGhahR/2sml+QG20EJgqGFrKuzTvUtLY9x6HReEVRb54cLRzzlwzVLHxmokqIMCnGfRgfBdljz2iWvS+zhOXN0E10dc+5bpOdsnPbCHLglio/HBXKQBUZIlazvWB/JlIKJvpbsf0Be5BCdknkFYwuvnLS74C30DiqX0C+c8KoxJFmTMZhLwJvKMhDECz6a/U7JeRXm+a5kda 4L/D7T4h T37e9rnjHckJ0AlphsDDff5Exq5fQ/m6KplIsBVlh+Isxeuc0cmhf0XSh9kPRpeHie8+tOqSPs6Qd2ag5lji8j6XX8NHbXUPi0c13/a73yC5BSlVwtROza+AC1Zub0QFJu5j73cJVsBQ4aypJ/jscSXMBbXqQOlHtjXv7 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 7032f6dd0ce1..eb09968ba27f 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -478,8 +478,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 = mas_walk(&mas); if (!vma) return -ENOMEM; @@ -575,7 +573,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); @@ -635,7 +639,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 Sat Jan 28 06:32:27 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13119697 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 C6787C38142 for ; Sat, 28 Jan 2023 06:32:47 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D57306B0073; Sat, 28 Jan 2023 01:32:46 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id CD4DD6B0078; Sat, 28 Jan 2023 01:32:46 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id AFFF66B0075; Sat, 28 Jan 2023 01:32:46 -0500 (EST) 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 9AEE66B0072 for ; Sat, 28 Jan 2023 01:32:46 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 7447B803FA for ; Sat, 28 Jan 2023 06:32:46 +0000 (UTC) X-FDA: 80403239532.25.530E2AD Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf21.hostedemail.com (Postfix) with ESMTP id 040131C0002 for ; Sat, 28 Jan 2023 06:32:43 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; spf=pass (imf21.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=1674887564; a=rsa-sha256; cv=none; b=EK5WQKwsQ1Zf+40cIoigyo9cB07N3aQ9DZOqipjD9q2kz3YMM+RSndZCe3KiLw6tGiJl3a EQoswcu0XTyBoWjfS6RFjVib5WRUJcJ7htOsDh8fwPjP/m7FJsnLqtcdTZ5S75o1peMpED UGiHWcD3oa8SYj5BTg+YdSuA50xbC+0= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; spf=pass (imf21.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=1674887564; 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=ebWwl8ttd/LjAbK0z3u1Sheo0/88GeQ0Xz8NqrDZ4Xs=; b=HjqK8hxeOkkxmF0ioHn6o9m6Gtw87/a9ugNCRdPOT0aJFPm42ivsOhmE1rsTihYUvb/91G LYExBS/eOsj7uiEhlioWHhZ6zkeIzWJbO4TzaVPnLgjbihwJ7Zb2rU8DZYSIUMxcQf/q/u efjmhW/YHfAoboHxlTd1czcZ/3b2xRA= Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.53]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4P3l1t3mC0z16NJj; Sat, 28 Jan 2023 14:30: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.2375.34; Sat, 28 Jan 2023 14:32:38 +0800 From: Wupeng Ma To: CC: , , , , Subject: [PATCH v3 2/4] mm/mempolicy: return EINVAL for if len overflows for set_mempolicy_home_node Date: Sat, 28 Jan 2023 14:32:27 +0800 Message-ID: <20230128063229.989058-3-mawupeng1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230128063229.989058-1-mawupeng1@huawei.com> References: <20230128063229.989058-1-mawupeng1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Queue-Id: 040131C0002 X-Rspamd-Server: rspam01 X-Stat-Signature: gjs491mzpeun335p6dwck6mgbdbpdoig X-HE-Tag: 1674887563-192795 X-HE-Meta: U2FsdGVkX18+HaHAbBE4mQJgrzF9zWqoaIUtwXVeHRecirs2hKhiLPHryvTcrWf2ywsRLHNaehV1b2QLAjgnXOq9Ad+E/9A2gKHoH1czWM8jFlOTRUZSKx4Ue2oypUn1KR7NgQiJJ6O+L4NKQXOJOlf7eFiEjM5WHeU8v2xd0h/RSPZPU13lSiQfEsJ4ECm11oLrhKiKkGnR5YqlzNYF03jgjP6dxtCAeTapSGac7H9SHQEO5It+x8ZhjA5QhGt5WFwDylqWaLDBAX5DNfG/7ZtYxDDmkGa+OPdK9rrnHib2V7Zb/QOMvw4qPyKggraRASH9TJDnUkAvulORAQBkgSUj7BJ+cgWjSoX9kIP22tGzZFgFtRwcTpQGAl/eBhh1lISEAWdz6QyKAndgwQwTgd7uJmURlyrh3RIM/cOcizlFgkQK7uN+82NsNaoa5oPZ5Tk+Hf4mJU5obRg8eAs/6AhwWeqbRk6ZP9FJKKmwggbSGPJ12HKwDGcNVcUC0YbWVzpfcOXq2CrRs99zuA9rZkj8uGUTltxRCCo4cmlDjqzOlFflMIL1VWji5w+pTaTeb2WPVGBKoWYoJsK4Kl7S1t7cEnfDzv4q1XaXF66PBsxgumq8o0F59eC8PipVpMcLbvzZ/spRBYPsIQmJV9DaqwsMtE6e324sBPOc3VIp3jgV9xvvxJ+Sx/KNnAfnrCwN6uCeTbtcQntENuZrYjh/M1DpM7FtLOZ2COQVnOLzbFx63ZJi+ncHJekqbPy0Qou9dAYH5MWzl0UycyzqMjpG7LK5wJ20IJO104yXav0A13qa6MwnZilXsA/HWrF+6MSzNnLF807UwW4QXH3vQzXgazpQh/3gUIs7BRVMx30ODJ5JcaGTNNgJeW/YyHuQvj/XJrLpaTbY4Xg5Gc5uGTD7K9C4mH9n8I0aovtU2YD78zZKl2AmmNj+10w6p++D9Nfuy/BPOt/326Hkav582SW FpGUMaex L6nwHm9x8/9bVNFu6eaK/PPlGJoPYPMcPnPYRlkwWplhm/kuaym1oO+S9jpjFSVne7iHOFqYQt4+l6g7J3JlXJEGSUFhDI24b6OpbW2A1bU34Bm2YyCPcyIzScCuOOxdYpuuru3cOTQW2479Ihiqacygx2SxX3+Moi+mUG+RnEkyexS0GWJ1GLI3ZnkPhHfCYCpYP3cBZCU+1cTnUUbBRUy59h4OhQHH7WkkX+CVSzqwcoy8= 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 02c8a712282f..85c5d3c2503b 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1512,13 +1512,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) { vmstart = max(start, vma->vm_start); From patchwork Sat Jan 28 06:32:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13119699 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 DFD23C27C76 for ; Sat, 28 Jan 2023 06:32:50 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 31A086B0072; Sat, 28 Jan 2023 01:32:47 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 2A2E46B0078; Sat, 28 Jan 2023 01:32:47 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id EFD1B6B0072; Sat, 28 Jan 2023 01:32:46 -0500 (EST) 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 C31886B0072 for ; Sat, 28 Jan 2023 01:32:46 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay08.hostedemail.com (Postfix) with ESMTP id 9D747140717 for ; Sat, 28 Jan 2023 06:32:46 +0000 (UTC) X-FDA: 80403239532.25.087D387 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf24.hostedemail.com (Postfix) with ESMTP id 2DD20180012 for ; Sat, 28 Jan 2023 06:32:43 +0000 (UTC) Authentication-Results: imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.189 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=1674887564; 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=cq0lGhehMcpKuqZK6xfRQ2nd7Nzf5gQMqL2POs8AuMw=; b=cuBthqwelzUuI358Zi0gxcv//d678mf/Lcxsd0hxjt+ql4dsp6nv01bY98ZpwFjWYc5md3 FTKGKBuc4NhaPQFO0xOiuRXhfiBtDNTl6V8Z7qcYLCtun4uGlHMdYNldswEgrGCfa4jIFh BD3IjMEVD+U7EOZs/3c8caQ2hLlrIeQ= ARC-Authentication-Results: i=1; imf24.hostedemail.com; dkim=none; spf=pass (imf24.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.189 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=1674887564; a=rsa-sha256; cv=none; b=qCgNQlXag7J/eBwh19q5BbzGMzzg53QltaoCSJu4hUWWOa3YBy6jkBH6pY2qWMOFCusu/z xasMGrpadatahqBOeMfPQrmNbnpUtJ6IiE8MQcR5TenDajZF/OAAchqAW/3jX3tXAXOYdt S/MO5/tMG9je9CCVy6Q7o5/0ocYIyvU= Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.54]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4P3kz26ScqzJqXP; Sat, 28 Jan 2023 14:28:14 +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.2375.34; Sat, 28 Jan 2023 14:32:39 +0800 From: Wupeng Ma To: CC: , , , , Subject: [PATCH v3 3/4] mm/mempolicy: return EINVAL if len overflows for mbind Date: Sat, 28 Jan 2023 14:32:28 +0800 Message-ID: <20230128063229.989058-4-mawupeng1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230128063229.989058-1-mawupeng1@huawei.com> References: <20230128063229.989058-1-mawupeng1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected X-Stat-Signature: hrh48dp8a9zbnwaxn6qnpb97hxwmdenb X-Rspam-User: X-Rspamd-Queue-Id: 2DD20180012 X-Rspamd-Server: rspam06 X-HE-Tag: 1674887563-562805 X-HE-Meta: U2FsdGVkX19o1yiNkM3rXrdSfpobtGo4ZCQZxCbg2imcVw7hIHiYake4aO8gqYVnkjNnwZqw1ioADjuINLGYgYpkl6lhXcpy1IwdT3vcDNLNR0PzyacKdl5PvoUcJRlq3/nDUyEU21uZSgv0ZrAdmIDecINbx+lgP+fz8g8X5dqSYqUSbMNtcEOP3I1gvQmOQ+gRI/OOPebno7W3vjqgc8JzZIQJYuVX6hiD9iNfpCFjnMUE1jSa38VvVuNOMCi51XQCpPtVqVXsqMVNCWxF1wPJnskCOV5bRHtro+0PmkC/jV/YGcPJnOe9EZS8dCTWwMcz/V1oCEzo34M3B+L3EpgdfiivfdtnMCoo5I8JXpHcdRDhdJTwFBw9pgkE+elnHCcuvxogBGk+j19PpAYojvJr2SgSl4olld94QETemJHpyrVDRVda+nwbamhw0B9lceARLPpaVFMjW+B9d7QFTHyqZmE9KK5iSR6mH69t50f47B87RxD+l4ZE6QpRsGd0e98yOKrmqox9R2VBE4+JAkx8ZSCT/2GjXwTNUvBK/80UZN6ZPk/NSCAUXfDE71AslWhYHgZPBpv4fpbdpijeq8V+uUS7/Hw5P0uaXeDzSkpN5RTP36rUp1o2nhpS/3MrXeTrxpQZMX9Ka5fxmmBqA0GzQtbtHbhRKEt0jJaQoObOZOTQvwIN/uYNvVqRQe9u2BTHdtocDn4+GCtxjuHB0H1I0idLCSPK4n+NSWCViq0mRv4kUM/GVeBVPl3kAimGYsBJpvG8N1U8FezPOiYqU92S7CoWR445N8MjINJY4wYLkfMwB1u0a9s61bP5tomX3gvKQRRtWang7B1o37pW9j9YC01Q/r3Jn6RvG4PM4dLVHWtF9zTznb08yHSMRe2jbor2fUXXvYJuXfomQVi5u61iGp3K7z7NbDDylZCth4NHSrUX5iIYTYcx50OhUau9nJpH3FcMTaAjCTVGRKw Rt21RT8f IM+UYekdNQMta8qfdmU5Yfg7u48Raq3HxnFZdRW8k/HO/syWrci++jwaFvdPaNjH/JYAdiFpW9dSpzRtI8YdWWoIbq1IBh4ZFNr1NVcYo+HN/+KQFOH0a6iYYurtCZCihMLlUoG5/urpvjuNBNjU9G4TzH50OpBz+i9Nz 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 85c5d3c2503b..7791be5a2677 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1275,13 +1275,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 Sat Jan 28 06:32:29 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13119701 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 704F8C38142 for ; Sat, 28 Jan 2023 06:32:53 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 07D4F6B0078; Sat, 28 Jan 2023 01:32:49 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 0049F6B007B; Sat, 28 Jan 2023 01:32:48 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id D99E26B007D; Sat, 28 Jan 2023 01:32:48 -0500 (EST) 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 BD1546B0078 for ; Sat, 28 Jan 2023 01:32:48 -0500 (EST) Received: from smtpin14.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay04.hostedemail.com (Postfix) with ESMTP id 7925A1A010B for ; Sat, 28 Jan 2023 06:32:48 +0000 (UTC) X-FDA: 80403239616.14.FA1EC4D Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by imf03.hostedemail.com (Postfix) with ESMTP id 3083520012 for ; Sat, 28 Jan 2023 06:32:45 +0000 (UTC) Authentication-Results: imf03.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf03.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.189 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=1674887566; 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=KleCs/On9A8+Xc2BEFyYBQpjuz0tpcleIWvv0oVYOy2LXFneMAuYQ2Cb62/im/bDgRzz5O Fy8ye30kNIk1+Sp1CuttWmhTwHWmkrH3TNn/JMBWXoBuDTIqtq+cQHrJuRZMbGkmEKIqip 7IXh1FOJiEITuN9KooOp9q2Fl56rl4I= ARC-Authentication-Results: i=1; imf03.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf03.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.189 as permitted sender) smtp.mailfrom=mawupeng1@huawei.com ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1674887566; a=rsa-sha256; cv=none; b=OzdCezrGsw3lO6od9pzNzO0g+Eoc0tVbnAJVahblJt5eHLwics8gRmW/ZVNivyODhXfPQN UUATjFxx7yEYan2Cv9va9HewdL3ZEuqYWmE8ZL9rEiMUzK9ihZ4sxKRDHgqWa44r4abbRW GLhGM5p23kDyaB2s6XyQH0aDMZpKVB4= Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.57]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4P3kz32VdVzJqM6; Sat, 28 Jan 2023 14:28:15 +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.2375.34; Sat, 28 Jan 2023 14:32:40 +0800 From: Wupeng Ma To: CC: , , , , Subject: [PATCH v3 4/4] mm/msync: return ENOMEM if len overflows for msync Date: Sat, 28 Jan 2023 14:32:29 +0800 Message-ID: <20230128063229.989058-5-mawupeng1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230128063229.989058-1-mawupeng1@huawei.com> References: <20230128063229.989058-1-mawupeng1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected X-Rspamd-Queue-Id: 3083520012 X-Rspamd-Server: rspam09 X-Rspam-User: X-Stat-Signature: iitawn55kzb4ea3g4r5rfwwag1bgah3p X-HE-Tag: 1674887565-944622 X-HE-Meta: U2FsdGVkX1+k2fbxmBho2Eu5uSrRGPDg+TrWoGDRd1rvHNleUjJn3k/WRCTKg2DmzOw0UlhrOVUzG/6MqPtj4lIko2zDM+M1WaoRCxX3QGQQUaVdGz5sB4quVL3aag13ZXwyWVRM8BvcTunNBGt6K+T1I7JLIHXleRdBp8txa1ZCt7V2O9wXgIzmxOZiKRVf3Juv77891/R23omzr03RRnq62+t+ltxpI9EroftYCouCV1zLqMuPcDu/Z2sK2ABMP6id6JpWuzOWZ6taOFhILiEMqdv3Ot48cDCyCK0load3uabo5l6Z88N2tkNp0DCNJaM/xgIWv0vM1gT35heohsjHVa3q4r7sqEFnsunokCqan+lrK+SZBGUm6/27akyMjiRpWNSDnh3qhdKe6tkSnDpn7A9ZzVhGc9w3MzokMVV+gLV87P0hlgxapqPmHcJjpsOVsPuvhgR43+6dLkiVQZHwEsSMVVJ+sGJx/X0DaZ5ilpXeoiLSOapuozlfV3m7Gn/Sf1w/7cyJnQhVEU4piDRSzq6in3grcPvX8Az8xTGDoUkRHFEm/PGV1jGZNF2FmqFDTVzOG2SSv+hH07a7p6uCGQnBsGr8rTfZrBnTyI1l3GYJLoZOYF4xg6KHNf5or0049LDEw/kVUHBx4UC9WXUMDmTwHwWFjxhyNYfPXZW0KwW5wDVH+OrN6apY+NvhrPB2QqEB337bRdxplFjwLUG0JR17J7JpcOAuHatSByeg6fFVU2dVT9G2LbVZiLPpo7ijXxF6+budDMb5I8Cw20d23gfpI8DcxXPWT+IwmaQDPx/rPMi8WQLsXRk3r+JP2A950Gxpahqc0gSA18Ij2137Rq8J42nVg9wJtObEh3GgQ5KEbfbw9a2nORG7kAtbAuSx53lq6CB8UMwQqa5flg0fB2d5xBcy35nW8ROcPgFj2ZUb4p+r3/U1oB+vAaDGjB0u/t/pQe732UMaI8K 6cflNKBK p7sOQwlp7kEpaT9mpfd6G7wIN41egPTEKRK0n1JOrkftlSIUlyBqJnUAAXMTgn3FjK2z24M4EpK7mHLFU3Xs3HTvfAFV+mA2xwVQGwmnMrMKyW2fZ1G5w9sE5CssGXf99GBNSqvuXh5UoOUi+rw2PZoqOTHhrZldNNQV1 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