From patchwork Mon Mar 20 02:47:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13180692 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 53FB1C6FD1F for ; Mon, 20 Mar 2023 02:47:57 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E911C900006; Sun, 19 Mar 2023 22:47:52 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id DF0D5900003; Sun, 19 Mar 2023 22:47:52 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id BAA23900006; Sun, 19 Mar 2023 22:47:52 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0016.hostedemail.com [216.40.44.16]) by kanga.kvack.org (Postfix) with ESMTP id A94E6900003 for ; Sun, 19 Mar 2023 22:47:52 -0400 (EDT) Received: from smtpin13.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id 7EF0316054B for ; Mon, 20 Mar 2023 02:47:52 +0000 (UTC) X-FDA: 80587741584.13.3D4505F Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf19.hostedemail.com (Postfix) with ESMTP id 075051A0003 for ; Mon, 20 Mar 2023 02:47:49 +0000 (UTC) Authentication-Results: imf19.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf19.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=1679280470; 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=/2E+nzFX9v8Ck0L7jBTEJgpMLzAEPJkIUtwPh5KpisU=; b=rqyOqiif+5+EgOKx836w4krwWjkS/O2SNRiIgNUH2uddf/0oV8vSkfDqBs5oOeC4jWmD6U S4ScEr7kQlVuJrmG0u0mVDY5+8zq0Vipy4y2FKfdau+8WWopugpb8u03NmRD1u72Bq05v3 tol7eD1KrCCmVNmaozOhKa3PlXpJ/QI= ARC-Authentication-Results: i=1; imf19.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf19.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=1679280470; a=rsa-sha256; cv=none; b=OcZbZqiwvsDu/xT4BKH/ddH5RuLr0jSXitVR49IW7iK82oXu5+sXmHuKrdjho2TyXgQhDn LLz0IUqQcoSDKQSED1pW9Umtyh2K/3+l6TtDZ8h+uGKvCPgdpe2O8Pyz7qoIIfpMM0GxlA /QUFT/igzxqih9sKQf84dojq7uDGAJc= Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.57]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4PfzbZ0F8dznYRR; Mon, 20 Mar 2023 10:44: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.2507.21; Mon, 20 Mar 2023 10:47:45 +0800 From: Wupeng Ma To: CC: , , , , , Subject: [PATCH v4 4/4] mm/msync: return ENOMEM if len overflows for msync Date: Mon, 20 Mar 2023 10:47:39 +0800 Message-ID: <20230320024739.224850-5-mawupeng1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20230320024739.224850-1-mawupeng1@huawei.com> References: <20230320024739.224850-1-mawupeng1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.112.125] X-ClientProxiedBy: dggems705-chm.china.huawei.com (10.3.19.182) To dggpemm500014.china.huawei.com (7.185.36.153) X-CFilter-Loop: Reflected X-Rspam-User: X-Rspamd-Server: rspam02 X-Rspamd-Queue-Id: 075051A0003 X-Stat-Signature: he16o3kr1hk3rskfo1xt1xyw71aesd65 X-HE-Tag: 1679280469-804495 X-HE-Meta: U2FsdGVkX1+5Afp3rwqLxRmspk5Lr6dXAFamqU12ejTeCTC4hgZ5WYXTBfJVdT2WF13wC8yQLabe6xVtAmq/KaOKpZpjQQsVB3m2+/7rQ61Mk3fWONP25KHQo0AzDkwSFwctDFCd2UuhXO6BVmOOkfoABqYXehASLsiXKARIo+yS91zLdj781C05T327Asm4u5Zp6RDeZCBirv2a/ImWTKGpFmsL0uWnrhUq0tONEwB/D1mSYAG4p68cy2wLGMsTpvGNDIkTyppaxVFj0SJRDIuLpG+hUu7B8T3Qiwhp6enbcIFhAvuhzmhDdz6MuO2w9SFmjClu+4gpUvdo37SwdXJrids4xrfm9GNMVJYcC4H0+jF6ECdnfB+0/qlh7p/cVBIlF+kqiLZAQu5QHSkF0608i0iBmpOUYrj5Sr0cevKvOT6kXGmtZRnwTxWgNRlbur35nrkRIJ42c4UO1RoYD0UTCniQkfR/RMe+68smLXn+tkIa3vwf43qzw8ZyRQpS0mmoUUGNUe+rQTIZ8VOMgUMAvUfehenemYnisFo7LOmNjikwpq+p0dpNviV+Aq1W+TzHNGfVRorTvWxTZIKlyGlDwxxXjp2GXuhlWllI2z0TIysLDXFYm5m97qEemAO9E62rebOhHeSANwqBKjViINMzZb4+bvicnueaIoIp94WVrFheUq7V6xAHmh4Gwh45QWvrtxt9VV/x/+cC3UyxeMayuAWH8XV432qVmBaa06rE3tbHDHCn4rPnhMU1XT9kSbZDbW6dlktStXEFRA3SPhq61CI3fo9mM+issQ4afaRa89JsNmyySbXl5cB/vcNyKUtd4pRo7jzTB218oen6DrgLpEAppoyKGKGIvp0VrYpMUAl43Y4ou5UmVTb2TwBHrwj3+7vpWKWJ+wLEInAPIxzQ5cJUvrtDrGw5miplIvHI1lYs0UhHytWLyFXMnPGe7mOIB3CowB3VPo8A5aD mco39/SW K+457kVuzxGqEdxftONZRGhr9rdMAivMGC2zFwdjPhvyjSO/ReJRZYmIl1WWxsMYAgpdL9TkiTOIAiQgRNQ8a3ne9+I3uYN3uVRKF68jSLcD0QCt4f2nTBhWzyRr9mJkyn9lx81q6vTMpR4k3AlxxaNY2Af52DaSlN5i9 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 Return -ENOMEM if len overflows for msync. Signed-off-by: Ma Wupeng --- mm/msync.c | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mm/msync.c b/mm/msync.c index ac4c9bfea2e7..8ac227ec38af 100644 --- a/mm/msync.c +++ b/mm/msync.c @@ -36,6 +36,7 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags) struct vm_area_struct *vma; int unmapped_error = 0; int error = -EINVAL; + size_t old_len = len; start = untagged_addr(start); @@ -48,7 +49,7 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags) error = -ENOMEM; len = (len + ~PAGE_MASK) & PAGE_MASK; end = start + len; - if (end < start) + if (end < start || (old_len != 0 && len == 0)) goto out; error = 0; if (end == start)