netfilter: nftables: fix incorrect increment of loop counter
Subsystems (4)
PATCH 1/1 netfilter: nftables: fix incorrect increment of loop counter
From: Colin Ian King <[email protected]>
The intention of the err_expr cleanup path is to iterate over the allocated expr_array objects and free them, starting from i - 1 and working down to the start of the array. Currently the loop counter is being incremented instead of decremented and also the index i is being used instead of k, repeatedly destroying the same expr_array element. Fix this by decrementing k and using k as the index into expr_array.
Addresses-Coverity: ("Infinite loop")
--- net/netfilter/nf_tables_api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
net/netfilter/nf_tables_api.c +2 -2
@@ -5254,8 +5254,8 @@ static int nft_set_elem_expr_clone(const struct nft_ctx *ctx,return 0 ; err_expr: -for (k = i -1 ; k >=0 ; k++) -nft_expr_destroy (ctx, expr_array[i]); +for (k = i -1 ; k >=0 ; k--) +nft_expr_destroy (ctx, expr_array[k]);return -ENOMEM ; }
Signature · 1 line
2.29.2
Hi,
Quoted 10 lines · Colin King
From: Colin Ian King <[email protected]>
The intention of the
err_exprcleanup path is to iterate over the allocatedexpr_arrayobjects and free them, starting from i - 1 and working down to the start of the array. Currently the loop counter is being incremented instead of decremented and also the index i is being used instead of k, repeatedly destroying the sameexpr_arrayelement. Fix this by decrementing k and using k as the index intoexpr_array.
Quoted 3 lines
Addresses-Coverity: ("Infinite loop")
Fixes 8cfd9b0f8515 ("netfilter: nftables: generalize set expressions support")Signed-off-by Colin Ian King <[email protected]>
@Jakub: Would you please take this one into net-next? Thanks!
Quoted 22 lines
--- net/netfilter/nf_tables_api.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)net/netfilter/nf_tables_api.c +2
-2@@ -5254,8 +5254,8 @@ static int nft_set_elem_expr_clone(const struct nft_ctx *ctx,return 0 ; err_expr: -for (k = i -1 ; k >=0 ; k++) -nft_expr_destroy (ctx, expr_array[i]); +for (k = i -1 ; k >=0 ; k--) +nft_expr_destroy (ctx, expr_array[k]);return -ENOMEM ; }Signature · 1 line
2.29.2
Pablo Neira Ayuso
maintainerQuoted 13 lines · Pablo Neira Ayuso
Hi,
Quoted 10 lines · Colin King
From: Colin Ian King <[email protected]>
The intention of the
err_exprcleanup path is to iterate over the allocatedexpr_arrayobjects and free them, starting from i - 1 and working down to the start of the array. Currently the loop counter is being incremented instead of decremented and also the index i is being used instead of k, repeatedly destroying the sameexpr_arrayelement. Fix this by decrementing k and using k as the index intoexpr_array.
Quoted 7 lines
Quoted 3 lines
Addresses-Coverity: ("Infinite loop")
Fixes 8cfd9b0f8515 ("netfilter: nftables: generalize set expressions support")Signed-off-by Colin Ian King <[email protected]>Reviewed-by Pablo Neira Ayuso <[email protected]>@Jakub: Would you please take this one into net-next? Thanks!
You marked as "Awaiting Upstream", I'll take care of it.
Thanks.
Quoted 9 lines · Colin King
From: Colin Ian King <[email protected]>
The intention of the
err_exprcleanup path is to iterate over the allocatedexpr_arrayobjects and free them, starting from i - 1 and working down to the start of the array. Currently the loop counter is being incremented instead of decremented and also the index i is being used instead of k, repeatedly destroying the sameexpr_arrayelement. Fix this by decrementing k and using k as the index intoexpr_array.
Applied to nf.git, thanks.