Source-Changes-HG archive

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

[src/trunk]: src/sys/kern ktrace(9): Make sure ktrkuser initializes the full ...



details:   https://anonhg.NetBSD.org/src/rev/11f71fe3b0ff
branches:  trunk
changeset: 368185:11f71fe3b0ff
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Jun 27 03:56:37 2022 +0000

description:
ktrace(9): Make sure ktrkuser initializes the full ktr_id member.

strlcpy does not; strncpy does.  However, the member must be
NUL-terminated, because kdump uses it, e.g., with printf("%s"), so
expicitly set the last byte to NUL.

Possible fix for a host of sanitizer complaints in syzkaller.

diffstat:

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

diffs (28 lines):

diff -r 601722c0e6da -r 11f71fe3b0ff sys/kern/kern_ktrace.c
--- a/sys/kern/kern_ktrace.c    Mon Jun 27 01:29:51 2022 +0000
+++ b/sys/kern/kern_ktrace.c    Mon Jun 27 03:56:37 2022 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: kern_ktrace.c,v 1.179 2022/03/12 17:45:53 riastradh Exp $      */
+/*     $NetBSD: kern_ktrace.c,v 1.180 2022/06/27 03:56:37 riastradh Exp $      */
 
 /*-
  * Copyright (c) 2006, 2007, 2008, 2020 The NetBSD Foundation, Inc.
@@ -61,7 +61,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.179 2022/03/12 17:45:53 riastradh Exp $");
+__KERNEL_RCSID(0, "$NetBSD: kern_ktrace.c,v 1.180 2022/06/27 03:56:37 riastradh Exp $");
 
 #include <sys/param.h>
 #include <sys/systm.h>
@@ -950,7 +950,8 @@
        if (error != 0)
                return;
 
-       strlcpy(ktp->ktr_id, id, KTR_USER_MAXIDLEN);
+       strncpy(ktp->ktr_id, id, KTR_USER_MAXIDLEN - 1);
+       ktp->ktr_id[KTR_USER_MAXIDLEN - 1] = '\0';
 
        memcpy(ktp + 1, addr, len);
 



Home | Main Index | Thread Index | Old Index