On Thu, Jun 20, 2019 at 12:37:20PM +0200, Borislav Petkov wrote:
> On Wed, Jun 19, 2019 at 02:34:04PM -0700, Fenghua Yu wrote:
> You need to test the sub-leaf index validity here before accessing
> subleaf 1:
> 
> diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
> index 4910cb421b82..dad20bc891d5 100644
> --- a/arch/x86/kernel/cpu/common.c
> +++ b/arch/x86/kernel/cpu/common.c
> @@ -848,8 +848,11 @@ void get_cpu_cap(struct cpuinfo_x86 *c)
>               c->x86_capability[CPUID_7_ECX] = ecx;
>               c->x86_capability[CPUID_7_EDX] = edx;
>  
> -             cpuid_count(0x00000007, 1, &eax, &ebx, &ecx, &edx);
> -             c->x86_capability[CPUID_7_1_EAX] = eax;
> +             /* Check valid sub-leaf index before accessing it */
> +             if (eax >= 1) {
> +                     cpuid_count(0x00000007, 1, &eax, &ebx, &ecx, &edx);
> +                     c->x86_capability[CPUID_7_1_EAX] = eax;
> +             }

You are right.

I tested the three patches in tip tree and they work as expected.

Thank you very much!

-Fenghua

Reply via email to