macsec: don't read an unset MAC header in macsec_encrypt()
Subsystems (4)
PATCH 1/1 macsec: don't read an unset MAC header in macsec_encrypt()
macsec_encrypt() reads the Ethernet header via eth_hdr(skb) (skb->head + skb->mac_header) to memmove() the 12 source/destination MAC bytes forward and make room for the SecTAG.
On the AF_PACKET SOCK_RAW + PACKET_QDISC_BYPASS transmit path the skb reaches the macsec ndo_start_xmit() with the MAC header unset, so eth_hdr(skb) resolves to skb->head + (u16)~0 and the read is out of
bounds: a 12-byte heap over-read that is also emitted on the wire as the frame's outer source/destination MAC. KASAN reports a slab-out-of-bounds read in macsec_start_xmit() on 6.0; on current mainline a CONFIG_DEBUG_NET build flags it as an unset mac header in skb_mac_header().
On the TX path the L2 header is at skb->data, so use skb_eth_hdr(), added by commit 96cc4b69581d ("macvlan: do not assume mac_header is set in macvlan_broadcast()") for exactly this purpose.
--- drivers/net/macsec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
drivers/net/macsec.c +1 -1
@@ -646,7 +646,7 @@ static struct sk_buff *macsec_encrypt(struct sk_buff *skb, } unprotected_len = skb->len; - eth =eth_hdr (skb); + eth =skb_eth_hdr (skb); sci_present =macsec_send_sci (secy); hh =skb_push (skb,macsec_extra_len (sci_present));memmove (hh, eth,2 *ETH_ALEN );
Signature · 1 line
2.54.0
Quoted 16 lines · Daehyeon Ko
macsec_encrypt()reads the Ethernet header viaeth_hdr(skb)(skb->head+skb->mac_header) tomemmove()the 12 source/destination MAC bytes forward and make room for the SecTAG.On the
AF_PACKETSOCK_RAW+PACKET_QDISC_BYPASStransmit path the skb reaches the macsecndo_start_xmit()with the MAC header unset, soeth_hdr(skb)resolves toskb->head+ (u16)~0 and the read is out of
bounds: a 12-byte heap over-read that is also emitted on the wire as the frame's outer source/destination MAC. KASAN reports a slab-out-of-bounds read inmacsec_start_xmit()on 6.0; on current mainline aCONFIG_DEBUG_NETbuild flags it as an unset mac header inskb_mac_header().On the TX path the L2 header is at
skb->data, so useskb_eth_hdr(), added by commit96cc4b69581d("macvlan: do not assumemac_headeris set inmacvlan_broadcast()") for exactly this purpose.
Quoted 6 lines
Fixes c09440f7dcb3 ("macsec: introduce IEEE 802.1AE driver")Signed-off-by Daehyeon Ko <[email protected]>--- drivers/net/macsec.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
Signature · 1 line
Sabrina
This patch was applied to netdev/net.git (main) by Paolo Abeni <[email protected]>:
Hello:
This patch was applied to netdev/net.git (main)
by Paolo Abeni <[email protected]>:
Quoted 12 lines · On Fri, 3 Jul 2026 17:36:33 +0900 you wrote:
macsec_encrypt()reads the Ethernet header viaeth_hdr(skb)(skb->head+skb->mac_header) tomemmove()the 12 source/destination MAC bytes forward and make room for the SecTAG.On the
AF_PACKETSOCK_RAW+PACKET_QDISC_BYPASStransmit path the skb reaches the macsecndo_start_xmit()with the MAC header unset, soeth_hdr(skb)resolves toskb->head+ (u16)~0 and the read is out of
bounds: a 12-byte heap over-read that is also emitted on the wire as the frame's outer source/destination MAC. KASAN reports a slab-out-of-bounds read inmacsec_start_xmit()on 6.0; on current mainline aCONFIG_DEBUG_NETbuild flags it as an unset mac header inskb_mac_header().
Quoted 1 line
[...]
Here is the summary with links:
- [net] macsec: don't read an unset MAC header in macsec_encrypt()
https://git.kernel.org/netdev/net/c/f5089008f90c
You are awesome, thank you!
Signature · 2 lines
Deet-doot-dot, I am a bot. https://korg.docs.kernel.org/patchwork/pwbot.html