From patchwork Mon Dec 5 03:41:05 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13064110 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 A5E2CC47089 for ; Mon, 5 Dec 2022 03:41:32 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id D99C38E0002; Sun, 4 Dec 2022 22:41:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 924408E0008; 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 5665F8E0007; Sun, 4 Dec 2022 22:41:28 -0500 (EST) 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 2DD8D8E0001 for ; Sun, 4 Dec 2022 22:41:28 -0500 (EST) Received: from smtpin22.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay07.hostedemail.com (Postfix) with ESMTP id EE6EC160280 for ; Mon, 5 Dec 2022 03:41:27 +0000 (UTC) X-FDA: 80206852614.22.211D6DA Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by imf11.hostedemail.com (Postfix) with ESMTP id 298964000D for ; Mon, 5 Dec 2022 03:41:25 +0000 (UTC) Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.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=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=NwtykVj9Dud2Or4c3t6+VlWZEj6+Tj9uP3fxvwkYhQA=; b=hYJ4M5UjXx/GfAONTIFOWXHcrRa+H7x/Ehwi19Jks8WHFmOBS6fsCwlzov3DIEIixETj3R s4nKqXRzK15ZUrI8ZAN4mHeTiHPXFew3UhyGfbjYwT9tYsVVlHud9opu2CVNclSPM2zoC1 AecOV0pCDLdo3PWNA5bqRxJOLpvfF+8= ARC-Authentication-Results: i=1; imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.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=1670211687; a=rsa-sha256; cv=none; b=dztO7PF9jRPzsm7N8kqc/clJGPnWPM2n6kX7U3/Dvh2mRwPyOuwamncA7yBSVOhmrY3KRL F594nKSCndPCNjbt3NwcJuQUQ+iYpU+m+8JqqChqkUp1nMSxSojdyBdRw1RIm+27dsbAw2 ywsENioxmcqvVqghQZu0c87XQ7LNb1I= Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.54]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4NQTpW2XpjzRpl3; Mon, 5 Dec 2022 11:40:35 +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:22 +0800 From: Wupeng Ma To: CC: , , , , , Subject: [PATCH 1/4] mm/mlock: return EINVAL for illegal user memory range in mlock Date: Mon, 5 Dec 2022 11:41:05 +0800 Message-ID: <20221205034108.3365182-2-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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 298964000D X-Stat-Signature: gwpxhzmfotq3xipetdw76tn1gxwgkxqt X-Spamd-Result: default: False [2.14 / 9.00]; R_MISSING_CHARSET(2.50)[]; MID_CONTAINS_FROM(1.00)[]; BAYES_HAM(-0.66)[75.86%]; 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-Rspam-User: X-HE-Tag: 1670211685-508824 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 While testing mlock, we have a problem if the len of mlock is ULONG_MAX. The return value of mlock is zero. But nothing will be locked since the len in do_mlock overflows to zero due to the following code in mlock: len = PAGE_ALIGN(len + (offset_in_page(start))); The same problem happens in munlock. Since TASK_SIZE is the maximum user space address. The start or len of mlock shouldn't be bigger than this. Function access_ok can be used to check this issue, so return -EINVAL if bigger. Signed-off-by: Ma Wupeng --- mm/mlock.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/mm/mlock.c b/mm/mlock.c index 7032f6dd0ce1..b9422a62a4cf 100644 --- a/mm/mlock.c +++ b/mm/mlock.c @@ -575,6 +575,9 @@ static __must_check int do_mlock(unsigned long start, size_t len, vm_flags_t fla if (!can_do_mlock()) return -EPERM; + if (unlikely(!access_ok((void __user *)start, len))) + return -EINVAL; + len = PAGE_ALIGN(len + (offset_in_page(start))); start &= PAGE_MASK; @@ -635,6 +638,9 @@ SYSCALL_DEFINE2(munlock, unsigned long, start, size_t, len) start = untagged_addr(start); + if (unlikely(!access_ok((void __user *)start, len))) + return -EINVAL; + len = PAGE_ALIGN(len + (offset_in_page(start))); start &= PAGE_MASK; From patchwork Mon Dec 5 03:41:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13064108 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 D9CD5C47088 for ; Mon, 5 Dec 2022 03:41:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 7D90C8E0003; Sun, 4 Dec 2022 22:41:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 739328E0001; 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 31A9C8E0002; Sun, 4 Dec 2022 22:41:28 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0012.hostedemail.com [216.40.44.12]) by kanga.kvack.org (Postfix) with ESMTP id 055878E0002 for ; Sun, 4 Dec 2022 22:41:28 -0500 (EST) Received: from smtpin23.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id CD54F804B5 for ; Mon, 5 Dec 2022 03:41:27 +0000 (UTC) X-FDA: 80206852614.23.3593B64 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf16.hostedemail.com (Postfix) with ESMTP id DD7C4180010 for ; Mon, 5 Dec 2022 03:41:26 +0000 (UTC) Authentication-Results: imf16.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf16.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=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=LsUG+ktbq1HteG4P3qrmzHvqbBSzloKCVllJKQeoous=; b=NqaspaT2puoe8oUrKv80mw+lA0yhhlUHqXKeKeikl2SGinToOYEwm6BjCx+5uCy2dwBqHE XHbYydAkcGBYx9M16f/QS4XKGX/neDvaqfVIIWP6APXDKhnuYWLIAtvjb63mJSd1NeJDeN TxKGfiHtcdt1VLmQxg+rfj6dXjC/vVk= ARC-Authentication-Results: i=1; imf16.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf16.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=1670211687; a=rsa-sha256; cv=none; b=iK3ME+pBI2U46O0qYHgofcd6HRo088eRO2LisL7lHmBGYXYjqX4fmqa+cHZXNH0XDExnat 5CtEkH8IUpIW6uYIrn2J1wRXGEX8ybWzkkrUVz4d3lAzjAwveeBiTIukvyMHO33aHcA5RS B6fbwPQ/Ir53rpyT6D6RzWfp310nQs0= Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NQTkg3JbbzqStg; Mon, 5 Dec 2022 11:37: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.31; Mon, 5 Dec 2022 11:41:22 +0800 From: Wupeng Ma To: CC: , , , , , Subject: [PATCH 2/4] mm/mempolicy: return EINVAL for illegal user memory range for set_mempolicy_home_node Date: Mon, 5 Dec 2022 11:41:06 +0800 Message-ID: <20221205034108.3365182-3-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-Spamd-Result: default: False [1.24 / 9.00]; BAYES_HAM(-2.56)[89.89%]; R_MISSING_CHARSET(2.50)[]; SUBJECT_HAS_UNDERSCORES(1.00)[]; MID_CONTAINS_FROM(1.00)[]; DMARC_POLICY_ALLOW(-0.50)[huawei.com,quarantine]; R_SPF_ALLOW(-0.20)[+ip4:45.249.212.187/29:c]; RCVD_NO_TLS_LAST(0.10)[]; MIME_GOOD(-0.10)[text/plain]; FROM_EQ_ENVFROM(0.00)[]; RCPT_COUNT_SEVEN(0.00)[7]; R_DKIM_NA(0.00)[]; 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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: DD7C4180010 X-Stat-Signature: hqfpjsdfwm8hni4xi7da4aundqqjmhtq X-HE-Tag: 1670211686-132617 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. Signed-off-by: Ma Wupeng --- mm/mempolicy.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index 61aa9aedb728..e3a2c465fe8a 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1499,6 +1499,10 @@ SYSCALL_DEFINE4(set_mempolicy_home_node, unsigned long, start, unsigned long, le start = untagged_addr(start); if (start & ~PAGE_MASK) return -EINVAL; + + if (unlikely(!access_ok((void __user *)start, len))) + return -EINVAL; + /* * flags is used for future extension if any. */ From patchwork Mon Dec 5 03:41:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13064111 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 C808AC4321E for ; Mon, 5 Dec 2022 03:41:33 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 0DA398E0007; Sun, 4 Dec 2022 22:41:29 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id C43288E0005; 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 9FD388E0007; Sun, 4 Dec 2022 22:41:28 -0500 (EST) 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 7FB408E0005 for ; Sun, 4 Dec 2022 22:41:28 -0500 (EST) Received: from smtpin17.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay09.hostedemail.com (Postfix) with ESMTP id 5C71C80179 for ; Mon, 5 Dec 2022 03:41:28 +0000 (UTC) X-FDA: 80206852656.17.FDC8638 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf26.hostedemail.com (Postfix) with ESMTP id 7CCF7140006 for ; Mon, 5 Dec 2022 03:41:26 +0000 (UTC) Authentication-Results: imf26.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf26.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=1670211688; 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=xKn90cRs20tjV+2ypNKNISYfa3aiejQalfBolX0oqB4=; b=Rn/eA9eo+D1iRQtFuo5Y/o/4CMOmhNXka/fRuc7z4d3B9ONDyRUrQNF+CyrFwKmnBcY63j jplcB6YtlTNU5od1KCdy+cWHYhPGqIk9F+peCctpfxFJxF2FmvGQz5uscK5GMYIv/pjLMz u3OOhMnYEPl7eSMhLaJqasOXNilH2vI= ARC-Authentication-Results: i=1; imf26.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf26.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=1670211688; a=rsa-sha256; cv=none; b=4Kx8J+EllNC/QetlYKzIc+6qkkKlJN7IBPY9vnO0WdL9CSdzcCaTrGXvgb2rrybIZCyGnG SOXexCWvYUZLz4kkDBTmYC93+WNRpW1NwGleDN01meB5c37qPxd6ejDyC8VpP89uQVOC2N XxGJZSS9trkqpiOdC5w7f4L3oCQxkCw= Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NQTpX55rrzmVdp; Mon, 5 Dec 2022 11:40:36 +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 3/4] mm/mempolicy: return EINVAL for illegal user memory range for mbind Date: Mon, 5 Dec 2022 11:41:07 +0800 Message-ID: <20221205034108.3365182-4-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-Rspamd-Server: rspam05 X-Rspamd-Queue-Id: 7CCF7140006 X-Stat-Signature: soz37gf9bmx9w8ano85jcdfjk1z9kpbf X-Spamd-Result: default: False [-0.04 / 9.00]; BAYES_HAM(-2.84)[91.05%]; 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:c]; RCVD_NO_TLS_LAST(0.10)[]; MIME_GOOD(-0.10)[text/plain]; RCPT_COUNT_SEVEN(0.00)[7]; R_DKIM_NA(0.00)[]; FROM_EQ_ENVFROM(0.00)[]; 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-Rspam-User: X-HE-Tag: 1670211686-367751 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 mbind. Signed-off-by: Ma Wupeng --- mm/mempolicy.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/mm/mempolicy.c b/mm/mempolicy.c index e3a2c465fe8a..a6bddf454953 100644 --- a/mm/mempolicy.c +++ b/mm/mempolicy.c @@ -1272,6 +1272,9 @@ static long do_mbind(unsigned long start, unsigned long len, if (start & ~PAGE_MASK) return -EINVAL; + if (unlikely(!access_ok((void __user *)start, len))) + return -EINVAL; + if (mode == MPOL_DEFAULT) flags &= ~MPOL_MF_STRICT; 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;