Skip to content

Commit

Permalink
xfrm: Silence warnings triggerable by bad packets
Browse files Browse the repository at this point in the history
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<maze@google.com>
Fixes: 5f24f41 ("xfrm: Remove inner/outer modes from input path")
Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au>
Reviewed-by: Maciej Żenczykowski <maze@google.com>
Signed-off-by: Steffen Klassert <steffen.klassert@secunet.com>
  • Loading branch information
herbertx authored and klassert committed Jul 10, 2023
1 parent d1e0e61 commit 57010b8
Showing 1 changed file with 9 additions and 13 deletions.
22 changes: 9 additions & 13 deletions net/xfrm/xfrm_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ static int xfrm4_remove_beet_encap(struct xfrm_state *x, struct sk_buff *skb)
int optlen = 0;
int err = -EINVAL;

skb->protocol = htons(ETH_P_IP);

if (unlikely(XFRM_MODE_SKB_CB(skb)->protocol == IPPROTO_BEETPH)) {
struct ip_beet_phdr *ph;
int phlen;
Expand Down Expand Up @@ -232,6 +234,8 @@ static int xfrm4_remove_tunnel_encap(struct xfrm_state *x, struct sk_buff *skb)
{
int err = -EINVAL;

skb->protocol = htons(ETH_P_IP);

if (!pskb_may_pull(skb, sizeof(struct iphdr)))
goto out;

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

skb->protocol = htons(ETH_P_IPV6);

if (!pskb_may_pull(skb, sizeof(struct ipv6hdr)))
goto out;

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

skb->protocol = htons(ETH_P_IPV6);

err = skb_cow_head(skb, size + skb->mac_len);
if (err)
goto out;
Expand Down Expand Up @@ -346,6 +354,7 @@ xfrm_inner_mode_encap_remove(struct xfrm_state *x,
return xfrm6_remove_tunnel_encap(x, skb);
break;
}
return -EINVAL;
}

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

switch (XFRM_MODE_SKB_CB(skb)->protocol) {
case IPPROTO_IPIP:
case IPPROTO_BEETPH:
skb->protocol = htons(ETH_P_IP);
break;
case IPPROTO_IPV6:
skb->protocol = htons(ETH_P_IPV6);
break;
default:
WARN_ON_ONCE(1);
break;
}

return xfrm_inner_mode_encap_remove(x, skb);
}

Expand Down

0 comments on commit 57010b8

Please sign in to comment.