From patchwork Mon Dec 5 03:41:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13064109 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 3BB33C4321E for ; Mon, 5 Dec 2022 03:41:31 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id A8F248E0001; Sun, 4 Dec 2022 22:41:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 7D7288E0002; Sun, 4 Dec 2022 22:41:28 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 3DF478E0003; Sun, 4 Dec 2022 22:41:28 -0500 (EST) 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 09D568E0003 for ; Sun, 4 Dec 2022 22:41:28 -0500 (EST) Received: from smtpin20.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CA626803B0 for ; Mon, 5 Dec 2022 03:41:27 +0000 (UTC) X-FDA: 80206852614.20.45400BC Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf21.hostedemail.com (Postfix) with ESMTP id AB5751C0002 for ; Mon, 5 Dec 2022 03:41:26 +0000 (UTC) Authentication-Results: imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.187 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=1670211687; a=rsa-sha256; cv=none; b=X/56PYiXaaxMO1ZtLkHLgdMXADDSLC+nl389kIy7YPRCrSIK9gKoCYYu9HO5IfiPmcuxNz YXIstP19hcno3veOIvVptL34xTM0F2unMYaMX12a6wRw2J2+Va7700absbeFd4o88VAtNw L6H94mlRFiWW2JVFAIomFSN658ZcV1Y= ARC-Authentication-Results: i=1; imf21.hostedemail.com; dkim=none; spf=pass (imf21.hostedemail.com: domain of mawupeng1@huawei.com designates 45.249.212.187 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=1670211687; 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=Yt7S88bvQ7l9rb9Fikm+kKJuA3+EiLHEdabimH5ct/s=; b=K0wmC/wYO79TnnG1yeszBsEahla0a21bn12Rwnsui5k2oB9+D5QhBEgKOqgORnldstgQfz +M0kVCM0fOu2o8+PgRTFYxDD/2CyLOhtmSK9AfJ4ojf+YGpEdccrfouENv+OG4Vkg3q+PB v65ZT6YWTor430k3u4C5K3gTHKiazBg= Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NQTkh2Tz1zqStr; Mon, 5 Dec 2022 11:37:16 +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.31; Mon, 5 Dec 2022 11:41:23 +0800 From: Wupeng Ma To: CC: , , , , , Subject: [PATCH 4/4] mm/msync: return EINVAL for illegal user memory range for msync Date: Mon, 5 Dec 2022 11:41:08 +0800 Message-ID: <20221205034108.3365182-5-mawupeng1@huawei.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20221205034108.3365182-1-mawupeng1@huawei.com> References: <20221205034108.3365182-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-Spamd-Result: default: False [-2.01 / 9.00]; BAYES_HAM(-4.81)[97.28%]; R_MISSING_CHARSET(2.50)[]; MID_CONTAINS_FROM(1.00)[]; DMARC_POLICY_ALLOW(-0.50)[huawei.com,quarantine]; R_SPF_ALLOW(-0.20)[+ip4:45.249.212.187/29]; MIME_GOOD(-0.10)[text/plain]; RCVD_NO_TLS_LAST(0.10)[]; R_DKIM_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_SEVEN(0.00)[7]; RCVD_COUNT_THREE(0.00)[3]; MIME_TRACE(0.00)[0:+]; HAS_XOIP(0.00)[]; TO_MATCH_ENVRCPT_SOME(0.00)[]; FROM_HAS_DN(0.00)[]; ARC_SIGNED(0.00)[hostedemail.com:s=arc-20220608:i=1]; TO_DN_NONE(0.00)[]; ARC_NA(0.00)[] X-Rspamd-Queue-Id: AB5751C0002 X-Rspamd-Server: rspam01 X-Stat-Signature: ehkt5wch6yixii99ic5x17gbr9grotsm X-HE-Tag: 1670211686-149854 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 Add access_ok to check user memory range and return EINVAL if overflows for msync. Signed-off-by: Ma Wupeng --- mm/msync.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/msync.c b/mm/msync.c index ac4c9bfea2e7..a87c3dca473a 100644 --- a/mm/msync.c +++ b/mm/msync.c @@ -43,6 +43,8 @@ SYSCALL_DEFINE3(msync, unsigned long, start, size_t, len, int, flags) goto out; if (offset_in_page(start)) goto out; + if (unlikely(!access_ok((void __user *)start, len))) + goto out; if ((flags & MS_ASYNC) && (flags & MS_SYNC)) goto out; error = -ENOMEM;