git: 86bd7f67c31f - stable/12 - pf: Make sure that pfi_update_status() always zeros counters

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Mon, 29 Aug 2022 13:07:05 UTC
The branch stable/12 has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=86bd7f67c31f30169e77235e329d72ee98a87a29

commit 86bd7f67c31f30169e77235e329d72ee98a87a29
Author:     Mark Johnston <markj@FreeBSD.org>
AuthorDate: 2022-06-30 14:19:23 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2022-08-29 13:06:03 +0000

    pf: Make sure that pfi_update_status() always zeros counters
    
    pfi_update_status() can return early if the status interface doesn't
    exist.  But in this case pf_getstatus() was copying uninitialized stack
    memory into the output nvlist.
    
    Reported by:    Jenkins (KMSAN job)
    Reviewed by:    kp
    MFC after:      2 weeks
    Sponsored by:   The FreeBSD Foundation
    Differential Revision:  https://reviews.freebsd.org/D35659
    
    (cherry picked from commit 333670372ffe2f1c562e1088a7779eb709006ba2)
---
 sys/netpfil/pf/pf_if.c | 9 +++++----
 1 file changed, 5 insertions(+), 4 deletions(-)

diff --git a/sys/netpfil/pf/pf_if.c b/sys/netpfil/pf/pf_if.c
index 806718863f34..54ac84365180 100644
--- a/sys/netpfil/pf/pf_if.c
+++ b/sys/netpfil/pf/pf_if.c
@@ -789,6 +789,11 @@ pfi_update_status(const char *name, struct pf_status *pfs)
 	CK_STAILQ_HEAD(, ifg_member) ifg_members;
 	int			 i, j, k;
 
+	if (pfs) {
+		bzero(pfs->pcounters, sizeof(pfs->pcounters));
+		bzero(pfs->bcounters, sizeof(pfs->bcounters));
+	}
+
 	strlcpy(key.pfik_name, name, sizeof(key.pfik_name));
 	p = RB_FIND(pfi_ifhead, &V_pfi_ifs, (struct pfi_kkif *)&key);
 	if (p == NULL)
@@ -804,10 +809,6 @@ pfi_update_status(const char *name, struct pf_status *pfs)
 		CK_STAILQ_INIT(&ifg_members);
 		CK_STAILQ_INSERT_TAIL(&ifg_members, &p_member, ifgm_next);
 	}
-	if (pfs) {
-		bzero(pfs->pcounters, sizeof(pfs->pcounters));
-		bzero(pfs->bcounters, sizeof(pfs->bcounters));
-	}
 	CK_STAILQ_FOREACH(ifgm, &ifg_members, ifgm_next) {
 		if (ifgm->ifgm_ifp == NULL || ifgm->ifgm_ifp->if_pf_kif == NULL)
 			continue;