netfilter: nf_flow_table: add missing locking
Subsystems (3)
PATCH 1/1 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
--- net/netfilter/nf_flow_table_offload.c | 4 ++++ 1 file changed, 4 insertions(+)
net/netfilter/nf_flow_table_offload.c +4 -0
@@ -1098,6 +1098,7 @@ static int nf_flow_table_block_setup(struct nf_flowtable *flowtable,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);
@@ -1112,6 +1113,7 @@ static int nf_flow_table_block_setup(struct nf_flowtable *flowtable,WARN_ON_ONCE (1 ); err = -EOPNOTSUPP ; } +up_write (&flowtable->flow_block_lock);return err; }
@@ -1168,7 +1170,9 @@ static int nf_flow_table_offload_cmd(struct flow_block_offload *bo,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;
Signature · 1 line
2.38.1
Quoted 5 lines · Felix Fietkau
nf_flow_table_block_setupand the driverTC_SETUP_FTcall 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 readersSigned-off-by Felix Fietkau <[email protected]>
Sorry, I forgot to add this:
- Felix
Quoted 6 lines · Felix Fietkau
Quoted 4 lines · Felix Fietkau
nf_flow_table_block_setupand the driverTC_SETUP_FTcall 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
Quoted 6 lines
Quoted 1 line
Signed-off-by Felix Fietkau <[email protected]>Sorry, I forgot to add this:
Reported-by Chad Monroe <[email protected]>- Felix
Hi Felix
Could you also add a Fixes: tag ?
Thanks.
Quoted 10 lines · Eric Dumazet
Quoted 9 lines · Felix Fietkau
Quoted 5 lines · Felix Fietkau
nf_flow_table_block_setupand the driverTC_SETUP_FTcall 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 readersSigned-off-by Felix Fietkau <[email protected]>Sorry, I forgot to add this:
Quoted 7 lines
Quoted 3 lines
Reported-by Chad Monroe <[email protected]>- Felix
Hi Felix
Could you also add a Fixes: tag ?
I don't know which commit to use for that tag.
- Felix
Jakub Kicinski
maintainerQuoted 3 lines · On Mon, 21 Nov 2022 21:08:12 +0100 Felix Fietkau wrote:
Quoted 1 line
Could you also add a Fixes: tag ?
I don't know which commit to use for that tag.
The oldest upstream commit where the problem you're solving can trigger?
Quoted 7 lines · Jakub Kicinski
Quoted 3 lines · On Mon, 21 Nov 2022 21:08:12 +0100 Felix Fietkau wrote:
Quoted 1 line
Could you also add a Fixes: tag ?
I don't know which commit to use for that tag.
The oldest upstream commit where the problem you're solving can trigger?
I know, but I'm having a hard time figuring that out. The initial version of that file came without locking. Later on some locking was added for supporting an extra API for registering to flow table events, but it didn't cover the cases that I'm fixing.
My guess is that the locking should have been present from the start, so:
- Felix
Quoted 3 lines · Felix Fietkau
nf_flow_table_block_setupand the driverTC_SETUP_FTcall 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
Applied, thanks