public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
From: "Richard W.M. Jones" <rjones@redhat.com>
To: Thomas Gleixner <tglx@linutronix.de>
Cc: Josh Boyer <jwboyer@fedoraproject.org>, x86 <x86@kernel.org>,
	"Linux-Kernel@Vger. Kernel. Org" <linux-kernel@vger.kernel.org>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH] x86/tsc: Prevent NULL pointer deref in calibrate_delay_is_known()
Date: Fri, 18 Mar 2016 10:17:49 +0000	[thread overview]
Message-ID: <20160318101749.GL1681@redhat.com> (raw)
In-Reply-To: <alpine.DEB.2.11.1603180843270.3978@nanos>

On Fri, Mar 18, 2016 at 08:48:06AM +0100, Thomas Gleixner wrote:
> Subject: x86/tsc: Prevent NULL pointer deref in calibrate_delay_is_known()
> From: Thomas Gleixner <tglx@linutronix.de>
> Date: Fri, 18 Mar 2016 08:35:29 +0100
> 
> The topology_core_cpumask is used to find a neighbour cpu in
> calibrate_delay_is_known(). It might not be allocated at the first invocation
> of that function on the boot cpu, when CONFIG_CPUMASK_OFFSTACK is set.
> 
> The mask is allocated later in native_smp_prepare_cpus. As a consequence the
> underlying find_next_bit() call dereferences a NULL pointer.
> 
> Add a proper check to prevent this.
> 
> Reported-by: Richard W.M. Jones <rjones@redhat.com>
> Fixes: c25323c07345 "x86/tsc: Use topology functions"
> Signed-off-by: Thomas Gleixner <tglx@linutronix.de>
> Cc: Josh Boyer <jwboyer@fedoraproject.org>

I have tested the current upstream kernel (9dffdb38d) and was able to
reproduce the bug.  I then added this patch on top and it fixes the
problem for me.  Therefore:

Tested-by: Richard W.M. Jones <rjones@redhat.com>

Thanks, Rich.

> ---
>  arch/x86/kernel/tsc.c |    6 +++++-
>  1 file changed, 5 insertions(+), 1 deletion(-)
> 
> --- a/arch/x86/kernel/tsc.c
> +++ b/arch/x86/kernel/tsc.c
> @@ -1306,11 +1306,15 @@ void __init tsc_init(void)
>  unsigned long calibrate_delay_is_known(void)
>  {
>  	int sibling, cpu = smp_processor_id();
> +	struct cpumask *mask = topology_core_cpumask(cpu);
>  
>  	if (!tsc_disabled && !cpu_has(&cpu_data(cpu), X86_FEATURE_CONSTANT_TSC))
>  		return 0;
>  
> -	sibling = cpumask_any_but(topology_core_cpumask(cpu), cpu);
> +	if (!mask)
> +		return 0;
> +
> +	sibling = cpumask_any_but(mask, cpu);
>  	if (sibling < nr_cpu_ids)
>  		return cpu_data(sibling).loops_per_jiffy;
>  	return 0;

-- 
Richard Jones, Virtualization Group, Red Hat http://people.redhat.com/~rjones
Read my programming and virtualization blog: http://rwmj.wordpress.com
virt-builder quickly builds VMs from scratch
http://libguestfs.org/virt-builder.1.html

  reply	other threads:[~2016-03-18 10:18 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-03-18  7:48 [PATCH] x86/tsc: Prevent NULL pointer deref in calibrate_delay_is_known() Thomas Gleixner
2016-03-18 10:17 ` Richard W.M. Jones [this message]
2016-03-18 13:54 ` [tip:x86/urgent] " tip-bot for Thomas Gleixner

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20160318101749.GL1681@redhat.com \
    --to=rjones@redhat.com \
    --cc=jwboyer@fedoraproject.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox