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
This commit is contained in:
parent
c88f6908b4
commit
60b4ad4b6b
@ -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),
|
void (*cpfn)(struct bpf_d *, caddr_t, u_int, void *, u_int),
|
||||||
struct bintime *bt)
|
struct bintime *bt)
|
||||||
{
|
{
|
||||||
|
static char zeroes[BPF_ALIGNMENT];
|
||||||
struct bpf_xhdr hdr;
|
struct bpf_xhdr hdr;
|
||||||
#ifndef BURN_BRIDGES
|
#ifndef BURN_BRIDGES
|
||||||
struct bpf_hdr hdr_old;
|
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;
|
struct bpf_hdr32 hdr32_old;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
int caplen, curlen, hdrlen, totlen;
|
int caplen, curlen, hdrlen, pad, totlen;
|
||||||
int do_wakeup = 0;
|
int do_wakeup = 0;
|
||||||
int do_timestamp;
|
int do_timestamp;
|
||||||
int tstype;
|
int tstype;
|
||||||
@ -2609,13 +2610,25 @@ catchpacket(struct bpf_d *d, u_char *pkt, u_int pktlen, u_int snaplen,
|
|||||||
ROTATE_BUFFERS(d);
|
ROTATE_BUFFERS(d);
|
||||||
do_wakeup = 1;
|
do_wakeup = 1;
|
||||||
curlen = 0;
|
curlen = 0;
|
||||||
} else if (d->bd_immediate || d->bd_state == BPF_TIMED_OUT)
|
} 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
|
* Immediate mode is set, or the read timeout has
|
||||||
* reader should be woken up.
|
* already expired during a select call. A packet
|
||||||
*/
|
* arrived, so the reader should be woken up.
|
||||||
do_wakeup = 1;
|
*/
|
||||||
|
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;
|
caplen = totlen - hdrlen;
|
||||||
tstype = d->bd_tstamp;
|
tstype = d->bd_tstamp;
|
||||||
do_timestamp = tstype != BPF_T_NONE;
|
do_timestamp = tstype != BPF_T_NONE;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user