From patchwork Fri Feb 21 06:12:19 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiayuan Chen X-Patchwork-Id: 13984857 X-Patchwork-Delegate: kuba@kernel.org Received: from out-176.mta1.migadu.com (out-176.mta1.migadu.com [95.215.58.176]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 04C911FC7C7 for ; Fri, 21 Feb 2025 06:12:45 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=95.215.58.176 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740118369; cv=none; b=I2NBSDQb9RpzNBoIXv4Ad1p5yNCDpuJL6VjqaioKC0Q1e4t9ytWoR/J8PQlc0vJoDj8og2kUKPr6H5U/9ishjYXX13x8Fd9gD6IPPZj/f39fEszwRhq3FDqLuUzPiN9TBYXsfERogxXHdCxkAfVmVZ9k4lbHs4rt85mGTZYKgQo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740118369; c=relaxed/simple; bh=BUrcvTp+Y3/YvlrmZlKJhjdFs5pFY7u9HZJVscHLqY0=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=Otiy9z+BcbFuzNjt9m5Hu9/30n9l2FMHVe74a+fjZSTt8AN5aJtNcEebEpKGKlwFzvtjB8djmZ1I6dP40p1W/lz9icKRjjFKfC1rjNruIAN0qPK0+CgUC4fCkqEV7VN4r3bbxhDzOFhtpb6paaIx48UALIEPLnQ5lNe0FmLxHG8= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev; spf=pass smtp.mailfrom=linux.dev; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b=IvHr7DYp; arc=none smtp.client-ip=95.215.58.176 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=linux.dev Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=linux.dev Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linux.dev header.i=@linux.dev header.b="IvHr7DYp" X-Report-Abuse: Please report any abuse attempt to abuse@migadu.com and include these headers. DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.dev; s=key1; t=1740118364; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=dTyRHMFg3xvOC3n3ff331CFtxOFXphnga1of86At6ZY=; b=IvHr7DYpZ1DpXah52GHF4TTh0dcXaByCPuACFWvTyC0RAVUtbfGAYysetEtYt2rl4ulrmO AVavo6qZO1OfGXNKt4P6rUO14za2+e6gvEbVe3Tf2YC4PUtpXNydbk+e+QGwzSCNfoHZ7X wgyXr5bo0ZPw2hRJbViS5qa38yqNOfE= From: Jiayuan Chen To: bpf@vger.kernel.org, netdev@vger.kernel.org Cc: andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, ricardo@marliere.net, jiayuan.chen@linux.dev, viro@zeniv.linux.org.uk, dmantipov@yandex.ru, aleksander.lobakin@intel.com, linux-ppp@vger.kernel.org, linux-kernel@vger.kernel.org, mrpre@163.com, syzbot+853242d9c9917165d791@syzkaller.appspotmail.com Subject: [PATCH net-next v2 1/1] ppp: Fix KMSAN warning by initializing 2-byte header Date: Fri, 21 Feb 2025 14:12:19 +0800 Message-ID: <20250221061219.295590-2-jiayuan.chen@linux.dev> In-Reply-To: <20250221061219.295590-1-jiayuan.chen@linux.dev> References: <20250221061219.295590-1-jiayuan.chen@linux.dev> Precedence: bulk X-Mailing-List: bpf@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 X-Migadu-Flow: FLOW_OUT X-Patchwork-Delegate: kuba@kernel.org The ppp program adds a 2-byte pseudo-header for socket filters, which is normally skipped by regular BPF programs generated by libpcap, causing no issues. However, for abnormal BPF programs that use these uninitialized 2 bytes, a KMSAN warning is triggered. Reported-by: syzbot+853242d9c9917165d791@syzkaller.appspotmail.com Closes: https://lore.kernel.org/bpf/000000000000dea025060d6bc3bc@google.com/ Signed-off-by: Jiayuan Chen --- drivers/net/ppp/ppp_generic.c | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c index 4583e15ad03a..ac95196c85df 100644 --- a/drivers/net/ppp/ppp_generic.c +++ b/drivers/net/ppp/ppp_generic.c @@ -1762,10 +1762,16 @@ 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. + * BPF filter instructions assume each PPP packet has a 4-byte + * header (e.g., those generated by libpcap), and then default + * to skipping the first 2 bytes at the beginning of the + * instruction. However, we still need to initialize these + * 2-byte new headers to prevent crafted BPF programs from + * reading them which would cause reading of uninitialized + * data. Here, we set the headers according to the RFC 1662. + */ + *(u16 *)skb_push(skb, 2) = htons(0xff03); if (ppp->pass_filter && bpf_prog_run(ppp->pass_filter, skb) == 0) { if (ppp->debug & 1)