From: Sean Christopherson <seanjc@google.com>
To: Paolo Bonzini <pbonzini@redhat.com>,
Nathan Chancellor <nathan@kernel.org>,
Nick Desaulniers <ndesaulniers@google.com>
Cc: Sean Christopherson <seanjc@google.com>,
Vitaly Kuznetsov <vkuznets@redhat.com>,
Wanpeng Li <wanpengli@tencent.com>,
Jim Mattson <jmattson@google.com>, Joerg Roedel <joro@8bytes.org>,
kvm@vger.kernel.org, clang-built-linux@googlegroups.com,
linux-kernel@vger.kernel.org
Subject: [PATCH] KVM: x86: Fix uninitialized return value bug in EXIT_HYPERCALL enabling
Date: Thu, 24 Jun 2021 11:06:25 -0700 [thread overview]
Message-ID: <20210624180625.159495-1-seanjc@google.com> (raw)
Zero out 'r' on success in the KVM_CAP_EXIT_HYPERCALL case. As noted by
clang, the happy path will return an uninitialized value:
arch/x86/kvm/x86.c:5649:7: error: variable 'r' is used uninitialized
whenever 'if' condition is false [-Werror,-Wsometimes-uninitialized]
if (cap->args[0] & ~KVM_EXIT_HYPERCALL_VALID_MASK) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/kvm/x86.c:5663:9: note: uninitialized use occurs here
return r;
^
arch/x86/kvm/x86.c:5649:3: note: remove the 'if' if its condition is always true
if (cap->args[0] & ~KVM_EXIT_HYPERCALL_VALID_MASK) {
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
arch/x86/kvm/x86.c:5540:7: note: initialize the variable 'r' to silence this warning
int r;
^
= 0
Opportunistically move the "r = -EINVAL;" above the check to match the
pattern used in almost all other cases.
Fixes: 0dbb11230437 ("KVM: X86: Introduce KVM_HC_MAP_GPA_RANGE hypercall")
Signed-off-by: Sean Christopherson <seanjc@google.com>
---
arch/x86/kvm/x86.c | 7 ++++---
1 file changed, 4 insertions(+), 3 deletions(-)
diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
index e4cea00c49a3..647922ba97df 100644
--- a/arch/x86/kvm/x86.c
+++ b/arch/x86/kvm/x86.c
@@ -5646,11 +5646,12 @@ int kvm_vm_ioctl_enable_cap(struct kvm *kvm,
r = kvm_x86_ops.vm_copy_enc_context_from(kvm, cap->args[0]);
return r;
case KVM_CAP_EXIT_HYPERCALL:
- if (cap->args[0] & ~KVM_EXIT_HYPERCALL_VALID_MASK) {
- r = -EINVAL;
+ r = -EINVAL;
+ if (cap->args[0] & ~KVM_EXIT_HYPERCALL_VALID_MASK)
break;
- }
+
kvm->arch.hypercall_exit_enabled = cap->args[0];
+ r = 0;
break;
case KVM_CAP_EXIT_ON_EMULATION_FAILURE:
kvm->arch.exit_on_emulation_error = cap->args[0];
--
2.32.0.93.g670b81a890-goog
next reply other threads:[~2021-06-24 18:06 UTC|newest]
Thread overview: 4+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-24 18:06 Sean Christopherson [this message]
2021-06-24 18:19 ` [PATCH] KVM: x86: Fix uninitialized return value bug in EXIT_HYPERCALL enabling Paolo Bonzini
2021-06-24 18:20 ` Nick Desaulniers
2021-06-24 18:22 ` Sean Christopherson
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20210624180625.159495-1-seanjc@google.com \
--to=seanjc@google.com \
--cc=clang-built-linux@googlegroups.com \
--cc=jmattson@google.com \
--cc=joro@8bytes.org \
--cc=kvm@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=nathan@kernel.org \
--cc=ndesaulniers@google.com \
--cc=pbonzini@redhat.com \
--cc=vkuznets@redhat.com \
--cc=wanpengli@tencent.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox