From patchwork Wed Feb 26 01:36:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiayuan Chen X-Patchwork-Id: 13991381 X-Patchwork-Delegate: kuba@kernel.org Received: from out-173.mta0.migadu.com (out-173.mta0.migadu.com [91.218.175.173]) (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 3D991197556 for ; Wed, 26 Feb 2025 01:37:22 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=91.218.175.173 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740533845; cv=none; b=RYa/JftAYsdOdK2xaitYrEoSHdXunoTrLEjySnxyeckBPxTHKxpAGz2IUyKQqbxL1uN1DcI19PTBOWX6sD0aXYkYKJIhhks6la2GojLjK3T69abplNO+gCNHvZM/VOVz4SgfLV2XOc5Qg9gIFkOqL1TCW4pcQBtuSO4svDO+KyM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1740533845; c=relaxed/simple; bh=6jMqSHCB1b/d3tIPznfvnPv5y2TPzXfyEbziUHnLOwg=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=eNabKdTNoeQ+9YD5UaJ/P/Aos0duZiQJXcUpBp9lYBIItK3qWA1PtbKOtk+nvCXDclJcOqjt5hDgCYmfsOySZcxYLZeYbXEAAv1GNMCIdp1+6kdBe2Kj6R6AhtyO6/YnMSm1H1M+T9cOp5TM9kNJHXvLfpyV4fyvbIZXoYB6mEM= 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=kp7NLbUb; arc=none smtp.client-ip=91.218.175.173 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="kp7NLbUb" 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=1740533840; 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=c6lV2O/MV07x2xCD5gRyXKU/naKq49lc8wVecRpyzJY=; b=kp7NLbUbFkijnU8Nd3tRXnRzRt88xeE3r6qyYDNVsdcLu//PHlllllF9cw62u2LxU+5zBp ECjKglKSRLHKZdKCdpmRA7RKSee9ZF81DFTevlbWlk7M0DsneewFBlbRtrXhJhTBYJ1e9j Gyr3tKio/MAG0NQGh5i0tQCoI+cqNus= From: Jiayuan Chen To: horms@kernel.org, kuba@kernel.org Cc: bpf@vger.kernel.org, netdev@vger.kernel.org, andrew+netdev@lunn.ch, davem@davemloft.net, edumazet@google.com, pabeni@redhat.com, ricardo@marliere.net, 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, Jiayuan Chen , syzbot+853242d9c9917165d791@syzkaller.appspotmail.com Subject: [PATCH net-next v4 1/1] ppp: Fix KMSAN warning by initializing 2-byte header Date: Wed, 26 Feb 2025 09:36:58 +0800 Message-ID: <20250226013658.891214-2-jiayuan.chen@linux.dev> In-Reply-To: <20250226013658.891214-1-jiayuan.chen@linux.dev> References: <20250226013658.891214-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 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: 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 | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c index 4583e15ad03a..b4433badf03c 100644 --- a/drivers/net/ppp/ppp_generic.c +++ b/drivers/net/ppp/ppp_generic.c @@ -72,6 +72,10 @@ #define PPP_PROTO_LEN 2 #define PPP_LCP_HDRLEN 4 +/* These are fields recognized by libpcap */ +#define PPP_FILTER_OUTBOUND_TAG 0x0100 +#define PPP_FILTER_INBOUND_TAG 0x0000 + /* * An instance of /dev/ppp can be associated with either a ppp * interface unit or a ppp channel. In both cases, file->private_data @@ -1762,10 +1766,15 @@ 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. + */ + *(__be16 *)skb_push(skb, 2) = htons(PPP_FILTER_OUTBOUND_TAG); if (ppp->pass_filter && bpf_prog_run(ppp->pass_filter, skb) == 0) { if (ppp->debug & 1)