[PATCH net-next v3 1/1] ppp: Fix KMSAN warning by initializing 2-byte header
Jiayuan Chen <[email protected]>
| Newsgroups | gmane.linux.ppp,gmane.linux.kernel.bpf,gmane.linux.network,gmane.linux.kernel |
|---|---|
| Message-ID | <[email protected]> |
The PPP driver adds an extra 2-byte header to enable socket filters to run correctly. However, the driver only initializes the first byte, which indicates the direction. For normal BPF programs, this is not a problem since they only read the first byte. Nevertheless, for carefully crafted BPF programs, if they read the second byte, this will trigger a KMSAN warning for reading uninitialized data. Reported-by: [email protected] Closes: https://lore.kernel.org/bpf/[email protected]/ Signed-off-by: Jiayuan Chen <[email protected]> --- drivers/net/ppp/ppp_generic.c | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c index 4583e15ad03a..29a7a21cb096 100644 --- a/drivers/net/ppp/ppp_generic.c +++ b/drivers/net/ppp/ppp_generic.c @@ -1762,10 +1762,17 @@ ppp_send_frame(struct ppp *ppp, struct sk_buff *skb) if (proto < 0x8000) { #ifdef CONFIG_PPP_FILTER - /* check if we should pass this packet */ - /* the filter instructions are constructed assuming - a four-byte PPP header on each packet */ - *(u8 *)skb_push(skb, 2) = 1; + /* Check if we should pass this packet. + * The filter instructions are constructed assuming + * a four-byte PPP header on each packet. The first byte + * indicates the direction, and the second byte is meaningless, + * but we still need to initialize it to prevent crafted BPF + * programs from reading them which would cause reading of + * uninitialized data. + */ + skb_push(skb, 2); + skb->data[0] = 1; + skb->data[1] = 0; if (ppp->pass_filter && bpf_prog_run(ppp->pass_filter, skb) == 0) { if (ppp->debug & 1) -- 2.47.1