From patchwork Sat Dec 25 12:06:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Kefeng Wang X-Patchwork-Id: 12699221 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 B5C7AC433EF for ; Sat, 25 Dec 2021 11:57:20 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id B9C1D6B0073; Sat, 25 Dec 2021 06:57:19 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id B4C356B0075; Sat, 25 Dec 2021 06:57:19 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id A3A9E6B0078; Sat, 25 Dec 2021 06:57:19 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0226.hostedemail.com [216.40.44.226]) by kanga.kvack.org (Postfix) with ESMTP id 954346B0073 for ; Sat, 25 Dec 2021 06:57:19 -0500 (EST) Received: from smtpin29.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay04.hostedemail.com (Postfix) with ESMTP id 4B89D87710 for ; Sat, 25 Dec 2021 11:57:19 +0000 (UTC) X-FDA: 78956166198.29.7ED4AB2 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by imf11.hostedemail.com (Postfix) with ESMTP id 6246240036 for ; Sat, 25 Dec 2021 11:57:14 +0000 (UTC) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.54]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4JLj4t03dTz1DK73; Sat, 25 Dec 2021 19:53:50 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Sat, 25 Dec 2021 19:57:02 +0800 Received: from localhost.localdomain.localdomain (10.175.113.25) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Sat, 25 Dec 2021 19:57:02 +0800 From: Kefeng Wang To: Kees Cook , Laura Abbott , "Mark Rutland" , , Andrew Morton , , Michael Ellerman , Benjamin Herrenschmidt , "Paul Mackerras" , CC: Nicholas Piggin , Kefeng Wang Subject: [PATCH v2 2/2] mm: usercopy: Warn vmalloc/module address in check_heap_object() Date: Sat, 25 Dec 2021 20:06:21 +0800 Message-ID: <20211225120621.13908-3-wangkefeng.wang@huawei.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20211225120621.13908-1-wangkefeng.wang@huawei.com> References: <20211225120621.13908-1-wangkefeng.wang@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.175.113.25] X-ClientProxiedBy: dggems702-chm.china.huawei.com (10.3.19.179) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam03 X-Rspamd-Queue-Id: 6246240036 X-Stat-Signature: gx3njtjtrzj5jaqu4rfkeghgg46y79h7 Authentication-Results: imf11.hostedemail.com; dkim=none; dmarc=pass (policy=quarantine) header.from=huawei.com; spf=pass (imf11.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.255 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com X-HE-Tag: 1640433434-972332 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: virt_addr_valid() could be insufficient to validate the virt addr on some architecture, which could lead to potential BUG which has been found on arm64/powerpc64. Let's add WARN_ON to check if the virt addr is passed virt_addr_valid() but is a vmalloc/module address. Signed-off-by: Kefeng Wang --- mm/usercopy.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/mm/usercopy.c b/mm/usercopy.c index b3de3c4eefba..ce83e0b137dd 100644 --- a/mm/usercopy.c +++ b/mm/usercopy.c @@ -228,6 +228,8 @@ static inline void check_heap_object(const void *ptr, unsigned long n, if (!virt_addr_valid(ptr)) return; + WARN_ON_ONCE(is_vmalloc_or_module_addr(ptr)); + /* * When CONFIG_HIGHMEM=y, kmap_to_page() will give either the * highmem page or fallback to virt_to_page(). The following