From mboxrd@z Thu Jan 1 00:00:00 1970 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 00B70C433EF for ; Tue, 28 Dec 2021 04:51:10 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id E2EC56B0072; Mon, 27 Dec 2021 23:51:09 -0500 (EST) Received: by kanga.kvack.org (Postfix, from userid 40) id DDEAB6B0073; Mon, 27 Dec 2021 23:51:09 -0500 (EST) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id CA6DC6B0074; Mon, 27 Dec 2021 23:51:09 -0500 (EST) X-Delivered-To: linux-mm@kvack.org Received: from forelay.hostedemail.com (smtprelay0160.hostedemail.com [216.40.44.160]) by kanga.kvack.org (Postfix) with ESMTP id B8C036B0072 for ; Mon, 27 Dec 2021 23:51:09 -0500 (EST) Received: from smtpin26.hostedemail.com (10.5.19.251.rfc1918.com [10.5.19.251]) by forelay03.hostedemail.com (Postfix) with ESMTP id 53CFD8249980 for ; Tue, 28 Dec 2021 04:51:09 +0000 (UTC) X-FDA: 78965978658.26.A387183 Received: from szxga01-in.huawei.com (szxga01-in.huawei.com [45.249.212.187]) by imf27.hostedemail.com (Postfix) with ESMTP id 4AE0740002 for ; Tue, 28 Dec 2021 04:51:07 +0000 (UTC) Received: from dggpemm500021.china.huawei.com (unknown [172.30.72.54]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4JNMTv63dHzZdtB; Tue, 28 Dec 2021 12:47:47 +0800 (CST) Received: from dggpemm500001.china.huawei.com (7.185.36.107) by dggpemm500021.china.huawei.com (7.185.36.109) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2308.20; Tue, 28 Dec 2021 12:51:04 +0800 Received: from [10.174.177.243] (10.174.177.243) by dggpemm500001.china.huawei.com (7.185.36.107) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2308.20; Tue, 28 Dec 2021 12:51:03 +0800 Message-ID: <4ca5a8e4-8edc-3ea4-34f0-26d6ff7c5db4@huawei.com> Date: Tue, 28 Dec 2021 12:51:03 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Thunderbird/91.2.0 Subject: Re: [PATCH v2 2/2] mm: usercopy: Warn vmalloc/module address in check_heap_object() Content-Language: en-US To: Christophe Leroy , Kees Cook , Laura Abbott , Mark Rutland , "linux-mm@kvack.org" , "Andrew Morton" , "linux-kernel@vger.kernel.org" , Michael Ellerman , Benjamin Herrenschmidt , Paul Mackerras , "linuxppc-dev@lists.ozlabs.org" CC: Nicholas Piggin References: <20211225120621.13908-1-wangkefeng.wang@huawei.com> <20211225120621.13908-3-wangkefeng.wang@huawei.com> From: Kefeng Wang In-Reply-To: Content-Type: text/plain; charset="UTF-8"; format=flowed X-Originating-IP: [10.174.177.243] X-ClientProxiedBy: dggeme707-chm.china.huawei.com (10.1.199.103) To dggpemm500001.china.huawei.com (7.185.36.107) X-CFilter-Loop: Reflected X-Rspamd-Server: rspam08 X-Rspamd-Queue-Id: 4AE0740002 X-Stat-Signature: puiwbsscyg7cxkbm8c8wadqzuu4kkakn Authentication-Results: imf27.hostedemail.com; dkim=none; spf=pass (imf27.hostedemail.com: domain of wangkefeng.wang@huawei.com designates 45.249.212.187 as permitted sender) smtp.mailfrom=wangkefeng.wang@huawei.com; dmarc=pass (policy=quarantine) header.from=huawei.com X-HE-Tag: 1640667067-253304 Content-Transfer-Encoding: quoted-printable 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: On 2021/12/27 1:33, Christophe Leroy wrote: > > Le 25/12/2021 =C3=A0 13:06, Kefeng Wang a =C3=A9crit=C2=A0: >> 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. > I think that's the responsibility of the architecture and doesn't > deserve a WARN_ON() in generic code. > > The generic code cannot check all what architectures do wrong. > > Eventually you can do some testing at startup, maybe with > CONFIG_DEBUG_VM_PGTABLE, but I don't think we should have such > verification in functions like check_heap_object() Ok, we could find other better place to add a virt_to_valid() check instead of this one. >> 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 *p= tr, unsigned long n, >> if (!virt_addr_valid(ptr)) >> return; >> =20 >> + WARN_ON_ONCE(is_vmalloc_or_module_addr(ptr)); >> + >> /* >> * When CONFIG_HIGHMEM=3Dy, kmap_to_page() will give either the >> * highmem page or fallback to virt_to_page(). The following