From patchwork Wed Jun 12 11:50:38 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13694861 Received: from mail-ej1-f50.google.com (mail-ej1-f50.google.com [209.85.218.50]) (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 F328216F0E4 for ; Wed, 12 Jun 2024 11:51:39 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.218.50 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718193101; cv=none; b=RGQWU2JHz7l5FxUdIdmeDIoyENrBdh8rTrfTrQfJLtgQmGHLm5I1Gsve4ILw9ex56m2RDwjCD38qe2tqUMhu+EmRtdEAt4jmFGFePo+d9tSpvsnfZnwhGwedUQuSScKN0iRxUSn/BBb9YyFiyeb2Ci+49e88dUdX7N5qEJ1w9NA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718193101; c=relaxed/simple; bh=Cqxmc4vU6fJ1ptk84gOC8RIBnHsYAaGlG8/IcCyV160=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=X/8OMSU2MB7dDxNdDRTznLqZYA7aCJCOV8bC2tBhkJKC7wsv7EarNbmMRGeWUubO4N7K/DWf1JXan7sk0EmwbWMOqF1vDePaihvH+kKOWRvSOTSIpOpoq9TM2+HR/H4O0vt4yDaRqfX/8XRXgTBlXiCUj1OeyDQ6xruTeMBnHCI= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=zZO2NDaR; arc=none smtp.client-ip=209.85.218.50 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="zZO2NDaR" Received: by mail-ej1-f50.google.com with SMTP id a640c23a62f3a-a6f0e153eddso498909966b.0 for ; Wed, 12 Jun 2024 04:51:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718193098; x=1718797898; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Md7Cta9c0UVJz/TGAYvqfK5C0UOgh9je44EY4i9/Lj8=; b=zZO2NDaRcaBHuQMozur+7Fm4cUyD18mS5kCo18VyegIi2+zicPXQ/TDCndb3n1NWYY TscsRuoWZabPoa4oM8TCUwNGE2ll2XNKpnp+0iamj/72zxs+y9INU1bSPbPTfGUdG+GO VihXA6Xs6tsyJga382tBdUp7EIN5H0rN01a4W1QstWSPEg3T8zbSdTPYHAx9lPccwTZl 4sMpUDp1WKseREnNioka0NBTfvSMW2M67v3d+7MXIgbDs5JPw4ow3jgLig9wpYnK2ARH tBo7uOcoupWhzs3Z1ywIydueDCQGi+jw2uqR+5MDIpoo9VVSWR3IlZ3XnUdf86nuXaaH JpAg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718193098; x=1718797898; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Md7Cta9c0UVJz/TGAYvqfK5C0UOgh9je44EY4i9/Lj8=; b=RG+X7M6ak1iyfNjd22P+MsNoInExAJLlaDMgElPBzHi9bWYB8HnE9h1pFIpMmSULAy 5HATXG9n94nBfGqjZre0yLHCampnoY0PJWinajEaQEeqOZqp4+iGtaXZLHiKziAa8Apg Cluy8M4wVyLnmBUHN5Js2HjZOz7OiiYmeFKK1tEBnLNF4+fSo+JF5moNGx1zpNzIYCb8 Qmo9jlxguzqYHHYXKplgJMte/jxcKbae7LKfv6V99Oid6fAdXHz+SmQJnXsqoaYndIDD y+Vu34jERJYgFvkq5xPt3k2Ro+IMwhwWwEN/LeJB3Z8wvJvmlFg23ZW7bXawik3GuvJB a/8Q== X-Forwarded-Encrypted: i=1; AJvYcCUcF06IjPjrdRQKpcF9kKNte9+OfbPUrzisoB4+7/2Qom8DkJSzD6rxcWEibWw4K/gnyEZVvyu61ompjBnOEq0wR4re X-Gm-Message-State: AOJu0YwiyEqifmAedia5Qtp5+xj9g8Q8wj6v1Z4X5vXg0ZXeKRakM4Rb uyMX2WkFA6vae3icG7IUp/ZMjiMFiRD9O6V6xlTwfPxS0SxgQTo69m3FvDK7oOk= X-Google-Smtp-Source: AGHT+IHWofN4XRRk27pqtnbrMr8jm0y9pVLTuG5m4eo7uZs4c3yYHlfkS480GWAJdWtb1ZyWojDx9A== X-Received: by 2002:a17:906:3bcb:b0:a6f:2ee7:b21a with SMTP id a640c23a62f3a-a6f48026d98mr104094766b.65.1718193098085; Wed, 12 Jun 2024 04:51:38 -0700 (PDT) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35f29d305b2sm5944700f8f.8.2024.06.12.04.51.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 04:51:37 -0700 (PDT) From: Dan Carpenter To: error27@gmail.com, Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Ashish Kalra , Brijesh Singh , Michael Roth Cc: Dan Carpenter , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 1/2] KVM: SVM: Fix uninitialized variable bug Date: Wed, 12 Jun 2024 14:50:38 +0300 Message-ID: <20240612115040.2423290-3-dan.carpenter@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240612115040.2423290-2-dan.carpenter@linaro.org> References: <20240612115040.2423290-2-dan.carpenter@linaro.org> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 If snp_lookup_rmpentry() fails then "assigned" is printed in the error message but it was never initialized. Initialize it to false. Fixes: dee5a47cc7a4 ("KVM: SEV: Add KVM_SEV_SNP_LAUNCH_UPDATE command") Signed-off-by: Dan Carpenter --- The compiler is generally already zeroing stack variables so this doesn't cost anything. arch/x86/kvm/svm/sev.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 43a450fb01fd..70d8d213d401 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2199,7 +2199,7 @@ static int sev_gmem_post_populate(struct kvm *kvm, gfn_t gfn_start, kvm_pfn_t pf for (gfn = gfn_start, i = 0; gfn < gfn_start + npages; gfn++, i++) { struct sev_data_snp_launch_update fw_args = {0}; - bool assigned; + bool assigned = false; int level; if (!kvm_mem_is_private(kvm, gfn)) { From patchwork Wed Jun 12 11:50:39 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dan Carpenter X-Patchwork-Id: 13694862 Received: from mail-wr1-f54.google.com (mail-wr1-f54.google.com [209.85.221.54]) (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 77A5D16F288 for ; Wed, 12 Jun 2024 11:51:43 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.54 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718193106; cv=none; b=KqypajhPHFr5v6ts18ZX9p9Qt7Hh6vj5oJzVpsQG5KACRhF8GpEE5q3AxofAhiDhzBpGa9Gg0tfIajd2ogEEbHC49Od9EOs8E/gLRRjsFZej/0S2Mmfe2LHNuhZWAzuo8NU8J6DqAVLx1dbhZy7UP1vGI44erBF/o4NRooFk7n4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1718193106; c=relaxed/simple; bh=Iap+yq/UFPMhzwMJN1/W29xopjf+UPCfBHcc+afOI+A=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=JqLJUroPC3k70tQFxsFIdQet44BEU6MkygZzyqHEhg6A517jKAsJ/KXvzhkafRoFLtZTV0rXcVGBPvwcSJH46DA/vwcW8gx+Kng/Fh6hnGaFm5KVtN03Yh0wNwyo+MQUz4EvHYeTYAAYuAb4Mw/EJ+5O6Vj59OSH48o7plvxRvQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org; spf=pass smtp.mailfrom=linaro.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b=MqOqwi/1; arc=none smtp.client-ip=209.85.221.54 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linaro.org Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=linaro.org header.i=@linaro.org header.b="MqOqwi/1" Received: by mail-wr1-f54.google.com with SMTP id ffacd0b85a97d-35f236a563cso1673188f8f.2 for ; Wed, 12 Jun 2024 04:51:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1718193102; x=1718797902; darn=vger.kernel.org; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=Ts2smytxY9xlqDn06N5ZqiAGp4oK5EeYYIBFYgm141E=; b=MqOqwi/12tRyx06FZsWZCfP1wvIWGqsOsevlrnRo/kDCrABrJasNNoHqyOnHXG9nAy fNAy8KlYwCoymLcuS5OBYJNOXqLYvppe7k0SVSjiRfMZmtLkwaQKHb+Ri89zwnjaMCXz 2TzCRRooM4fN1as7wdzUcAOuxNnQXz4TyjlLUEL+P16cdLza1ZgJiDpKU8srCeW59GBP qPI8SgFm4L3uPBxv3jVevR+ZY/s3bCuEuACv9/1SY+tGAM598YxNyPSL8bCppk7gY0Kp gG7KnR3usgr6XsK+uuj3FCQPcGzi8m+RDYdtDsVIB5i2+9xw1EZUPnGLnJnQP1jv6N7p lq2w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718193102; x=1718797902; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ts2smytxY9xlqDn06N5ZqiAGp4oK5EeYYIBFYgm141E=; b=sk+7x1zcEALOsOtScFyOvOMkcxzd1Oy7QEBCvRiZbyL6q/0oWA8HFmPJL0AsTWsRaE 65R0kqnN3k2NZBPqQWGY5br9Js1vJs+lSr+rLa9aFUlz/ZQpY/Vn9slwKjNKEgDsbtLq RfJEPoLJ9/ESqTkSNQDgKTUcdbQIRl+be0TX6jgbHiZDvUE/WPPwIg0tv4mRO7PZEkNE dkoms+FmCErhm6huy3p8aof82MqhKu21zeD6MaMEHOF5cJVnMWnPNnxk2wGZaK0p7UVw BoZbb8SbaxcKvCe5gif5rJimxSgpE4kXn8G2oABva1eMo060DwaQ7+Jj86wNtlBcLGpT HTsA== X-Forwarded-Encrypted: i=1; AJvYcCVsf3cUeZBUtlePDj3FVK+OmInLaYx4pVWrAljN5FnWyXNKILo7QWK3pUWTftZTXCCH6DJCCTqm/trUx0XBCbJndn+L X-Gm-Message-State: AOJu0YwY2VrXpCDXuITIBKS0on0svngv0ERdAEA/zQL++agOwiCJOceN R4yVX4hXECV7fmdu5fOcGWduNSdJ+P9Ay0fS5Bhk/tDpVmsxepSu8VClK0iiLXE= X-Google-Smtp-Source: AGHT+IGB21Kf+Yq70AofnMnKtJ/sAErPjS2QGuOdCNlXD6VJnixK2VEnojOvLWIJ653dzNytJ5zyZA== X-Received: by 2002:a05:6000:196c:b0:35f:1c6b:2b24 with SMTP id ffacd0b85a97d-35fe88c9498mr1167357f8f.29.1718193101706; Wed, 12 Jun 2024 04:51:41 -0700 (PDT) Received: from localhost ([102.222.70.76]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-35f23fe7a64sm8174762f8f.89.2024.06.12.04.51.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 12 Jun 2024 04:51:41 -0700 (PDT) From: Dan Carpenter To: error27@gmail.com, Sean Christopherson , Paolo Bonzini , Thomas Gleixner , Ingo Molnar , Borislav Petkov , Dave Hansen , x86@kernel.org, "H. Peter Anvin" , Brijesh Singh , Michael Roth , Ashish Kalra Cc: Dan Carpenter , kvm@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH 2/2] KVM: SVM: Fix an error code in sev_gmem_post_populate() Date: Wed, 12 Jun 2024 14:50:39 +0300 Message-ID: <20240612115040.2423290-4-dan.carpenter@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240612115040.2423290-2-dan.carpenter@linaro.org> References: <20240612115040.2423290-2-dan.carpenter@linaro.org> Precedence: bulk X-Mailing-List: kvm@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 The copy_from_user() function returns the number of bytes which it was not able to copy. Return -EFAULT instead. Fixes: dee5a47cc7a4 ("KVM: SEV: Add KVM_SEV_SNP_LAUNCH_UPDATE command") Signed-off-by: Dan Carpenter --- arch/x86/kvm/svm/sev.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/arch/x86/kvm/svm/sev.c b/arch/x86/kvm/svm/sev.c index 70d8d213d401..14bb52ebd65a 100644 --- a/arch/x86/kvm/svm/sev.c +++ b/arch/x86/kvm/svm/sev.c @@ -2220,9 +2220,10 @@ static int sev_gmem_post_populate(struct kvm *kvm, gfn_t gfn_start, kvm_pfn_t pf if (src) { void *vaddr = kmap_local_pfn(pfn + i); - ret = copy_from_user(vaddr, src + i * PAGE_SIZE, PAGE_SIZE); - if (ret) + if (copy_from_user(vaddr, src + i * PAGE_SIZE, PAGE_SIZE)) { + ret = -EFAULT; goto err; + } kunmap_local(vaddr); }