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