[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <Zpq4B2I1xcMLmuox@google.com>
Date: Fri, 19 Jul 2024 12:01:27 -0700
From: Sean Christopherson <seanjc@...gle.com>
To: Mirsad Todorovac <mtodorovac69@...il.com>
Cc: kvm@...r.kernel.org, Paolo Bonzini <pbonzini@...hat.com>,
Thomas Gleixner <tglx@...utronix.de>, Ingo Molnar <mingo@...hat.com>, Borislav Petkov <bp@...en8.de>,
Dave Hansen <dave.hansen@...ux.intel.com>, x86@...nel.org,
"H. Peter Anvin" <hpa@...or.com>, linux-kernel@...r.kernel.org,
David Edmondson <david.edmondson@...cle.com>
Subject: Re: [BUG] arch/x86/kvm/x86.c: In function ‘prepare_emulation_failure_exit’: error: use of NULL ‘data’
where non-null expected
On Fri, Jul 19, 2024, Mirsad Todorovac wrote:
> Hi, all!
>
> On linux-stable 6.10 vanilla tree, another NULL pointer is passed, which was detected
> by the fortify-string.h mechanism.
>
> arch/x86/kvm/x86.c
> ==================
>
> 13667 kvm_prepare_emulation_failure_exit(vcpu);
>
> calls
>
> 8796 __kvm_prepare_emulation_failure_exit(vcpu, NULL, 0);
>
> which calls
>
> 8790 prepare_emulation_failure_exit(vcpu, data, ndata, NULL, 0);
>
> Note here that data == NULL and ndata = 0.
>
> again data == NULL and ndata == 0, which passes unchanged all until
>
> 8773 memcpy(&run->internal.data[info_start + ARRAY_SIZE(info)], data, ndata * sizeof(data[0]));
My reading of the C99 is that KVM's behavior is fine.
Where an argument declared as size_t n specifies the length of the array for a
function, n can have the value zero on a call to that function. Unless explicitly stated
otherwise in the description of a particular function in this subclause, pointer arguments
on such a call shall still have valid values, as described in 7.1.4. On such a call, a
function that locates a character finds no occurrence, a function that compares two
character sequences returns zero, and a function that copies characters copies zero
characters.
If the function copies zero characters, then there can't be a store to the NULL
pointer, and if there's no store, there's no NULL pointer explosion.
I suppose arguably one could argue the builtin memcpy() could deliberately fail
on an invalid pointer, but that'd be rather ridiculous.
Powered by blists - more mailing lists