vlan: ensure sufficient headroom in vlan_dev_hard_header()
Subsystems (5)
v2 cover vlan: ensure sufficient headroom in vlan_dev_hard_header()
Callers that only reserve ETH_HLEN or less, or skbs allocated before dynamic device/headroom changes (such as toggling VLAN_FLAG_REORDER_HDR or bonding/team switching slaves), can reach vlan_dev_hard_header() with insufficient headroom and trigger skb_under_panic().
When vlan_dev_hard_header() returns -ENOMEM upon skb_cow_head() failure, a few callers of dev_hard_header() / llc_mac_hdr_init() had pre-existing error-handling bugs:
- Patch 1 fixes a UAF/double-free of skb and leak of nskb in llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(), as well as nskb leaks in llc_sap_action_send_xid_r() and llc_sap_action_send_test_r() when llc_mac_hdr_init() fails.
- Patch 2 checks the return value of llc_mac_hdr_init() in br_send_bpdu() and frees the skb on error.
- Patch 3 removes a shadowed 'int err;' variable in __teql_resolve() so negative errors from dev_hard_header() are properly returned as -EINVAL.
- Patch 4 uses skb_cow_head() in vlan_dev_hard_header() when VLAN_FLAG_REORDER_HDR is not set to ensure sufficient headroom for the VLAN header(s) and the underlying device hard header.
v2:
- Add patches 1-3 to fix pre-existing error handling in llc, bridge, and sch_teql when dev_hard_header() fails (Sashiko).
- Use READ_ONCE() when reading dev->hard_header_len and dev->needed_headroom in vlan_dev_hard_header(), and explain why LL_RESERVED_SPACE(dev) is not used here (Hangbin Liu, Sashiko).
- Link to v1: https://lore.kernel.org/netdev/[email protected]/
Eric Dumazet (4):
llc: fix skb UAF and leaks on llc_mac_hdr_init() failure
bridge: check llc_mac_hdr_init() return value in br_send_bpdu() net/sched: sch_teql: fix shadowed err in __teql_resolve()
vlan: ensure sufficient headroom in vlan_dev_hard_header()
net/8021q/vlan_dev.c | 5 +++++ net/bridge/br_stp_bpdu.c | 5 ++++- net/llc/llc_c_ac.c | 2 +- net/llc/llc_s_ac.c | 4 ++++ net/sched/sch_teql.c | 7 ++----- 5 files changed, 16 insertions(+), 7 deletions(-)
Signature · 1 line
2.56.0.rc1.310.g51773c2048-goog
PATCH v2 1/4 llc: fix skb UAF and leaks on llc_mac_hdr_init() failure
In llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(), if llc_mac_hdr_init() fails, kfree_skb(skb) is called instead of kfree_skb(nskb). This leaks the newly allocated nskb, reads from the freed skb via LLC_I_GET_NR(pdu), and double-frees skb when llc_conn_state_process() drops its reference.
In llc_sap_action_send_xid_r() and llc_sap_action_send_test_r(), nskb is leaked if llc_mac_hdr_init() returns an error.
Free nskb in all three error paths.
--- net/llc/llc_c_ac.c | 2 +- net/llc/llc_s_ac.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-)
net/llc/llc_c_ac.c +1 -1
@@ -437,7 +437,7 @@ int llc_conn_ac_resend_i_xxx_x_set_0_or_send_rr(struct sock *sk,if (likely (!rc))llc_conn_send_pdu (sk, nskb);else -kfree_skb (skb); +kfree_skb (nskb); }if (rc) { nr =LLC_I_GET_NR (pdu);
net/llc/llc_s_ac.c +4 -0
@@ -121,6 +121,8 @@ int llc_sap_action_send_xid_r(struct llc_sap *sap, struct sk_buff *skb) rc =llc_mac_hdr_init (nskb, mac_sa, mac_da);if (likely (!rc)) rc =dev_queue_xmit (nskb); +else +kfree_skb (nskb); out:return rc; }
@@ -170,6 +172,8 @@ int llc_sap_action_send_test_r(struct llc_sap *sap, struct sk_buff *skb) rc =llc_mac_hdr_init (nskb, mac_sa, mac_da);if (likely (!rc)) rc =dev_queue_xmit (nskb); +else +kfree_skb (nskb); out:return rc; }
Signature · 1 line
2.56.0.rc1.310.g51773c2048-goog
PATCH v2 2/4 bridge: check llc_mac_hdr_init() return value in br_send_bpdu()
In reply to Eric DumazetIf llc_mac_hdr_init() fails (for instance if the port device type does not support LLC or dev_hard_header() fails), br_send_bpdu() should drop the skb instead of resetting the mac header to the LLC payload and transmitting a malformed frame.
--- net/bridge/br_stp_bpdu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)
net/bridge/br_stp_bpdu.c +4 -1
@@ -52,7 +52,10 @@ static void br_send_bpdu(struct net_bridge_port *p, LLC_SAP_BSPAN, LLC_PDU_CMD);llc_pdu_init_as_ui_cmd (skb); -llc_mac_hdr_init (skb, p->dev->dev_addr, p->br->group_addr); +if (llc_mac_hdr_init (skb, p->dev->dev_addr, p->br->group_addr)) { +kfree_skb (skb); +return ; + }skb_reset_mac_header (skb);
Signature · 1 line
2.56.0.rc1.310.g51773c2048-goog
Re: [PATCH v2 net 2/4] bridge: check llc_mac_hdr_init() return value in br_send_bpdu()
Quoted 21 lines · Eric Dumazet
If
llc_mac_hdr_init()fails (for instance if the port device type does not support LLC ordev_hard_header()fails),br_send_bpdu()should drop the skb instead of resetting the mac header to the LLC payload and transmitting a malformed frame.Fixes 1da177e4c3f4 ("Linux-2.6.12-rc2")Cc Nikolay Aleksandrov <[email protected]>Cc Ido Schimmel <[email protected]>Signed-off-by Eric Dumazet <[email protected]>--- net/bridge/br_stp_bpdu.c | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-)net/bridge/br_stp_bpdu.c +0
-0@@ -52,7 +52,10 @@ static void br_send_bpdu(struct net_bridge_port *p, LLC_SAP_BSPAN, LLC_PDU_CMD);
net/bridge/br_stp_bpdu.c static void br_send_bpdu(struct net_bridge_port *p, · line 61
Quoted 10 lines
net/bridge/br_stp_bpdu.c +4
-1llc_pdu_init_as_ui_cmd (skb); -llc_mac_hdr_init (skb, p->dev->dev_addr, p->br->group_addr); +if (llc_mac_hdr_init (skb, p->dev->dev_addr, p->br->group_addr)) { +kfree_skb (skb); +return ; + }skb_reset_mac_header (skb);
PATCH v2 3/4 net/sched: sch_teql: fix shadowed err in __teql_resolve()
In reply to Eric Dumazet__teql_resolve() declares an inner 'int err;' inside the 'if (neigh_event_send(n, skb_res) == 0)' block, shadowing the outer 'int err = 0;'. As a result, a negative return from dev_hard_header() is written to the inner variable and __teql_resolve() still returns 0.
Remove the shadowed variable and set the outer err to -EINVAL when dev_hard_header() returns a negative error.
--- net/sched/sch_teql.c | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-)
net/sched/sch_teql.c +2 -5
@@ -265,14 +265,11 @@ __teql_resolve(struct sk_buff *skb, struct sk_buff *skb_res, }if (neigh_event_send (n, skb_res) ==0 ) { -int err;char haddr[MAX_ADDR_LEN ];neigh_ha_snapshot (haddr, n, dev); - err =dev_hard_header (skb, dev,ntohs (skb_protocol (skb, false)), - haddr,NULL , skb->len); - -if (err <0 ) +if (dev_hard_header (skb, dev,ntohs (skb_protocol (skb, false)), + haddr,NULL , skb->len) <0 ) err = -EINVAL ; }else { err = (skb_res ==NULL ) ? -EAGAIN :1 ;
Signature · 1 line
2.56.0.rc1.310.g51773c2048-goog
PATCH v2 4/4 vlan: ensure sufficient headroom in vlan_dev_hard_header()
In reply to Eric DumazetCallers that only reserve ETH_HLEN or less (such as llc_alloc_frame()), or skbs allocated before dynamic device/headroom changes (e.g. toggling VLAN_FLAG_REORDER_HDR or bonding/team switching slaves), can reach vlan_dev_hard_header() with insufficient headroom and trigger skb_under_panic().
Use skb_cow_head() in vlan_dev_hard_header() when VLAN_FLAG_REORDER_HDR is not set to ensure sufficient headroom for the VLAN header(s) and the underlying device hard header.
Use READ_ONCE() to read dev->hard_header_len and dev->needed_headroom as they can be updated concurrently under RTNL (e.g. in vlan_transfer_features()) while vlan_dev_hard_header() runs locklessly on the transmit path. Also avoid LL_RESERVED_SPACE(dev) here so that the extra HH_DATA_MOD alignment padding does not trigger unnecessary pskb_expand_head() reallocations on inner stacked VLAN devices after the outer VLAN header has been pushed.
--- net/8021q/vlan_dev.c | 5 +++++ 1 file changed, 5 insertions(+)
net/8021q/vlan_dev.c +5 -0
@@ -55,6 +55,11 @@ static int vlan_dev_hard_header(struct sk_buff *skb, struct net_device *dev,int rc;if (!(vlan->flags &VLAN_FLAG_REORDER_HDR )) { +unsigned int hlen =READ_ONCE (dev->hard_header_len) + +READ_ONCE (dev->needed_headroom); + +if (skb_cow_head (skb, hlen) <0 ) +return -ENOMEM ; vhdr =skb_push (skb,VLAN_HLEN ); vlan_tci = vlan->vlan_id;
Signature · 1 line
2.56.0.rc1.310.g51773c2048-goog
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 10 lines · On Thu, 24 Sep 2026 08:29:47 +0000 you wrote:
Callers that only reserve
ETH_HLENor less, or skbs allocated before dynamic device/headroom changes (such as togglingVLAN_FLAG_REORDER_HDRor bonding/team switching slaves), can reachvlan_dev_hard_header()with insufficient headroom and triggerskb_under_panic().When
vlan_dev_hard_header()returns-ENOMEMuponskb_cow_head()failure, a few callers ofdev_hard_header()/llc_mac_hdr_init()had pre-existing error-handling bugs:[...]
Here is the summary with links:
- [v2,net,1/4] llc: fix skb UAF and leaks on llc_mac_hdr_init() failure
https://git.kernel.org/netdev/net/c/72f9dd522f8d - [v2,net,2/4] bridge: check llc_mac_hdr_init() return value in br_send_bpdu() https://git.kernel.org/netdev/net/c/ac704ff08e51 - [v2,net,3/4] net/sched: sch_teql: fix shadowed err in __teql_resolve() https://git.kernel.org/netdev/net/c/907b978e82cb - [v2,net,4/4] vlan: ensure sufficient headroom in vlan_dev_hard_header() https://git.kernel.org/netdev/net/c/cd5dd68267c4
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html