Skip to content

Commit d344591

Browse files
HenryHsiuynezz
authored andcommitted
netfilter: fix crash in flow offload by adding netns support
Commit fcb41de ("config: enable some useful features on !SMALL_FLASH devices") enabled netns, which in turn lead to the crash in the flow offload target. When the flow offloading framework intends to delete a flow from the hardware table, it is necessary to retrieve the namespace from nf_flowtable->ft_net. However, no one ever wrote the namespace into nf_flowtable->ft_net in advance. So the framework will mistakenly use a NULL namespace to execute dev_get_by_index_rcu(net, ifindex), leading to the kernel panic. Ref: FS#2321 Fixes: fcb41de ("config: enable some useful features on !SMALL_FLASH devices") Tested-by: Simon Tretter <[email protected]> Signed-off-by: HsiuWen Yen <[email protected]> [merged patch into offload patch, fix for 4.19, SOB fix, commit subj/msg touches] Signed-off-by: Petr Štetiar <[email protected]>
1 parent 545bfbc commit d344591

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

target/linux/generic/hack-4.14/650-netfilter-add-xt_OFFLOAD-target.patch

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Signed-off-by: Felix Fietkau <[email protected]>
9898
obj-$(CONFIG_NETFILTER_XT_TARGET_LED) += xt_LED.o
9999
--- /dev/null
100100
+++ b/net/netfilter/xt_FLOWOFFLOAD.c
101-
@@ -0,0 +1,403 @@
101+
@@ -0,0 +1,408 @@
102102
+/*
103103
+ * Copyright (C) 2018 Felix Fietkau <[email protected]>
104104
+ *
@@ -342,12 +342,13 @@ Signed-off-by: Felix Fietkau <[email protected]>
342342
+flowoffload_tg(struct sk_buff *skb, const struct xt_action_param *par)
343343
+{
344344
+ const struct xt_flowoffload_target_info *info = par->targinfo;
345+
+ const struct nf_conn_help *help;
345346
+ enum ip_conntrack_info ctinfo;
346347
+ enum ip_conntrack_dir dir;
347348
+ struct nf_flow_route route;
348349
+ struct flow_offload *flow;
349350
+ struct nf_conn *ct;
350-
+ const struct nf_conn_help *help;
351+
+ struct net *net;
351352
+
352353
+ if (xt_flowoffload_skip(skb))
353354
+ return XT_CONTINUE;
@@ -396,6 +397,10 @@ Signed-off-by: Felix Fietkau <[email protected]>
396397
+ xt_flowoffload_check_device(xt_in(par));
397398
+ xt_flowoffload_check_device(xt_out(par));
398399
+
400+
+ net = read_pnet(&nf_flowtable.ft_net);
401+
+ if (!net)
402+
+ write_pnet(&nf_flowtable.ft_net, xt_net(par));
403+
+
399404
+ if (info->flags & XT_FLOWOFFLOAD_HW)
400405
+ nf_flow_offload_hw_add(xt_net(par), flow, ct);
401406
+

target/linux/generic/hack-4.19/650-netfilter-add-xt_OFFLOAD-target.patch

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ Signed-off-by: Felix Fietkau <[email protected]>
9898
obj-$(CONFIG_NETFILTER_XT_TARGET_LED) += xt_LED.o
9999
--- /dev/null
100100
+++ b/net/netfilter/xt_FLOWOFFLOAD.c
101-
@@ -0,0 +1,366 @@
101+
@@ -0,0 +1,371 @@
102102
+/*
103103
+ * Copyright (C) 2018 Felix Fietkau <[email protected]>
104104
+ *
@@ -344,6 +344,7 @@ Signed-off-by: Felix Fietkau <[email protected]>
344344
+ struct nf_flow_route route;
345345
+ struct flow_offload *flow;
346346
+ struct nf_conn *ct;
347+
+ struct net *net;
347348
+
348349
+ if (xt_flowoffload_skip(skb))
349350
+ return XT_CONTINUE;
@@ -391,6 +392,10 @@ Signed-off-by: Felix Fietkau <[email protected]>
391392
+ xt_flowoffload_check_device(xt_in(par));
392393
+ xt_flowoffload_check_device(xt_out(par));
393394
+
395+
+ net = read_pnet(&nf_flowtable.ft_net);
396+
+ if (!net)
397+
+ write_pnet(&nf_flowtable.ft_net, xt_net(par));
398+
+
394399
+ if (info->flags & XT_FLOWOFFLOAD_HW)
395400
+ nf_flow_offload_hw_add(xt_net(par), flow, ct);
396401
+

0 commit comments

Comments
 (0)