Module Name: src Committed By: rmind Date: Mon Sep 30 22:04:33 UTC 2019
Modified Files: src/sys/net/npf: npf_if.c Log Message: npf_ifmap_copylogname: be more defensive. To generate a diff of this commit: cvs rdiff -u -r1.11 -r1.12 src/sys/net/npf/npf_if.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/sys/net/npf/npf_if.c diff -u src/sys/net/npf/npf_if.c:1.11 src/sys/net/npf/npf_if.c:1.12 --- src/sys/net/npf/npf_if.c:1.11 Sun Sep 29 17:00:29 2019 +++ src/sys/net/npf/npf_if.c Mon Sep 30 22:04:33 2019 @@ -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 @@ npf_ifmap_getid(npf_t *npf, const ifnet_ } /* - * 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);