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 5B36FC48BC1 for ; Mon, 12 Feb 2024 20:19:35 +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=CXMrT5C6m9mZXkBf+mFPDmuhwu4FABzxqh2WEgr/Da8=; b=gz/JTerMNwh5v+ AvgPFWo1n4/5CBRqF3LafSJynaSNN4k8qQy9Xxtvl48Z/bdz3G56BeQiIIT5IYKQKOJxGmP+JZQ+Y q1YNXoqg+FBwqZtgxsS6t+b7vuWd5brKvHbw49rUjol9T1wKElHKGksEFVbqsAmDfwEIHYvGSaCya HCK0LqwPsQSbe0Ha1NqoBc8Xw3pm3J8MCwWhFCQA0dN0+KV0Y7zv07g7tOhgQnNT7E0iSTSU58/SB lfO/Yggrfm3qIMOe7ISnynmeF3a4k1L4+qONbEN0bXjPNEiS4jTuQ+PJQ4JZ0+tvTM33Hqe8eMFRE Klk0tY0dro/g7mX4QwhA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZclw-00000006qvD-0ttz; Mon, 12 Feb 2024 20:19:24 +0000 Received: from out-171.mta1.migadu.com ([95.215.58.171]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZclt-00000006qug-2fne for linux-arm-kernel@lists.infradead.org; Mon, 12 Feb 2024 20:19:23 +0000 Date: Mon, 12 Feb 2024 20:19:10 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1707769158; 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: in-reply-to:in-reply-to:references:references; bh=6nYiM9R96Ih/XpIMMmFH+5yUjveGVIQsheV6FPrZ+VA=; b=so9pZx2XjKB64K0F7Ovv4TTtHHFnJmlCTCzvwDMbF9/PstYHS0el9ZsBz2GwYAeeCYjKEa Pd3RWdiTYlrIIhx5PJrCJNE1kfa2ogHN5YGtM6KjWQpil7l1FvhQGUckcZL397s8z3GJ94 hCczhgKqMVSG9Y1umyUVP+Uw+GAFvUM= X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. From: Oliver Upton To: Will Deacon Cc: kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Marc Zyngier , Ricardo Koller Subject: Re: [RFC PATCH] KVM: arm64: Fix double-free following kvm_pgtable_stage2_free_unlinked() Message-ID: References: <20240212193052.27765-1-will@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: X-Migadu-Flow: FLOW_OUT X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240212_121921_848842_445C7338 X-CRM114-Status: GOOD ( 26.90 ) 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 Mon, Feb 12, 2024 at 08:14:41PM +0000, Oliver Upton wrote: > On Mon, Feb 12, 2024 at 07:30:52PM +0000, Will Deacon wrote: > > kvm_pgtable_stage2_free_unlinked() does the final put_page() on the > > root page of the sub-tree before returning, so remove the additional > > put_page() invocations in the callers. > > > > Cc: Marc Zyngier > > Cc: Oliver Upton > > Cc: Ricardo Koller > > Signed-off-by: Will Deacon > > --- > > > > Hi folks, > > > > Sending this as an RFC as I only spotted it from code inspection and I'm > > surprised others aren't seeing fireworks if it's a genuine bug. I also > > couldn't come up with a sensible Fixes tag, as all of: > > > > e7c05540c694b ("KVM: arm64: Add helper for creating unlinked stage2 subtrees") > > 8f5a3eb7513fc ("KVM: arm64: Add kvm_pgtable_stage2_split()") > > f6a27d6dc51b2 ("KVM: arm64: Drop last page ref in kvm_pgtable_stage2_free_removed()") > > > > are actually ok in isolation. Hrm. Please tell me I'm wrong? > > > > arch/arm64/kvm/hyp/pgtable.c | 2 -- > > 1 file changed, 2 deletions(-) > > > > diff --git a/arch/arm64/kvm/hyp/pgtable.c b/arch/arm64/kvm/hyp/pgtable.c > > index c651df904fe3..ab9d05fcf98b 100644 > > --- a/arch/arm64/kvm/hyp/pgtable.c > > +++ b/arch/arm64/kvm/hyp/pgtable.c > > @@ -1419,7 +1419,6 @@ kvm_pte_t *kvm_pgtable_stage2_create_unlinked(struct kvm_pgtable *pgt, > > level + 1); > > if (ret) { > > kvm_pgtable_stage2_free_unlinked(mm_ops, pgtable, level); > > - mm_ops->put_page(pgtable); > > return ERR_PTR(ret); > > } > > AFAICT, this entire branch is effectively dead code, unless there's a > KVM bug lurking behind the page table walk. The sub-tree isn't visible > to other software or hardware walkers yet, so none of the PTE races > could cause this to pop. > > So while this is very obviously a bug, it might be pure luck that folks > haven't seen smoke here. Perhaps while fixing the bug we should take the > opportunity to promote the condition to WARN_ON_ONCE(). > > > @@ -1502,7 +1501,6 @@ static int stage2_split_walker(const struct kvm_pgtable_visit_ctx *ctx, > > > > if (!stage2_try_break_pte(ctx, mmu)) { > > kvm_pgtable_stage2_free_unlinked(mm_ops, childp, level); > > - mm_ops->put_page(childp); > > return -EAGAIN; > > } > > This, on the other hand, seems possible. There exists a race where an > old block PTE could have the AF set on it and the underlying cmpxchg() > could fail. That is to say, a race with a *HW* update to the PTE that sets AF. > There shouldn't be a race with any software walkers, as we > hold the MMU lock for write here. > > -- > Thanks, > Oliver -- Thanks, Oliver _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel