Source-Changes-HG archive

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

[src/trunk]: src/sys/kern Avoid unaligned pointer arithmetic in check_label_m...



details:   https://anonhg.NetBSD.org/src/rev/d56d8bee8a93
branches:  trunk
changeset: 460862:d56d8bee8a93
user:      kamil <kamil%NetBSD.org@localhost>
date:      Wed Nov 06 13:07:32 2019 +0000

description:
Avoid unaligned pointer arithmetic in check_label_magic()

Replace the logic of calculating the address with with base + offset.

Reported by GCC8.

Reported-by: syzbot+56769dece0ec3e35731e%syzkaller.appspotmail.com@localhost

diffstat:

 sys/kern/subr_disk_mbr.c |  11 +++++++----
 1 files changed, 7 insertions(+), 4 deletions(-)

diffs (32 lines):

diff -r 0d4c11e2228e -r d56d8bee8a93 sys/kern/subr_disk_mbr.c
--- a/sys/kern/subr_disk_mbr.c  Wed Nov 06 11:55:18 2019 +0000
+++ b/sys/kern/subr_disk_mbr.c  Wed Nov 06 13:07:32 2019 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: subr_disk_mbr.c,v 1.51 2019/05/17 18:50:40 christos Exp $      */
+/*     $NetBSD: subr_disk_mbr.c,v 1.52 2019/11/06 13:07:32 kamil Exp $ */
 
 /*
  * Copyright (c) 1982, 1986, 1988 Regents of the University of California.
@@ -54,7 +54,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: subr_disk_mbr.c,v 1.51 2019/05/17 18:50:40 christos Exp $");
+__KERNEL_RCSID(0, "$NetBSD: subr_disk_mbr.c,v 1.52 2019/11/06 13:07:32 kamil Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -571,8 +571,11 @@
 static bool
 check_label_magic(const struct disklabel *dlp, uint32_t diskmagic)
 {
-       return memcmp(&dlp->d_magic, &diskmagic, sizeof(diskmagic)) == 0 &&
-           memcmp(&dlp->d_magic2, &diskmagic, sizeof(diskmagic)) == 0;
+
+       return memcmp((const char *)dlp + offsetof(struct disklabel, d_magic),
+                     &diskmagic, sizeof(diskmagic)) == 0 &&
+           memcmp((const char *)dlp + offsetof(struct disklabel, d_magic2),
+                  &diskmagic, sizeof(diskmagic)) == 0;
 }
 
 #ifdef DISKLABEL_EI



Home | Main Index | Thread Index | Old Index