From patchwork Fri Nov 1 18:15:26 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dionna Amalie Glaze X-Patchwork-Id: 13859662 Received: from mail-pj1-f73.google.com (mail-pj1-f73.google.com [209.85.216.73]) (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 52DC71C9DFA for ; Fri, 1 Nov 2024 18:15:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.216.73 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730484949; cv=none; b=MDNEc16KegcQpqZfWMeIjs8dt/0epsDDLrqL4fr9vH0vJeBXOjSoBE3FneJqHODJal6lQxZUnGMY8TJf9zbzBQS3wFB28MlAJX+gwdLPXdFpoyAKWqJm9tUwIrdFlSlSsF9PJxUzJqdgqCpC2okT15AnZVgobXNIePSp7qBX/Dc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1730484949; c=relaxed/simple; bh=FW8JHk3YGfbCYGtZ3Mzk1ogv3Mmj+0IgvWXC0ldYUQ8=; h=Date:In-Reply-To:Mime-Version:References:Message-ID:Subject:From: To:Cc:Content-Type; b=pgL1wpUmSS4/Y2LLDskYac59SWCxZVIzS9AR6XQAGFV/ULvKML+IK9Oe+7AR8KXCCCrBdT3pgxcJWDvLAtc/YKmWT7QpKTnz5TF4y66O6+16HUds8j1ENhXPuJf4EqjYJzNBYwSH0EAXnLdvDqigdIHOQpli01GVkstKdW5xQE0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=reject dis=none) header.from=google.com; spf=pass smtp.mailfrom=flex--dionnaglaze.bounces.google.com; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b=DhPIakyU; arc=none smtp.client-ip=209.85.216.73 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--dionnaglaze.bounces.google.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=google.com header.i=@google.com header.b="DhPIakyU" Received: by mail-pj1-f73.google.com with SMTP id 98e67ed59e1d1-2e2ed2230fcso2694408a91.0 for ; Fri, 01 Nov 2024 11:15:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=20230601; t=1730484948; x=1731089748; darn=vger.kernel.org; h=cc:to:from:subject:message-id:references:mime-version:in-reply-to :date:from:to:cc:subject:date:message-id:reply-to; bh=q2bdkQ9H/fP+Nu98WcPEJqY3qMdHmveh6b6/XkHLIus=; b=DhPIakyU+PGljn1IYsHRJVHApfz5j7W8fLttrF7UCdH7rPJezxDMskrTzm1OFfjINW NSqzlasgKXkhEvKZ7HuwuENlL/+1CbRpU0CMrIdsuyoz64WYdmZN/Le1jL5MvCls4aaU bjhZvi2n1vz93RzxOg8fLCbN87wyJ6u/gVv1AuDqRFfsehrDq+lWTzArpYJrBtl6XWW7 OgAn7PDdxc3aX36wfNudo1AL6ipuB1pj7KYKcJfuN3E20J5pdyg53kbYqNDpxkfT1SPS 9aKwI26xrSAOBlg32C26DMzY7vEYFZiA3KS04TrYMCyWQ7jT7wDJqlKdF14fCUoKEO/K fb3Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1730484948; x=1731089748; h=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; bh=q2bdkQ9H/fP+Nu98WcPEJqY3qMdHmveh6b6/XkHLIus=; b=ljLlu6GCYDMIt9yjf9jVpF+V8felhDbdso+A45EL05YMOkEl+gtpz95ntEF5hMd9UT QcBVN5oJMu4EcheyqAZNAcTdTHqhbrUJzOLXfXqS8+UrKuyRmlDA9Sg/UDhke3NcPuQR SmxByjCQuU3OUbcWFA2aoE/TOaSVWGIFwBZvN6ZMtMBFEE4tDz/CfPExdqxlMu/mMTbl O47Owo8MtpoC0lomI7ZAgahZa0Et3lq+mEw0AYXEpIM1PQBrkcD+1QabrghuGAeCLnxu M3rDwuCfG7qYwcCSP3D07ugUAaLaNGjFpW95vUTLqJf2PV9hF6iv2L6ODFgt4xHbzb6s rdqA== X-Gm-Message-State: AOJu0Yz9XoirMV0psTK16ljCtuFA/Mfi52t+al5mP5d5xyHYbQdLDy0l L7POgXntDaAXAgBZ28eXRkphAWRvKHFJYKREtM/u0cjehIAfAIFd4fSGLq7XVhZ58JZ0jjjToAx x+btBjRqOu1C5oGCt2s9IL/CBVPFXx4KZcKnqnwrt8bf++Ru0s0hBbULUYmmr57GqaCtsikyGYQ qY8TLdZIYWXDZAx0kXyWBGChhGGhdP1HJhoNXoLk5tk2u/d5q4qtOlTdnYz4D1Qqvhx2U= X-Google-Smtp-Source: AGHT+IFlwPuf/K5AJA0znbtgKqO2qjyZICURRqpIPVlJ0DxEHxgaCJsPPCi1KIaDOmrvJ9kcdz+yRyVUuPdSr5nT+g== X-Received: from dionnaglaze.c.googlers.com ([fda3:e722:ac3:cc00:36:e7b8:ac13:c9e8]) (user=dionnaglaze job=sendgmr) by 2002:a17:90a:62c5:b0:2e2:bad0:926e with SMTP id 98e67ed59e1d1-2e93c1c9adamr28528a91.4.1730484946570; Fri, 01 Nov 2024 11:15:46 -0700 (PDT) Date: Fri, 1 Nov 2024 18:15:26 +0000 In-Reply-To: <20241101181533.1976040-1-dionnaglaze@google.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 References: <20241101181533.1976040-1-dionnaglaze@google.com> X-Mailer: git-send-email 2.47.0.163.g1226f6d8fa-goog Message-ID: <20241101181533.1976040-2-dionnaglaze@google.com> Subject: [PATCH v2 1/4] kvm: svm: Fix gctx page leak on invalid inputs From: Dionna Glaze To: linux-kernel@vger.kernel.org, x86@kernel.org, Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , "H. Peter Anvin" , Michael Roth , Brijesh Singh , Ashish Kalra Cc: Dionna Glaze , Tom Lendacky , John Allen , Herbert Xu , "David S. Miller" , Luis Chamberlain , Russ Weight , Danilo Krummrich , Greg Kroah-Hartman , "Rafael J. Wysocki" , Tianfei zhang , kvm@vger.kernel.org Ensure that snp gctx page allocation is adequately deallocated on failure during snp_launch_start. Fixes: 136d8bc931c8 ("KVM: SEV: Add KVM_SEV_SNP_LAUNCH_START command") CC: Sean Christopherson CC: Paolo Bonzini CC: Thomas Gleixner CC: Ingo Molnar CC: Borislav Petkov CC: Dave Hansen CC: Ashish Kalra CC: Tom Lendacky CC: John Allen CC: Herbert Xu CC: "David S. Miller" CC: Michael Roth CC: Luis Chamberlain CC: Russ Weight CC: Danilo Krummrich CC: Greg Kroah-Hartman CC: "Rafael J. Wysocki" CC: Tianfei zhang Signed-off-by: Dionna Glaze --- arch/x86/kvm/svm/sev.c | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 714c517dd4b72..f6e96ec0a5caa 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2212,10 +2212,6 @@ static int snp_launch_start(struct kvm *kvm, struct kvm_sev_cmd *argp) if (sev->snp_context) return -EINVAL; - sev->snp_context = snp_context_create(kvm, argp); - if (!sev->snp_context) - return -ENOTTY; - if (params.flags) return -EINVAL; @@ -2230,6 +2226,10 @@ static int snp_launch_start(struct kvm *kvm, struct kvm_sev_cmd *argp) if (params.policy & SNP_POLICY_MASK_SINGLE_SOCKET) return -EINVAL; + sev->snp_context = snp_context_create(kvm, argp); + if (!sev->snp_context) + return -ENOTTY; + start.gctx_paddr = __psp_pa(sev->snp_context); start.policy = params.policy; memcpy(start.gosvw, params.gosvw, sizeof(params.gosvw));