Skip to content

Commit 7a4b614

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: nft_flow_offload: update tcp state flags under lock
The conntrack entry is already public, there is a small chance that another CPU is handling a packet in reply direction and racing with the tcp state update. Move this under ct spinlock. This is done once, when ct is about to be offloaded, so this should not result in a noticeable performance hit. Fixes: 8437a62 ("netfilter: nft_flow_offload: set liberal tracking mode for tcp") Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent d9d7b48 commit 7a4b614

File tree

1 file changed

+11
-5
lines changed

1 file changed

+11
-5
lines changed

net/netfilter/nft_flow_offload.c

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,15 @@ static bool nft_flow_offload_skip(struct sk_buff *skb, int family)
289289
return false;
290290
}
291291

292+
static void flow_offload_ct_tcp(struct nf_conn *ct)
293+
{
294+
/* conntrack will not see all packets, disable tcp window validation. */
295+
spin_lock_bh(&ct->lock);
296+
ct->proto.tcp.seen[0].flags |= IP_CT_TCP_FLAG_BE_LIBERAL;
297+
ct->proto.tcp.seen[1].flags |= IP_CT_TCP_FLAG_BE_LIBERAL;
298+
spin_unlock_bh(&ct->lock);
299+
}
300+
292301
static void nft_flow_offload_eval(const struct nft_expr *expr,
293302
struct nft_regs *regs,
294303
const struct nft_pktinfo *pkt)
@@ -356,11 +365,8 @@ static void nft_flow_offload_eval(const struct nft_expr *expr,
356365
goto err_flow_alloc;
357366

358367
flow_offload_route_init(flow, &route);
359-
360-
if (tcph) {
361-
ct->proto.tcp.seen[0].flags |= IP_CT_TCP_FLAG_BE_LIBERAL;
362-
ct->proto.tcp.seen[1].flags |= IP_CT_TCP_FLAG_BE_LIBERAL;
363-
}
368+
if (tcph)
369+
flow_offload_ct_tcp(ct);
364370

365371
__set_bit(NF_FLOW_HW_BIDIRECTIONAL, &flow->flags);
366372
ret = flow_offload_add(flowtable, flow);

0 commit comments

Comments
 (0)