Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/sys/compat Avoid signed integer overflow when convering linu...



details:   https://anonhg.NetBSD.org/src/rev/b837869644e8
branches:  trunk
changeset: 459669:b837869644e8
user:      kamil <kamil%NetBSD.org@localhost>
date:      Fri Sep 20 15:25:19 2019 +0000

description:
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.

diffstat:

 sys/compat/linux/common/linux_misc.c       |  6 +++---
 sys/compat/linux32/common/linux32_unistd.c |  6 +++---
 2 files changed, 6 insertions(+), 6 deletions(-)

diffs (54 lines):

diff -r 5a5a9c00d28c -r b837869644e8 sys/compat/linux/common/linux_misc.c
--- a/sys/compat/linux/common/linux_misc.c      Fri Sep 20 15:16:41 2019 +0000
+++ b/sys/compat/linux/common/linux_misc.c      Fri Sep 20 15:25:19 2019 +0000
@@ -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 @@
                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
diff -r 5a5a9c00d28c -r b837869644e8 sys/compat/linux32/common/linux32_unistd.c
--- a/sys/compat/linux32/common/linux32_unistd.c        Fri Sep 20 15:16:41 2019 +0000
+++ b/sys/compat/linux32/common/linux32_unistd.c        Fri Sep 20 15:25:19 2019 +0000
@@ -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 @@
                        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)) {
                        /*



Home | Main Index | Thread Index | Old Index