git: 6c2430c72b4c - stable/14 - bpf: Add IfAPI analogue for bpf_peers_present()
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Tue, 24 Sep 2024 04:32:06 UTC
The branch stable/14 has been updated by zlei:
URL: https://cgit.FreeBSD.org/src/commit/?id=6c2430c72b4c3516752b7541b100847522ab2225
commit 6c2430c72b4c3516752b7541b100847522ab2225
Author: Justin Hibbits <jhibbits@FreeBSD.org>
AuthorDate: 2023-10-04 20:56:52 +0000
Commit: Zhenlei Huang <zlei@FreeBSD.org>
CommitDate: 2024-09-24 04:30:48 +0000
bpf: Add IfAPI analogue for bpf_peers_present()
An interface's bpf could feasibly not exist, in which case
bpf_peers_present() would panic from a NULL pointer dereference. Solve
this by adding a new IfAPI that could deal with a NULL bpf, if such
could occur in the network stack.
Reviewed by: zlei
Sponsored by: Juniper Networks, Inc.
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D42082
(cherry picked from commit 8f31b879ecaf9e738dba631df4606742ee404e8e)
bpf: Prefer the boolean form when calling bpf_peers_present()
Reviewed by: markj, kp, #network
MFC with: 8f31b879ecaf
Differential Revision: https://reviews.freebsd.org/D45509
(cherry picked from commit 89204d9dcbe28558fae65936a0e93f44d926b88f)
---
sys/dev/firewire/if_fwip.c | 4 ++--
sys/dev/hyperv/netvsc/if_hn.c | 4 ++--
sys/dev/my/if_my.c | 2 +-
sys/dev/usb/usb_pf.c | 4 +---
sys/net/bpf.c | 12 ++++++++++++
sys/net/bpf.h | 1 +
6 files changed, 19 insertions(+), 8 deletions(-)
diff --git a/sys/dev/firewire/if_fwip.c b/sys/dev/firewire/if_fwip.c
index 91a27800f308..6350ec9cb56e 100644
--- a/sys/dev/firewire/if_fwip.c
+++ b/sys/dev/firewire/if_fwip.c
@@ -778,7 +778,7 @@ fwip_stream_input(struct fw_xferq *xferq)
* Record the sender ID for possible BPF usage.
*/
src = ntohl(p[1]) >> 16;
- if (bpf_peers_present(if_getbpf(ifp))) {
+ if (bpf_peers_present_if(ifp)) {
mtag = m_tag_alloc(MTAG_FIREWIRE,
MTAG_FIREWIRE_SENDER_EUID,
2*sizeof(uint32_t), M_NOWAIT);
@@ -878,7 +878,7 @@ fwip_unicast_input(struct fw_xfer *xfer)
goto done;
}
- if (bpf_peers_present(if_getbpf(ifp))) {
+ if (bpf_peers_present_if(ifp)) {
/*
* Record the sender ID for possible BPF usage.
*/
diff --git a/sys/dev/hyperv/netvsc/if_hn.c b/sys/dev/hyperv/netvsc/if_hn.c
index 41be4226e592..9f51f5b32199 100644
--- a/sys/dev/hyperv/netvsc/if_hn.c
+++ b/sys/dev/hyperv/netvsc/if_hn.c
@@ -3263,7 +3263,7 @@ hn_txpkt(if_t ifp, struct hn_tx_ring *txr, struct hn_txdesc *txd)
int error, send_failed = 0, has_bpf;
again:
- has_bpf = bpf_peers_present(if_getbpf(ifp));
+ has_bpf = bpf_peers_present_if(ifp);
if (has_bpf) {
/*
* Make sure that this txd and any aggregated txds are not
@@ -5973,7 +5973,7 @@ hn_transmit(if_t ifp, struct mbuf *m)
omcast = (m->m_flags & M_MCAST) != 0;
if (sc->hn_xvf_flags & HN_XVFFLAG_ACCBPF) {
- if (bpf_peers_present(if_getbpf(ifp))) {
+ if (bpf_peers_present_if(ifp)) {
m_bpf = m_copypacket(m, M_NOWAIT);
if (m_bpf == NULL) {
/*
diff --git a/sys/dev/my/if_my.c b/sys/dev/my/if_my.c
index 3de394f424a2..6064c9de46c3 100644
--- a/sys/dev/my/if_my.c
+++ b/sys/dev/my/if_my.c
@@ -1146,7 +1146,7 @@ my_rxeof(struct my_softc * sc)
* broadcast packet, multicast packet, matches our ethernet
* address or the interface is in promiscuous mode.
*/
- if (bpf_peers_present(if_getbpf(ifp))) {
+ if (bpf_peers_present_if(ifp)) {
bpf_mtap_if(ifp, m);
if (if_getflags(ifp) & IFF_PROMISC &&
(bcmp(eh->ether_dhost, if_getlladdr(sc->my_ifp),
diff --git a/sys/dev/usb/usb_pf.c b/sys/dev/usb/usb_pf.c
index 3b03e80db489..0e7a75d04d6a 100644
--- a/sys/dev/usb/usb_pf.c
+++ b/sys/dev/usb/usb_pf.c
@@ -402,9 +402,7 @@ usbpf_xfertap(struct usb_xfer *xfer, int type)
bus = xfer->xroot->bus;
/* sanity checks */
- if (bus->ifp == NULL || if_getbpf(bus->ifp) == NULL)
- return;
- if (!bpf_peers_present(if_getbpf(bus->ifp)))
+ if (bus->ifp == NULL || !bpf_peers_present_if(bus->ifp))
return;
totlen = usbpf_xfer_precompute_size(xfer, type);
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index 61eb674a7c0a..e65d890f891b 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -2879,6 +2879,12 @@ bpfdetach(struct ifnet *ifp)
BPF_UNLOCK();
}
+bool
+bpf_peers_present_if(struct ifnet *ifp)
+{
+ return (bpf_peers_present(ifp->if_bpf));
+}
+
/*
* Get a list of available data link type of the interface.
*/
@@ -3162,6 +3168,12 @@ bpfdetach(struct ifnet *ifp)
{
}
+bool
+bpf_peers_present_if(struct ifnet *ifp)
+{
+ return (false);
+}
+
u_int
bpf_filter(const struct bpf_insn *pc, u_char *p, u_int wirelen, u_int buflen)
{
diff --git a/sys/net/bpf.h b/sys/net/bpf.h
index 7b76129aec94..ed3239971db5 100644
--- a/sys/net/bpf.h
+++ b/sys/net/bpf.h
@@ -428,6 +428,7 @@ void bpf_mtap2_if(struct ifnet *, void *, u_int, struct mbuf *);
void bpfattach(struct ifnet *, u_int, u_int);
void bpfattach2(struct ifnet *, u_int, u_int, struct bpf_if **);
void bpfdetach(struct ifnet *);
+bool bpf_peers_present_if(struct ifnet *);
#ifdef VIMAGE
int bpf_get_bp_params(struct bpf_if *, u_int *, u_int *);
#endif