Skip to content

Commit 7b3ba18

Browse files
wdebruijkuba-moo
authored andcommitted
llc: verify mac len before reading mac header
LLC reads the mac header with eth_hdr without verifying that the skb has an Ethernet header. Syzbot was able to enter llc_rcv on a tun device. Tun can insert packets without mac len and with user configurable skb->protocol (passing a tun_pi header when not configuring IFF_NO_PI). BUG: KMSAN: uninit-value in llc_station_ac_send_test_r net/llc/llc_station.c:81 [inline] BUG: KMSAN: uninit-value in llc_station_rcv+0x6fb/0x1290 net/llc/llc_station.c:111 llc_station_ac_send_test_r net/llc/llc_station.c:81 [inline] llc_station_rcv+0x6fb/0x1290 net/llc/llc_station.c:111 llc_rcv+0xc5d/0x14a0 net/llc/llc_input.c:218 __netif_receive_skb_one_core net/core/dev.c:5523 [inline] __netif_receive_skb+0x1a6/0x5a0 net/core/dev.c:5637 netif_receive_skb_internal net/core/dev.c:5723 [inline] netif_receive_skb+0x58/0x660 net/core/dev.c:5782 tun_rx_batched+0x3ee/0x980 drivers/net/tun.c:1555 tun_get_user+0x54c5/0x69c0 drivers/net/tun.c:2002 Add a mac_len test before all three eth_hdr(skb) calls under net/llc. There are further uses in include/net/llc_pdu.h. All these are protected by a test skb->protocol == ETH_P_802_2. Which does not protect against this tun scenario. But the mac_len test added in this patch in llc_fixup_skb will indirectly protect those too. That is called from llc_rcv before any other LLC code. It is tempting to just add a blanket mac_len check in llc_rcv, but not sure whether that could break valid LLC paths that do not assume an Ethernet header. 802.2 LLC may be used on top of non-802.3 protocols in principle. The below referenced commit shows that used to, on top of Token Ring. At least one of the three eth_hdr uses goes back to before the start of git history. But the one that syzbot exercises is introduced in this commit. That commit is old enough (2008), that effectively all stable kernels should receive this. Fixes: f83f176 ("[LLC]: skb allocation size for responses") Reported-by: [email protected] Signed-off-by: Willem de Bruijn <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent d280783 commit 7b3ba18

File tree

3 files changed

+14
-2
lines changed

3 files changed

+14
-2
lines changed

net/llc/llc_input.c

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,8 +127,14 @@ static inline int llc_fixup_skb(struct sk_buff *skb)
127127
skb->transport_header += llc_len;
128128
skb_pull(skb, llc_len);
129129
if (skb->protocol == htons(ETH_P_802_2)) {
130-
__be16 pdulen = eth_hdr(skb)->h_proto;
131-
s32 data_size = ntohs(pdulen) - llc_len;
130+
__be16 pdulen;
131+
s32 data_size;
132+
133+
if (skb->mac_len < ETH_HLEN)
134+
return 0;
135+
136+
pdulen = eth_hdr(skb)->h_proto;
137+
data_size = ntohs(pdulen) - llc_len;
132138

133139
if (data_size < 0 ||
134140
!pskb_may_pull(skb, data_size))

net/llc/llc_s_ac.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ int llc_sap_action_send_test_r(struct llc_sap *sap, struct sk_buff *skb)
153153
int rc = 1;
154154
u32 data_size;
155155

156+
if (skb->mac_len < ETH_HLEN)
157+
return 1;
158+
156159
llc_pdu_decode_sa(skb, mac_da);
157160
llc_pdu_decode_da(skb, mac_sa);
158161
llc_pdu_decode_ssap(skb, &dsap);

net/llc/llc_station.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,6 +76,9 @@ static int llc_station_ac_send_test_r(struct sk_buff *skb)
7676
u32 data_size;
7777
struct sk_buff *nskb;
7878

79+
if (skb->mac_len < ETH_HLEN)
80+
goto out;
81+
7982
/* The test request command is type U (llc_len = 3) */
8083
data_size = ntohs(eth_hdr(skb)->h_proto) - 3;
8184
nskb = llc_alloc_frame(NULL, skb->dev, LLC_PDU_TYPE_U, data_size);

0 commit comments

Comments
 (0)