Skip to content

Commit ac758e3

Browse files
kaberDavid S. Miller
authored andcommitted
[XFRM]: beet: fix worst case header_len calculation
esp_init_state doesn't account for the beet pseudo header in the header_len calculation, which may result in undersized skbs hitting xfrm4_beet_output, causing unnecessary reallocations in ip_finish_output2. The skbs should still always have enough room to avoid causing skb_under_panic in skb_push since we have at least 16 bytes available from LL_RESERVED_SPACE in xfrm_state_check_space. Signed-off-by: Patrick McHardy <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent c5c2523 commit ac758e3

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

net/ipv4/esp4.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,6 @@ static u32 esp4_get_mtu(struct xfrm_state *x, int mtu)
294294
break;
295295
case XFRM_MODE_BEET:
296296
/* The worst case. */
297-
mtu -= IPV4_BEET_PHMAXLEN;
298297
mtu += min_t(u32, IPV4_BEET_PHMAXLEN, rem);
299298
break;
300299
}
@@ -409,6 +408,8 @@ static int esp_init_state(struct xfrm_state *x)
409408
x->props.header_len = sizeof(struct ip_esp_hdr) + esp->conf.ivlen;
410409
if (x->props.mode == XFRM_MODE_TUNNEL)
411410
x->props.header_len += sizeof(struct iphdr);
411+
else if (x->props.mode == XFRM_MODE_BEET)
412+
x->props.header_len += IPV4_BEET_PHMAXLEN;
412413
if (x->encap) {
413414
struct xfrm_encap_tmpl *encap = x->encap;
414415

net/ipv4/xfrm4_mode_beet.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static int xfrm4_beet_output(struct xfrm_state *x, struct sk_buff *skb)
4040
if (unlikely(optlen))
4141
hdrlen += IPV4_BEET_PHMAXLEN - (optlen & 4);
4242

43-
skb_push(skb, x->props.header_len + hdrlen);
43+
skb_push(skb, x->props.header_len - IPV4_BEET_PHMAXLEN + hdrlen);
4444
skb_reset_network_header(skb);
4545
top_iph = ip_hdr(skb);
4646
skb->transport_header += sizeof(*iph) - hdrlen;

0 commit comments

Comments
 (0)