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] [thread-next>] [day] [month] [year] [list]
Date:   Wed, 23 Feb 2022 18:56:28 +0000
From:   Sean Christopherson <seanjc@...gle.com>
To:     Nathan Chancellor <nathan@...nel.org>
Cc:     Paolo Bonzini <pbonzini@...hat.com>,
        Nick Desaulniers <ndesaulniers@...gle.com>,
        Vitaly Kuznetsov <vkuznets@...hat.com>,
        Wanpeng Li <wanpengli@...cent.com>,
        Jim Mattson <jmattson@...gle.com>,
        Joerg Roedel <joro@...tes.org>, kvm@...r.kernel.org,
        llvm@...ts.linux.dev, linux-kernel@...r.kernel.org,
        Like Xu <like.xu.linux@...il.com>
Subject: Re: [PATCH] KVM: x86: Fix pointer mistmatch warning when patching
 RET0 static calls

On Wed, Feb 23, 2022, Nathan Chancellor wrote:
> On Wed, Feb 23, 2022 at 05:59:05PM +0000, Sean Christopherson wrote:
> > On Wed, Feb 23, 2022, Nathan Chancellor wrote:
> > > Hi Sean,
> > > 
> > > On Wed, Feb 23, 2022 at 04:23:55PM +0000, Sean Christopherson wrote:
> > > > Cast kvm_x86_ops.func to 'void *' when updating KVM static calls that are
> > > > conditionally patched to __static_call_return0().  clang complains about
> > > > using mismatching pointers in the ternary operator, which breaks the
> > > > build when compiling with CONFIG_KVM_WERROR=y.
> > > > 
> > > >   >> arch/x86/include/asm/kvm-x86-ops.h:82:1: warning: pointer type mismatch
> > > >   ('bool (*)(struct kvm_vcpu *)' and 'void *') [-Wpointer-type-mismatch]
> > > > 
> > > > Fixes: 5be2226f417d ("KVM: x86: allow defining return-0 static calls")
> > > > Reported-by: Like Xu <like.xu.linux@...il.com>
> > > > Reported-by: kernel test robot <lkp@...el.com>
> > > > Signed-off-by: Sean Christopherson <seanjc@...gle.com>
> > > 
> > > Thank you for the patch! Is this a bug in clang?
> > 
> > IMO, no.  I think it's completely reasonable for the compiler to complain that KVM
> > is generating two different pointer types out of a ternary operator.
> > 
> > clang is somewhat inconsistent, though it may be deliberate.  clang doesn't complain
> > about implicitly casting a 'void *' to another data type, e.g. this complies clean,
> > where "data" is a 'void *'
> > 
> > 	struct kvm_vcpu *x = vcpu ? : data;
> 
> Right, I would assume this is deliberate. I think warning in this case
> might be quite noisy, as the kernel implicitly converts 'void *' to
> typed pointers for certain function pointer callbacks (although this
> particular case is probably pretty rare).

Aha!  Looks like clang's behavior is correct, assuming a function is not considered
an "object".  From C99 "6.5.15 Conditional operator":

  One of the following shall hold for the second and third operands:
    — both operands have arithmetic type;
    — both operands have the same structure or union type;
    — both operands have void type;
    — both operands are pointers to qualified or unqualified versions of compatible types;
    — one operand is a pointer and the other is a null pointer constant; or
    — one operand is a pointer to an object or incomplete type and the other is a pointer to a
      qualified or unqualified version of void.

That last case would explain why clang warns about a function pointer but not a
object pointer when the third operand is a 'void *'.

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ