aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMark Johnston <markj@FreeBSD.org>2022-08-05 20:25:05 +0000
committerMark Johnston <markj@FreeBSD.org>2022-08-05 20:26:34 +0000
commit220818ac030726c24cbf9df6df5c9d019993b875 (patch)
tree17f10d7d044770ab34b83395482e43234a5510e5
parente9552d8b45d67ca44d91b3ec09c91253e7e99b28 (diff)
downloadsrc-220818ac030726c24cbf9df6df5c9d019993b875.tar.gz
src-220818ac030726c24cbf9df6df5c9d019993b875.zip
bpf: Fix BIOCPROMISC locking
BPF might put an interface in promiscuous mode when handling the BIOCSDLT ioctl. When this happens, a flag is set in the BPF descriptor so that the old interface can be restored when the BPF descriptor is destroyed. The BIOCPROMISC ioctl can also be used to put a BPF descriptor's interface into promiscuous mode, but there was nothing synchronizing the flag. Fix this by modifying the ioctl handler to acquire the global BPF mutex, which is used to synchronize ifpromisc() calls elsewhere in BPF. Reviewed by: kp, melifaro MFC after: 2 weeks Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D36045
-rw-r--r--sys/net/bpf.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index 2a390c1e7d30..4c8c77d1e948 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -1515,18 +1515,18 @@ bpfioctl(struct cdev *dev, u_long cmd, caddr_t addr, int flags,
* Put interface into promiscuous mode.
*/
case BIOCPROMISC:
+ BPF_LOCK();
if (d->bd_bif == NULL) {
/*
* No interface attached yet.
*/
error = EINVAL;
- break;
- }
- if (d->bd_promisc == 0) {
+ } else if (d->bd_promisc == 0) {
error = ifpromisc(d->bd_bif->bif_ifp, 1);
if (error == 0)
d->bd_promisc = 1;
}
+ BPF_UNLOCK();
break;
/*