Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 12 Apr 2021 09:55:47 GMT
From:      Kristof Provost <kp@FreeBSD.org>
To:        src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org
Subject:   git: 5e98cae661f3 - main - pf: Ensure that we don't use kif passed to pfi_kkif_attach()
Message-ID:  <202104120955.13C9tlej035695@gitrepo.freebsd.org>

next in thread | raw e-mail | index | archive | help
The branch main has been updated by kp:

URL: https://cgit.FreeBSD.org/src/commit/?id=5e98cae661f3a7e85df7f277660765b823454073

commit 5e98cae661f3a7e85df7f277660765b823454073
Author:     Kristof Provost <kp@FreeBSD.org>
AuthorDate: 2021-04-12 09:45:48 +0000
Commit:     Kristof Provost <kp@FreeBSD.org>
CommitDate: 2021-04-12 09:55:21 +0000

    pf: Ensure that we don't use kif passed to pfi_kkif_attach()
    
    Once a kif is passed to pfi_kkif_attach() we must ensure we never re-use
    it for anything else.
    Set the kif to NULL afterwards to guarantee this.
    
    Reported-by: syzbot+be5d4f4a7a4c295e659a@syzkaller.appspotmail.com
    MFC after:      4 weeks
    Sponsored by:   Rubicon Communications, LLC ("Netgate")
---
 sys/netpfil/pf/pf_if.c    | 1 +
 sys/netpfil/pf/pf_ioctl.c | 3 +++
 2 files changed, 4 insertions(+)

diff --git a/sys/netpfil/pf/pf_if.c b/sys/netpfil/pf/pf_if.c
index be290a1e1f2e..4630098221c8 100644
--- a/sys/netpfil/pf/pf_if.c
+++ b/sys/netpfil/pf/pf_if.c
@@ -486,6 +486,7 @@ pfi_dynaddr_setup(struct pf_addr_wrap *aw, sa_family_t af)
 		dyn->pfid_kif = pfi_kkif_attach(kif, IFG_ALL);
 	else
 		dyn->pfid_kif = pfi_kkif_attach(kif, aw->v.ifname);
+	kif = NULL;
 	pfi_kkif_ref(dyn->pfid_kif);
 
 	dyn->pfid_net = pfi_unmask(&aw->v.a.mask);
diff --git a/sys/netpfil/pf/pf_ioctl.c b/sys/netpfil/pf/pf_ioctl.c
index 0b8570f294bf..6ea2a1c4571c 100644
--- a/sys/netpfil/pf/pf_ioctl.c
+++ b/sys/netpfil/pf/pf_ioctl.c
@@ -2345,6 +2345,7 @@ pf_ioctl_addrule(struct pf_krule *rule, uint32_t ticket,
 		rule->nr = 0;
 	if (rule->ifname[0]) {
 		rule->kif = pfi_kkif_attach(kif, rule->ifname);
+		kif = NULL;
 		pfi_kkif_ref(rule->kif);
 	} else
 		rule->kif = NULL;
@@ -2962,6 +2963,7 @@ DIOCGETRULENV_error:
 			if (newrule->ifname[0]) {
 				newrule->kif = pfi_kkif_attach(kif,
 				    newrule->ifname);
+				kif = NULL;
 				pfi_kkif_ref(newrule->kif);
 			} else
 				newrule->kif = NULL;
@@ -3747,6 +3749,7 @@ DIOCGETSTATES_full:
 		}
 		if (pa->ifname[0]) {
 			pa->kif = pfi_kkif_attach(kif, pa->ifname);
+			kif = NULL;
 			pfi_kkif_ref(pa->kif);
 		} else
 			pa->kif = NULL;



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?202104120955.13C9tlej035695>