netfilter: nft_set_rbtree: allocate same array size on updates
Subsystems (2)
Pablo Neira Ayuso
maintainerPATCH v2 1/1 netfilter: nft_set_rbtree: allocate same array size on updates
The array resize function increments the size of the array in NFT_ARRAY_EXTRA_SIZE slots for each update, this is unnecesarily increasing the array size.
To determine the number of array slots:
- Use NFT_ARRAY_EXTRA_SIZE for new sets.
- Use the current maximum number of intervals in the live array.
---
v2: fix crash with new sets, reported by Florian.
net/netfilter/nft_set_rbtree.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)
net/netfilter/nft_set_rbtree.c +6 -1
@@ -646,7 +646,12 @@ static int nft_array_may_resize(const struct nft_set *set)struct nft_array *array;if (!priv->array_next) { - array =nft_array_alloc (nelems +NFT_ARRAY_EXTRA_SIZE ); +if (priv->array) + new_max_intervals = priv->array->max_intervals; +else + new_max_intervals =NFT_ARRAY_EXTRA_SIZE ; + + array =nft_array_alloc (new_max_intervals);if (!array)return -ENOMEM ;
Signature · 1 line
2.47.3
Pablo Neira Ayuso
maintainerThis is an incorrect resend, apologies.
Quoted 40 lines · Pablo Neira Ayuso
The array resize function increments the size of the array in
NFT_ARRAY_EXTRA_SIZEslots for each update, this is unnecesarily increasing the array size.To determine the number of array slots:
- Use
NFT_ARRAY_EXTRA_SIZEfor new sets.
- Use the current maximum number of intervals in the live array.Reported-by Chris Arges <[email protected]>Fixes 7e43e0a1141d ("netfilter: nft_set_rbtree: translate rbtree to array for binary search")Signed-off-by Pablo Neira Ayuso <[email protected]>---
v2: fix crash with new sets, reported by Florian.net/netfilter/nft_set_rbtree.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-)net/netfilter/nft_set_rbtree.c +6
-1@@ -646,7 +646,12 @@ static int nft_array_may_resize(const struct nft_set *set)struct nft_array *array;if (!priv->array_next) { - array =nft_array_alloc (nelems +NFT_ARRAY_EXTRA_SIZE ); +if (priv->array) + new_max_intervals = priv->array->max_intervals; +else + new_max_intervals =NFT_ARRAY_EXTRA_SIZE ; + + array =nft_array_alloc (new_max_intervals);if (!array)return -ENOMEM ;Signature · 1 line
2.47.3