Skip to contentSkip to conversation

pi-futex: Validate futex type instead of oopsing

PATCH New Thomas Gleixner 1 participant 1 message Jul 6, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 pi-futex: Validate futex type instead of oopsing

Calling futex_lock_pi is called with a reference to a non PI futex and waiters exist already, lookup_pi_state() oopses due to pi_state == NULL. Check this condition and return -EINVAL to userspace.

kernel/futex.c +6 -0
index 1dc98e4..cf0c8e2 100644
@@ -476,6 +476,12 @@ lookup_pi_state(u32 uval, struct futex_h
 			 * the refcount and return its pi_state:
 			 */
 			pi_state = this->pi_state;
+			/*
+			 * Userspace might have messed up non PI and PI futexes
+			 */
+			if (unlikely(!pi_state))
+				return -EINVAL;
+
 			atomic_inc(&pi_state->refcount);
 			me->pi_state = pi_state;