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 X-Spam-Level: X-Spam-Status: No, score=-10.6 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH, MAILING_LIST_MULTI,NICE_REPLY_A,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_SANE_1 autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 791A6C48BDF for ; Thu, 24 Jun 2021 12:43:05 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 41340613F9 for ; Thu, 24 Jun 2021 12:43:05 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 41340613F9 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender:Content-Type: Content-Transfer-Encoding:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:Date:Message-ID:From: References:Cc:To:Subject:Reply-To:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:List-Owner; bh=e6/1Oai6XZS/74g15pAtU1S3KE+oz/1bacsKfav1L78=; b=tDxk3Wjt6kzzb4thWguXdPQnJS M0lXDTWNdawYrezs5urMgCTOYSeSc/SQasIffNJI04pdqlCBz3WEsTtRtndvU8+xwnbw9tgNjO7cc GyO43fzyig+cWbnaeNdQQ2TuSH4BDvG7Buzcv8QLBk8e5+TX2wpjblLqILkAgpNvkOCxMLKZ9nV02 xXg6TbFP9P2Xj/oKUH5ewpNI+HlksJLhB8TfERd40q1zQafv+B2r+xTUmNr0CDyXYxqsD5B0ERKgR UXp5YYvMJPCKjSuo+APD9edMnVdJrvKxA6CZDU/1oaWnVp0ngeLTX2cTmbP6t3itJ00MiTWm4MA21 +gsqHGbA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1lwOfk-00EeM6-QU; Thu, 24 Jun 2021 12:41:33 +0000 Received: from us-smtp-delivery-124.mimecast.com ([216.205.24.124]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1lwOfg-00EeKW-4R for linux-arm-kernel@lists.infradead.org; Thu, 24 Jun 2021 12:41:29 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1624538486; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=Ao/aik86DETd7ceeMOwWvzTcaJv+rZayOURU+D31sn8=; b=GjvelJK9NqzwPH+wQt4p2rrMHQ+NmPcPSNVXrH2f0EGBGBkRWu28p8uhXdnkGg+jIxxi35 K18CZYpwAQXIXJe/qoc0AAtBS6Xqn7n7gbbZtzOsuIr22LchymDudqsIDKQkzI+6dF6VBX PM/RTYHUvoAjjDy3wrUPGHfG0iT5m+I= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-573-W6XvFZVMN06267vasphNLQ-1; Thu, 24 Jun 2021 08:41:25 -0400 X-MC-Unique: W6XvFZVMN06267vasphNLQ-1 Received: by mail-wr1-f70.google.com with SMTP id g8-20020a5d54080000b0290124a2d22ff8so1581030wrv.4 for ; Thu, 24 Jun 2021 05:41:25 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=Ao/aik86DETd7ceeMOwWvzTcaJv+rZayOURU+D31sn8=; b=Igy4ETV9UkMljrdNRcb42ZyMKs3/FmM/LJl17Ee1ksOo88CUYEfTsG6GFAe5U5OpLz S3kpjVDemHDJg58mwh+i6G4+ca6Y3bH5BSazragizcO0Y8Bb6RkZk5SXZsfkm/kfYG79 8fojLDYjcTdTUjzpNMOf/OmpspCVFxAFkJU1xUCOmhEjia77yKNAj0RBOWkaN1DMB0uB BMJRdQoLrOR1US9TzAIYjCgxOZ73UoNYA2/lk9Ben92TV/dU9kw0+5o+V4RISdK5+Gp5 xCrbaWKP6LxpyASE6SeBpeLwJ8O5YI5PiB4pQsFIb636+f6kQheykLVBkzxVUx95CMk8 z1/w== X-Gm-Message-State: AOAM531/IRKfVlXEBtZ6gY5B4YN7qANo+lUOT8IRY5hYtrJT7NrRo0q4 QTP29/wOEGA+3Zg6oGEJ1lsNfKYEiV1XZz/whePnPqRmplSF1KtJADrsnc4f1lTcY2pF6QyI0YE 0blgaIdbMD95cNajR7Jk1KdAgDhQjt4uNJd8= X-Received: by 2002:adf:f88e:: with SMTP id u14mr4211978wrp.391.1624538484097; Thu, 24 Jun 2021 05:41:24 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxX2C4aDAGP4h4xfzWoN2DoJE9Xd7OTVDMCCB2JExPqVzxr2MgGsOeSZupCF70+GqEZaJi1OA== X-Received: by 2002:adf:f88e:: with SMTP id u14mr4211952wrp.391.1624538483934; Thu, 24 Jun 2021 05:41:23 -0700 (PDT) Received: from ?IPv6:2001:b07:6468:f312:c8dd:75d4:99ab:290a? ([2001:b07:6468:f312:c8dd:75d4:99ab:290a]) by smtp.gmail.com with ESMTPSA id 22sm2818691wmi.4.2021.06.24.05.41.22 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 24 Jun 2021 05:41:23 -0700 (PDT) Subject: Re: [PATCH 0/6] KVM: Remove uses of struct page from x86 and arm64 MMU To: Nicholas Piggin , Aleksandar Markovic , Huacai Chen , Marc Zyngier , Paul Mackerras , David Stevens , Zhenyu Wang , Zhi Wang Cc: Alexandru Elisei , dri-devel@lists.freedesktop.org, intel-gfx@lists.freedesktop.org, intel-gvt-dev@lists.freedesktop.org, James Morse , Jim Mattson , Joerg Roedel , kvmarm@lists.cs.columbia.edu, kvm-ppc@vger.kernel.org, kvm@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mips@vger.kernel.org, linuxppc-dev@lists.ozlabs.org, Sean Christopherson , David Stevens , Suzuki K Poulose , Vitaly Kuznetsov , Wanpeng Li , Will Deacon References: <20210624035749.4054934-1-stevensd@google.com> <1624530624.8jff1f4u11.astroid@bobo.none> <1624534759.nj0ylor2eh.astroid@bobo.none> From: Paolo Bonzini Message-ID: <0d3a699a-15eb-9f1b-0735-79d14736f38c@redhat.com> Date: Thu, 24 Jun 2021 14:41:21 +0200 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: <1624534759.nj0ylor2eh.astroid@bobo.none> Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=pbonzini@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210624_054128_336498_1B853D59 X-CRM114-Status: GOOD ( 36.91 ) 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-Transfer-Encoding: 7bit Content-Type: text/plain; charset="us-ascii"; Format="flowed" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On 24/06/21 13:42, Nicholas Piggin wrote: > Excerpts from Nicholas Piggin's message of June 24, 2021 8:34 pm: >> Excerpts from David Stevens's message of June 24, 2021 1:57 pm: >>> KVM supports mapping VM_IO and VM_PFNMAP memory into the guest by using >>> follow_pte in gfn_to_pfn. However, the resolved pfns may not have >>> assoicated struct pages, so they should not be passed to pfn_to_page. >>> This series removes such calls from the x86 and arm64 secondary MMU. To >>> do this, this series modifies gfn_to_pfn to return a struct page in >>> addition to a pfn, if the hva was resolved by gup. This allows the >>> caller to call put_page only when necessated by gup. >>> >>> This series provides a helper function that unwraps the new return type >>> of gfn_to_pfn to provide behavior identical to the old behavior. As I >>> have no hardware to test powerpc/mips changes, the function is used >>> there for minimally invasive changes. Additionally, as gfn_to_page and >>> gfn_to_pfn_cache are not integrated with mmu notifier, they cannot be >>> easily changed over to only use pfns. >>> >>> This addresses CVE-2021-22543 on x86 and arm64. >> >> Does this fix the problem? (untested I don't have a POC setup at hand, >> but at least in concept) > > This one actually compiles at least. Unfortunately I don't have much > time in the near future to test, and I only just found out about this > CVE a few hours ago. And it also works (the reproducer gets an infinite stream of userspace exits and especially does not crash). We can still go for David's solution later since MMU notifiers are able to deal with this pages, but it's a very nice patch for stable kernels. If you provide a Signed-off-by, I can integrate it. Paolo > --- > > > It's possible to create a region which maps valid but non-refcounted > pages (e.g., tail pages of non-compound higher order allocations). These > host pages can then be returned by gfn_to_page, gfn_to_pfn, etc., family > of APIs, which take a reference to the page, which takes it from 0 to 1. > When the reference is dropped, this will free the page incorrectly. > > Fix this by only taking a reference on the page if it was non-zero, > which indicates it is participating in normal refcounting (and can be > released with put_page). > > --- > virt/kvm/kvm_main.c | 19 +++++++++++++++++-- > 1 file changed, 17 insertions(+), 2 deletions(-) > > diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c > index 6a6bc7af0e28..46fb042837d2 100644 > --- a/virt/kvm/kvm_main.c > +++ b/virt/kvm/kvm_main.c > @@ -2055,6 +2055,13 @@ static bool vma_is_valid(struct vm_area_struct *vma, bool write_fault) > return true; > } > > +static int kvm_try_get_pfn(kvm_pfn_t pfn) > +{ > + if (kvm_is_reserved_pfn(pfn)) > + return 1; > + return get_page_unless_zero(pfn_to_page(pfn)); > +} > + > static int hva_to_pfn_remapped(struct vm_area_struct *vma, > unsigned long addr, bool *async, > bool write_fault, bool *writable, > @@ -2104,13 +2111,21 @@ static int hva_to_pfn_remapped(struct vm_area_struct *vma, > * Whoever called remap_pfn_range is also going to call e.g. > * unmap_mapping_range before the underlying pages are freed, > * causing a call to our MMU notifier. > + * > + * Certain IO or PFNMAP mappings can be backed with valid > + * struct pages, but be allocated without refcounting e.g., > + * tail pages of non-compound higher order allocations, which > + * would then underflow the refcount when the caller does the > + * required put_page. Don't allow those pages here. > */ > - kvm_get_pfn(pfn); > + if (!kvm_try_get_pfn(pfn)) > + r = -EFAULT; > > out: > pte_unmap_unlock(ptep, ptl); > *p_pfn = pfn; > - return 0; > + > + return r; > } > > /* > _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel