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=-7.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_ADSP_CUSTOM_MED,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS autolearn=no 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 BF157C4345A for ; Wed, 22 Jul 2020 15:56:12 +0000 (UTC) Received: from merlin.infradead.org (merlin.infradead.org [205.233.59.134]) (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 8DFB022CAF for ; Wed, 22 Jul 2020 15:56:12 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="vljAIWhB"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=google.com header.i=@google.com header.b="Fc6AThDw" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 8DFB022CAF Authentication-Results: mail.kernel.org; dmarc=fail (p=reject dis=none) header.from=google.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=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References:Message-ID: Subject: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=s9pin7ouVGFNxPSMUEtsK0Zeg4tDb5rVoyYMucPd448=; b=vljAIWhBZ9uCbkj3utO2DLocp zwQCVBYVDP257RNkmCxjBc1jQwEvpRa9t+7FiJ7HjQRnPVHGGmeohXKEy9bHK9JXvjpVSR4Rwb0QD D0CNaxx2UIjKkL2WC3z0c2Y1aW69CU0juK6T3a9irvFwvQpvfIXdB48Yk3EQBxCjZpCEFueAuLbqH bSeB+LjaxaD0RxXuA6O7nKzqJpJpfnzhrUu6/F9PjvrKZrD1Cg154tdXxajoK47WpLh/GW8TRE7tm FczNhwyUXIPnz9OEG0MZCc0WlimcTKI1rb9WJZTaCeAh/St2VADms3XmoGb1OEPeEao2Xb9asfhvI XAM6OKJPg==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyH4p-0002MA-0V; Wed, 22 Jul 2020 15:54:39 +0000 Received: from mail-wr1-x443.google.com ([2a00:1450:4864:20::443]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jyH4m-0002Lp-Kd for linux-arm-kernel@lists.infradead.org; Wed, 22 Jul 2020 15:54:37 +0000 Received: by mail-wr1-x443.google.com with SMTP id f1so1855468wro.2 for ; Wed, 22 Jul 2020 08:54:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20161025; h=date:from:to:cc:subject:message-id:references:mime-version :content-disposition:in-reply-to; bh=MIgLg/+oCtXlnnVfAH5YGWvDn4tjulz+CHstgUNDuBI=; b=Fc6AThDwpMZFaDh1J0ZF6aEYxH5PWsiLQnsPcR1msZjugsxaTlPNJI1EaPiYtBVUrL w7/aLZZWVHoz96ozYeZPpGKs1CgLpnSC8NvJMSz1tAty6ZTzfV2MIHXG2k1Ap+gkx6KW uR8LAOJFitbxsqxEeqS85LtqoOb9fLCCRKzFz2Jp2jcPk7sBGzwJPzuK4yNzDm12i5Q2 +Br4rSACN+TBzT16HLMpPbKnDWFd3VexUwg9izcccJw/AYqrjWCWt1g47A231rQxUTIr H0kYmZqtfksQSJpjjrgRTWNLWAJFJ1JDmFIZdeOQz1sBGfeS0uDm/K3gFJoGV/AExT7P ksmA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:date:from:to:cc:subject:message-id:references :mime-version:content-disposition:in-reply-to; bh=MIgLg/+oCtXlnnVfAH5YGWvDn4tjulz+CHstgUNDuBI=; b=DTdDuZgiDMRdV/HwhemmGdjLhCauQApde75qKfbNyvFZ0gC3jeXcervImmE8yIPjw7 nz7vITKKJm5Zaau6elzbkub5QgOOT6a7WlIQbpeAVtw+PU+49bW/DYpkDkGZVMwZOMen Z4PZ7jg6wFGlv420oGXUg+BW7ahKTo7u6zCK8OO3Sd1N9N5r5RAPUh5PX3ffE8I5IbHs pDpJELcwusLCYH5ifUEY3ydRyavM+9MSo4qla23fZtZAHVZtwMkgU/CL96Qym5xX+Jmi faFoaPcvtDDQ6rKW8+WfbDnu8ixDyDBJ5hGfWBC+woqo9upSRw3CVnwGQx9CZuVLQgVC BHQw== X-Gm-Message-State: AOAM530gEMaJ0j7kwXIwzqNNaR8cyWH2Ny9fm0EB/LdXtcQzDuwgygEG pYPvhSogyK3DO4MxbIB+wMFhJg== X-Google-Smtp-Source: ABdhPJyQ3z9VjiLaef75OMhJ7VefC8duEZSjc0/Ra37mpKst2cgL8HBdMjFok5IZBXkFsUtMCGezDQ== X-Received: by 2002:adf:ed88:: with SMTP id c8mr169859wro.233.1595433272651; Wed, 22 Jul 2020 08:54:32 -0700 (PDT) Received: from google.com ([2a00:79e0:d:110:f693:9fff:fef4:a7ef]) by smtp.gmail.com with ESMTPSA id c7sm378288wrq.58.2020.07.22.08.54.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Jul 2020 08:54:31 -0700 (PDT) Date: Wed, 22 Jul 2020 16:54:28 +0100 From: Quentin Perret To: Will Deacon Subject: Re: [PATCH] KVM: arm64: Don't inherit exec permission across page-table levels Message-ID: <20200722155428.GA275809@google.com> References: <20200722131511.14639-1-will@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20200722131511.14639-1-will@kernel.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200722_115436_691789_B2CBC2D4 X-CRM114-Status: GOOD ( 15.26 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: suzuki.poulose@arm.com, Marc Zyngier , stable@vger.kernel.org, james.morse@arm.com, kernel-team@android.com, kvmarm@lists.cs.columbia.edu, linux-arm-kernel@lists.infradead.org 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 Hey Will, On Wednesday 22 Jul 2020 at 14:15:10 (+0100), Will Deacon wrote: > diff --git a/arch/arm64/kvm/mmu.c b/arch/arm64/kvm/mmu.c > index 8c0035cab6b6..69dc36d1d486 100644 > --- a/arch/arm64/kvm/mmu.c > +++ b/arch/arm64/kvm/mmu.c > @@ -1326,7 +1326,7 @@ static bool stage2_get_leaf_entry(struct kvm *kvm, phys_addr_t addr, > return true; > } > > -static bool stage2_is_exec(struct kvm *kvm, phys_addr_t addr) > +static bool stage2_is_exec(struct kvm *kvm, phys_addr_t addr, unsigned long sz) > { > pud_t *pudp; > pmd_t *pmdp; > @@ -1338,9 +1338,9 @@ static bool stage2_is_exec(struct kvm *kvm, phys_addr_t addr) > return false; > > if (pudp) > - return kvm_s2pud_exec(pudp); > + return sz == PUD_SIZE && kvm_s2pud_exec(pudp); > else if (pmdp) > - return kvm_s2pmd_exec(pmdp); > + return sz == PMD_SIZE && kvm_s2pmd_exec(pmdp); > else > return kvm_s2pte_exec(ptep); This wants a 'sz == PAGE_SIZE' check, otherwise you'll happily inherit the exec flag when a PTE has exec rights while you create a block mapping on top. Also, I think it should be safe to make the PMD and PUD case more permissive, as 'sz <= PMD_SIZE' for instance, as the icache invalidation shouldn't be an issue there? That probably doesn't matter all that much though. > } > @@ -1958,7 +1958,8 @@ static int user_mem_abort(struct kvm_vcpu *vcpu, phys_addr_t fault_ipa, > * execute permissions, and we preserve whatever we have. > */ > needs_exec = exec_fault || > - (fault_status == FSC_PERM && stage2_is_exec(kvm, fault_ipa)); > + (fault_status == FSC_PERM && > + stage2_is_exec(kvm, fault_ipa, vma_pagesize)); > > if (vma_pagesize == PUD_SIZE) { > pud_t new_pud = kvm_pfn_pud(pfn, mem_type); > -- > 2.28.0.rc0.105.gf9edc3c819-goog > FWIW, I reproduced the issue with a dummy guest accessing memory just the wrong way, and toggling dirty logging at the right moment. And this patch + my suggestion above seems to cure things. So, with the above applied: Reviewed-by: Quentin Perret Tested-by: Quentin Perret Thanks, Quentin _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel