From nobody Mon Jun 20 17:00:31 2022 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 0F01D877763; Mon, 20 Jun 2022 17:00:32 +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 4LRbW33kyWz3DDg; Mon, 20 Jun 2022 17:00:31 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655744431; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qqTJRDA7wtu7cWRhWcx5u+xpHsVvrSPMsoZS2SSyvlY=; b=lQBMXJlRIucGAV3rY5lpFtnPcYGvQulNbTjMQ4XSg9DgZKr7rWlSgUrHsXioEW0E3Ui++Z JCSrEiHOH7XIA7VyW5aESviyf00lfdo3/y+E4bUEFkDkccrTUk+GLp6Vb4welqKQ3CGFJ+ 3G13bJAJUDajWNoFJdIyKbcf74kQjt2TTw+1NX77xl1TOLJKcRaywY8QWqmTSRvYb3c5KK qzfRK5cJFBBdkGyKMlnNWalgDVI9aCQWsYTs+4OcoOSAiMoF9vpXimur+QeiS+vfzVUueh UUhMend1GGUPvZQQi75hzGG1WSR0WbkXwF7KEVctm3tYMRBDg1reUOwMo+6DZg== 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 355EE2118F; Mon, 20 Jun 2022 17:00:31 +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 25KH0Vlk049796; Mon, 20 Jun 2022 17:00:31 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25KH0VHW049795; Mon, 20 Jun 2022 17:00:31 GMT (envelope-from git) Date: Mon, 20 Jun 2022 17:00:31 GMT Message-Id: <202206201700.25KH0VHW049795@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: 60b4ad4b6b56 - main - bpf: Zero pad bytes preceding BPF headers 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: 60b4ad4b6b561ac2d9129a3576a74db3607ad90c Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1655744431; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=qqTJRDA7wtu7cWRhWcx5u+xpHsVvrSPMsoZS2SSyvlY=; b=GiepdyNePHm8ZN1DmQr4HxxMnUrrzECfpuQfUQ0Z0myn3oEPGS6jTOZSpiDJXR++RhTKgM qNln9f5B2fL/kJ9scKHRXdCuuHxRaaI4/dEyOIdatQeVGfkm/LKpU5c3+RrkGCF8sAJacD 4NrN6Luohjb1W0RYZ0NC0kg5rrbUg6ZPve1LtLJh9f5foi9vnFwBpRvppby57JNvHm5wCu AhPZi+yffyZGE0QgIh17FRhy5+aTc5kGBOY9mFSNOv9j94ATq9EAvYIqYIF8QRYRmTTJy9 Ard2UnQLpdE/z6afWyrW7/68PK62BRoVZryy4wwFrxkF9GhjUNzdcNQJzwykdw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1655744431; a=rsa-sha256; cv=none; b=KNO7D+58UBolp62iAKRMx4HmuLow0+ZTnFQaj/wrkUZvK4lN5kq6cXp/O2TA2hC5zFyL3+ tcLKMH/XIMzZvXSWceaC62wY/PRnV1hwmfCDuzeywKc8vHfc22QTIySutxKoe03JBgqF3z xxTJUUOeQoLauWdJfsY/VFT4dPSryJJhWAfWQGlK45zvIF8y6P686G5ZeIm6wUa6rjgmfX 7fU73Ugb8uQQh5n0A1K/qohFnRS9iwCg1KDkLpbAq9p+D+h9Rv8WxGUxTibyGxmmQ8xwqO 38eLWJKfiNRO+kBLZHk3dPJCyCvSKrK9D8NMEt2olsUOC1/vlS3MTzx8nUNAqA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=60b4ad4b6b561ac2d9129a3576a74db3607ad90c commit 60b4ad4b6b561ac2d9129a3576a74db3607ad90c Author: Mark Johnston AuthorDate: 2022-06-20 16:03:37 +0000 Commit: Mark Johnston CommitDate: 2022-06-20 16:48:13 +0000 bpf: Zero pad bytes preceding BPF headers BPF headers are word-aligned when copied into the store buffer. Ensure that pad bytes following the preceding packet are cleared. Reported by: KMSAN MFC after: 1 week Sponsored by: The FreeBSD Foundation --- sys/net/bpf.c | 29 +++++++++++++++++++++-------- 1 file changed, 21 insertions(+), 8 deletions(-) diff --git a/sys/net/bpf.c b/sys/net/bpf.c index b229dd81b127..2a390c1e7d30 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -2536,6 +2536,7 @@ catchpacket(struct bpf_d *d, u_char *pkt, u_int pktlen, u_int snaplen, void (*cpfn)(struct bpf_d *, caddr_t, u_int, void *, u_int), struct bintime *bt) { + static char zeroes[BPF_ALIGNMENT]; struct bpf_xhdr hdr; #ifndef BURN_BRIDGES struct bpf_hdr hdr_old; @@ -2543,7 +2544,7 @@ catchpacket(struct bpf_d *d, u_char *pkt, u_int pktlen, u_int snaplen, struct bpf_hdr32 hdr32_old; #endif #endif - int caplen, curlen, hdrlen, totlen; + int caplen, curlen, hdrlen, pad, totlen; int do_wakeup = 0; int do_timestamp; int tstype; @@ -2609,13 +2610,25 @@ catchpacket(struct bpf_d *d, u_char *pkt, u_int pktlen, u_int snaplen, ROTATE_BUFFERS(d); do_wakeup = 1; curlen = 0; - } else if (d->bd_immediate || d->bd_state == BPF_TIMED_OUT) - /* - * Immediate mode is set, or the read timeout has already - * expired during a select call. A packet arrived, so the - * reader should be woken up. - */ - do_wakeup = 1; + } else { + if (d->bd_immediate || d->bd_state == BPF_TIMED_OUT) { + /* + * Immediate mode is set, or the read timeout has + * already expired during a select call. A packet + * arrived, so the reader should be woken up. + */ + do_wakeup = 1; + } + pad = curlen - d->bd_slen; + KASSERT(pad >= 0 && pad <= sizeof(zeroes), + ("%s: invalid pad byte count %d", __func__, pad)); + if (pad > 0) { + /* Zero pad bytes. */ + bpf_append_bytes(d, d->bd_sbuf, d->bd_slen, zeroes, + pad); + } + } + caplen = totlen - hdrlen; tstype = d->bd_tstamp; do_timestamp = tstype != BPF_T_NONE;