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