Received: by 2002:a05:6a10:af89:0:0:0:0 with SMTP id iu9csp862446pxb; Fri, 21 Jan 2022 05:09:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJzGVg+HfZK5nRSI5MYIGsPfuGUCYDDk15tyZRLm9zbVZVDs0rMd606A1pF7SytOF3EXVgA8 X-Received: by 2002:a17:90b:390f:: with SMTP id ob15mr672115pjb.205.1642770570594; Fri, 21 Jan 2022 05:09:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1642770570; cv=none; d=google.com; s=arc-20160816; b=GOZXt1ueuDiW7DyuPA9D/Vb3fItEoqHELFdrM7Z4nYu1EB3SFLCtn9mU1J7EcNad9D WxSuqx1NLPweZ49mNx46W7yxk4B9quJSRQNQyI6t88uRYacwKzpRSy6GiCpGWpQYHi8R e/FXlqjOU0ESOXwihbC0Akxj6Oj8ZVXaVlZvvOq5JACzTqnT9ut7QTmhFXb8pkQZc4aJ 9Ml8wqf5KCsKEeYiSae3dwDHIs9zh8rO19qcb20hkPflFUk9dr3hr4jVMb2QkIPmkJb1 Yg4eQp/9ZljKAcIlWIMkn39zRKpcu13bIMCwpnWrlV8dtCkDmkhS9MXRVgxhrBnVyGpn z0Tg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:in-reply-to:content-disposition:mime-version :references:message-id:subject:cc:to:from:date:dkim-signature; bh=bSFNXBAL3L/sZMcUTYCHF8j9CNgzUTePNEfP42fi6WM=; b=Eb3g/ikTKR186MyaxYu7AtQAVX3exesqvd8sNRTc2Zkgb5GKn6LBrgYpHonwNIKylp Y/97tWnXO1Zv5r9cxxaofpffCZiQsnHIypNDPOAdEcOv14fE4ulUfJkfvO46V1F821EY bTrpvib+0J6qJlXVB3GHjWfKWrHE/00Kwreq4I4Szl0InUiXzMF159Rn5c6WeH+a9qWF DZHy9uTxwvVwfToxFvOB5mb/kOmNN3tOeCCWyiIBhi/1ID+gaXjAIflyjFrfuBQMxOVv UFB/xmNcFI1u+3S3rbSrYfj7J5kBoJcgOtdbdPF2AcKNsufX/1NuRYn8S0t88YqLv0Y7 BlNA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ITKBmPkj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id j14si4525836plr.553.2022.01.21.05.09.18; Fri, 21 Jan 2022 05:09:30 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@infradead.org header.s=casper.20170209 header.b=ITKBmPkj; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1350475AbiASAvt (ORCPT + 99 others); Tue, 18 Jan 2022 19:51:49 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58238 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235175AbiASAvs (ORCPT ); Tue, 18 Jan 2022 19:51:48 -0500 Received: from casper.infradead.org (casper.infradead.org [IPv6:2001:8b0:10b:1236::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 498C7C061574 for ; Tue, 18 Jan 2022 16:51:48 -0800 (PST) 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=bSFNXBAL3L/sZMcUTYCHF8j9CNgzUTePNEfP42fi6WM=; b=ITKBmPkjINkr+kVaj6Y+dKIcDI BvqOngu/9IT5Rn4s9sTLn2PzesWshv2YBsi96+rofQ3+BVYoqVcjkMtC6rlUmPtTMSq/ul5NyOAI/ q9DfCSH+rEK9qqPiFSGY2rKngDe1XMI3RfAvmOn5EOBwbK7ns9ErE/q+y6JdyZZMHbSjln06B+F5d HQZHhSFi8mSfC9SP34IMzIrPdTN5zgIjUDjXMh1S7jqBjTqVUJ0QXKMfoUJYqorDpNzxB298VO7vG XIkw1MnizDFVQjXTcqksKReY9AwdDKZBSf1YV0Kkn1jYYD8jqYGonSDHHpgNXaVS+PGt16D+BzX3X cqw5cPlw==; Received: from willy by casper.infradead.org with local (Exim 4.94.2 #2 (Red Hat Linux)) id 1n9zCB-009rPJ-HZ; Wed, 19 Jan 2022 00:51:27 +0000 Date: Wed, 19 Jan 2022 00:51:27 +0000 From: Matthew Wilcox To: Yury Norov Cc: 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, Uladzislau Rezki Subject: Re: [PATCH] vmap(): don't allow invalid pages Message-ID: References: <20220118235244.540103-1-yury.norov@gmail.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20220118235244.540103-1-yury.norov@gmail.com> Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Jan 18, 2022 at 03:52:44PM -0800, Yury Norov wrote: > vmap() takes struct page *pages as one of arguments, and user may provide > an invalid pointer which would lead to DABT at address translation later. Could we spell out 'DABT'? Presumably that's an ARM-specific thing. Just like we don't say #PF for Intel page faults, I think this is probably a 'data abort'? > Currently, kernel checks the pages against NULL. In my case, however, the > address was not NULL, and was big enough so that the hardware generated > Address Size Abort on arm64. > > Interestingly, this abort happens even if copy_from_kernel_nofault() is > used, which is quite inconvenient for debugging purposes. > > This patch adds a pfn_valid() check into vmap() path, so that invalid > mapping will not be created. > > RFC: https://lkml.org/lkml/2022/1/18/815 > v1: use pfn_valid() instead of adding an arch-specific > arch_vmap_page_valid(). Thanks to Matthew Wilcox for the hint. > > Signed-off-by: Yury Norov Suggested-by: Matthew Wilcox (Oracle) > --- > mm/vmalloc.c | 2 ++ > 1 file changed, 2 insertions(+) > > diff --git a/mm/vmalloc.c b/mm/vmalloc.c > index d2a00ad4e1dd..a4134ee56b10 100644 > --- a/mm/vmalloc.c > +++ b/mm/vmalloc.c > @@ -477,6 +477,8 @@ static int vmap_pages_pte_range(pmd_t *pmd, unsigned long addr, > return -EBUSY; > if (WARN_ON(!page)) > return -ENOMEM; > + if (WARN_ON(!pfn_valid(page_to_pfn(page)))) > + return -EINVAL; > set_pte_at(&init_mm, addr, pte, mk_pte(page, prot)); > (*nr)++; > } while (pte++, addr += PAGE_SIZE, addr != end); > -- > 2.30.2 >