Skip to content

Commit 4b549cc

Browse files
Christian Langrockklassert
authored andcommitted
xfrm: replay: Fix ESN wrap around for GSO
When using GSO it can happen that the wrong seq_hi is used for the last packets before the wrap around. This can lead to double usage of a sequence number. To avoid this, we should serialize this last GSO packet. Fixes: d7dbefc ("xfrm: Add xfrm_replay_overflow functions for offloading") Co-developed-by: Steffen Klassert <[email protected]> Signed-off-by: Christian Langrock <[email protected]> Signed-off-by: Steffen Klassert <[email protected]>
1 parent d83f704 commit 4b549cc

File tree

4 files changed

+21
-2
lines changed

4 files changed

+21
-2
lines changed

net/ipv4/esp4_offload.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,9 @@ static int esp_xmit(struct xfrm_state *x, struct sk_buff *skb, netdev_features_
314314
xo->seq.low += skb_shinfo(skb)->gso_segs;
315315
}
316316

317+
if (xo->seq.low < seq)
318+
xo->seq.hi++;
319+
317320
esp.seqno = cpu_to_be64(seq + ((u64)xo->seq.hi << 32));
318321

319322
ip_hdr(skb)->tot_len = htons(skb->len);

net/ipv6/esp6_offload.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -346,6 +346,9 @@ static int esp6_xmit(struct xfrm_state *x, struct sk_buff *skb, netdev_features
346346
xo->seq.low += skb_shinfo(skb)->gso_segs;
347347
}
348348

349+
if (xo->seq.low < seq)
350+
xo->seq.hi++;
351+
349352
esp.seqno = cpu_to_be64(xo->seq.low + ((u64)xo->seq.hi << 32));
350353

351354
len = skb->len - sizeof(struct ipv6hdr);

net/xfrm/xfrm_device.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,18 @@ static void xfrm_outer_mode_prep(struct xfrm_state *x, struct sk_buff *skb)
9797
}
9898
}
9999

100+
static inline bool xmit_xfrm_check_overflow(struct sk_buff *skb)
101+
{
102+
struct xfrm_offload *xo = xfrm_offload(skb);
103+
__u32 seq = xo->seq.low;
104+
105+
seq += skb_shinfo(skb)->gso_segs;
106+
if (unlikely(seq < xo->seq.low))
107+
return true;
108+
109+
return false;
110+
}
111+
100112
struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t features, bool *again)
101113
{
102114
int err;
@@ -134,7 +146,8 @@ struct sk_buff *validate_xmit_xfrm(struct sk_buff *skb, netdev_features_t featur
134146
return skb;
135147
}
136148

137-
if (skb_is_gso(skb) && unlikely(x->xso.dev != dev)) {
149+
if (skb_is_gso(skb) && (unlikely(x->xso.dev != dev) ||
150+
unlikely(xmit_xfrm_check_overflow(skb)))) {
138151
struct sk_buff *segs;
139152

140153
/* Packet got rerouted, fixup features and segment it. */

net/xfrm/xfrm_replay.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -714,7 +714,7 @@ static int xfrm_replay_overflow_offload_esn(struct xfrm_state *x, struct sk_buff
714714
oseq += skb_shinfo(skb)->gso_segs;
715715
}
716716

717-
if (unlikely(oseq < replay_esn->oseq)) {
717+
if (unlikely(xo->seq.low < replay_esn->oseq)) {
718718
XFRM_SKB_CB(skb)->seq.output.hi = ++oseq_hi;
719719
xo->seq.hi = oseq_hi;
720720
replay_esn->oseq_hi = oseq_hi;

0 commit comments

Comments
 (0)