Skip to content

Commit 57010b8

Browse files
herbertxklassert
authored andcommitted
xfrm: Silence warnings triggerable by bad packets
After the elimination of inner modes, a couple of warnings that were previously unreachable can now be triggered by malformed inbound packets. Fix this by: 1. Moving the setting of skb->protocol into the decap functions. 2. Returning -EINVAL when unexpected protocol is seen. Reported-by: Maciej Żenczykowski<[email protected]> Fixes: 5f24f41 ("xfrm: Remove inner/outer modes from input path") Signed-off-by: Herbert Xu <[email protected]> Reviewed-by: Maciej Żenczykowski <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent d1e0e61 commit 57010b8

File tree

1 file changed

+9
-13
lines changed

1 file changed

+9
-13
lines changed

net/xfrm/xfrm_input.c

+9-13
Original file line numberDiff line numberDiff line change
@@ -180,6 +180,8 @@ static int xfrm4_remove_beet_encap(struct xfrm_state *x, struct sk_buff *skb)
180180
int optlen = 0;
181181
int err = -EINVAL;
182182

183+
skb->protocol = htons(ETH_P_IP);
184+
183185
if (unlikely(XFRM_MODE_SKB_CB(skb)->protocol == IPPROTO_BEETPH)) {
184186
struct ip_beet_phdr *ph;
185187
int phlen;
@@ -232,6 +234,8 @@ static int xfrm4_remove_tunnel_encap(struct xfrm_state *x, struct sk_buff *skb)
232234
{
233235
int err = -EINVAL;
234236

237+
skb->protocol = htons(ETH_P_IP);
238+
235239
if (!pskb_may_pull(skb, sizeof(struct iphdr)))
236240
goto out;
237241

@@ -267,6 +271,8 @@ static int xfrm6_remove_tunnel_encap(struct xfrm_state *x, struct sk_buff *skb)
267271
{
268272
int err = -EINVAL;
269273

274+
skb->protocol = htons(ETH_P_IPV6);
275+
270276
if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
271277
goto out;
272278

@@ -296,6 +302,8 @@ static int xfrm6_remove_beet_encap(struct xfrm_state *x, struct sk_buff *skb)
296302
int size = sizeof(struct ipv6hdr);
297303
int err;
298304

305+
skb->protocol = htons(ETH_P_IPV6);
306+
299307
err = skb_cow_head(skb, size + skb->mac_len);
300308
if (err)
301309
goto out;
@@ -346,6 +354,7 @@ xfrm_inner_mode_encap_remove(struct xfrm_state *x,
346354
return xfrm6_remove_tunnel_encap(x, skb);
347355
break;
348356
}
357+
return -EINVAL;
349358
}
350359

351360
WARN_ON_ONCE(1);
@@ -366,19 +375,6 @@ static int xfrm_prepare_input(struct xfrm_state *x, struct sk_buff *skb)
366375
return -EAFNOSUPPORT;
367376
}
368377

369-
switch (XFRM_MODE_SKB_CB(skb)->protocol) {
370-
case IPPROTO_IPIP:
371-
case IPPROTO_BEETPH:
372-
skb->protocol = htons(ETH_P_IP);
373-
break;
374-
case IPPROTO_IPV6:
375-
skb->protocol = htons(ETH_P_IPV6);
376-
break;
377-
default:
378-
WARN_ON_ONCE(1);
379-
break;
380-
}
381-
382378
return xfrm_inner_mode_encap_remove(x, skb);
383379
}
384380

0 commit comments

Comments
 (0)