linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* Coverity: kvm_hv_flush_tlb(): Uninitialized variables
@ 2022-12-01 16:25 coverity-bot
  2022-12-01 16:45 ` Vitaly Kuznetsov
  0 siblings, 1 reply; 2+ messages in thread
From: coverity-bot @ 2022-12-01 16:25 UTC (permalink / raw)
  To: Vitaly Kuznetsov
  Cc: Sean Christopherson, x86, linux-kernel, Borislav Petkov,
	Ingo Molnar, H. Peter Anvin, Thomas Gleixner, Paolo Bonzini, kvm,
	Dave Hansen, Gustavo A. R. Silva, linux-next, linux-hardening

Hello!

This is an experimental semi-automated report about issues detected by
Coverity from a scan of next-20221201 as part of the linux-next scan project:
https://scan.coverity.com/projects/linux-next-weekly-scan

You're getting this email because you were associated with the identified
lines of code (noted below) that were touched by commits:

  Fri Nov 18 12:59:05 2022 -0500
    260970862c88 ("KVM: x86: hyper-v: Handle HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST{,EX} calls gently")

Coverity reported the following:

*** CID 1527764:  Uninitialized variables  (UNINIT)
arch/x86/kvm/hyperv.c:2024 in kvm_hv_flush_tlb()
2018     		 * Hyper-V TLFS doesn't explicitly forbid non-empty sparse vCPU
2019     		 * banks (and, thus, non-zero 'var_cnt') for the 'all vCPUs'
2020     		 * case (HV_GENERIC_SET_ALL).  Always adjust data_offset and
2021     		 * consumed_xmm_halves to make sure TLB flush entries are read
2022     		 * from the correct offset.
2023     		 */
vvv     CID 1527764:  Uninitialized variables  (UNINIT)
vvv     Using uninitialized value "data_offset".
2024     		data_offset += hc->var_cnt * sizeof(sparse_banks[0]);
2025     		consumed_xmm_halves += hc->var_cnt;
2026     	}
2027
2028     	if (hc->code == HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE ||
2029     	    hc->code == HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX ||

If this is a false positive, please let us know so we can mark it as
such, or teach the Coverity rules to be smarter. If not, please make
sure fixes get into linux-next. :) For patches fixing this, please
include these lines (but double-check the "Fixes" first):

Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
Addresses-Coverity-ID: 1527764 ("Uninitialized variables")
Fixes: 260970862c88 ("KVM: x86: hyper-v: Handle HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST{,EX} calls gently")

Thanks for your attention!

-- 
Coverity-bot

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Coverity: kvm_hv_flush_tlb(): Uninitialized variables
  2022-12-01 16:25 Coverity: kvm_hv_flush_tlb(): Uninitialized variables coverity-bot
@ 2022-12-01 16:45 ` Vitaly Kuznetsov
  0 siblings, 0 replies; 2+ messages in thread
From: Vitaly Kuznetsov @ 2022-12-01 16:45 UTC (permalink / raw)
  To: coverity-bot
  Cc: Sean Christopherson, x86, linux-kernel, Borislav Petkov,
	Ingo Molnar, H. Peter Anvin, Thomas Gleixner, Paolo Bonzini, kvm,
	Dave Hansen, Gustavo A. R. Silva, linux-next, linux-hardening

coverity-bot <keescook@chromium.org> writes:

> Hello!
>
> This is an experimental semi-automated report about issues detected by
> Coverity from a scan of next-20221201 as part of the linux-next scan project:
> https://scan.coverity.com/projects/linux-next-weekly-scan
>
> You're getting this email because you were associated with the identified
> lines of code (noted below) that were touched by commits:
>
>   Fri Nov 18 12:59:05 2022 -0500
>     260970862c88 ("KVM: x86: hyper-v: Handle HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST{,EX} calls gently")
>
> Coverity reported the following:
>
> *** CID 1527764:  Uninitialized variables  (UNINIT)
> arch/x86/kvm/hyperv.c:2024 in kvm_hv_flush_tlb()
> 2018     		 * Hyper-V TLFS doesn't explicitly forbid non-empty sparse vCPU
> 2019     		 * banks (and, thus, non-zero 'var_cnt') for the 'all vCPUs'
> 2020     		 * case (HV_GENERIC_SET_ALL).  Always adjust data_offset and
> 2021     		 * consumed_xmm_halves to make sure TLB flush entries are read
> 2022     		 * from the correct offset.
> 2023     		 */
> vvv     CID 1527764:  Uninitialized variables  (UNINIT)
> vvv     Using uninitialized value "data_offset".
> 2024     		data_offset += hc->var_cnt * sizeof(sparse_banks[0]);
> 2025     		consumed_xmm_halves += hc->var_cnt;
> 2026     	}
> 2027
> 2028     	if (hc->code == HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE ||
> 2029     	    hc->code == HVCALL_FLUSH_VIRTUAL_ADDRESS_SPACE_EX ||
>
> If this is a false positive, please let us know so we can mark it as
> such, or teach the Coverity rules to be smarter. If not, please make
> sure fixes get into linux-next. :) For patches fixing this, please
> include these lines (but double-check the "Fixes" first):

Looks half legit) 'data_offset' can only be uninitialized here in
'hc->fast' case but this also means that the only user of 'data_offset'
(kvm_hv_get_tlb_flush_entries()) below will not use it. So yes, we do
increment an uninitialized variable but we won't use the result. I think
we're better off fixing this, even if there's no real issue. I'll send a
patch, hopefully tomorrow.

Thanks!

>
> Reported-by: coverity-bot <keescook+coverity-bot@chromium.org>
> Addresses-Coverity-ID: 1527764 ("Uninitialized variables")
> Fixes: 260970862c88 ("KVM: x86: hyper-v: Handle HVCALL_FLUSH_VIRTUAL_ADDRESS_LIST{,EX} calls gently")
>
> Thanks for your attention!

-- 
Vitaly


^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2022-12-01 16:46 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-12-01 16:25 Coverity: kvm_hv_flush_tlb(): Uninitialized variables coverity-bot
2022-12-01 16:45 ` Vitaly Kuznetsov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).