From: Felix Fietkau Date: Mon, 21 Nov 2022 19:43:12 +0000 (+0100) Subject: kernel: add a locking fix for netfilter hardware flow offloading X-Git-Url: http://git.lede-project.org./?a=commitdiff_plain;h=e410833bdd6117228a00aad35bbc56de91f7251e;p=openwrt%2Fstaging%2Fneocturne.git kernel: add a locking fix for netfilter hardware flow offloading Protect the flow block cb list readers against concurrent updates Reported-by: Chad Monroe Signed-off-by: Felix Fietkau --- diff --git a/target/linux/generic/pending-5.10/706-netfilter-nf_flow_table-add-missing-locking.patch b/target/linux/generic/pending-5.10/706-netfilter-nf_flow_table-add-missing-locking.patch new file mode 100644 index 0000000000..b77d71cc94 --- /dev/null +++ b/target/linux/generic/pending-5.10/706-netfilter-nf_flow_table-add-missing-locking.patch @@ -0,0 +1,39 @@ +From: Felix Fietkau +Date: Sat, 19 Nov 2022 18:48:42 +0100 +Subject: [PATCH] netfilter: nf_flow_table: add missing locking + +nf_flow_table_block_setup and the driver TC_SETUP_FT call can modify the flow +block cb list while they are being traversed elsewhere, causing a crash. +Add a write lock around the calls to protect readers + +Signed-off-by: Felix Fietkau +--- + +--- a/net/netfilter/nf_flow_table_offload.c ++++ b/net/netfilter/nf_flow_table_offload.c +@@ -1015,6 +1015,7 @@ static int nf_flow_table_block_setup(str + struct flow_block_cb *block_cb, *next; + int err = 0; + ++ down_write(&flowtable->flow_block_lock); + switch (cmd) { + case FLOW_BLOCK_BIND: + list_splice(&bo->cb_list, &flowtable->flow_block.cb_list); +@@ -1029,6 +1030,7 @@ static int nf_flow_table_block_setup(str + WARN_ON_ONCE(1); + err = -EOPNOTSUPP; + } ++ up_write(&flowtable->flow_block_lock); + + return err; + } +@@ -1085,7 +1087,9 @@ static int nf_flow_table_offload_cmd(str + + nf_flow_table_block_offload_init(bo, dev_net(dev), cmd, flowtable, + extack); ++ down_write(&flowtable->flow_block_lock); + err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_FT, bo); ++ up_write(&flowtable->flow_block_lock); + if (err < 0) + return err; + diff --git a/target/linux/generic/pending-5.15/701-netfilter-nf_flow_table-add-missing-locking.patch b/target/linux/generic/pending-5.15/701-netfilter-nf_flow_table-add-missing-locking.patch new file mode 100644 index 0000000000..9ff393a8b7 --- /dev/null +++ b/target/linux/generic/pending-5.15/701-netfilter-nf_flow_table-add-missing-locking.patch @@ -0,0 +1,39 @@ +From: Felix Fietkau +Date: Sat, 19 Nov 2022 18:48:42 +0100 +Subject: [PATCH] netfilter: nf_flow_table: add missing locking + +nf_flow_table_block_setup and the driver TC_SETUP_FT call can modify the flow +block cb list while they are being traversed elsewhere, causing a crash. +Add a write lock around the calls to protect readers + +Signed-off-by: Felix Fietkau +--- + +--- a/net/netfilter/nf_flow_table_offload.c ++++ b/net/netfilter/nf_flow_table_offload.c +@@ -1074,6 +1074,7 @@ static int nf_flow_table_block_setup(str + struct flow_block_cb *block_cb, *next; + int err = 0; + ++ down_write(&flowtable->flow_block_lock); + switch (cmd) { + case FLOW_BLOCK_BIND: + list_splice(&bo->cb_list, &flowtable->flow_block.cb_list); +@@ -1088,6 +1089,7 @@ static int nf_flow_table_block_setup(str + WARN_ON_ONCE(1); + err = -EOPNOTSUPP; + } ++ up_write(&flowtable->flow_block_lock); + + return err; + } +@@ -1144,7 +1146,9 @@ static int nf_flow_table_offload_cmd(str + + nf_flow_table_block_offload_init(bo, dev_net(dev), cmd, flowtable, + extack); ++ down_write(&flowtable->flow_block_lock); + err = dev->netdev_ops->ndo_setup_tc(dev, TC_SETUP_FT, bo); ++ up_write(&flowtable->flow_block_lock); + if (err < 0) + return err; +