Skip to content

Commit 698eb82

Browse files
author
peterz@infradead.org
committed
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
1 parent 5694289 commit 698eb82

File tree

2 files changed

+13
-0
lines changed

2 files changed

+13
-0
lines changed

kernel/futex/futex.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ static inline bool futex_flags_valid(unsigned int flags)
8585
return true;
8686
}
8787

88+
static inline bool futex_validate_input(unsigned int flags, u64 val)
89+
{
90+
int bits = 8 * futex_size(flags);
91+
92+
if (bits < 64 && (val >> bits))
93+
return false;
94+
95+
return true;
96+
}
97+
8898
#ifdef CONFIG_FAIL_FUTEX
8999
extern bool should_fail_futex(bool fshared);
90100
#else

kernel/futex/syscalls.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,9 @@ static int futex_parse_waitv(struct futex_vector *futexv,
209209
if (!futex_flags_valid(flags))
210210
return -EINVAL;
211211

212+
if (!futex_validate_input(flags, aux.val))
213+
return -EINVAL;
214+
212215
futexv[i].w.flags = flags;
213216
futexv[i].w.val = aux.val;
214217
futexv[i].w.uaddr = aux.uaddr;

0 commit comments

Comments
 (0)