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);