* [PATCH] futex: make FUTEX_OP_OPARG_SHIFT unsigned
@ 2016-10-24 10:21 Jiri Slaby
2016-10-26 11:22 ` Thomas Gleixner
0 siblings, 1 reply; 2+ messages in thread
From: Jiri Slaby @ 2016-10-24 10:21 UTC (permalink / raw)
To: tglx; +Cc: linux-kernel, Jiri Slaby
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
^ permalink raw reply [flat|nested] 2+ messages in thread* Re: [PATCH] futex: make FUTEX_OP_OPARG_SHIFT unsigned
2016-10-24 10:21 [PATCH] futex: make FUTEX_OP_OPARG_SHIFT unsigned Jiri Slaby
@ 2016-10-26 11:22 ` Thomas Gleixner
0 siblings, 0 replies; 2+ messages in thread
From: Thomas Gleixner @ 2016-10-26 11:22 UTC (permalink / raw)
To: Jiri Slaby; +Cc: linux-kernel
On Mon, 24 Oct 2016, Jiri Slaby wrote:
> 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'
shift exponent 776 ????
Thanks,
tglx
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2016-10-26 11:25 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-10-24 10:21 [PATCH] futex: make FUTEX_OP_OPARG_SHIFT unsigned Jiri Slaby
2016-10-26 11:22 ` Thomas Gleixner
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®