mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.cz>
To: tglx@linutronix.de
Cc: linux-kernel@vger.kernel.org, Jiri Slaby <jslaby@suse.cz>
Subject: [PATCH] futex: make FUTEX_OP_OPARG_SHIFT unsigned
Date: Mon, 24 Oct 2016 12:21:27 +0200	[thread overview]
Message-ID: <20161024102127.28220-1-jslaby@suse.cz> (raw)

FUTEX_OP_OPARG_SHIFT is shifted left by 28 in futex_atomic_op_inuser and
other places. Since FUTEX_OP_OPARG_SHIFT is 8, we actually do (8 << 28).
But given both are ints, we perform operation with undefined behaviour
about which UBSAN reports:
UBSAN: Undefined behaviour in arch/x86/include/asm/futex.h:53:13
shift exponent 776 is too large for 32-bit type 'int'
CPU: 1 PID: 27469 Comm: trinity-c1 Tainted: G            EL     4.4.26-0-default #1
Hardware name: QEMU Standard PC (i440FX + PIIX, 1996), BIOS rel-1.9.1-0-gb3ef39f-prebuilt.qemu-project.org 04/01/2014
 0000000000000000 ffff880553ad7908 ffffffff81cbcc16 0000000041b58ab3
 ffffffff82f515a3 ffffffff81cbcb16 ffff880553ad7930 ffff880553ad78d0
 ffffffff837d7d60 0000000000000000 0000000000000308 ffffffff837d7d62
Call Trace:
 [<ffffffff81d9ec50>] ? __ubsan_handle_shift_out_of_bounds+0x29c/0x300
 [<ffffffff81d9e9b4>] ? __ubsan_handle_load_invalid_value+0x1ba/0x1ba
 [<ffffffff814202a9>] ? get_futex_key+0x4f9/0xf80
 [<ffffffff81422456>] ? futex_wake_op+0x636/0xfc0
 [<ffffffff8141fdb0>] ? futex_lock_pi_atomic+0x2a0/0x2a0
 [<ffffffff81422b09>] ? futex_wake_op+0xce9/0xfc0
 [<ffffffff81421e20>] ? futex_wait_restart+0x240/0x240
 [<ffffffff814266ae>] ? do_futex+0x54e/0xb60
 [<ffffffff81426df8>] ? SyS_futex+0x138/0x2b0

Fix that by having FUTEX_OP_OPARG_SHIFT unsigned.

Signed-off-by: Jiri Slaby <jslaby@suse.cz>
---
 include/uapi/linux/futex.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/include/uapi/linux/futex.h b/include/uapi/linux/futex.h
index 0b1f716373c7..954a23b18e68 100644
--- a/include/uapi/linux/futex.h
+++ b/include/uapi/linux/futex.h
@@ -130,7 +130,7 @@ struct robust_list_head {
 #define FUTEX_OP_ANDN		3	/* *(int *)UADDR2 &= ~OPARG; */
 #define FUTEX_OP_XOR		4	/* *(int *)UADDR2 ^= OPARG; */
 
-#define FUTEX_OP_OPARG_SHIFT	8	/* Use (1 << OPARG) instead of OPARG.  */
+#define FUTEX_OP_OPARG_SHIFT	8U	/* Use (1 << OPARG) instead of OPARG.  */
 
 #define FUTEX_OP_CMP_EQ		0	/* if (oldval == CMPARG) wake */
 #define FUTEX_OP_CMP_NE		1	/* if (oldval != CMPARG) wake */
-- 
2.10.1

             reply	other threads:[~2016-10-24 10:21 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-10-24 10:21 Jiri Slaby [this message]
2016-10-26 11:22 ` 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=20161024102127.28220-1-jslaby@suse.cz \
    --to=jslaby@suse.cz \
    --cc=linux-kernel@vger.kernel.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

all inboxes | Powered by JetHome®