lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [<thread-prev] [day] [month] [year] [list]
Message-ID: <538DC978.5040300@redhat.com>
Date:	Tue, 03 Jun 2014 15:11:20 +0200
From:	Paolo Bonzini <pbonzini@...hat.com>
To:	Michael Tokarev <mjt@....msk.ru>,
	Rickard Strandqvist <rickard_strandqvist@...ctrumdigital.se>,
	Gleb Natapov <gleb@...nel.org>
CC:	Thomas Gleixner <tglx@...utronix.de>,
	Ingo Molnar <mingo@...hat.com>,
	"H. Peter Anvin" <hpa@...or.com>, x86@...nel.org,
	kvm@...r.kernel.org, linux-kernel@...r.kernel.org
Subject: Re: [PATCH] arch: x86: kvm: x86.c:  Cleaning up uninitialized variables

Il 03/06/2014 15:06, Michael Tokarev ha scritto:
> 03.06.2014 16:04, Paolo Bonzini wrote:
>> Il 01/06/2014 01:05, Rickard Strandqvist ha scritto:
>>> There is a risk that the variable will be used without being initialized.
>>>
>>> This was largely found by using a static code analysis program called cppcheck.
>>>
>>> Signed-off-by: Rickard Strandqvist <rickard_strandqvist@...ctrumdigital.se>
>>
>> No, there isn't.  The full context looks like this:
>>
>>         longmode = is_long_mode(vcpu) && cs_l == 1;
>>         if (!longmode) {
>>                 param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX) << 32) |
>>                         (kvm_register_read(vcpu, VCPU_REGS_RAX) & 0xffffffff);
>>                 ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX) << 32) |
>>                         (kvm_register_read(vcpu, VCPU_REGS_RCX) & 0xffffffff);
>>                 outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI) << 32) |
>>                         (kvm_register_read(vcpu, VCPU_REGS_RSI) & 0xffffffff);
>>         }
>> #ifdef CONFIG_X86_64
>>         else {
>>                 param = kvm_register_read(vcpu, VCPU_REGS_RCX);
>>                 ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
>>                 outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
>>         }
>> #endif
>>
>> and longmode must be zero if !CONFIG_X86_64:
>
> This is not the first time this code is attempted to be changed.
>
> Maybe adding an additional #ifdef..endif around the longmode
> assignment and the "if" above will solve this for good?
>
> Or maybe something like this:
>
>  #ifdef CONFIG_X86_64
>          if (!(is_long_mode(vcpu) && cs_l == 1)) {
>  #else
>          if (1) {
>  #endif
>                  param = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDX) << 32) |
>                          (kvm_register_read(vcpu, VCPU_REGS_RAX) & 0xffffffff);
>                  ingpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RBX) << 32) |
>                          (kvm_register_read(vcpu, VCPU_REGS_RCX) & 0xffffffff);
>                  outgpa = ((u64)kvm_register_read(vcpu, VCPU_REGS_RDI) << 32) |
>                          (kvm_register_read(vcpu, VCPU_REGS_RSI) & 0xffffffff);
>          }
>          else {
>                  param = kvm_register_read(vcpu, VCPU_REGS_RCX);
>                  ingpa = kvm_register_read(vcpu, VCPU_REGS_RDX);
>                  outgpa = kvm_register_read(vcpu, VCPU_REGS_R8);
>          }
>
> , to make it all explicit and obvious?

... and ugly too.

If the first person who got the answer had reported a bug against 
cppcheck, this perhaps would have been avoided.

Paolo

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ