From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752296AbdLLKbJ (ORCPT ); Tue, 12 Dec 2017 05:31:09 -0500 Received: from mail-wr0-f194.google.com ([209.85.128.194]:43912 "EHLO mail-wr0-f194.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751542AbdLLKbG (ORCPT ); Tue, 12 Dec 2017 05:31:06 -0500 X-Google-Smtp-Source: ACJfBosSJ++rGBe6FWKXSnOAh9W7svMoY/oGCWoqsBO405h8v0eANxFi5Ci5q254HaBq0W0EPQlC3Q== Date: Tue, 12 Dec 2017 11:31:02 +0100 From: Ingo Molnar To: Thomas Gleixner Cc: Darren Hart , LKML , Ingo Molnar , Peter Zijlstra Subject: Re: [PATCH] futex: Check for uaddr alignment as early as possible Message-ID: <20171212103102.lzvchgpillhzomer@gmail.com> References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: NeoMutt/20170609 (1.8.3) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org * Thomas Gleixner wrote: > On Fri, 8 Dec 2017, Darren Hart wrote: > > > From: "Darren Hart (VMware)" > > > > 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) > > Cc: Thomas Gleixner > > Cc: Ingo Molnar > > Cc: Peter Zijlstra > > Cc: Darren Hart > > --- > > 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)) > > Errm. How is that supposed to work? uaddr2 is not used by all opcodes..... So to explain the curious timing of the mails from Thomas and me: I told Thomas about the breakage over IRC and he found the likely bug! ;-) Thanks, Ingo