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