Module Name:    src
Committed By:   uwe
Date:           Thu Jun 14 10:30:56 UTC 2018

Modified Files:
        src/sys/compat/sys: time_types.h
        src/sys/dev/wscons: wsevent.c

Log Message:
timespec_to_timespec50 - don't leak kernel memory in struct padding.

On 64-bit machines struct timespec50 has padding between 32-bit tv_sec
and long tv_nsec that is not affected by normal assignment.  Scrub it.
The result is most likely about to be passed to the user space by the
caller, so do it here to take care of them all.


To generate a diff of this commit:
cvs rdiff -u -r1.1 -r1.2 src/sys/compat/sys/time_types.h
cvs rdiff -u -r1.38 -r1.39 src/sys/dev/wscons/wsevent.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/sys/time_types.h
diff -u src/sys/compat/sys/time_types.h:1.1 src/sys/compat/sys/time_types.h:1.2
--- src/sys/compat/sys/time_types.h:1.1	Thu Nov  5 16:59:01 2009
+++ src/sys/compat/sys/time_types.h	Thu Jun 14 10:30:55 2018
@@ -1,4 +1,4 @@
-/*	$NetBSD: time_types.h,v 1.1 2009/11/05 16:59:01 pooka Exp $	*/
+/*	$NetBSD: time_types.h,v 1.2 2018/06/14 10:30:55 uwe Exp $	*/
 
 /*
  * Copyright (c) 1982, 1986, 1993
@@ -89,6 +89,9 @@ static __inline void timespec50_to_times
 static __inline void timespec_to_timespec50(const struct timespec *ts,
     struct timespec50 *ts50)
 {
+#if INT32_MAX < LONG_MAX	/* scrub padding */
+	memset(ts50, 0, offsetof(struct timespec50, tv_nsec));
+#endif
 	ts50->tv_sec = (int32_t)ts->tv_sec;
 	ts50->tv_nsec = ts->tv_nsec;
 }

Index: src/sys/dev/wscons/wsevent.c
diff -u src/sys/dev/wscons/wsevent.c:1.38 src/sys/dev/wscons/wsevent.c:1.39
--- src/sys/dev/wscons/wsevent.c:1.38	Wed Jun 13 02:09:09 2018
+++ src/sys/dev/wscons/wsevent.c	Thu Jun 14 10:30:55 2018
@@ -1,4 +1,4 @@
-/* $NetBSD: wsevent.c,v 1.38 2018/06/13 02:09:09 uwe Exp $ */
+/* $NetBSD: wsevent.c,v 1.39 2018/06/14 10:30:55 uwe Exp $ */
 
 /*-
  * Copyright (c) 2006, 2008 The NetBSD Foundation, Inc.
@@ -104,7 +104,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: wsevent.c,v 1.38 2018/06/13 02:09:09 uwe Exp $");
+__KERNEL_RCSID(0, "$NetBSD: wsevent.c,v 1.39 2018/06/14 10:30:55 uwe Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_compat_netbsd.h"
@@ -202,9 +202,6 @@ wsevent_copyout_events50(const struct ws
 
 		ev50.type = ev->type;
 		ev50.value = ev->value;
-#if INT32_MAX < LONG_MAX	/* scrub padding */
-		memset(&ev50.time, 0, offsetof(struct timespec50, tv_nsec));
-#endif
 		timespec_to_timespec50(&ev->time, &ev50.time);
 
 		error = uiomove(&ev50, sizeof(ev50), uio);

Reply via email to