From nobody Fri Oct 13 18:28:48 2023 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4S6ZlN34wgz4wc4k; Fri, 13 Oct 2023 18:28:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4S6ZlN2cKTz4Rr1; Fri, 13 Oct 2023 18:28:48 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697221728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=j39kjJrDSb7gxO0p7Nb476RAkuzmN71fX8G9x8Nl4w0=; b=CoiGhYQsemsx8F+KwWHO8pIafDyuy3d07T5Ap4K4RXwV0nZO4EPYn4tC2YFDpTZ7pRXJA4 AQdJdmkJRjH6vjUN7GgMAVaVum1JNEHg/Tyw2UBgD+lgqAq5DdtrLGzaa3RbQTIgkzAYsK lKlH+L8Sp7v5G4Dx+981/7OSIP6NCxLLRjg2qbH5CyKW61cAgbtFxn/ED1yjG8uggKmcxZ D/J58FHuNWLu2gmud71fyQN4EkjxhHwNlFFo3ljvI0B69A2UfL41zReRpXpBzejQuivSKo w6ruptUUPXzxd8eDRTXmmWsI2OP0g+Ht6S418jF0LL+GM8esxGHDJCleOxeKFg== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1697221728; a=rsa-sha256; cv=none; b=Qzcukxfy8fpUyFqooyVN+SxpZinXhyJkSmOAcj4exc2Jw7ZZ+3pYSqw4fhJDD6qjJ71DTE ukKm1dClGOPpx5oRWWguympBbKFjA6Laf6HZ7IXgYTZWXXrY0zb9uY5C5jxUzOOE1EAMcs 67GhAj4rtXItoPGEg3l0K2AkZKoI+yffHKKLFrC+9LzpX6FFKE5iBsst+S8j+ovR6sYEso bK/KwNgAxPQcytD4s0BN9gZItT8jVLWRq3dof5zi/vX+IdHonpSoVnTq+nRkVb4D79iGsV 3i2pkBQLuggDeF6PbHdt8GsgsNcwpck/7MvknQOVUFq+wsfo3t5nZgnEU91RIg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1697221728; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=j39kjJrDSb7gxO0p7Nb476RAkuzmN71fX8G9x8Nl4w0=; b=o9OrfsD2mOTS/WhRExEgDk4aAOigLNWKC+u0b2WCJrxioUCXvkPB3XlLz2EHY9FPUvKskR xwXe5/IpWhgljQPGSI3j9lPa1pHVzMBcQWvsTTn9kD0G5l8kV8SNb6phTAYKu3FLe0oA2g 5HPuA6z6FUwRL6/RoyqO3wYLioOErqtuLeYmemcKnEEeEjYGknrT/3zmj8gae7/iv+06wD aRE9+AKus69c07YT8cO6zUj59H2I7X8CajtYfBnTJXeHauLRBWECCy0dycg0BpPmacTF7t PXppCu1VmoCsGHk8ntCexKaUompCZWbw5en5G81PbyMq7IG/rvugtawB15REbw== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4S6ZlN1M4qzy8t; Fri, 13 Oct 2023 18:28:48 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 39DISmiN083113; Fri, 13 Oct 2023 18:28:48 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 39DISmnu083110; Fri, 13 Oct 2023 18:28:48 GMT (envelope-from git) Date: Fri, 13 Oct 2023 18:28:48 GMT Message-Id: <202310131828.39DISmnu083110@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Justin Hibbits Subject: git: 8f31b879ecaf - main - bpf: Add IfAPI analogue for bpf_peers_present() List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhibbits X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 8f31b879ecaf9e738dba631df4606742ee404e8e Auto-Submitted: auto-generated The branch main has been updated by jhibbits: URL: https://cgit.FreeBSD.org/src/commit/?id=8f31b879ecaf9e738dba631df4606742ee404e8e commit 8f31b879ecaf9e738dba631df4606742ee404e8e Author: Justin Hibbits AuthorDate: 2023-10-04 20:56:52 +0000 Commit: Justin Hibbits CommitDate: 2023-10-13 18:33:31 +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 --- 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 | 14 ++++++++++++++ sys/net/bpf.h | 1 + 6 files changed, 21 insertions(+), 8 deletions(-) diff --git a/sys/dev/firewire/if_fwip.c b/sys/dev/firewire/if_fwip.c index 5237c555d999..b698db6c9620 100644 --- a/sys/dev/firewire/if_fwip.c +++ b/sys/dev/firewire/if_fwip.c @@ -780,7 +780,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); @@ -880,7 +880,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 7d8e1914163e..f6f885873a79 100644 --- a/sys/dev/hyperv/netvsc/if_hn.c +++ b/sys/dev/hyperv/netvsc/if_hn.c @@ -3262,7 +3262,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 @@ -5972,7 +5972,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 2bf4573d337b..631c38df9dca 100644 --- a/sys/dev/my/if_my.c +++ b/sys/dev/my/if_my.c @@ -1152,7 +1152,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 43e819684857..4da59419a7c6 100644 --- a/sys/dev/usb/usb_pf.c +++ b/sys/dev/usb/usb_pf.c @@ -408,9 +408,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 8ca6e941e646..96420b709911 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -2879,6 +2879,14 @@ bpfdetach(struct ifnet *ifp) BPF_UNLOCK(); } +bool +bpf_peers_present_if(struct ifnet *ifp) +{ + struct bpf_if *bp = ifp->if_bpf; + + return (bpf_peers_present(bp) > 0); +} + /* * Get a list of available data link type of the interface. */ @@ -3162,6 +3170,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 924dea5fc9f4..31968445aac1 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