summaryrefslogtreecommitdiff
path: root/kernel/futex.c
diff options
context:
space:
mode:
authorThomas Gleixner <tglx@linutronix.de>2021-08-15 23:29:15 +0200
committerIngo Molnar <mingo@kernel.org>2021-08-17 19:05:54 +0200
commitd69cba5c719b0c551f6380ec5da4ed8c20a3815a (patch)
treea402dea690a0e99a1cd54746e5f1fc52377e1857 /kernel/futex.c
parentc18eaa3aca43688a3aee199d85ce4227686a29b6 (diff)
futex: Reorder sanity checks in futex_requeue()
No point in allocating memory when the input parameters are bogus. Validate all parameters before proceeding. Suggested-by: Davidlohr Bueso <dave@stgolabs.net> Signed-off-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org> Signed-off-by: Ingo Molnar <mingo@kernel.org> Link: https://lore.kernel.org/r/20210815211305.581789253@linutronix.de
Diffstat (limited to 'kernel/futex.c')
-rw-r--r--kernel/futex.c14
1 files changed, 7 insertions, 7 deletions
diff --git a/kernel/futex.c b/kernel/futex.c
index 8d8bad5e07bb..a5232f62de75 100644
--- a/kernel/futex.c
+++ b/kernel/futex.c
@@ -1934,13 +1934,6 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
return -EINVAL;
/*
- * requeue_pi requires a pi_state, try to allocate it now
- * without any locks in case it fails.
- */
- if (refill_pi_state_cache())
- return -ENOMEM;
-
- /*
* futex_requeue() allows the caller to define the number
* of waiters to wake up via the @nr_wake argument. With
* REQUEUE_PI, waking up more than one waiter is creating
@@ -1963,6 +1956,13 @@ static int futex_requeue(u32 __user *uaddr1, unsigned int flags,
*/
if (nr_wake != 1)
return -EINVAL;
+
+ /*
+ * requeue_pi requires a pi_state, try to allocate it now
+ * without any locks in case it fails.
+ */
+ if (refill_pi_state_cache())
+ return -ENOMEM;
}
retry: