From nobody Tue Oct 26 14:01:02 2021 X-Original-To: dev-commits-src-main@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 A8FBD182646A; Tue, 26 Oct 2021 14:01:02 +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 4HdtlL4NZqz3R3F; Tue, 26 Oct 2021 14:01:02 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 766871DD40; Tue, 26 Oct 2021 14:01:02 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 19QE12Ut056862; Tue, 26 Oct 2021 14:01:02 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 19QE12HX056861; Tue, 26 Oct 2021 14:01:02 GMT (envelope-from git) Date: Tue, 26 Oct 2021 14:01:02 GMT Message-Id: <202110261401.19QE12HX056861@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mark Johnston Subject: git: 426682b05a4c - main - bpf: Fix the write filter for detached descriptors List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: markj X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 426682b05a4cf700c20d503516bfa07c043fecf8 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=426682b05a4cf700c20d503516bfa07c043fecf8 commit 426682b05a4cf700c20d503516bfa07c043fecf8 Author: Mark Johnston AuthorDate: 2021-10-26 13:57:27 +0000 Commit: Mark Johnston CommitDate: 2021-10-26 14:00:39 +0000 bpf: Fix the write filter for detached descriptors A BPF descriptor only has an associated interface descriptor once it is attached to an interface, e.g., with BIOCSETIF. Avoid dereferencing a NULL pointer in filt_bpfwrite() if the BPF descriptor is not attached. Reviewed by: ae Reported by: syzbot+ae45d5166afe15a5a21d@syzkaller.appspotmail.com Fixes: ded77e0237a8 ("Allow the BPF to be select for write.") Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D32561 --- lib/libc/sys/kqueue.2 | 4 ++-- sys/net/bpf.c | 15 ++++++++++++--- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/lib/libc/sys/kqueue.2 b/lib/libc/sys/kqueue.2 index 68929e973dc0..afa1dc5dcb4a 100644 --- a/lib/libc/sys/kqueue.2 +++ b/lib/libc/sys/kqueue.2 @@ -390,8 +390,8 @@ For eventfds, will contain the maximum value that can be added to the counter without blocking. .Pp -For BPF devices, the filter always indicates that it is possible to -write and +For BPF devices, when the descriptor is attached to an interface the filter +always indicates that it is possible to write and .Va data will contain the MTU size of the underlying interface. .It Dv EVFILT_EMPTY diff --git a/sys/net/bpf.c b/sys/net/bpf.c index ce7aba5a9bcd..b229dd81b127 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -763,6 +763,10 @@ bpf_attachd(struct bpf_d *d, struct bpf_if *bp) CK_LIST_INSERT_HEAD(&bp->bif_dlist, d, bd_next); reset_d(d); + + /* Trigger EVFILT_WRITE events. */ + bpf_wakeup(d); + BPFD_UNLOCK(d); bpf_bpfd_cnt++; @@ -2229,11 +2233,16 @@ static int filt_bpfwrite(struct knote *kn, long hint) { struct bpf_d *d = (struct bpf_d *)kn->kn_hook; - BPFD_LOCK_ASSERT(d); - kn->kn_data = d->bd_bif->bif_ifp->if_mtu; + BPFD_LOCK_ASSERT(d); - return (1); + if (d->bd_bif == NULL) { + kn->kn_data = 0; + return (0); + } else { + kn->kn_data = d->bd_bif->bif_ifp->if_mtu; + return (1); + } } #define BPF_TSTAMP_NONE 0