From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-pj1-f74.google.com (mail-pj1-f74.google.com [209.85.216.74]) (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 CA20F257431 for ; Wed, 25 Feb 2026 01:21:06 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.74 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771982467; cv=none; b=fc3zRyYt3GDgDtBX9Sf0VgL+pZhX4DCY/+GlF2ijQFuZfT/EHx6dF47m9GCG63ADFhL1DSy1w1QPb2LTNVaD72/6PFuBPedjVb+15q3tqDxlYlp7dbznjwM6lEEGKkJHJedEuUA0smensQ5z5HJAAFfGAEl64OFEvFs47B0VQFc= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1771982467; c=relaxed/simple; bh=YugX2YLyYIqesMyLVhe1vuRLpba0vyw2iEWUNwc9aeU=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=H1qqqiwk3cgrEIKvciFJZdzFRUfVA1pDtkZOeE9aBTL3MILL0gh/IKjTl/V3icZQk+N15P06bu5VHHrxfskzgcfICzEQrd7Gf/Po7sGtHq4ta9Wj3u3JoPjQ3nzg3q/Itl7/rxboGOGDMqW7dKXOb3O++SIq53Ui5kCcJ2/SzAg= 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=EghX4vDZ; arc=none smtp.client-ip=209.85.216.74 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="EghX4vDZ" Received: by mail-pj1-f74.google.com with SMTP id 98e67ed59e1d1-3562370038dso5388247a91.3 for ; Tue, 24 Feb 2026 17:21:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1771982466; x=1772587266; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:from:to:cc:subject:date:message-id:reply-to; bh=U5hmNv02IBvGPnO8Neh+XMn/il3YSxAkvHfsbK9B4L0=; b=EghX4vDZyn+mqoAu5lR8XTM56GUhSs0EV/EXjz0SQCYmIUvAvFNu7Nx68/ESPD82MF djiQIsBNz7FcqVrApJEPDV7VYUAtaTIbRUSQoLeBgfAa64Nf1QmbLTwfLY4vf+eu+Rnw NBDt3P86dI0YRcwahUHq8VWcpX2O18SK7I6G8bW5rtHQUlY9MU/hSJ/IIVfP2+5HuSeO gJgaUBVJQrPtrqthmd7sPO4kAyKK7Mitc3ECvwiTJhPmlZYQC5Q08H6xUIOSeCEeJ94O 4b5yXvYKVnA4ox2n7ja8OuhpTLxjX44CcbQg4Smco5jW5QQJ9VPjiX7tOYxcZm4WCLv3 L1Bw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1771982466; x=1772587266; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:reply-to:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=U5hmNv02IBvGPnO8Neh+XMn/il3YSxAkvHfsbK9B4L0=; b=QE/s/7605FOkFBlolyc6erXyACJ4C7fuRMLLj3ml6Dd1izbeoIwopbTcfW4jgrbxFL gv35czwsBb0GfXqxSPhHcYgpT106mNWm6yXcSsRGS+Q0zy9LBshhZHUWWj18oOWkd73K 4Hk8EEPD9LMzdt051IU8nHsTZYJn1uw5eQhvJ0k2EtX0VhJd0ZiFzO6QHmXTRiaA6DhE /68qu2PlG7JHouWTqNN41I4vuL0eXIMjw1qvB+cvMMv8OWJ5j5NBf9SZ5SlIxA7t7rGY UG80BU0I+bYdoDYSV1j6OgT5P0x2Bk/55CRgCUdwLVrpSw048fZN0gCFWz8CwxUHa0GW T2BA== X-Forwarded-Encrypted: i=1; AJvYcCX3gvPglOL03llPSgO0iJKP8LwNHX3DVEHcSWOakJ8RLn5aBJr7ejTX37JdGRBmjJCZYvLrpxGZa3uFh8o=@vger.kernel.org X-Gm-Message-State: AOJu0Yy5k9lG2mff9yhPVo1m6u9o7KUt+6D5IOB6XAXZVeM4AwgDwQCB 0V6/Rna+01JBxoXatscySaluhKou90uzkWILt/ZcxMZL/rfQRPNwp20lQQ4rzgIbPaXNEXyDeX5 mOyf89A== X-Received: from pjee13.prod.google.com ([2002:a17:90b:578d:b0:358:f01f:25f3]) (user=seanjc job=prod-delivery.src-stubby-dispatcher) by 2002:a17:90b:248f:b0:359:79e:39bb with SMTP id 98e67ed59e1d1-359079e3faemr996889a91.24.1771982465502; Tue, 24 Feb 2026 17:21:05 -0800 (PST) Reply-To: Sean Christopherson Date: Tue, 24 Feb 2026 17:20:42 -0800 In-Reply-To: <20260225012049.920665-1-seanjc@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20260225012049.920665-1-seanjc@google.com> X-Mailer: git-send-email 2.53.0.414.gf7e9f6c205-goog Message-ID: <20260225012049.920665-8-seanjc@google.com> Subject: [PATCH 07/14] KVM: x86: Harden SEV-ES MMIO against on-stack use-after-free From: Sean Christopherson To: Sean Christopherson , Paolo Bonzini , Kiryl Shutsemau Cc: kvm@vger.kernel.org, x86@kernel.org, linux-coco@lists.linux.dev, linux-kernel@vger.kernel.org, Yashu Zhang , Rick Edgecombe , Binbin Wu , Xiaoyao Li , Tom Lendacky , Michael Roth Content-Type: text/plain; charset="UTF-8" Add a sanity check to ensure KVM doesn't use an on-stack variable when handling an MMIO request for an SEV-ES guest. The source/destination for SEV-ES MMIO should _always_ be the #VMGEXIT scratch area. Opportunistically update the comment in the completion side of things to clarify that frag->data doesn't need to be copied anywhere, and the VMEGEXIT is trap-like (the current comment doesn't clarify *how* RIP is advanced). Signed-off-by: Sean Christopherson --- arch/x86/kvm/x86.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c index 7abd6f93c386..2db0bf738d2d 100644 --- a/arch/x86/kvm/x86.c +++ b/arch/x86/kvm/x86.c @@ -14273,8 +14273,10 @@ static int complete_sev_es_emulated_mmio(struct kvm_vcpu *vcpu) if (vcpu->mmio_cur_fragment >= vcpu->mmio_nr_fragments) { vcpu->mmio_needed = 0; - // VMG change, at this point, we're always done - // RIP has already been advanced + /* + * All done, as frag->data always points at the GHCB scratch + * area and VMGEXIT is trap-like (RIP is advanced by hardware). + */ return 1; } @@ -14297,7 +14299,7 @@ int kvm_sev_es_mmio_write(struct kvm_vcpu *vcpu, gpa_t gpa, unsigned int bytes, int handled; struct kvm_mmio_fragment *frag; - if (!data) + if (!data || WARN_ON_ONCE(object_is_on_stack(data))) return -EINVAL; handled = write_emultor.read_write_mmio(vcpu, gpa, bytes, data); @@ -14336,7 +14338,7 @@ int kvm_sev_es_mmio_read(struct kvm_vcpu *vcpu, gpa_t gpa, unsigned int bytes, int handled; struct kvm_mmio_fragment *frag; - if (!data) + if (!data || WARN_ON_ONCE(object_is_on_stack(data))) return -EINVAL; handled = read_emultor.read_write_mmio(vcpu, gpa, bytes, data); -- 2.53.0.414.gf7e9f6c205-goog