In bpf_setf(), protect against races between multiple user threads
attempting to change the BPF filter on a BPF descriptor at the same time: retrieve the old filter pointer under the same locked region as setting the new pointer. MFC after: 3 days
This commit is contained in:
parent
ba21b23c12
commit
6ae9352b09
@ -947,11 +947,11 @@ bpf_setf(d, fp)
|
||||
struct bpf_insn *fcode, *old;
|
||||
u_int flen, size;
|
||||
|
||||
old = d->bd_filter;
|
||||
if (fp->bf_insns == NULL) {
|
||||
if (fp->bf_len != 0)
|
||||
return (EINVAL);
|
||||
BPFD_LOCK(d);
|
||||
old = d->bd_filter;
|
||||
d->bd_filter = NULL;
|
||||
reset_d(d);
|
||||
BPFD_UNLOCK(d);
|
||||
@ -968,6 +968,7 @@ bpf_setf(d, fp)
|
||||
if (copyin((caddr_t)fp->bf_insns, (caddr_t)fcode, size) == 0 &&
|
||||
bpf_validate(fcode, (int)flen)) {
|
||||
BPFD_LOCK(d);
|
||||
old = d->bd_filter;
|
||||
d->bd_filter = fcode;
|
||||
reset_d(d);
|
||||
BPFD_UNLOCK(d);
|
||||
|
Loading…
x
Reference in New Issue
Block a user