Source-Changes-HG archive

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

[src/trunk]: src/sys/altq sys/altq: Memset zero before copyout.



details:   https://anonhg.NetBSD.org/src/rev/9c28f6ef1014
branches:  trunk
changeset: 985553:9c28f6ef1014
user:      riastradh <riastradh%NetBSD.org@localhost>
date:      Mon Aug 30 08:40:31 2021 +0000

description:
sys/altq: Memset zero before copyout.

Just in case of uninitialized padding which would lead to kernel
stack disclosure.  If the compiler can prove the memset redundant
then it can optimize it away; otherwise better safe than sorry.

diffstat:

 sys/altq/altq_hfsc.c |  5 +++--
 sys/altq/altq_priq.c |  7 +++----
 2 files changed, 6 insertions(+), 6 deletions(-)

diffs (56 lines):

diff -r 8040fbafe137 -r 9c28f6ef1014 sys/altq/altq_hfsc.c
--- a/sys/altq/altq_hfsc.c      Mon Aug 30 08:40:00 2021 +0000
+++ b/sys/altq/altq_hfsc.c      Mon Aug 30 08:40:31 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: altq_hfsc.c,v 1.28 2018/11/15 10:23:55 maxv Exp $      */
+/*     $NetBSD: altq_hfsc.c,v 1.29 2021/08/30 08:40:31 riastradh Exp $ */
 /*     $KAME: altq_hfsc.c,v 1.26 2005/04/13 03:44:24 suz Exp $ */
 
 /*
@@ -43,7 +43,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: altq_hfsc.c,v 1.28 2018/11/15 10:23:55 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_hfsc.c,v 1.29 2021/08/30 08:40:31 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -2182,6 +2182,7 @@
        usp = ap->stats;
        for (n = 0; cl != NULL && n < nclasses; cl = hfsc_nextclass(cl), n++) {
 
+               memset(&stats, 0, sizeof(stats));
                get_class_stats(&stats, cl);
 
                if ((error = copyout((void *)&stats, (void *)usp++,
diff -r 8040fbafe137 -r 9c28f6ef1014 sys/altq/altq_priq.c
--- a/sys/altq/altq_priq.c      Mon Aug 30 08:40:00 2021 +0000
+++ b/sys/altq/altq_priq.c      Mon Aug 30 08:40:31 2021 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: altq_priq.c,v 1.26 2018/11/15 10:23:55 maxv Exp $      */
+/*     $NetBSD: altq_priq.c,v 1.27 2021/08/30 08:40:31 riastradh Exp $ */
 /*     $KAME: altq_priq.c,v 1.13 2005/04/13 03:44:25 suz Exp $ */
 /*
  * Copyright (C) 2000-2003
@@ -31,7 +31,7 @@
  */
 
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: altq_priq.c,v 1.26 2018/11/15 10:23:55 maxv Exp $");
+__KERNEL_RCSID(0, "$NetBSD: altq_priq.c,v 1.27 2021/08/30 08:40:31 riastradh Exp $");
 
 #ifdef _KERNEL_OPT
 #include "opt_altq.h"
@@ -958,10 +958,9 @@
        usp = ap->stats;
        for (pri = 0; pri <= pif->pif_maxpri; pri++) {
                cl = pif->pif_classes[pri];
+               memset(&stats, 0, sizeof(stats));
                if (cl != NULL)
                        get_class_stats(&stats, cl);
-               else
-                       memset(&stats, 0, sizeof(stats));
                if ((error = copyout((void *)&stats, (void *)usp++,
                                     sizeof(stats))) != 0)
                        return (error);



Home | Main Index | Thread Index | Old Index