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
This commit is contained in:
Mark Johnston 2022-06-30 10:19:23 -04:00
parent bc83b35922
commit 333670372f
1 changed files with 5 additions and 4 deletions

View File

@ -803,6 +803,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)
@ -818,10 +823,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;