summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorcheloha <cheloha@openbsd.org>2020-12-11 05:00:21 +0000
committercheloha <cheloha@openbsd.org>2020-12-11 05:00:21 +0000
commit54b3831179727349c9c86519a934aad56a12cb3d (patch)
treecf88686f1e5edaf89908f6140d8654089dc4e85b
parentipmi(4): tsleep(9) -> tsleep_nsec(9) (diff)
downloadwireguard-openbsd-54b3831179727349c9c86519a934aad56a12cb3d.tar.xz
wireguard-openbsd-54b3831179727349c9c86519a934aad56a12cb3d.zip
bpf(4): BIOCGRTIMEOUT, BIOCSRTIMEOUT: protect bd_rtout with bd_mtx
Reading and writing bd_rtout is not an atomic operation, so it needs to be done under the per-descriptor mutex. While here, start annotating locking in bpfdesc.h. There's lots more to do on this front, but you have to start somewhere. Tweaked by mpi@. ok mpi@
-rw-r--r--sys/net/bpf.c6
-rw-r--r--sys/net/bpfdesc.h10
2 files changed, 13 insertions, 3 deletions
diff --git a/sys/net/bpf.c b/sys/net/bpf.c
index ebb4bc95115..0de4c0cd020 100644
--- a/sys/net/bpf.c
+++ b/sys/net/bpf.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: bpf.c,v 1.193 2020/11/04 04:40:13 gnezdo Exp $ */
+/* $OpenBSD: bpf.c,v 1.194 2020/12/11 05:00:21 cheloha Exp $ */
/* $NetBSD: bpf.c,v 1.33 1997/02/21 23:59:35 thorpej Exp $ */
/*
@@ -873,9 +873,11 @@ bpfioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
break;
}
rtout += tv->tv_usec / tick;
+ mtx_enter(&d->bd_mtx);
d->bd_rtout = rtout;
if (d->bd_rtout == 0 && tv->tv_usec != 0)
d->bd_rtout = 1;
+ mtx_leave(&d->bd_mtx);
break;
}
@@ -886,8 +888,10 @@ bpfioctl(dev_t dev, u_long cmd, caddr_t addr, int flag, struct proc *p)
{
struct timeval *tv = (struct timeval *)addr;
+ mtx_enter(&d->bd_mtx);
tv->tv_sec = d->bd_rtout / hz;
tv->tv_usec = (d->bd_rtout % hz) * tick;
+ mtx_leave(&d->bd_mtx);
break;
}
diff --git a/sys/net/bpfdesc.h b/sys/net/bpfdesc.h
index 330b091b9db..62c15c598fb 100644
--- a/sys/net/bpfdesc.h
+++ b/sys/net/bpfdesc.h
@@ -1,4 +1,4 @@
-/* $OpenBSD: bpfdesc.h,v 1.41 2020/05/13 21:34:37 cheloha Exp $ */
+/* $OpenBSD: bpfdesc.h,v 1.42 2020/12/11 05:00:21 cheloha Exp $ */
/* $NetBSD: bpfdesc.h,v 1.11 1995/09/27 18:30:42 thorpej Exp $ */
/*
@@ -42,6 +42,12 @@
#ifdef _KERNEL
+/*
+ * Locks used to protect struct members in this file:
+ *
+ * m the per-descriptor mutex (bpf_d.bd_mtx)
+ */
+
struct bpf_program_smr {
struct bpf_program bps_bf;
struct smr_entry bps_smr;
@@ -72,7 +78,7 @@ struct bpf_d {
int bd_in_uiomove; /* for debugging purpose */
struct bpf_if *bd_bif; /* interface descriptor */
- u_long bd_rtout; /* Read timeout in 'ticks' */
+ u_long bd_rtout; /* [m] Read timeout in 'ticks' */
u_long bd_rdStart; /* when the read started */
int bd_rnonblock; /* true if nonblocking reads are set */
struct bpf_program_smr