From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mail-yx1-f42.google.com (mail-yx1-f42.google.com [74.125.224.42]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 7292F3EA979 for ; Wed, 5 Aug 2026 12:48:56 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=74.125.224.42 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785934139; cv=none; b=bRZLh+5ATCAx39zhHuW/GHhLhq76VFNhWlWDFqvTeoTePLT907zoGhmtzUTChkg8BnKD7qtgKTt2Qg3tUF52JPr7l3Y/9VjlJ6Nyopam2/oikCpalqbESZBwco0PItIU3+3vwIXcWU8ICXJzjLVpKjEAc2cmVySFxtPFdp9Qcsg= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1785934139; c=relaxed/simple; bh=kM470gmL33Iv9aSAOr0xztTIhSMUcmHJisJS6g9iA4U=; h=Date:From:To:Cc:Message-ID:In-Reply-To:References:Subject: Mime-Version:Content-Type; b=FVv89LAkeCvxFXZ6YZFcyy2RhxRGButxnDPKlgJRPmLi5OzQmnCv2SzupZBkEmXmgVwdbEjD4qWpAYaAsni39C0sdpu8LkOFClu+WH2Pyf6UeERJlWvIuhS35aLqNJqpsNS/0pQZzyEB11pXJ+Q6CkZsqKwIIVpygGVBY93ZYeE= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=RRAu6Hwo; arc=none smtp.client-ip=74.125.224.42 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="RRAu6Hwo" Received: by mail-yx1-f42.google.com with SMTP id 956f58d0204a3-6685001353fso988021d50.1 for ; Wed, 05 Aug 2026 05:48:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20251104; t=1785934135; x=1786538935; darn=vger.kernel.org; h=content-transfer-encoding:content-type:mime-version:subject :references:in-reply-to:message-id:cc:to:from:date:from:to:cc :subject:date:message-id:reply-to:content-type; bh=fDYKkUKm21fBzkrus0DJYqlBResm+tuLY/EKfmGA+zg=; b=RRAu6HwotnhvqoUKmpcIkvV2RNe+APHPyRiKn2RBRveD4A9gDrzbx6icfbxWHL2l0c JUzmK28yHo64ke7Hg7WON938v6kXsKctlWoc1TPkofPvjAODYSxcLeQe55/k4xnTyoiN 5EQ/NvD6kFvj5WJiPhe+JTs9sAIcI1zBPaLnPh84cClrKNsgy0tgrjFv9X399HYNHMnw BNvMBENt18VSJfIdhPBKzJKLFU3oOZx1dAeETBNzPy+G+/hGTgCc3fctFoA8Z7mlojl3 sVgUbNc+hnzJR2+y01MwI1+mVuu/IZLhMXa24P0c3An0zFlyYcifYS8UGg53YayK2wbW xmTg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20251104; t=1785934135; x=1786538935; h=content-transfer-encoding:content-type:mime-version:subject :references:in-reply-to:message-id:cc:to:from:date:x-gm-gg :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to :content-type; bh=fDYKkUKm21fBzkrus0DJYqlBResm+tuLY/EKfmGA+zg=; b=ZPTqD+XZGZFS3G8qQxlhs4YogUf3ylH1v7GSBEC3vRTrmG473TKgdlOBMH8Y9TKgzW EJalVn3ENCKKhLtFoEVdkgn5Gi+/NNJmCHc4BwqSs2MuQsUcxCq/5B71GxBD0Qfou4Zs 8HSuwvO3tCYplO6Y+twU5haB7kfXthgTL9DubR0Q5xxPBtHSgA5BboxBrS3XN022OLwp zsmxUudTHFiRX7H15sii89byak+Ojsu0vqlepO3UbvKB+9xwRkzkfNjYKSUl7iSFLZw7 amP8cAW4QyUh7VAp2jkDmELT5KJVGmjswpoSo9sAHheKOxFEtXXyRpSDtVaEWw5z8j/e yM6Q== X-Forwarded-Encrypted: i=1; AHgh+RrrLC730wFWOeqyIzXwNqCk4nVTChQAQAzv4m05Pmj7/kaxveWK/QM3HLNST8HcSRMI9+YRYR5aA4ysgjg=@vger.kernel.org X-Gm-Message-State: AOJu0YzJNMaYJP8l8oz+fyXHWMONzP3qAKtwivasm9j/viwYgWZLjgMN FJ500BKeP7WIg0lvWD5md9cY8Lqv3sPxmXPEGvKWTkLRHfd4zJ0JC3MK X-Gm-Gg: AR+sD11XHSlXh4coAw1wUhj8y9YegMLMT/OEmGaZFkkPyHetxnJCjtRTdazbOZw2xbd 4r1NF1gsc1kHYSONm062YpjjtiWKHxblyc9bNSCZ4I3WsTAKJg4oV/Ppg1TpstXYqMBjh0XEhRN Rrg0PKkppNQzbGytL7Cs1VV1JHo8FOj1RlRmG4VISEVSPbMntgtcTOT6gu1kBV0LXK5itmPUhRt ssWuuB8vV2Dfd4q0622lbAirh0cabM17Yo60/Rlw4zGv0dVWbw5MMHNf9wigazhr7HrfL167UE1 cWdUHDoOk4mGRpRMxUA6XAsaHuB/H+fiMPiT5GNbVqQPYv9ZNXRUbraewmSrlwg3IGXA6IgQvwM qvelJ+KKFstXmAGOnm6rVW2lGePyi9oCxev7ZLx+T7DHD69XRwNf2ohuH5SqExcPqEMQC9dJ699 SAhf3uD4AobT5JGXWCkkxgYvW2i3MvUJxnyd+EFSgXUd3uXtg7e4lAtKe7d2f/+61kYzJiXZk4J 3aYDFcReYmVSBWC8xF9I4vWFe2IeytCwVw7 X-Received: by 2002:a53:bf01:0:b0:669:8f5f:fec7 with SMTP id 956f58d0204a3-6699a8ca5a6mr2644538d50.16.1785934134658; Wed, 05 Aug 2026 05:48:54 -0700 (PDT) Received: from gmail.com (250.4.48.34.bc.googleusercontent.com. [34.48.4.250]) by smtp.gmail.com with ESMTPSA id 956f58d0204a3-669915f5a6asm2913336d50.12.2026.08.05.05.48.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 05 Aug 2026 05:48:53 -0700 (PDT) Date: Wed, 05 Aug 2026 08:48:53 -0400 From: Willem de Bruijn To: wei.fang@oss.nxp.com, willemdebruijn.kernel@gmail.com, davem@davemloft.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, horms@kernel.org, liuhangbin@gmail.com, mst@redhat.com, jasowangio@gmail.com, andrew+netdev@lunn.ch, ast@kernel.org, daniel@iogearbox.net, hawk@kernel.org, john.fastabend@gmail.com, sdf@fomichev.me Cc: wei.fang@nxp.com, imx@lists.linux.dev, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Message-ID: In-Reply-To: <20260805105314.3882595-3-wei.fang@oss.nxp.com> References: <20260805105314.3882595-1-wei.fang@oss.nxp.com> <20260805105314.3882595-3-wei.fang@oss.nxp.com> Subject: Re: [PATCH net 2/2] net: tap: fix skb->protocol not updated after VLAN network header adjustment Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit wei.fang@ wrote: > From: Wei Fang > > In tap_get_user_xdp(), when processing a VLAN-tagged frame, > skb_set_network_header() is called with the depth returned by > vlan_get_protocol_and_depth() to advance network_header past the VLAN > tag to the inner protocol header. However, skb->protocol was not updated > to reflect the inner EtherType, leaving it pointing to the outer VLAN > EtherType (e.g. ETH_P_8021Q). > > This mismatch has two consequences. First, skb_probe_transport_header() > is called after the VLAN adjustment with proto=ETH_P_8021Q but nhoff > already pointing past the VLAN tag to the inner header. The flow > dissector interprets the inner header bytes as a VLAN header, fails to > find a recognizable encapsulated protocol, and returns false. > Consequently, transport_header is never set and remains at its > uninitialized sentinel value (~0U), causing any subsequent > skb_transport_header() or udp_hdr() call to dereference a pointer > 65535 bytes past skb->head, potentially corrupting arbitrary kernel > memory. Second, TC egress and eBPF programs that inspect skb->protocol > directly (e.g. bpf_skb_net_base_len(), bpf_skb_net_grow(), > __bpf_redirect_neigh()) will see ETH_P_8021Q instead of the inner > protocol and behave incorrectly. > > Save the return value of vlan_get_protocol_and_depth(), which already > resolves the inner EtherType, and assign it to skb->protocol after > skb_set_network_header(). This keeps skb->protocol and network_header > consistent for all subsequent processing. > > Fixes: 8c76e77f9069 ("tap: call skb_probe_transport_header after setting skb->dev") > Assisted-by: WChat:claude-opus-4-8 > Signed-off-by: Wei Fang > --- > drivers/net/tap.c | 12 +++++++++--- > 1 file changed, 9 insertions(+), 3 deletions(-) > > diff --git a/drivers/net/tap.c b/drivers/net/tap.c > index fae115915c8e..afcc4919bd04 100644 > --- a/drivers/net/tap.c > +++ b/drivers/net/tap.c > @@ -1081,9 +1081,15 @@ static int tap_get_user_xdp(struct tap_queue *q, struct xdp_buff *xdp) > } > > /* Move network header to the right position for VLAN tagged packets */ > - if (eth_type_vlan(skb->protocol) && > - vlan_get_protocol_and_depth(skb, skb->protocol, &depth) != 0) > - skb_set_network_header(skb, depth); > + if (eth_type_vlan(skb->protocol)) { > + __be16 proto = vlan_get_protocol_and_depth(skb, skb->protocol, > + &depth); > + > + if (proto != 0) { > + skb_set_network_header(skb, depth); > + skb->protocol = proto; > + } > + } Does the same apply to the same call in tap_get_user? And in general to other callers of vlan_get_protocol_and_depth, including through wrapper skb_network_protocol? > > rcu_read_lock(); > tap = rcu_dereference(q->tap); > -- > 2.34.1 >