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 6BCD5C433F5 for ; Tue, 10 May 2022 03:37:39 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 938D96B0072; Mon, 9 May 2022 23:37:38 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 8EAB26B0073; Mon, 9 May 2022 23:37:38 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7AFDC6B0074; Mon, 9 May 2022 23:37:38 -0400 (EDT) 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 6C0226B0072 for ; Mon, 9 May 2022 23:37:38 -0400 (EDT) Received: from smtpin05.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay11.hostedemail.com (Postfix) with ESMTP id 43DAA812B9 for ; Tue, 10 May 2022 03:37:38 +0000 (UTC) X-FDA: 79448423796.05.2DCE9AD Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by imf13.hostedemail.com (Postfix) with ESMTP id 23DF32008D for ; Tue, 10 May 2022 03:37:20 +0000 (UTC) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 47843B81AEB; Tue, 10 May 2022 03:37:35 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BA34AC385A6; Tue, 10 May 2022 03:37:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linux-foundation.org; s=korg; t=1652153853; bh=u0w2ountQEspnJx1OvB2xdh1GwR7pdX0UpLOdtxe4No=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=gcsYmCSOoAIwhc5cmUD0Dp6prNRhWcGrWK3kOdCYa7lT6TAUqs7SrTI4LEwGg31Xa v3ugo6H39von+tP/vYGROB5IjTTjuno0WEsz89L19+6CodY7claO0bYjDZ6eN8biEx hEwOo3dBW6F2gz88FgpNebscQBOtWDMy1bLJKfqU= Date: Mon, 9 May 2022 20:37:32 -0700 From: Andrew Morton To: Yuanzheng Song Cc: , , Kees Cook , Matthew Wilcox Subject: Re: [PATCH] mm: usercopy: move the virt_addr_valid() below the is_vmalloc_addr() Message-Id: <20220509203732.951da2e00ddfa628decf24a2@linux-foundation.org> In-Reply-To: <20220505071037.4121100-1-songyuanzheng@huawei.com> References: <20220505071037.4121100-1-songyuanzheng@huawei.com> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.33; x86_64-redhat-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-Rspamd-Server: rspam04 X-Rspamd-Queue-Id: 23DF32008D X-Stat-Signature: qyu5srbycw5nzhowesazzqtnizzsic7a X-Rspam-User: Authentication-Results: imf13.hostedemail.com; dkim=pass header.d=linux-foundation.org header.s=korg header.b=gcsYmCSO; spf=pass (imf13.hostedemail.com: domain of akpm@linux-foundation.org designates 145.40.68.75 as permitted sender) smtp.mailfrom=akpm@linux-foundation.org; dmarc=none X-HE-Tag: 1652153840-178542 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: Matthew & Kees, On Thu, 5 May 2022 07:10:37 +0000 Yuanzheng Song wrote: > The is_kmap_addr() and the is_vmalloc_addr() in the check_heap_object() > will not work, because the virt_addr_valid() will exclude the kmap and > vmalloc regions. So let's move the virt_addr_valid() below > the is_vmalloc_addr(). The author, > Signed-off-by: Yuanzheng Song Tells me off-list that this fix: > --- a/mm/usercopy.c > +++ b/mm/usercopy.c > @@ -163,9 +163,6 @@ static inline void check_heap_object(const void *ptr, unsigned long n, > { > struct folio *folio; > > - if (!virt_addr_valid(ptr)) > - return; > - > if (is_kmap_addr(ptr)) { > unsigned long page_end = (unsigned long)ptr | (PAGE_SIZE - 1); > > @@ -190,6 +187,9 @@ static inline void check_heap_object(const void *ptr, unsigned long n, > return; > } > > + if (!virt_addr_valid(ptr)) > + return; > + > folio = virt_to_folio(ptr); > > if (folio_test_slab(folio)) { is required to fix patches "mm/usercopy: Check kmap addresses properly" and "mm/usercopy: Detect vmalloc overruns".