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 59B1CC48260 for ; Tue, 13 Feb 2024 12:12:23 +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=U7/mOUwdcyKPmsB2KsGqJDrs/xwJXpTqAsPlT/yFv1U=; b=z2OlAcFgku6YaV pP3NkG5k9mwuC7Txbw/7zNLuo1HSgs3LtHe7O3rZVSAxZPrXG33Xah7dcfSJd/OEWUASDkRkyqKV1 FCWKj1OeB3vUiDVczQCczI36wpVniFS0okMJKXpGVzxBR9OvYiMe5/TRiFDSDHOkHZMSjlWkeIAs5 6yrWfu3xLmW5xGhCcCjVKbhpRUCLW/a+dk5beWfR+nUktMqOFqVzgSZ8x1RDa15P/DLbHlOCBQKaT eqx4cHq6xXSvsRS0ak2fx+tP5EXclkYYqy3tAv4bVlk/GIO536iPukKDF/L7zTOCh84g9NZsI3ssC AVv0rHs7AFmehmgom6mQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZrdz-000000098Np-2yyW; Tue, 13 Feb 2024 12:12:11 +0000 Received: from sin.source.kernel.org ([145.40.73.55]) by bombadil.infradead.org with esmtps (Exim 4.97.1 #2 (Red Hat Linux)) id 1rZrdx-000000098MI-0S0c for linux-arm-kernel@lists.infradead.org; Tue, 13 Feb 2024 12:12:10 +0000 Received: from smtp.kernel.org (transwarp.subspace.kernel.org [100.75.92.58]) by sin.source.kernel.org (Postfix) with ESMTP id 5B283CE1A95; Tue, 13 Feb 2024 12:12:07 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 5B0FDC43390; Tue, 13 Feb 2024 12:12:05 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1707826326; bh=ib6PZ8xXRpfgU5jIgXHVcqSo6CO9mgmFcvdOj5YPt6k=; h=Date:From:To:Cc:Subject:References:In-Reply-To:From; b=bLdx5kyFQjxOp5IYua7o7cVsJmsJy2pBEm3Yy7q2STJO4bSvzi7zwLSe5tzY8sIa7 uZmcgQrvfFs6LT+qVv7aKjSDO3j45v7i6IRtRta/LiSFQfkYGHZWpTBgUdOToX/GVp y0z5d9wIQAEsjkxVZKagE/t5lap6MwcngGWPt29IafqIQH3DAZfC+WumxJRLqM6fKr nFZDvcIJQEJbEB3idooxRE2/u1w0YV513qPeqwnnUKJJe8enga9EaLfd5EGKrYwFgc vTIQPSsNLJ53oNstXGzX8ZymOi0KYRNflmALGumljUjorSn0IXqw5YoKOzA9Iv/lYA ZKXiy/ZJG2C8Q== Date: Tue, 13 Feb 2024 12:12:01 +0000 From: Will Deacon To: Marc Zyngier Cc: Oliver Upton , kvmarm@lists.linux.dev, linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Ricardo Koller Subject: Re: [RFC PATCH] KVM: arm64: Fix double-free following kvm_pgtable_stage2_free_unlinked() Message-ID: <20240213121201.GA28682@willie-the-truck> References: <20240212193052.27765-1-will@kernel.org> <86cyt062jh.wl-maz@kernel.org> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <86cyt062jh.wl-maz@kernel.org> User-Agent: Mutt/1.10.1 (2018-07-13) X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20240213_041209_345457_BADF66DD X-CRM114-Status: GOOD ( 21.28 ) 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 Tue, Feb 13, 2024 at 11:12:34AM +0000, Marc Zyngier wrote: > On Mon, 12 Feb 2024 20:14:37 +0000, > Oliver Upton wrote: > > On Mon, Feb 12, 2024 at 07:30:52PM +0000, Will Deacon wrote: > > > 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()") > > I'd blame it on the last commit, as we really ought to have it if we > have the others. Yes, that's probably the best approach if you're adding a Fixes tag. > > > @@ -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. There shouldn't be a race with any software walkers, as we > > hold the MMU lock for write here. > > AF update is indeed a likely candidate. > > In any case, this patch looks good to me as it is, and we can always > have a separate tweak to adjust the severity of the first case as > required. Unless anyone objects, I'd like to queue it shortly. Fine by me! Even though I found it by inspection, I have taken the patch for a spin to check that I (somehow) didn't break something else. Will _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel