All of lore.kernel.org
 help / color / mirror / Atom feed
From: Thomas Gleixner <tglx@linutronix.de>
To: Dan Williams <dan.j.williams@intel.com>
Cc: Rasmus Villemoes <rasmus.villemoes@prevas.dk>,
	LKML <linux-kernel@vger.kernel.org>,
	Ingo Molnar <mingo@kernel.org>,
	Linus Torvalds <torvalds@linux-foundation.org>,
	David Woodhouse <dwmw@amazon.co.uk>,
	Greg KH <gregkh@linuxfoundation.org>
Subject: Re: [PATCH] posix-timers: Protect posix clock array access against speculation
Date: Thu, 15 Feb 2018 15:53:14 +0100 (CET)	[thread overview]
Message-ID: <alpine.DEB.2.21.1802151550330.1296@nanos.tec.linutronix.de> (raw)
In-Reply-To: <CAPcyv4i-bULZp1WTUgUVtdEY5i_fTGkFWKBsVLDu6dsuxUwoug@mail.gmail.com>

On Thu, 15 Feb 2018, Dan Williams wrote:
> On Thu, Feb 15, 2018 at 6:05 AM, Rasmus Villemoes
> <rasmus.villemoes@prevas.dk> wrote:
> > (2) The line "if (id >= ARRAY_SIZE(posix_clocks) || !posix_clocks[id])"
> > still seems to allow speculatively accessing posix_clocks[id]. Is that
> > ok, and even if so, wouldn't it be cleaner to elide the
> > !posix_clocks[id] check and just return the NULL safely fetched from the
> > array in the following line?
> 
> Right, this looks broken. I would expect:

Indeed. Missed that.

>         if (id >= ARRAY_SIZE(posix_clocks))
>                 return NULL;
>         idx = array_index_nospec(idx, ARRAY_SIZE(posix_clocks));
>         if (!posix_clocks[idx])
>                 return NULL;
>         return posix_clocks[idx];

The !posix_clocks[idx] check is pointless and always was.

	if (id >= ARRAY_SIZE(posix_clocks))
		return NULL;

	idx = array_index_nospec(idx, ARRAY_SIZE(posix_clocks));
	return posix_clocks[idx];

is sufficient. It returns NULL for !posix_clocks[idx] anyway.

Thanks,

	tglx

  reply	other threads:[~2018-02-15 14:53 UTC|newest]

Thread overview: 13+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-02-15 13:27 [PATCH] posix-timers: Protect posix clock array access against speculation Thomas Gleixner
2018-02-15 14:05 ` Rasmus Villemoes
2018-02-15 14:39   ` Dan Williams
2018-02-15 14:53     ` Thomas Gleixner [this message]
2018-02-15 16:21       ` [PATCH V2] " Thomas Gleixner
2018-02-15 17:01         ` Peter Zijlstra
2018-03-07 18:13           ` Dan Williams
2018-03-22 11:34         ` [tip:timers/urgent] " tip-bot for Thomas Gleixner
2018-02-15 19:52     ` [PATCH] linux/nospec.h: allow index argument to have const-qualified type Rasmus Villemoes
2018-02-15 20:59       ` Linus Torvalds
2018-02-15 21:56         ` Dan Williams
2018-02-15 22:03           ` Linus Torvalds
2018-02-15 22:08             ` Dan Williams

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=alpine.DEB.2.21.1802151550330.1296@nanos.tec.linutronix.de \
    --to=tglx@linutronix.de \
    --cc=dan.j.williams@intel.com \
    --cc=dwmw@amazon.co.uk \
    --cc=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@kernel.org \
    --cc=rasmus.villemoes@prevas.dk \
    --cc=torvalds@linux-foundation.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.