Source-Changes-HG archive

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

[src/trunk]: src/sys/net/npf npf_ifmap_copylogname: be more defensive.



details:   https://anonhg.NetBSD.org/src/rev/11a45f72af41
branches:  trunk
changeset: 459898:11a45f72af41
user:      rmind <rmind%NetBSD.org@localhost>
date:      Mon Sep 30 22:04:33 2019 +0000

description:
npf_ifmap_copylogname: be more defensive.

diffstat:

 sys/net/npf/npf_if.c |  14 ++++++++------
 1 files changed, 8 insertions(+), 6 deletions(-)

diffs (40 lines):

diff -r c182e80a773b -r 11a45f72af41 sys/net/npf/npf_if.c
--- a/sys/net/npf/npf_if.c      Mon Sep 30 21:18:00 2019 +0000
+++ b/sys/net/npf/npf_if.c      Mon Sep 30 22:04:33 2019 +0000
@@ -56,7 +56,7 @@
 
 #ifdef _KERNEL
 #include <sys/cdefs.h>
-__KERNEL_RCSID(0, "$NetBSD: npf_if.c,v 1.11 2019/09/29 17:00:29 rmind Exp $");
+__KERNEL_RCSID(0, "$NetBSD: npf_if.c,v 1.12 2019/09/30 22:04:33 rmind Exp $");
 
 #include <sys/param.h>
 #include <sys/types.h>
@@ -191,20 +191,22 @@
 }
 
 /*
- * This function is toxic; it can return garbage since we don't
- * lock, but it is only used temporarily and only for logging.
+ * npf_ifmap_copylogname: this function is toxic; it can return garbage
+ * as we don't lock, but it is only used temporarily and only for logging.
  */
 void
 npf_ifmap_copylogname(npf_t *npf, unsigned id, char *buf, size_t len)
 {
-       if (id != NPF_IFMAP_NOID) {
-               const unsigned i = NPF_IFMAP_ID2SLOT(npf, id);
-               npf_ifmap_t *ifmap = &npf->ifmap[i];
+       const unsigned i = NPF_IFMAP_ID2SLOT(npf, id);
 
+       membar_consumer();
+
+       if (id != NPF_IFMAP_NOID && i < NPF_MAX_IFMAP) {
                /*
                 * Lock-free access is safe as there is an extra byte
                 * with a permanent NUL terminator at the end.
                 */
+               const npf_ifmap_t *ifmap = &npf->ifmap[i];
                strlcpy(buf, ifmap->ifname, MIN(len, IFNAMSIZ));
        } else {
                strlcpy(buf, "???", len);



Home | Main Index | Thread Index | Old Index