From nobody Mon Jun 27 14:11:35 2022 X-Original-To: dev-commits-src-all@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 2926787E08E; Mon, 27 Jun 2022 14:11:36 +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 4LWqQw0gHtz3rdg; Mon, 27 Jun 2022 14:11:36 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656339096; 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=0Vpz2yWbnD0UVv24lIg53d1WsDha/UkPZQlx15sjuGE=; b=rwzpeVnP5l5I5Ae2ntyY5/pu9rNqQw+0DpWu/Hu63KY7na+m+spJ8dSngGG1O06tZdkHbA qYcwJTLQ2DuJXGllESnnbQWDlySSLwT+ublxORQiBXni/q3ZP0D0v8dfV4fSaGiUC2vFaO WzIZ1DOzbAgS9MScXURdCZD0SleetwVN0+YaDVu6+X8na0u7poQkCzBB2k4qScG4uAFbYJ XwogNzaU5MbDIV+LRcmq1uBPXHbg/MXY5TSPj3Rzowv4jIUVhHC8QORclkf8VteKSbRyll XkXqFZcPkVf2BS56B47SEokom8PNj6R4K4yMymg++aQBOfBlxNBRl7K6Zbzm/A== 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 EBA9D18B2; Mon, 27 Jun 2022 14:11:35 +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 25REBZ2s079136; Mon, 27 Jun 2022 14:11:35 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 25REBZH2079135; Mon, 27 Jun 2022 14:11:35 GMT (envelope-from git) Date: Mon, 27 Jun 2022 14:11:35 GMT Message-Id: <202206271411.25REBZH2079135@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mark Johnston Subject: git: 18c53b8dde2e - stable/13 - bpf: Zero pad bytes preceding BPF headers List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@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/stable/13 X-Git-Reftype: branch X-Git-Commit: 18c53b8dde2edbdc2da63e5895b85e1a84b6cdcb Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1656339096; 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=0Vpz2yWbnD0UVv24lIg53d1WsDha/UkPZQlx15sjuGE=; b=ClHG08cp2b1Hmd+NXSiknXVCURV7YZZ52P/Nv7o6GU+79kllqAYAv0wZmU6a/R/4mXVPDY e0vBuWRFYbZSO49VTZoFuiJK7wpxbKLAq8bwOIHbdIGhXP2kQVYw+JvBGgyaAFTkX6nFAI t3syA5AZP+p8/pBt1AVBqJ9QKmhWcc22xYMaAwFYjF8mdd3mtt/PKkN37aqrLYps7jAtwT 76d9hTLkQBB/SU51oLj/fLyk56oSkTQcEaBqZZcJTfPB/b4UDQuB+kJiJiSMkFnS4Bz9HF j4he4vta9bKznLGc3R9j/Q24cdbeaBqt0D+JYzVrBZAJqnPiS632QSL2xauYCw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1656339096; a=rsa-sha256; cv=none; b=cQM7xtoZvKwsIO+NGiu4T6E/gq+lhE8zW5DNa7AFU/YbZ9YDaZSBsiwGqRUMXHvy1PPAFe XvygC9wUBPoYy9zfgxeAO5UeDlJ0V6OIl6ktvIxAvXvpZQXVUNpdvheRcju2S4Wy7Bj6nE ToyTBCP545sPVeIP0aeYWjRq9mv4EUqMelMFEFua8+CRH5B9eCO9gSt4WpVRIyaH2hIxVW gsHW7zhx75oZWwdvRuMiSHG6jx3op8WGgs7WrwppBTRvYIErdUS9fAGxIWiQiDQ9hhMe3r dCwg1RiS2fTPMq5xp1uJzoesE0yIkTuuy90digxz45ttVxi3XJLp3LQsyy5gEw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by markj: URL: https://cgit.FreeBSD.org/src/commit/?id=18c53b8dde2edbdc2da63e5895b85e1a84b6cdcb commit 18c53b8dde2edbdc2da63e5895b85e1a84b6cdcb Author: Mark Johnston AuthorDate: 2022-06-20 16:03:37 +0000 Commit: Mark Johnston CommitDate: 2022-06-27 14:11:10 +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 Sponsored by: The FreeBSD Foundation (cherry picked from commit 60b4ad4b6b561ac2d9129a3576a74db3607ad90c) --- 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 6ae0699c949f..81d88305e1a1 100644 --- a/sys/net/bpf.c +++ b/sys/net/bpf.c @@ -2497,6 +2497,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; @@ -2504,7 +2505,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; @@ -2570,13 +2571,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;