Module Name:    src
Committed By:   kamil
Date:           Sat Feb 22 00:24:15 UTC 2020

Modified Files:
        src/tests/modules: t_modctl.c

Log Message:
Avoid undefined behavior in get_modstat_info

t_modctl.c:114:16, member access within misaligned address 0x71bf5bcede84
for type 'struct modstat_t'

t_modctl.c:116:13, load of misaligned address 0x7e81bc3c9104 for type
'struct modstat_t' which requires 8 byte alignment


To generate a diff of this commit:
cvs rdiff -u -r1.14 -r1.15 src/tests/modules/t_modctl.c

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

Modified files:

Index: src/tests/modules/t_modctl.c
diff -u src/tests/modules/t_modctl.c:1.14 src/tests/modules/t_modctl.c:1.15
--- src/tests/modules/t_modctl.c:1.14	Sun Apr 21 11:45:09 2019
+++ src/tests/modules/t_modctl.c	Sat Feb 22 00:24:15 2020
@@ -1,4 +1,4 @@
-/*	$NetBSD: t_modctl.c,v 1.14 2019/04/21 11:45:09 maya Exp $	*/
+/*	$NetBSD: t_modctl.c,v 1.15 2020/02/22 00:24:15 kamil Exp $	*/
 /*
  * Copyright (c) 2008 The NetBSD Foundation, Inc.
  * All rights reserved.
@@ -27,7 +27,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v 1.14 2019/04/21 11:45:09 maya Exp $");
+__KERNEL_RCSID(0, "$NetBSD: t_modctl.c,v 1.15 2020/02/22 00:24:15 kamil Exp $");
 
 #include <sys/module.h>
 #include <sys/sysctl.h>
@@ -87,6 +87,7 @@ get_modstat_info(const char *name, modst
 	int count;
 	struct iovec iov;
 	modstat_t *ms;
+	modstat_t m;
 
 	check_permission();
 	for (len = 8192; ;) {
@@ -111,9 +112,10 @@ get_modstat_info(const char *name, modst
 	count = *(int *)iov.iov_base;
 	ms = (modstat_t *)((char *)iov.iov_base + sizeof(int));
 	while ( count ) {
-		if (strcmp(ms->ms_name, name) == 0) {
+		memcpy(&m, ms, sizeof(m));
+		if (strcmp(m.ms_name, name) == 0) {
 			if (msdest != NULL)
-				*msdest = *ms;
+				memcpy(msdest, &m, sizeof(*msdest));
 			found = true;
 			break;
 		}

Reply via email to