Message ID | 5011977-d876-6a24-a3fc-c7e6a02877b8@google.com |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp3363113vqo; Tue, 9 May 2023 21:48:04 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ55yGAJdLZKv0Y+j4zRwA5KLGBR8iud2EyVJdSt9GHi7fN2WMZBNn0uInaJB7D81wb+6yPR X-Received: by 2002:a17:902:f693:b0:1ac:8148:8c42 with SMTP id l19-20020a170902f69300b001ac81488c42mr9797242plg.62.1683694084504; Tue, 09 May 2023 21:48:04 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1683694084; cv=none; d=google.com; s=arc-20160816; b=nUs/2xhOiN9re6d/x75AIp5kF9oUg9Ni/6JYhkHoV/oWa3QGsOmv4WC8iJkWaqNhtq 3f/dzuyIGheG026t/Up8py7zjS5/rKg71qxkv+Rx7YnWrCZwypsTmTefrIJgQNFNriny zcn8w7fwV6JKAeBvcElHb7toPK71XKJZf4t4cvUiwu6/ZYwj3uyT6Cpo2oBScp8yc/D6 WWsfvf5hf/0f3+6XqXmfTnxhZEEsk2FLZ2loe4gMW06m07FPOoGYWWjK606wZaKpPDzV EdXkWjhj7ymtCUJ1GUiU7VBdLoOgww7/94t4dsoBmKJc2hr5R4fK6/DA+RR6VQWqkIcB 6I1A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:references:message-id:in-reply-to :subject:cc:to:from:date:dkim-signature; bh=1YvWeTkG3kfP7WDkFLxY3Kk7w85fUEyISH4lFagFGGw=; b=i9Ml3xzP5wcDVB6iPQ2d/FNYSpsMiviab/I3LSUOsaynWPdfCVUWhBwf8sYdVEiSqa ePiErXRKNXXCM4dYXEhpA7FRxObMdolKf6bqtbcmctXPGnSHY41JYr8npjNZ6i3ReqZv HFxvz3DoafMBY0ty4T/Shp0nnPAzIldtJGGEx7qpkTis8Y/6bgP5Lhg1TUShrXIK8j27 VS/cNt8op4si//H+KCWG6/etBEQzOnjXvNLPyQnFRgm1NKRzk8mx+io8vFmYQ9vLvmuM lOLRzyZvxjW/Yej74aoLoB0ngSMkLY0I5qCiDZb8uyycO49z3U5/g0ZlwdF2bq7f2jG0 BkYw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ATuPznBP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h6-20020a170902b94600b001a531f29044si2955489pls.521.2023.05.09.21.47.52; Tue, 09 May 2023 21:48:04 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@google.com header.s=20221208 header.b=ATuPznBP; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=google.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235407AbjEJEnB (ORCPT <rfc822;baris.duru.linux@gmail.com> + 99 others); Wed, 10 May 2023 00:43:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44232 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229633AbjEJEm5 (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Wed, 10 May 2023 00:42:57 -0400 Received: from mail-yb1-xb2c.google.com (mail-yb1-xb2c.google.com [IPv6:2607:f8b0:4864:20::b2c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F2A844203 for <linux-kernel@vger.kernel.org>; Tue, 9 May 2023 21:42:55 -0700 (PDT) Received: by mail-yb1-xb2c.google.com with SMTP id 3f1490d57ef6-b9ddcf0afb3so8787072276.3 for <linux-kernel@vger.kernel.org>; Tue, 09 May 2023 21:42:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20221208; t=1683693775; x=1686285775; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:from:to:cc:subject:date:message-id:reply-to; bh=1YvWeTkG3kfP7WDkFLxY3Kk7w85fUEyISH4lFagFGGw=; b=ATuPznBP6lohY0dnWFYXaaNOQNunJEFtD7eF3OFa8KJJUXbFYwyofisXF7mtL2ymFH oTBz56agCcLhFx8YonoqBW6ZmAtrhlvPrmdJAcSpRqyP2mLR5Z/WoSQhVEg2s8MVqDuy Ip95cEIMx73t6Gdt8YSQEVRJTa89FntSD+Di4V6VUK9+4KRIMxTr8+RCmD6ANZu4Rjel BJF/aQ9/sAdSWOQreL897UcsYcMJJWTONr2aX5YmKG/bIAxUtAEn1GX4Jh5f4y/r990Z htjctO7o35ZbKLLksPTYN1h3aK5mSo9ZrVIIV1mS/G/Fv32O9W6ivMXImV5mGNDY0z+m 21CQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1683693775; x=1686285775; h=mime-version:references:message-id:in-reply-to:subject:cc:to:from :date:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=1YvWeTkG3kfP7WDkFLxY3Kk7w85fUEyISH4lFagFGGw=; b=MCmlqY4JU+uKsWjLHLcVgBSfhVucDbtxKwKTgcsmz6lsFY1hnmH7CiDu/eEFhKN48e kMMwHjZTTn0zYpxipWq6r4tx+VMbvW5IgYacwgplholqQiFl3Ml+H/1rLb152AlC6M0w Qqc4ONNkLqfH2yVASCMOcJi4XUChN82N8av6FvX8Dz7izt5jN3T1KE4xOvBJvi5F74Gc VGWDDFykGBbu0Bdzi1x0lSz32pFd5MnJH9dZfWGFOYPvRJvS+Q3QRi6fSWZguPRYY9Ki j90aR+Ke7TIw1gGAHCLT4Dap4vm374C4aAEemSoHFzy5xgMZxiFXsVaWtEfcCO7fakJ6 R48g== X-Gm-Message-State: AC+VfDz0vPMgLYCC9Mvgh4Iwc4K3PkgMuk6kmH5C6UtccK1kuTuQw16+ K9Veoulw1P3pUJsGV33bQ2teOg== X-Received: by 2002:a25:ad98:0:b0:b9d:a8fa:fd6d with SMTP id z24-20020a25ad98000000b00b9da8fafd6dmr17660831ybi.12.1683693775053; Tue, 09 May 2023 21:42:55 -0700 (PDT) Received: from ripple.attlocal.net (172-10-233-147.lightspeed.sntcca.sbcglobal.net. [172.10.233.147]) by smtp.gmail.com with ESMTPSA id x4-20020a056902102400b00b9def138173sm3425234ybt.1.2023.05.09.21.42.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 May 2023 21:42:54 -0700 (PDT) Date: Tue, 9 May 2023 21:42:44 -0700 (PDT) From: Hugh Dickins <hughd@google.com> X-X-Sender: hugh@ripple.attlocal.net To: Andrew Morton <akpm@linux-foundation.org> cc: Mike Kravetz <mike.kravetz@oracle.com>, Mike Rapoport <rppt@kernel.org>, "Kirill A. Shutemov" <kirill.shutemov@linux.intel.com>, Matthew Wilcox <willy@infradead.org>, David Hildenbrand <david@redhat.com>, Suren Baghdasaryan <surenb@google.com>, Qi Zheng <zhengqi.arch@bytedance.com>, Russell King <linux@armlinux.org.uk>, Catalin Marinas <catalin.marinas@arm.com>, Will Deacon <will@kernel.org>, Geert Uytterhoeven <geert@linux-m68k.org>, Greg Ungerer <gerg@linux-m68k.org>, Michal Simek <monstr@monstr.eu>, Thomas Bogendoerfer <tsbogend@alpha.franken.de>, Helge Deller <deller@gmx.de>, John David Anglin <dave.anglin@bell.net>, "Aneesh Kumar K.V" <aneesh.kumar@linux.ibm.com>, Michael Ellerman <mpe@ellerman.id.au>, Alexandre Ghiti <alexghiti@rivosinc.com>, Palmer Dabbelt <palmer@dabbelt.com>, Heiko Carstens <hca@linux.ibm.com>, Christian Borntraeger <borntraeger@linux.ibm.com>, Claudio Imbrenda <imbrenda@linux.ibm.com>, John Paul Adrian Glaubitz <glaubitz@physik.fu-berlin.de>, "David S. Miller" <davem@davemloft.net>, Chris Zankel <chris@zankel.net>, Max Filippov <jcmvbkbc@gmail.com>, x86@kernel.org, linux-arm-kernel@lists.infradead.org, linux-ia64@vger.kernel.org, linux-m68k@lists.linux-m68k.org, linux-mips@vger.kernel.org, linux-parisc@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, linux-riscv@lists.infradead.org, linux-s390@vger.kernel.org, linux-sh@vger.kernel.org, sparclinux@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org Subject: [PATCH 01/23] arm: allow pte_offset_map[_lock]() to fail In-Reply-To: <77a5d8c-406b-7068-4f17-23b7ac53bc83@google.com> Message-ID: <5011977-d876-6a24-a3fc-c7e6a02877b8@google.com> References: <77a5d8c-406b-7068-4f17-23b7ac53bc83@google.com> MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII X-Spam-Status: No, score=-17.6 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF, ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_PASS, T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL,USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1765481208324262979?= X-GMAIL-MSGID: =?utf-8?q?1765481208324262979?= |
Series |
arch: allow pte_offset_map[_lock]() to fail
|
|
Commit Message
Hugh Dickins
May 10, 2023, 4:42 a.m. UTC
In rare transient cases, not yet made possible, pte_offset_map() and
pte_offset_map_lock() may not find a page table: handle appropriately.
Signed-off-by: Hugh Dickins <hughd@google.com>
---
arch/arm/lib/uaccess_with_memcpy.c | 3 +++
arch/arm/mm/fault-armv.c | 5 ++++-
arch/arm/mm/fault.c | 3 +++
3 files changed, 10 insertions(+), 1 deletion(-)
Comments
On Tue, May 09, 2023 at 09:42:44PM -0700, Hugh Dickins wrote: > diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c > index e4c2677cc1e9..2f6163f05e93 100644 > --- a/arch/arm/lib/uaccess_with_memcpy.c > +++ b/arch/arm/lib/uaccess_with_memcpy.c > @@ -74,6 +74,9 @@ pin_page_for_write(const void __user *_addr, pte_t **ptep, spinlock_t **ptlp) > return 0; > > pte = pte_offset_map_lock(current->mm, pmd, addr, &ptl); > + if (unlikely(!pte)) > + return 0; Failing seems like the wrong thig to do if we transitioned from a PTE to PMD here? Looks to me like we should goto a new label right after the 'pmd = pmd_offset(pud, addr);', no?
On Wed, 10 May 2023, Matthew Wilcox wrote: > On Tue, May 09, 2023 at 09:42:44PM -0700, Hugh Dickins wrote: > > diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c > > index e4c2677cc1e9..2f6163f05e93 100644 > > --- a/arch/arm/lib/uaccess_with_memcpy.c > > +++ b/arch/arm/lib/uaccess_with_memcpy.c > > @@ -74,6 +74,9 @@ pin_page_for_write(const void __user *_addr, pte_t **ptep, spinlock_t **ptlp) > > return 0; > > > > pte = pte_offset_map_lock(current->mm, pmd, addr, &ptl); > > + if (unlikely(!pte)) > > + return 0; > > Failing seems like the wrong thig to do if we transitioned from a PTE > to PMD here? Looks to me like we should goto a new label right after > the 'pmd = pmd_offset(pud, addr);', no? I'm pretty sure it's right as is; but probably more by luck than care - I do not think I studied this code as closely as you have now made me do; and it's clear that this is a piece of code where rare transient issues could come up, and must be handled correctly. Thank you for making me look again. The key is in the callers of pin_page_for_write(): __copy_to_user_memcpy() and __clear_user_memset(). They're doing "while (!pin_page_for_write())" loops - they hope for the fast path of getting pte_lock or pmd_lock on the page, and doing a __memcpy() or __memset() to the user address; but if anything goes "wrong", a __put_user() to fault in the page (or fail) then pin_page_for_write() again. "if (unlikely(!pte)) return 0" says that the expected fast path did not succeed, so please __put_user() and have another go. It is somewhere I could have done a "goto again", but that would be superfluous when it's already designed that way at the outer level. Hugh
diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c index e4c2677cc1e9..2f6163f05e93 100644 --- a/arch/arm/lib/uaccess_with_memcpy.c +++ b/arch/arm/lib/uaccess_with_memcpy.c @@ -74,6 +74,9 @@ pin_page_for_write(const void __user *_addr, pte_t **ptep, spinlock_t **ptlp) return 0; pte = pte_offset_map_lock(current->mm, pmd, addr, &ptl); + if (unlikely(!pte)) + return 0; + if (unlikely(!pte_present(*pte) || !pte_young(*pte) || !pte_write(*pte) || !pte_dirty(*pte))) { pte_unmap_unlock(pte, ptl); diff --git a/arch/arm/mm/fault-armv.c b/arch/arm/mm/fault-armv.c index 0e49154454a6..ca5302b0b7ee 100644 --- a/arch/arm/mm/fault-armv.c +++ b/arch/arm/mm/fault-armv.c @@ -117,8 +117,11 @@ static int adjust_pte(struct vm_area_struct *vma, unsigned long address, * must use the nested version. This also means we need to * open-code the spin-locking. */ - ptl = pte_lockptr(vma->vm_mm, pmd); pte = pte_offset_map(pmd, address); + if (!pte) + return 0; + + ptl = pte_lockptr(vma->vm_mm, pmd); do_pte_lock(ptl); ret = do_adjust_pte(vma, address, pfn, pte); diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c index 2418f1efabd8..83598649a094 100644 --- a/arch/arm/mm/fault.c +++ b/arch/arm/mm/fault.c @@ -85,6 +85,9 @@ void show_pte(const char *lvl, struct mm_struct *mm, unsigned long addr) break; pte = pte_offset_map(pmd, addr); + if (!pte) + break; + pr_cont(", *pte=%08llx", (long long)pte_val(*pte)); #ifndef CONFIG_ARM_LPAE pr_cont(", *ppte=%08llx",