linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Ingo Molnar <mingo@kernel.org>
To: Darren Hart <dvhart@infradead.org>
Cc: LKML <linux-kernel@vger.kernel.org>,
	Thomas Gleixner <tglx@linutronix.de>,
	Ingo Molnar <mingo@redhat.com>,
	Peter Zijlstra <peterz@infradead.org>
Subject: Re: [PATCH] futex: Check for uaddr alignment as early as possible
Date: Tue, 12 Dec 2017 11:23:10 +0100	[thread overview]
Message-ID: <20171212102310.jp6jnw77x6d77rae@gmail.com> (raw)
In-Reply-To: <ed71745a4d33829791c89c37517ba35ab0242b05.1512781589.git.dvhart@infradead.org>


* Darren Hart <dvhart@infradead.org> wrote:

> From: "Darren Hart (VMware)" <dvhart@infradead.org>
> 
> uaddr alignment is currently tested by get_futex_key(). We can catch
> misalignment earlier in sys_futex and return -EINVAL sooner. This
> simplifies get_futex_key() a little, but more importantly exits the
> kernel as soon as an invalid parameter is detected.
> 
> Passes all selftests/futex testcases on a dual socket Xeon E5-2670, 16
> physical cores total, 32 threads total.
> 
> Signed-off-by: Darren Hart (VMware) <dvhart@infradead.org>
> Cc: Thomas Gleixner <tglx@linutronix.de>
> Cc: Ingo Molnar <mingo@redhat.com>
> Cc: Peter Zijlstra <peterz@infradead.org>
> Cc: Darren Hart <dvhart@infradead.org>
> ---
>  kernel/futex.c | 7 +++++--
>  1 file changed, 5 insertions(+), 2 deletions(-)
> 
> diff --git a/kernel/futex.c b/kernel/futex.c
> index 76ed592..c3ee6c4 100644
> --- a/kernel/futex.c
> +++ b/kernel/futex.c
> @@ -509,8 +509,6 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
>  	 * The futex address must be "naturally" aligned.
>  	 */
>  	key->both.offset = address % PAGE_SIZE;
> -	if (unlikely((address % sizeof(u32)) != 0))
> -		return -EINVAL;
>  	address -= key->both.offset;
>  
>  	if (unlikely(!access_ok(rw, uaddr, sizeof(u32))))
> @@ -3525,6 +3523,11 @@ SYSCALL_DEFINE6(futex, u32 __user *, uaddr, int, op, u32, val,
>  	u32 val2 = 0;
>  	int cmd = op & FUTEX_CMD_MASK;
>  
> +	/* Only allow for aligned uaddr variables */
> +	if (unlikely((unsigned long)uaddr % sizeof(u32) != 0 ||
> +		     (unsigned long)uaddr2 % sizeof(u32) != 0))
> +		return -EINVAL;
> +
>  	if (utime && (cmd == FUTEX_WAIT || cmd == FUTEX_LOCK_PI ||
>  		      cmd == FUTEX_WAIT_BITSET ||
>  		      cmd == FUTEX_WAIT_REQUEUE_PI)) {

Yeah, so I applied this yesterday, then -tip started regressing sporadically 
during distro networking bring-up, and it took me half a day of debugging to 
statistically bisect it back to this patch :-/

So it's apparently broken, but I don't see yet how.

Thanks,

	Ingo

      parent reply	other threads:[~2017-12-12 10:23 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-12-09  1:06 [PATCH] futex: Check for uaddr alignment as early as possible Darren Hart
2017-12-12 10:23 ` Thomas Gleixner
2017-12-12 10:31   ` Ingo Molnar
2017-12-12 15:57     ` Darren Hart
2017-12-12 10:23 ` Ingo Molnar [this message]

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=20171212102310.jp6jnw77x6d77rae@gmail.com \
    --to=mingo@kernel.org \
    --cc=dvhart@infradead.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=mingo@redhat.com \
    --cc=peterz@infradead.org \
    --cc=tglx@linutronix.de \
    /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;
as well as URLs for NNTP newsgroup(s).