Module Name:    src
Committed By:   kamil
Date:           Fri Sep 20 15:25:19 UTC 2019

Modified Files:
        src/sys/compat/linux/common: linux_misc.c
        src/sys/compat/linux32/common: linux32_unistd.c

Log Message:
Avoid signed integer overflow when convering linux timeval to timespec

Linux accepts garbage as timeout and attempts to set it to something
meaningful. Instead of checking for valid ranges of usec, just convert
the type safely, regardless of what is inside it.


To generate a diff of this commit:
cvs rdiff -u -r1.244 -r1.245 src/sys/compat/linux/common/linux_misc.c
cvs rdiff -u -r1.40 -r1.41 src/sys/compat/linux32/common/linux32_unistd.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/sys/compat/linux/common/linux_misc.c
diff -u src/sys/compat/linux/common/linux_misc.c:1.244 src/sys/compat/linux/common/linux_misc.c:1.245
--- src/sys/compat/linux/common/linux_misc.c:1.244	Sat Aug 24 14:21:13 2019
+++ src/sys/compat/linux/common/linux_misc.c	Fri Sep 20 15:25:19 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux_misc.c,v 1.244 2019/08/24 14:21:13 maxv Exp $	*/
+/*	$NetBSD: linux_misc.c,v 1.245 2019/09/20 15:25:19 kamil Exp $	*/
 
 /*-
  * Copyright (c) 1995, 1998, 1999, 2008 The NetBSD Foundation, Inc.
@@ -57,7 +57,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.244 2019/08/24 14:21:13 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux_misc.c,v 1.245 2019/09/20 15:25:19 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -875,7 +875,7 @@ linux_select1(struct lwp *l, register_t 
 		if ((error = copyin(timeout, &ltv, sizeof(ltv))))
 			return error;
 		uts.tv_sec = ltv.tv_sec;
-		uts.tv_nsec = ltv.tv_usec * 1000;
+		uts.tv_nsec = (long)((unsigned long)ltv.tv_usec * 1000);
 		if (itimespecfix(&uts)) {
 			/*
 			 * The timeval was invalid.  Convert it to something

Index: src/sys/compat/linux32/common/linux32_unistd.c
diff -u src/sys/compat/linux32/common/linux32_unistd.c:1.40 src/sys/compat/linux32/common/linux32_unistd.c:1.41
--- src/sys/compat/linux32/common/linux32_unistd.c:1.40	Tue Dec 26 08:30:58 2017
+++ src/sys/compat/linux32/common/linux32_unistd.c	Fri Sep 20 15:25:19 2019
@@ -1,4 +1,4 @@
-/*	$NetBSD: linux32_unistd.c,v 1.40 2017/12/26 08:30:58 kamil Exp $ */
+/*	$NetBSD: linux32_unistd.c,v 1.41 2019/09/20 15:25:19 kamil Exp $ */
 
 /*-
  * Copyright (c) 2006 Emmanuel Dreyfus, all rights reserved.
@@ -33,7 +33,7 @@
 
 #include <sys/cdefs.h>
 
-__KERNEL_RCSID(0, "$NetBSD: linux32_unistd.c,v 1.40 2017/12/26 08:30:58 kamil Exp $");
+__KERNEL_RCSID(0, "$NetBSD: linux32_unistd.c,v 1.41 2019/09/20 15:25:19 kamil Exp $");
 
 #include <sys/types.h>
 #include <sys/param.h>
@@ -165,7 +165,7 @@ linux32_select1(struct lwp *l, register_
 			return error;
 
 		uts.tv_sec = utv32.tv_sec;
-		uts.tv_nsec = utv32.tv_usec * 1000;
+		uts.tv_nsec = (long)((unsigned long)utv32.tv_usec * 1000);
 
 		if (itimespecfix(&uts)) {
 			/*

Reply via email to