From patchwork Mon Dec 5 03:41:04 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: mawupeng X-Patchwork-Id: 13064107 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 489FFC47089 for ; Mon, 5 Dec 2022 03:41:29 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 321308E0006; Sun, 4 Dec 2022 22:41:28 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id 27E9C8E0005; 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 08EE58E0001; Sun, 4 Dec 2022 22:41:28 -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 E94BB8E0001 for ; Sun, 4 Dec 2022 22:41:27 -0500 (EST) Received: from smtpin25.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id BC39A1C5E2C for ; Mon, 5 Dec 2022 03:41:27 +0000 (UTC) X-FDA: 80206852614.25.F7EB74C Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf02.hostedemail.com (Postfix) with ESMTP id 626C980002 for ; Mon, 5 Dec 2022 03:41:25 +0000 (UTC) Authentication-Results: imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.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: references; bh=OamIp5a6pdqe+w7IVFf9CxGepfumEh8YsEE5Oeo96DI=; b=RM7dQF3O+aJDd9CxIBPYVtbsRFz8Av+aPyeX8gCOgdZT04DhDM/nV+9Wj9GxlH35gWp7sf 0p8o9qCP8ZUo1G+JTc7bWuGnuaSq1IUL+X+0ELJQyYYkT1U5hwrFJedqY4kkfqcrkWREIe 6MS5WZEahbCbNkOb8gA5UBwXVumpxdw= ARC-Authentication-Results: i=1; imf02.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf02.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=UamM4jnfcxpnseMTMs7SYlKMaOXjsBkrs7tUONqVLrzheq/nL91BT+4E9TO8mJ7gDPqvQ1 DTi9ZdsB6xUG+wKXdgyy3Y4NcJt6at69MfjxoK0szmU8TDUq8RVlbw30YWVFaxCshz1oDs e4bW+FXrIRvnuYHCjlz2CCaKRO9jFV4= Received: from dggpemm500014.china.huawei.com (unknown [172.30.72.53]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4NQTpW2lqwzmWKj; 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:21 +0800 From: Wupeng Ma To: CC: , , , , , Subject: [PATCH 0/4] return EINVAL for illegal user memory range Date: Mon, 5 Dec 2022 11:41:04 +0800 Message-ID: <20221205034108.3365182-1-mawupeng1@huawei.com> X-Mailer: git-send-email 2.25.1 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.56 / 9.00]; R_MISSING_CHARSET(2.50)[]; BAYES_HAM(-1.24)[82.10%]; 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-Rspam-User: X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 626C980002 X-Stat-Signature: dm1dijr4mbnsuptn5frx3rgxmgjwaqpm X-HE-Tag: 1670211685-213422 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))); However this problem appear in multiple syscalls. 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. Ma Wupeng (4): mm/mlock: return EINVAL for illegal user memory range in mlock mm/mempolicy: return EINVAL for illegal user memory range for set_mempolicy_home_node mm/mempolicy: return EINVAL for illegal user memory range for mbind mm/msync: return EINVAL for illegal user memory range for msync mm/mempolicy.c | 7 +++++++ mm/mlock.c | 6 ++++++ mm/msync.c | 2 ++ 3 files changed, 15 insertions(+)