summaryrefslogtreecommitdiff
path: root/sys/net/bpf.c
AgeCommit message (Collapse)Author
2020-04-07Abstract the head of knote lists. This allows extending the lists,Visa Hankala
for example, with locking assertions. OK mpi@, anton@
2020-02-20Replace field f_isfd with field f_flags in struct filterops to allowVisa Hankala
adding more filter properties without cluttering the struct. OK mpi@, anton@
2020-02-14Push the KERNEL_LOCK() insidge pgsigio() and selwakeup().Martin Pieuchot
The 3 subsystems: signal, poll/select and kqueue can now be addressed separatly. Note that bpf(4) and audio(4) currently delay the wakeups to a separate context in order to respect the KERNEL_LOCK() requirement. Sockets (UDP, TCP) and pipes spin to grab the lock for the sames reasons. ok anton@, visa@
2020-01-27update bpf_iflist in bpfsdetach instead of bpfdetach as some driversJoshua Stein
like USB only use the former and bpf_iflist was otherwise retaining references to a freed bpf_if. ok sashan
2020-01-08Unify handling of ioctls FIOSETOWN/SIOCSPGRP/TIOCSPGRP andVisa Hankala
FIOGETOWN/SIOCGPGRP/TIOCGPGRP. Do this by determining the meaning of the ID parameter inside the sigio code. Also add cases for FIOSETOWN and FIOGETOWN where there have been TIOCSPGRP and TIOCGPGRP before. These changes allow removing the ID translation from sys_fcntl() and sys_ioctl(). Idea from NetBSD OK mpi@, claudio@
2020-01-02Switch bpf to use pgsigio(9) and sigio_init(9) instead of handrollingClaudio Jeker
something with csignal(). OK visa@
2019-12-31Use C99 designated initializers with struct filterops. In addition,Visa Hankala
make the structs const so that the data are put in .rodata. OK mpi@, deraadt@, anton@, bluhm@
2019-10-21put bpfdesc reference counting back, revert change introduced in 1.175 as:Alexandr Nedvedicky
BPF: remove redundant reference counting of filedescriptors Anton@ made problem crystal clear: I've been looking into a similar bpf panic reported by syzkaller, which looks somewhat related. The one reported by syzkaller is caused by issuing ioctl(SIOCIFDESTROY) on the interface which the packet filter is attached to. This will in turn invoke the following functions expressed as an inverted stacktrace: 1. bpfsdetach() 2. vdevgone() 3. VOP_REVOKE() 4. vop_generic_revoke() 5. vgonel() 6. vclean(DOCLOSE) 7. VOP_CLOSE() 8. bpfclose() Note that bpfclose() is called before changing the vnode type. In bpfclose(), the `struct bpf_d` is immediately removed from the global bpf_d_list list and might end up sleeping inside taskq_barrier(systq). Since the bpf file descriptor (fd) is still present and valid, another thread could perform an ioctl() on the fd only to fault since bpfilter_lookup() will return NULL. The vnode is not locked in this path either so it won't end up waiting on the ongoing vclean(). Steps to trigger the similar type of panic are straightforward, let there be two processes running concurrently: process A: while true ; do ifconfig tun0 up ; ifconfig tun0 destroy ; done process B: while true ; do tcpdump -i tun0 ; done panic happens within few secs (Dell PowerEdge 710) OK @visa, OK @anton
2019-10-01remove the internal plumbing that supported a custom mbuf copy function.David Gwynne
this is not needed now that the "public" api does not provide a way to pass a custom copy function in for the internals to pass around. ok claudio@ visa@
2019-09-30remove the "copy function" argument to bpf_mtap_hdr.David Gwynne
it was previously (ab)used by pflog, which has since been fixed. apart from that nothing else used it, so we can trim the cruft. ok kn@ claudio@ visa@ visa@ also made sure i fixed ipw(4) so i386 won't break.
2019-09-12we don't need to cast hdr arguments to caddr_t for bpf_mtap_hdr anymore.David Gwynne
pointed out by naddy@
2019-09-12make bpf_mtap_hdr take a const void *, not a caddr_t.David Gwynne
this makes it easier to call at least, and makes it consistent with bpf_tap_hdr. ok stsp@ sashan@
2019-06-13free(9) sizes for buffers.Martin Pieuchot
ok anton@, sashan@
2019-06-10use m_microtime to get the packet rx time it might be available.David Gwynne
2019-05-18BPF: remove redundant reference counting of filedescriptorsAlexandr Nedvedicky
OK visa@, OK mpi@
2019-04-25Lower the accepted upper bound for bd_rtout to INT_MAX in order toanton
prevent passing negative values to timeout_add(). While here, protect against unsigned wrap around during addition of bd_rdStart and bd_rtout since it could also cause passing negative values to timeout_add(). ok bluhm@ Reported-by: syzbot+6771e3d6d9567b3983aa@syzkaller.appspotmail.com
2019-04-15moving BPF to RCUAlexandr Nedvedicky
OK visa@
2019-04-03Reject negative and too large timeouts passed to BIOCSRTIMEOUT. Sinceanton
the timeout converted to ticks is later passed timeout_add(), it could cause a panic if the timeout is negative. ok deraadt@ millert@ Reported-by: syzbot+82cb4dfe6a1fc3d8b490@syzkaller.appspotmail.com
2019-03-18extend BIOCSFILDROP so it can be configured to not capture packets.David Gwynne
BIOCSFILDROP was already able to be used as a quick and dirty firewall, which is especially useful when you you want to filter non-ip things. however, capturing the packets you're dropping is a lot of overhead when you just want to drop stuff. this extends fildrop so you can tell bpf not to capture the packets it drops. ok sthen@ mikeb@ claudio@ visa@
2018-07-13Some USB network interfaces like rum(4) report ENXIO from theirAlexander Bluhm
ioctl function after the device has been pulled out. Also accept this error code in bpf_detachd() to prevent a kernel panic. tcpdump(8) may run while the interface is detached. from Moritz Buhl; OK stsp@
2018-03-02Protect the calls to ifpromisc() in bpf(4) with net lock. ThisAlexander Bluhm
affects the bpfioctl() and bpfclose() path. lock assertion reported and fix tested by Pierre Emeriaud; OK visa@
2018-02-19Remove almost unused `flags' argument of suser().Martin Pieuchot
The account flag `ASU' will no longer be set but that makes suser() mpsafe since it no longer mess with a per-process field. No objection from millert@, ok tedu@, bluhm@
2018-02-01add bpf_tap_hdr(), for handling a buffer (not an mbuf) with a header.David Gwynne
internally it uses mbufs to handle the chain of buffers, but the caller doesnt have to deal with that or allocate a temporary buffer with the header attached. ok mpi@
2018-01-24add support for bpf on "subsystems", not just network interfacesDavid Gwynne
bpf assumed that it was being unconditionally attached to network interfaces, and maintained a pointer to a struct ifnet *. this was mostly used to get at the name of the interface, which is how userland asks to be attached to a particular interface. this diff adds a pointer to the name and uses it instead of the interface pointer for these lookups. this in turn allows bpf to be attached to arbitrary subsystems in the kernel which just have to supply a name rather than an interface pointer. for example, bpf could be attached to pf_test so you can see what packets are about to be filtered. mpi@ is using this to look at usb transfers. bpf still uses the interface pointer for bpfwrite, and for enabling and disabling promisc. however, these are nopped out for subsystems. ok mpi@
2017-12-30Don't pull in <sys/file.h> just to get fcntl.hPhilip Guenther
ok deraadt@ krw@
2017-08-11Remove NET_LOCK()'s argument.Martin Pieuchot
Tested by Hrvoje Popovski, ok bluhm@
2017-05-24When using "tcpdump proto 128" the filter never matched. A signAlexander Bluhm
expansion bug in bpf prevented protocols above 127. m_data is signed, bpf_mbuf_ldb() returns unsigned. bug report Matthias Pitzl; OK deraadt@ millert@
2017-05-04Introduce sstosa() for converting sockaddr_storage with a type safeAlexander Bluhm
inline function instead of casting it to sockaddr. While there, use inline instead of __inline for all these conversions. Some struct sockaddr casts can be avoided completely. OK dhill@ mpi@
2017-04-20Tweak lock inits to make the system runnable with witness(4)Visa Hankala
on amd64 and i386.
2017-01-24splsoftnet() to NET_LOCK() in bpfwrite().Martin Pieuchot
ok dlg@, visa@
2017-01-24A space here, a space there. Soon we're talking real whitespaceKenneth R Westerback
rectification.
2017-01-09Use a mutex to serialize accesses to buffer slots.Martin Pieuchot
With this change bpf_catchpacket() no longer need the KERNEL_LOCK(). Tested by Hrvoje Popovski who reported a recursion in the previous attempt. ok bluhm@
2017-01-03Revert previous, there's still a problem with recursive entries inMartin Pieuchot
bpf_mpath_ether(). Problem reported by Hrvoje Popovski.
2017-01-02Use a mutex to serialize accesses to buffer slots.Martin Pieuchot
With this change bpf_catchpacket() no longer need the KERNEL_LOCK(). ok bluhm@, jmatthew@
2016-11-28Make sure the descriptor has been removed from the interface listMartin Pieuchot
before we call ifpromisc() and possibly sleep. ok bluhm@
2016-11-21Make sure bpf_wakeup() is called at most once when matching conditionsMartin Pieuchot
are fulfilled in bpf_catchpacket().
2016-11-21Rename bpf_reset_d() to match bpf_{attach,reset}d().Martin Pieuchot
2016-11-16Use goto in bpf{read,write}() to ease review of locked sections.Martin Pieuchot
While here properly account for used reference in bpfwrite(). ok bluhm@
2016-11-16Allow bpf_allocbufs() to fail when allocating memory.Martin Pieuchot
This will help trading the KERNEL_LOCK for a mutex. ok bluhm@
2016-10-16Fix bpf_catchpacket comment.Jeremie Courreges-Anglas
2016-09-12bpf_tap() is long dead! Long live bpf_mtap() & friends.Kenneth R Westerback
ok natano@ deraadt@
2016-08-22Call csignal() and selwakeup() from a KERNEL_LOCK'd task.Martin Pieuchot
This will allow us make bpf_tap() KERNEL_LOCK() free. Discussed with dlg@ and input from guenther@
2016-08-15No need to reset si_selpid after calling selwakeup() the functionMartin Pieuchot
already does it.
2016-08-15Introduce bpf_put() and bpf_get() instead of mixing macro and functionsMartin Pieuchot
for the reference counting. ok dlg@
2016-08-15Check if ``bd_bif'' is NULL inside bpf_catchpacket() to match bpfread()Martin Pieuchot
and bpfwrite(), all of which will need to grabe a lock to protect the buffers. ok dlg@
2016-08-15Merge bpfilter_create() into bpfopen() and make it such that theMartin Pieuchot
descriptor is referenced before it is inserted in the global list. ok dlg@
2016-07-25Make sure closed bpf devices are removed from bpf_d_list to free theMartin Natano
minor number for reuse by the device cloning code. This fixes a panic reported by bluhm@. initial diff from tedu ok deraadt
2016-06-10Add the "llprio" field to struct ifnet, and the corresponding keywordVincent Gross
to ifconfig. "llprio" allows one to set the priority of packets that do not go through pf(4), as the case is for arp(4) or bpf(4). ok sthen@ mikeb@
2016-05-18rework the srp api so it takes an srp_ref struct that the caller provides.David Gwynne
the srp_ref struct is used to track the location of the callers hazard pointer so later calls to srp_follow and srp_enter already know what to clear. this in turn means most of the caveats around using srps go away. specifically, you can now: - switch cpus while holding an srp ref - ie, you can sleep while holding an srp ref - you can take and release srp refs in any order the original intent was to simplify use of the api when dealing with complicated data structures. the caller now no longer has to track the location of the srp a value was fetched from, the srp_ref effectively does that for you. srp lists have been refactored to use srp_refs instead of srpl_iter structs. this is in preparation of using srps inside the ART code. ART is a complicated data structure, and lookups require overlapping holds of srp references. ok mpi@ jmatthew@
2016-05-10make the bpf tap functions take const struct mbuf *David Gwynne
this makes it more obvious that the bpf code should only read packets, never modify them. now possible because the paths that care about M_FILDROP set it after calling bpf_mtap. ok mpi@ visa@ deraadt@