net: fix eth_type_trans() crashes on skbs coming from the stack
Subsystems (9)
Eric Dumazet
maintainerv2 cover net: fix eth_type_trans() crashes on skbs coming from the stack
eth_type_trans() assumes ETH_HLEN bytes are present in skb->head. NIC drivers always provide this, and they should keep using the fast version, without an extra pskb_may_pull().
Devices looping skbs from their transmit path back to their receive path get skbs built by the stack instead. tc actions (act_vlan pop_eth, act_ife decode), BPF helpers (bpf_skb_change_head() before a redirect) or OVS actions (pop_eth followed by pop_mpls/pop_nsh) can leave fewer than ETH_HLEN bytes in the linear part, and eth_type_trans() then hits the BUG() in __skb_pull().
Instead of fixing every producer, or adding a check to all eth_type_trans() users, fix the few consumers exposed to this:
- Patch 1 adds eth_type_trans_careful(), which pulls the Ethernet header first and returns a drop reason on failure.
- Patch 2 uses it in loopback_xmit().
- Patch 3 uses it in __dev_forward_skb2(), used by BPF redirects to ingress and by veth, macvlan, ipvlan, netdevsim and l2tp_eth.
- Patch 4 uses it in OVS internal_dev_recv(), covering both the MPLS (TEB) and NSH pop cases at once (only the MPLS case was tested).
- Patch 5 (from Jamal) fixes act_ife decode on egress, which was consuming the inner Ethernet header. This is no longer a crash after patch 2, but egress decode never delivered a correct frame.
Other eth_type_trans() users already pull the header or never see such skbs:
- vrf_process_v{4,6}_outbound() already pull ETH_HLEN + IP header before vrf_local_xmit().
- tun already uses pskb_may_pull_reason(skb, ETH_HLEN).
- XDP: bpf_xdp_adjust_head() and bpf_xdp_adjust_tail() keep at least ETH_HLEN bytes in the linear part, and multi-buffer tail shrinking only trims frags.
Tested under virtme-ng with AF_PACKET reproducers. Without the series, all four cases crash in eth_type_trans():
- lo egress "action vlan pop_eth", eth/eth/8192 bytes frame
- lo egress "action ife decode pipe", IFE frame with 8192 bytes payload
- lo egress "action vlan pop_eth continue", then a BPF program doing bpf_skb_change_head(skb, 1, 0) + bpf_redirect(veth1, BPF_F_INGRESS)
- OVS flow "pop_eth,pop_mpls(0x6558),0" to the internal port, eth/mpls/eth/4096 bytes frame
With the series, no crash. An ICMP echo inside an IFE frame decoded on lo egress is now received and answered. Normal traffic on lo, veth (including 8000 byte pings) and vrf is unchanged.
v2:
- Patch 3: update the empty_skb BPF selftest. At lwt_xmit, its "veth ETH_HLEN+1" packet is a 1-byte skb, which is now dropped on veth ingress, as veth_xmit() already does on egress (BPF CI).
- Rebased on latest net, collected tags from Aaron, Willem and Jamal.
- No kernel code change.
v1: https://lore.kernel.org/netdev/[email protected]/
Eric Dumazet (4):
net: add eth_type_trans_careful()
loopback: use eth_type_trans_careful()
net: use eth_type_trans_careful() in __dev_forward_skb2()
openvswitch: use eth_type_trans_careful() in internal_dev_recv()
Jamal Hadi Salim (1):
net/sched: act_ife: do not consume the inner header on egress
drivers/net/loopback.c | 8 +++++- include/linux/etherdevice.h | 28 +++++++++++++++++++ net/core/dev.c | 18 ++++++++---- net/openvswitch/vport-internal_dev.c | 8 +++++- net/sched/act_ife.c | 4 +++ .../selftests/bpf/prog_tests/empty_skb.c | 19 ++++++++----- 6 files changed, 71 insertions(+), 14 deletions(-)
Signature · 1 line
2.53.0
Eric Dumazet
maintainerPATCH v2 1/5 net: add eth_type_trans_careful()
eth_type_trans() assumes ETH_HLEN bytes are present in skb->head. NIC drivers always provide this, and they should keep using the fast version.
Devices looping skbs from their transmit path back to their receive path get skbs built by the stack instead. Their link-layer header might have been popped by tc actions (act_vlan pop_eth, act_ife decode) or OVS actions (pop_eth + pop_mpls / pop_nsh), leaving fewer than ETH_HLEN bytes in the linear part. eth_type_trans() then hits the BUG() in __skb_pull().
Add eth_type_trans_careful(), which first pulls the Ethernet header, and returns a drop reason on failure, so that the few devices exposed to this can drop such packets.
--- include/linux/etherdevice.h | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+)
include/linux/etherdevice.h +28 -0
@@ -38,6 +38,34 @@ int fwnode_get_mac_address(struct fwnode_handle *fwnode, char *addr);u32 eth_get_headlen (const struct net_device *dev,const void *data,u32 len);__be16 eth_type_trans (struct sk_buff *skb,struct net_device *dev); + +/** +* eth_type_trans_careful - eth_type_trans() for skbs coming from the stack +* @skb: buffer, possibly with less than ETH_HLEN bytes in its linear area +* @dev: receiving network device +* +* eth_type_trans() expects ETH_HLEN bytes in skb->head, which NIC drivers +* provide. Devices looping skbs from their transmit path back to the +* receive path (loopback, OVS internal ports) get skbs built by the stack, +* whose link-layer header might have been popped by tc or OVS actions. +* +* Sets skb->protocol on success. +* +* Return: SKB_NOT_DROPPED_YET on success, or a drop reason. In the latter +* case, the caller must free @skb. +*/ +static inline enum skb_drop_reason +eth_type_trans_careful (struct sk_buff *skb,struct net_device *dev) +{ +enum skb_drop_reason reason =pskb_may_pull_reason (skb,ETH_HLEN ); + +if (unlikely (reason)) +return reason; + + skb->protocol =eth_type_trans (skb, dev); +return SKB_NOT_DROPPED_YET ; +} +extern const struct header_ops eth_header_ops; int eth_header(struct sk_buff *skb, struct net_device *dev, unsigned short type,
Signature · 1 line
2.53.0
Eric Dumazet
maintainerPATCH v2 2/5 loopback: use eth_type_trans_careful()
In reply to Eric Dumazettc egress actions can leave an skb with fewer than ETH_HLEN bytes in its linear part. loopback_xmit() then crashes in eth_type_trans():
tc qdisc add dev lo clsact
tc filter add dev lo egress matchall action vlan pop_eth # AF_PACKET SOCK_RAW: eth / eth / 8192 bytes of payload
kernel BUG at include/linux/skbuff.h:2839!
RIP: 0010:eth_type_trans (include/linux/etherdevice.h:635 net/ethernet/eth.c:163) Call Trace: loopback_xmit (drivers/net/loopback.c:87) dev_hard_start_xmit (include/linux/netdevice.h:5455 include/linux/netdevice.h:5464 net/core/dev.c:4057 net/core/dev.c:4073) __dev_queue_xmit (net/core/dev.c:5066) packet_sendmsg (net/packet/af_packet.c:3157 net/packet/af_packet.c:3189)
The same happens with "action ife decode" on lo egress.
Use eth_type_trans_careful(), and drop the packet if the Ethernet header can not be pulled.
--- drivers/net/loopback.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
drivers/net/loopback.c +7 -1
@@ -70,6 +70,7 @@ EXPORT_SYMBOL(blackhole_netdev);static netdev_tx_t loopback_xmit (struct sk_buff *skb,struct net_device *dev) { +enum skb_drop_reason reason;int len;skb_tx_timestamp (skb);
@@ -84,7 +85,12 @@ static netdev_tx_t loopback_xmit(struct sk_buff *skb,*/ skb_dst_force (skb); - skb->protocol =eth_type_trans (skb, dev); + reason =eth_type_trans_careful (skb, dev); +if (unlikely (reason)) { +dev_core_stats_tx_dropped_inc (dev); +kfree_skb_reason (skb, reason); +return NETDEV_TX_OK ; + } len = skb->len;if (likely (__netif_rx (skb) ==NET_RX_SUCCESS ))
Signature · 1 line
2.53.0
Re: [PATCH net v2 2/5] loopback: use eth_type_trans_careful()
Quoted 20 lines · Eric Dumazet
tc egress actions can leave an skb with fewer than
ETH_HLENbytes in its linear part.loopback_xmit()then crashes ineth_type_trans():tc qdisc add dev lo clsact
tc filter add dev lo egress matchall action vlanpop_eth#AF_PACKETSOCK_RAW: eth / eth / 8192 bytes of payloadkernel BUG at
include/linux/skbuff.h:2839!RIP: 0010:eth_type_trans (include/linux/etherdevice.h:635 net/ethernet/eth.c:163) Call Trace: loopback_xmit (drivers/net/loopback.c:87) dev_hard_start_xmit (include/linux/netdevice.h:5455 include/linux/netdevice.h:5464 net/core/dev.c:4057 net/core/dev.c:4073) __dev_queue_xmit (net/core/dev.c:5066) packet_sendmsg (net/packet/af_packet.c:3157 net/packet/af_packet.c:3189)The same happens with "action ife decode" on lo egress.
Use
eth_type_trans_careful(), and drop the packet if the Ethernet header can not be pulled.
Quoted 6 lines
Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Reported-by Vega <[email protected]>Signed-off-by Eric Dumazet <[email protected]>Reviewed-by Jamal Hadi Salim <[email protected]>Tested-by Jamal Hadi Salim <[email protected]>
Eric Dumazet
maintainerPATCH v2 3/5 net: use eth_type_trans_careful() in __dev_forward_skb2()
In reply to Eric DumazetA tc egress BPF program can push a tiny link-layer header with bpf_skb_change_head() on an skb whose head is almost empty, then redirect it to an Ethernet device ingress. __bpf_redirect_common() only checks mac_header < network_header, and __dev_forward_skb2() crashes in eth_type_trans():
tc filter add dev lo egress pref 1 matchall action vlan pop_eth continue tc filter add dev lo egress pref 2 bpf da obj prog.o
# prog: bpf_skb_change_head(skb, 1, 0);
# return bpf_redirect(veth1_ifindex, BPF_F_INGRESS);
# AF_PACKET SOCK_RAW on lo: eth / eth / 8192 bytes of payload
kernel BUG at include/linux/skbuff.h:2839!
RIP: 0010:eth_type_trans (include/linux/etherdevice.h:635 net/ethernet/eth.c:163) Call Trace: __dev_forward_skb2 (net/core/dev.c:2507) dev_forward_skb_nomtu (net/core/dev.c:2546) __dev_queue_xmit (net/core/dev.c:4738 net/core/dev.c:4998) packet_sendmsg (net/packet/af_packet.c:3157 net/packet/af_packet.c:3189)
Use eth_type_trans_careful(), and drop the packet if the Ethernet header can not be pulled. This also covers other dev_forward_skb() users (veth, macvlan, ipvlan, netdevsim, l2tp_eth).
Update the empty_skb BPF selftest: at lwt_xmit, BPF_PROG_TEST_RUN strips the Ethernet header, so the "veth ETH_HLEN+1" packet is a 1-byte skb. Redirecting it to veth ingress used to read the Ethernet header past skb->tail and deliver a 1-byte frame; it is now dropped with NET_RX_DROP, as veth_xmit() already does at egress.
--- net/core/dev.c | 18 +++++++++++++----- .../selftests/bpf/prog_tests/empty_skb.c | 19 ++++++++++++------- 2 files changed, 25 insertions(+), 12 deletions(-)
net/core/dev.c +13 -5
@@ -2501,14 +2501,22 @@ EXPORT_SYMBOL_GPL(is_skb_forwardable);static int __dev_forward_skb2 (struct net_device *dev,struct sk_buff *skb,bool check_mtu) { -int ret =____dev_forward_skb (dev, skb, check_mtu); +enum skb_drop_reason reason; +int ret; + + ret =____dev_forward_skb (dev, skb, check_mtu); +if (unlikely (ret)) +return ret; -if (likely (!ret)) { - skb->protocol =eth_type_trans (skb, dev); -skb_postpull_rcsum (skb,eth_hdr (skb),ETH_HLEN ); + reason =eth_type_trans_careful (skb, dev); +if (unlikely (reason)) { +dev_core_stats_rx_dropped_inc (dev); +kfree_skb_reason (skb, reason); +return NET_RX_DROP ; } +skb_postpull_rcsum (skb,eth_hdr (skb),ETH_HLEN ); -return ret; +return 0 ; }int __dev_forward_skb (struct net_device *dev,struct sk_buff *skb)
tools/testing/selftests/bpf/prog_tests/empty_skb.c +12 -7
@@ -24,7 +24,7 @@ void test_empty_skb(void)int *ifindex;int err;int ret; -int lwt_egress_ret;/* expected retval at lwt/egress */ +int lwt_ret;/* expected retval at lwt */ __be16 h_proto;bool success_on_tc;bool adjust_room;
@@ -82,7 +82,7 @@ void test_empty_skb(void) .data_size_in = sizeof(eth_hlen), .ifindex = &veth_ifindex, .ret = -ERANGE, - .lwt_egress_ret = -ERANGE, + .lwt_ret = -ERANGE, .success_on_tc = true, }, {
@@ -96,17 +96,23 @@ void test_empty_skb(void) .data_size_in = sizeof(eth_hlen), .ifindex = &ipip_ifindex, .ret = -ERANGE, - .lwt_egress_ret = -ERANGE, + .lwt_ret = -ERANGE, }, -/* ETH_HLEN+1-sized packet should be redirected. */ +/* ETH_HLEN+1-sized packet should be redirected at TC. +* At LWT, the Ethernet header is not part of the skb, and +* a 1-byte packet is too short for an Ethernet device. +*/ { .msg = "veth ETH_HLEN+1 packet ingress", .data_in = eth_hlen_pp, .data_size_in = sizeof(eth_hlen_pp), .ifindex = &veth_ifindex, - .lwt_egress_ret = 1, /* veth_xmit NET_XMIT_DROP */ +/* lwt: skb->len=1, dropped by veth_xmit() at egress +* and by __dev_forward_skb2() at ingress. +*/ + .lwt_ret =1 ,/* NET_XMIT_DROP / NET_RX_DROP */ }, { .msg = "ipip ETH_HLEN+1 packet ingress",
@@ -144,7 +150,6 @@ void test_empty_skb(void) eth_hlen.h_proto = tests[i].h_proto;bpf_object__for_each_program (prog, bpf_obj->obj) { -bool at_egress =strstr (bpf_program__name (prog),"egress" ) !=NULL ;bool at_tc = !strncmp (bpf_program__section_name (prog),"tc" ,2 );bool is_adjust_room = !strcmp (bpf_program__name (prog),"tc_adjust_room" );int expected_ret;
@@ -153,7 +158,7 @@ void test_empty_skb(void)if (tests[i].adjust_room != is_adjust_room)continue ; - expected_ret = at_egress && !at_tc ? tests[i].lwt_egress_ret : tests[i].ret; + expected_ret = at_tc ? tests[i].ret : tests[i].lwt_ret; tattr.data_in = tests[i].data_in; tattr.data_size_in = tests[i].data_size_in;
Signature · 1 line
2.53.0
Re: [PATCH net v2 3/5] net: use eth_type_trans_careful() in __dev_forward_skb2()
Quoted 30 lines · Eric Dumazet
A tc egress BPF program can push a tiny link-layer header with
bpf_skb_change_head()on an skb whose head is almost empty, then redirect it to an Ethernet device ingress.__bpf_redirect_common()only checksmac_header<network_header, and__dev_forward_skb2()crashes ineth_type_trans():tc filter add dev lo egress pref 1 matchall action vlan
pop_ethcontinue tc filter add dev lo egress pref 2 bpf da obj prog.o
# prog:bpf_skb_change_head(skb, 1, 0);
# returnbpf_redirect(veth1_ifindex, BPF_F_INGRESS);
#AF_PACKETSOCK_RAWon lo: eth / eth / 8192 bytes of payloadkernel BUG at
include/linux/skbuff.h:2839!RIP: 0010:eth_type_trans (include/linux/etherdevice.h:635 net/ethernet/eth.c:163) Call Trace: __dev_forward_skb2 (net/core/dev.c:2507) dev_forward_skb_nomtu (net/core/dev.c:2546) __dev_queue_xmit (net/core/dev.c:4738 net/core/dev.c:4998) packet_sendmsg (net/packet/af_packet.c:3157 net/packet/af_packet.c:3189)Use
eth_type_trans_careful(), and drop the packet if the Ethernet header can not be pulled. This also covers otherdev_forward_skb()users (veth, macvlan, ipvlan, netdevsim,l2tp_eth).Update the
empty_skbBPF selftest: atlwt_xmit,BPF_PROG_TEST_RUNstrips the Ethernet header, so the "veth ETH_HLEN+1" packet is a 1-byte skb. Redirecting it to veth ingress used to read the Ethernet header pastskb->tailand deliver a 1-byte frame; it is now dropped withNET_RX_DROP, asveth_xmit()already does at egress.
Quoted 4 lines
Fixes 3a0af8fd61f9 ("bpf: BPF for lightweight tunnel infrastructure")Signed-off-by Eric Dumazet <[email protected]>Reviewed-by Jamal Hadi Salim <[email protected]>Tested-by Jamal Hadi Salim <[email protected]>
Eric Dumazet
maintainerPATCH v2 4/5 openvswitch: use eth_type_trans_careful() in internal_dev_recv()
In reply to Eric DumazetOVS actions like pop_eth followed by pop_mpls(ETH_P_TEB) or pop_nsh can expose an inner Ethernet header which is not in the linear part of the skb. Output to an internal port then crashes in eth_type_trans():
flow: in_port(0),eth(),eth_type(0x8847),mpls(lse=0x00010140)
actions: pop_eth,pop_mpls(0x6558),0
# AF_PACKET SOCK_RAW on dp0: eth / mpls / eth / 4096 bytes of payload
kernel BUG at include/linux/skbuff.h:2839!
RIP: 0010:eth_type_trans (include/linux/etherdevice.h:635 net/ethernet/eth.c:163) Call Trace: internal_dev_recv (net/openvswitch/vport-internal_dev.c:202) openvswitch do_execute_actions (net/openvswitch/actions.c:1296) openvswitch ovs_execute_actions (net/openvswitch/actions.c:1606) openvswitch ovs_dp_process_packet (net/openvswitch/datapath.c:310) openvswitch ovs_vport_receive (net/openvswitch/vport.c:448) openvswitch internal_dev_xmit (net/openvswitch/vport-internal_dev.c:42) openvswitch dev_hard_start_xmit (include/linux/netdevice.h:5455 include/linux/netdevice.h:5464 net/core/dev.c:4057 net/core/dev.c:4073) __dev_queue_xmit (net/core/dev.c:5066) packet_sendmsg (net/packet/af_packet.c:3157 net/packet/af_packet.c:3189)
Use eth_type_trans_careful(), and drop the packet if the Ethernet header can not be pulled. This covers all OVS actions at the consumer, instead of fixing each producer.
--- net/openvswitch/vport-internal_dev.c | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-)
net/openvswitch/vport-internal_dev.c +7 -1
@@ -188,6 +188,7 @@ static void internal_dev_destroy(struct vport *vport)static int internal_dev_recv (struct sk_buff *skb) {struct net_device *netdev = skb->dev; +enum skb_drop_reason reason;if (unlikely (!(netdev->flags &IFF_UP ))) {kfree_skb (skb);
@@ -199,7 +200,12 @@ static int internal_dev_recv(struct sk_buff *skb)nf_reset_ct (skb); skb->pkt_type =PACKET_HOST ; - skb->protocol =eth_type_trans (skb, netdev); + reason =eth_type_trans_careful (skb, netdev); +if (unlikely (reason)) { +dev_core_stats_rx_dropped_inc (netdev); +kfree_skb_reason (skb, reason); +return NETDEV_TX_OK ; + }skb_postpull_rcsum (skb,eth_hdr (skb),ETH_HLEN );dev_sw_netstats_rx_add (netdev, skb->len);
Signature · 1 line
2.53.0
Re: [PATCH net v2 4/5] openvswitch: use eth_type_trans_careful() in internal_dev_recv()
Quoted 25 lines · Eric Dumazet
OVS actions like
pop_ethfollowed bypop_mpls(ETH_P_TEB)orpop_nshcan expose an inner Ethernet header which is not in the linear part of the skb. Output to an internal port then crashes ineth_type_trans():flow: in_port(0),eth(),eth_type(0x8847),mpls(lse=0x00010140)
actions: pop_eth,pop_mpls(0x6558),0
#AF_PACKETSOCK_RAWon dp0: eth / mpls / eth / 4096 bytes of payloadkernel BUG at
include/linux/skbuff.h:2839!RIP: 0010:eth_type_trans (include/linux/etherdevice.h:635 net/ethernet/eth.c:163) Call Trace: internal_dev_recv (net/openvswitch/vport-internal_dev.c:202) openvswitch do_execute_actions (net/openvswitch/actions.c:1296) openvswitch ovs_execute_actions (net/openvswitch/actions.c:1606) openvswitch ovs_dp_process_packet (net/openvswitch/datapath.c:310) openvswitch ovs_vport_receive (net/openvswitch/vport.c:448) openvswitch internal_dev_xmit (net/openvswitch/vport-internal_dev.c:42) openvswitch dev_hard_start_xmit (include/linux/netdevice.h:5455 include/linux/netdevice.h:5464 net/core/dev.c:4057 net/core/dev.c:4073) __dev_queue_xmit (net/core/dev.c:5066) packet_sendmsg (net/packet/af_packet.c:3157 net/packet/af_packet.c:3189)Use
eth_type_trans_careful(), and drop the packet if the Ethernet header can not be pulled. This covers all OVS actions at the consumer, instead of fixing each producer.
Quoted 6 lines
Fixes b2d0f5d5dc53 ("openvswitch: enable NSH support")Fixes f66b53fdbb22 ("openvswitch: New MPLS actions for layer 2 tunnelling")Signed-off-by Eric Dumazet <[email protected]>Reviewed-by Aaron Conole <[email protected]>Reviewed-by Jamal Hadi Salim <[email protected]>Tested-by Jamal Hadi Salim <[email protected]>
Eric Dumazet
maintainerPATCH v2 5/5 net/sched: act_ife: do not consume the inner header on egress
In reply to Eric DumazetFrom: Jamal Hadi Salim <[email protected]>
The issue:tcf_ife_decode() unconditionally calls eth_type_trans(), which pulls ETH_HLEN. On egress this consumes the inner Ethernet header, and the device receives an skb whose data points to the L3 header:
- loopback_xmit() parses L3 data as Ethernet: the "ethertype" comes from the inner IPv4 source address, and the decapsulated packet is dropped or misparsed.
- a real NIC transmits the frame without its Ethernet header.
(The __skb_pull() BUG this used to trigger in loopback_xmit() when the remaining linear area was short is handled by "loopback: use eth_type_trans_careful()".)
The Fix:
Parse the inner Ethernet header with eth_type_trans() in both directions, then restore the egress data position and MAC length. On ingress the existing behavior is unchanged. On egress, push the inner Ethernet header back after parsing so the xmit path sees the original frame and later actions see a consistent network header.
Conditions to recreate the bug:
- egress tc filter on lo: action ife decode pipe;
- AF_PACKET SOCK_RAW frame: outer Ethernet with ETH_P_IFE, IFE metadata, inner Ethernet + a valid IPv4 ICMP echo request to a local address;
- before this patch, no echo is received; after it, the echo is delivered and answered.
--- net/sched/act_ife.c | 4 ++++ 1 file changed, 4 insertions(+)
net/sched/act_ife.c +4 -0
@@ -769,6 +769,10 @@ static int tcf_ife_decode(struct sk_buff *skb, const struct tc_action *a, skb->protocol =eth_type_trans (skb, skb->dev);skb_reset_network_header (skb); +if (!skb_at_tc_ingress (skb)) { +skb_push (skb,ETH_HLEN ); +skb_reset_mac_len (skb); + }return action; }
Signature · 1 line
2.53.0
Quoted 2 lines · Eric Dumazet
Other
eth_type_trans()users already pull the header or never see such skbs:
netkit_xmit() has the same problem, I think.
It calls eth_skb_pull_mac() directly, not eth_type_trans(). It pulls ETH_HLEN before netkit_run(). The prog can shrink the linear part after that:
AF_PACKET SOCK_RAW on nk0 eth (ETH_P_IP) / eth / 8192 bytes
tc egress on nk0
vlan pop_eth skb_headlen() == 0
skb_mac_header_len() == 0
netkit_xmit()
pskb_may_pull(skb, ETH_HLEN) skb_headlen() == 14
netkit_run()
bpf_skb_adjust_room(skb, -1, BPF_ADJ_ROOM_MAC, 0)
bpf_skb_generic_pop() off == 0, skb_headlen() == 13
eth_skb_pull_mac() BUG() in __skb_pull()It's an old bug and it doesn't block this series. It can be a follow up.
Something like this (compile tested only):
drivers/net/netkit.c +3 -0
@@ -116,6 +116,9 @@ static netdev_tx_t netkit_xmit(struct sk_buff *skb, struct net_device *dev)switch (ret) {case NETKIT_NEXT :case NETKIT_PASS : +/* The prog may have shrunk the linear part */ +if (unlikely (!pskb_may_pull (skb,ETH_HLEN ))) + goto drop;eth_skb_pull_mac (skb);skb_postpull_rcsum (skb,eth_hdr (skb),ETH_HLEN );if (likely (__netif_rx (skb) ==NET_RX_SUCCESS )) {
For the series:
Daniel Borkmann
maintainerQuoted 30 lines · Alexei Starovoitov
Quoted 2 lines · Eric Dumazet
Other
eth_type_trans()users already pull the header or never see such skbs:
netkit_xmit()has the same problem, I think.
It callseth_skb_pull_mac()directly, noteth_type_trans(). It pullsETH_HLENbeforenetkit_run(). The prog can shrink the linear part after that:AF_PACKET SOCK_RAW on nk0 eth (ETH_P_IP) / eth / 8192 bytes tc egress on nk0 vlan pop_eth skb_headlen() == 0 skb_mac_header_len() == 0 netkit_xmit() pskb_may_pull(skb, ETH_HLEN) skb_headlen() == 14 netkit_run() bpf_skb_adjust_room(skb, -1, BPF_ADJ_ROOM_MAC, 0) bpf_skb_generic_pop() off == 0, skb_headlen() == 13 eth_skb_pull_mac() BUG() in __skb_pull()It's an old bug and it doesn't block this series. It can be a follow up.
Something like this (compile tested only):
drivers/net/netkit.c +0
-0
drivers/net/netkit.c static netdev_tx_t netkit_xmit(struct sk_buff *skb, struct net_device *dev) · line 124
Quoted 9 lines
drivers/net/netkit.c +3
-0@@ -116,6 +116,9 @@ static netdev_tx_t netkit_xmit(struct sk_buff *skb, struct net_device *dev)switch (ret) {case NETKIT_NEXT :case NETKIT_PASS : +/* The prog may have shrunk the linear part */ +if (unlikely (!pskb_may_pull (skb,ETH_HLEN ))) + goto drop;eth_skb_pull_mac (skb);skb_postpull_rcsum (skb,eth_hdr (skb),ETH_HLEN );if (likely (__netif_rx (skb) ==NET_RX_SUCCESS )) {
Reproduced locally with a BPF selftest, and that fixes it. Feel free to add my Acked-by.
Thanks,
Daniel
This series was applied to netdev/net.git (main) by Jakub Kicinski <[email protected]>:
Hello:
This series was applied to netdev/net.git (main)
by Jakub Kicinski <[email protected]>:
Quoted 4 lines · On Wed, 28 Oct 2026 13:26:58 +0100 you wrote:
eth_type_trans()assumesETH_HLENbytes are present inskb->head. NIC drivers always provide this, and they should keep using the fast version, without an extrapskb_may_pull().
Quoted 8 lines
Devices looping skbs from their transmit path back to their receive path get skbs built by the stack instead. tc actions (
act_vlanpop_eth,act_ifedecode), BPF helpers (bpf_skb_change_head()before a redirect) or OVS actions (pop_ethfollowed by pop_mpls/pop_nsh) can leave fewer thanETH_HLENbytes in the linear part, andeth_type_trans()then hits theBUG()in__skb_pull().[...]
Here is the summary with links:
- [net,v2,1/5] net: add eth_type_trans_careful()
https://git.kernel.org/netdev/net/c/2519a6fe7a8b - [net,v2,2/5] loopback: use eth_type_trans_careful() https://git.kernel.org/netdev/net/c/093a28998374 - [net,v2,3/5] net: use eth_type_trans_careful() in __dev_forward_skb2() https://git.kernel.org/netdev/net/c/695e1408eb90 - [net,v2,4/5] openvswitch: use eth_type_trans_careful() in internal_dev_recv() https://git.kernel.org/netdev/net/c/b55e5a0159c8 - [net,v2,5/5] net/sched: act_ife: do not consume the inner header on egress https://git.kernel.org/netdev/net/c/498c631f9c6d
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html