[PATCH] futex: Support smaller futexes of one byte or two byte size.
From: Malte Skarupke
Date: Sat Dec 21 2019 - 10:58:37 EST
And hello one more time,
turns out a last minute change broke my patch for "option 2". I had moved some
lines around and didn't test the results properly... As a result I literally
woke up from a nightmare at 4am tonight, immediately knowing that there was a
bug in the code I had sent. Below you'll find a patch with the fix.
I re-emailed the whole patch to make it easier to use if you want to go with
option 2. But if you're curious what the difference is between this new
version and the last version, the diff between the two is just this:
diff --git a/kernel/futex.c b/kernel/futex.c
index e2308cea7580..ac460fd612ae 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -569,10 +569,6 @@ get_futex_key(u32 __user *uaddr, int flags, union futex_key *key, enum futex_acc
size = futex_size(flags);
key->both.offset = address % PAGE_SIZE;
- if (size == sizeof(u8))
- key->both.offset |= FUT_OFF_8_BITS;
- else if (size == sizeof(u16))
- key->both.offset |= FUT_OFF_16_BITS;
/*
* The futex address must be "naturally" aligned.
@@ -581,6 +577,11 @@ get_futex_key(u32 __user *uaddr, int flags, union futex_key *key, enum futex_acc
return -EINVAL;
address -= key->both.offset;
+ if (size == sizeof(u8))
+ key->both.offset |= FUT_OFF_8_BITS;
+ else if (size == sizeof(u16))
+ key->both.offset |= FUT_OFF_16_BITS;
+
if (unlikely(!access_ok(uaddr, size)))
return -EFAULT;