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 bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 4F1F4C433EF for ; Wed, 19 Jan 2022 19:37:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Fkuyn4q0el2nZeEd8JP9NasY4JfawKhT/Rni+K9lFBM=; b=Vh5+LRYXtaF3aT VDiyebRd3WT4u+NE8DcII1vqk/xj3i96pz5EuozBue8chRLvSzwlVr+M4BIP9aU8+WnNl8QTSV0aT DK3yvURQ6GrzvbGyycTEQssVIl7NQdFfqq09FEv8IhLTPAxn377trT5xTjIBb09vqnEn8NYfBCroQ KHgQmNNAhD+RVYs2xXzfVmtFqBfrGVpzTtFG9AJK8MCDOlCkGv8wgjuRquqHXXn7v0dmEV0Dr7Hsf P9FT1vj6M/91a3DgpIg2JSu3dQgTKxIMLVbfDX2+KhumxR0qqmCEaq8eS36sBkuDZlOWOixGNLCWR gWcXPcExMMbsxRBYU1pw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1nAGkA-0075U9-Ef; Wed, 19 Jan 2022 19:35:42 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1nAGk7-0075SV-4n for linux-arm-kernel@bombadil.infradead.org; Wed, 19 Jan 2022 19:35:39 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=In-Reply-To:Content-Type:MIME-Version: References:Message-ID:Subject:Cc:To:From:Date:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=BTctFDlugghbPb+mT0fgLBcwlvNBpzSgllYA3xjcWrs=; b=jcnZQSl5oKu5z9MZdKcUVh/HDN QIRUbKxvEgbiqaoJ8yVLCy8UxESf7Ve2AtfN42EmuXgcCMBS8LQl4VNpa8nZEK/FzdZaXnlOh5neE X+ALUAl+ZF8C9z0qIpLd4axHfWML+pcSJ3TYZ75vfXLre1Esd+GX0bdzwElrlbbJWOesI9MG/NYbj qi3cmhafL8em48vvoN4EAoL8fbjZCHbkd4hpmArMAbbpDhS84XPpQAYEI1RW6kcdfbTH/E6q+s9ap +c2vLEmj+5VKpXS4MZkOKUT6FAQL7RVaGnvQGCox80+T0EwnwL0foIvDx5jef9sazBRLGiW4dZ4Gr 2wts/3lw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1nAGk1-00BvrJ-F0; Wed, 19 Jan 2022 19:35:33 +0000 Date: Wed, 19 Jan 2022 19:35:33 +0000 From: Matthew Wilcox To: "Russell King (Oracle)" Cc: Robin Murphy , Yury Norov , Catalin Marinas , Will Deacon , Andrew Morton , Nicholas Piggin , Ding Tianhong , Anshuman Khandual , Alexey Klimov , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: Re: [PATCH] vmap(): don't allow invalid pages Message-ID: References: <20220118235244.540103-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Wed, Jan 19, 2022 at 06:57:34PM +0000, Russell King (Oracle) wrote: > On Wed, Jan 19, 2022 at 06:01:24PM +0000, Matthew Wilcox wrote: > > On Wed, Jan 19, 2022 at 05:54:15PM +0000, Russell King (Oracle) wrote: > > > On Wed, Jan 19, 2022 at 04:27:32PM +0000, Matthew Wilcox wrote: > > > > On Wed, Jan 19, 2022 at 01:28:14PM +0000, Robin Murphy wrote: > > > > > > + if (WARN_ON(!pfn_valid(page_to_pfn(page)))) > > > > > > > > > > Is it page_to_pfn() guaranteed to work without blowing up if page is invalid > > > > > in the first place? Looking at the CONFIG_SPARSEMEM case I'm not sure that's > > > > > true... > > > > > > > > Even if it does blow up, at least it's blowing up here where someone > > > > can start to debug it, rather than blowing up on first access, where > > > > we no longer have the invlid struct page pointer. > > > > > > > > I don't think we have a 'page_valid' function which will tell us whether > > > > a random pointer is actually a struct page or not. > > > > > > Isn't it supposed to be: > > > > > > if (!pfn_valid(pfn)) { > > > handle invalid pfn; > > > } > > > > > > page = pfn_to_page(pfn); > > > > > > Anything else - even trying to convert an invalid page back to a pfn, > > > could well be unreliable (sparsemem or discontigmem). > > > > This function is passed an array of pages. We have no way of doing > > what you propose. > > You can't go from a struct page to "this is valid", it's too late by the > time you call vmap() - that's my fundamental point. Yes, and we have debugging code in __virt_to_phys() that would have caught this, had Yury enabled CONFIG_DEBUG_VIRTUAL. My point is that in this instance, page_to_pfn() doesn't crash, which lets vmap() set up a mapping to a completely bogus physical address. We're better off checking pfn_valid() here than not. > If the translation from a PFN to a struct page can return pointers to > something that isn't a valid struct page, then it can also (with > sparsemem) return a pointer to _another_ struct page that could well > be valid depending on how the struct page arrays are laid out in > memory. Sure, it's not going to catch everything. But I don't think that letting perfect be the enemy of the good here is the right approach. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel