From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pg1-f198.google.com (mail-pg1-f198.google.com [209.85.215.198]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 289143F0A94 for ; Mon, 10 Aug 2026 16:29:30 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.215.198 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786379371; cv=none; b=MPrvx8s796PYUbEpjFBorM+AZmHR2p8S9uyOWRts++yqC5FrRBBaoNdQbfpAZNblgEBqetVZdLB0EMX3FXlvImjh5FhJKGCpY3Hu+zJjvhqwfjz2TjLsYENq/vte1zgjnYRL0htaqCZeGbQFkQlZVen+xakf6fqFFaks9JZ4FMI= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1786379371; c=relaxed/simple; bh=cB3t5Wt/v5lqDAqABYRu5BRDHci0OZngRYQCJr4+fBc=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=T7TawR0/o8oTQ/Iwcedi/htyjuU8fNGTjuhLSvW7RRvfaLKVr562ZRSScBO751gM7n9jcitzvJJRHAL91NCXRXvh6M0nho1YCx6J7rXrygU6RWjMzFZpQrzmMEGiQT5xBDDtX+UXjOO98KDFL5j6FNOKsSG4tCG64iibrlGk9bw= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=WBH6kTaz; arc=none smtp.client-ip=209.85.215.198 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=flex--seanjc.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="WBH6kTaz" Received: by mail-pg1-f198.google.com with SMTP id 41be03b00d2f7-c856470fe9fso1567219a12.2 for ; Mon, 10 Aug 2026 09:29:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20251104; t=1786379369; x=1786984169; darn=vger.kernel.org; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:from:to:cc:subject:date:message-id:reply-to :content-type; bh=iRqatjF6laSho8dqZBckVCKdXvkaRYO7dn0sgVFL7kA=; b=WBH6kTazTNHPlRsvqnx9brrHzrFQf68MzfJ0K5iy7KPSDrOwyNJOQ4qxLGx2u3WDHV 1OX4Jw7mCjbcjyYjOPfHwNXiU37XKpYHEL91dFLtnqIP5CdKws5fKdLQaWixAbyrFlGu JTWcEvdu50BrIJjyjcRIb4p89CI8UWk705joWeXrQ51CCvQVfHzSMAgVzdP9FTK7n3Aa EU9epKdh8DsRsBrYI30xKlca6R8ZNlTaAJ13OSra4cIH2AZbjM6ioLZMuG1JX2+IIADL 6fXfH5tAHsHbzMGQP2kyh1NDg+xJzPfjkgwj0ays7jZv/7gNGmH9x7811i2od5L331Dj ZuFA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1786379369; x=1786984169; h=content-type:cc:to:from:subject:message-id:references:mime-version :in-reply-to:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to:content-type; bh=iRqatjF6laSho8dqZBckVCKdXvkaRYO7dn0sgVFL7kA=; b=EvJNs7CpdKPbUtiWzaOFF3uDDjfgXJjhmRSPNetYTXYJKj3/kZ9TgErvMbm4ogzysv jkTAmqNtko2gxbdI0p1yAaYlxAZjz8RAL5JVLBXkrBss+T4nY9u4w+if9xp6ufS0cbaG l/stubQRClqt+jC0m6RPTP8e/5CXAUowhihBnunClfPbBBUbxUtFBYlFQQFxQ+zstIkF KUE6dL4YKcn9KagJG/nkDSagiSWGVSqjPPPoDzStDwOAfehsqQ+7fnwcAmAkvBIV9jCT ZW0I5m28O+Ws37wtlmHtVCczewqQgan3J4jphLlX+vHkoZfmwr+ngeevisUiuT7elNkd 3atA== X-Forwarded-Encrypted: i=1; AHgh+Rqfnad47BRbsmal0hUh24bOpf2J988JjJY/O6IX+GenQEpRAWKq5PG+L5ZHFdTdEzf/5hMj9Ii4q76/Jco=@vger.kernel.org X-Gm-Message-State: AOJu0Yw2yku/ME0mbf+im/hnN85H0xKA939ZHwvc2uFNprF2nctw0uJh QjN88EQh7MLWR6P1jjEj5TBoOVN4KYF2MAG7h5LY4TkivN3jB9uSHIT9po5FcSpPBZXj23G8HLt B574uCw== X-Received: from pgki17.prod.google.com ([2002:a63:e451:0:b0:c99:aff5:7092]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a05:6a21:69a:b0:3c8:e313:8d42 with SMTP id adf61e73a8af0-3cbce96f6dcmr23916356637.31.1786379369244; Mon, 10 Aug 2026 09:29:29 -0700 (PDT) Date: Mon, 10 Aug 2026 09:29:28 -0700 In-Reply-To: <20260810-x86-kvm-setpagedirty-v1-1-85f180892d4f@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260810-x86-kvm-setpagedirty-v1-1-85f180892d4f@google.com> Message-ID: Subject: Re: [PATCH] KVM: SEV: Fix page dirtying in sev_gmem_post_populate() From: Sean Christopherson To: Jann Horn Cc: Paolo Bonzini , Ackerley Tng , kvm@vger.kernel.org, linux-kernel@vger.kernel.org, "Matthew Wilcox (Oracle)" , Jan Kara Content-Type: text/plain; charset="us-ascii" On Mon, Aug 10, 2026, Jann Horn wrote: > set_page_dirty() requires that the caller holds some kind of lock to > ensure that the page's mapping does not concurrently go away. > That is not the case for a random page we got from get_user_pages_fast(), > so use set_page_dirty_lock(). FWIW, I verified that __kvm_gmem_populate() unlocks the destination folio before post_populate(), so we shouldn't run into deadlock when in-place conversion comes along and userspace does something odd. > Fixes: 97cd21d57e9b ("KVM: SEV: Mark source page dirty when writing back CPUID data on failure") > Signed-off-by: Jann Horn > --- > Note that I have only convinced myself that this is a UAF bug by reading > the source code, and I have only compile-tested this patch; I do not > have SEV-SNP hardware to actually test this. > > This bug was introduced in v7.2-rc1, so if we can get the fix in before > the 7.2 release, this won't require a stable backport. Ya, that would be lovely. Paolo? > For context, I have seen similar bugs (set_page_dirty() on a page from > GUP) in two out-of-tree drivers in the past, where this led to UAF. > Evidently set_page_dirty() is a bit of a footgun for GUP users... Heh, and that's a bit of an understatement :-D Reviewed-by: Sean Christopherson