summaryrefslogtreecommitdiffstats
path: root/kernel/futex/futex.h
diff options
context:
space:
mode:
authorpeterz@infradead.org <peterz@infradead.org>2023-09-21 12:45:09 +0200
committerPeter Zijlstra <peterz@infradead.org>2023-09-21 19:22:06 +0200
commit698eb826383616ce0e817d2384da6413d1439fb6 (patch)
treebd22f2fa7f6a8a57253b9040778f5d12f5c43228 /kernel/futex/futex.h
parent5694289ce183bc3336407a78c8c722a0b9208f9b (diff)
downloadlinux-stable-698eb826383616ce0e817d2384da6413d1439fb6.tar.gz
linux-stable-698eb826383616ce0e817d2384da6413d1439fb6.tar.bz2
linux-stable-698eb826383616ce0e817d2384da6413d1439fb6.zip
futex: Validate futex value against futex size
Ensure the futex value fits in the given futex size. Since this adds a constraint to an existing syscall, it might possibly change behaviour. Currently the value would be truncated to a u32 and any high bits would get silently lost. Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Link: https://lore.kernel.org/r/20230921105247.828934099@noisy.programming.kicks-ass.net
Diffstat (limited to 'kernel/futex/futex.h')
-rw-r--r--kernel/futex/futex.h10
1 files changed, 10 insertions, 0 deletions
diff --git a/kernel/futex/futex.h b/kernel/futex/futex.h
index 68fc052dc09b..a3f1fceafcbe 100644
--- a/kernel/futex/futex.h
+++ b/kernel/futex/futex.h
@@ -85,6 +85,16 @@ static inline bool futex_flags_valid(unsigned int flags)
return true;
}
+static inline bool futex_validate_input(unsigned int flags, u64 val)
+{
+ int bits = 8 * futex_size(flags);
+
+ if (bits < 64 && (val >> bits))
+ return false;
+
+ return true;
+}
+
#ifdef CONFIG_FAIL_FUTEX
extern bool should_fail_futex(bool fshared);
#else