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