Skip to contentSkip to conversation

Check and validate futex timeval

PATCH New Thomas Gleixner 1 participant 1 message Mar 25, 2006

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 Check and validate futex timeval

The futex timeval is not checked for correctness. The change does not break existing applications as the timeval is supplied by glibc (and glibc always passes a correct value), but the glibc-internal tests for this functionality fail.

----

 kernel/futex.c        |    4 +++-
 kernel/futex_compat.c |    4 +++-
 2 files changed, 6 insertions(+), 2 deletions(-)
kernel/futex.c +3 -1
Index: linux/kernel/futex.c
===================================================================
@@ -1039,9 +1039,11 @@ asmlinkage long sys_futex(u32 __user *ua
 	unsigned long timeout = MAX_SCHEDULE_TIMEOUT;
 	int val2 = 0;
 
-	if ((op == FUTEX_WAIT) && utime) {
+	if (utime && (op == FUTEX_WAIT)) {
 		if (copy_from_user(&t, utime, sizeof(t)) != 0)
 			return -EFAULT;
+		if (!timespec_valid(&t))
+			return -EINVAL;
 		timeout = timespec_to_jiffies(&t) + 1;
 	}
 	/*
kernel/futex_compat.c +3 -1
Index: linux/kernel/futex_compat.c
===================================================================
@@ -129,9 +129,11 @@ asmlinkage long compat_sys_futex(u32 __u
 	unsigned long timeout = MAX_SCHEDULE_TIMEOUT;
 	int val2 = 0;
 
-	if ((op == FUTEX_WAIT) && utime) {
+	if (utime && (op == FUTEX_WAIT)) {
 		if (get_compat_timespec(&t, utime))
 			return -EFAULT;
+		if (!timespec_valid(&t))
+			return -EINVAL;
 		timeout = timespec_to_jiffies(&t) + 1;
 	}
 	if (op >= FUTEX_REQUEUE)