netfilter: nf_tables: handle more than 8 * PAGE_SIZE set name allocations
Subsystems (2)
PATCH 1/1 netfilter: nf_tables: handle more than 8 * PAGE_SIZE set name allocations
We currently have a limit of 8 * PAGE_SIZE anonymous sets. Lift that limit by continuing the scan if the entire page is exhausted.
--- net/netfilter/nf_tables_api.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)
net/netfilter/nf_tables_api.c +10 -5
@@ -2004,7 +2004,7 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set,const struct nft_set *i;const char *p;unsigned long *inuse; -unsigned int n =0 ; +unsigned int n =0 , min =0 ; p =strnchr (name,IFNAMSIZ ,'%' );if (p !=NULL ) {
@@ -2014,23 +2014,28 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set, inuse = (unsigned long *)get_zeroed_page (GFP_KERNEL );if (inuse ==NULL )return -ENOMEM ; - +cont:list_for_each_entry (i, &ctx->table->sets, list) {int tmp;if (!sscanf (i->name, name, &tmp))continue ; -if (tmp <0 || tmp >=BITS_PER_BYTE *PAGE_SIZE ) +if (tmp < min || tmp >= min +BITS_PER_BYTE *PAGE_SIZE )continue ; -set_bit (tmp, inuse); +set_bit (tmp - min, inuse); } n =find_first_zero_bit (inuse,BITS_PER_BYTE *PAGE_SIZE ); +if (n >=BITS_PER_BYTE *PAGE_SIZE ) { + min +=BITS_PER_BYTE *PAGE_SIZE ; +memset (inuse,0 ,PAGE_SIZE ); + goto cont; + }free_page ((unsigned long )inuse); } -snprintf (set->name,sizeof (set->name), name, n); +snprintf (set->name,sizeof (set->name), name, min + n);list_for_each_entry (i, &ctx->table->sets, list) {if (!strcmp (set->name, i->name))return -ENFILE ;
Signature · 1 line
1.8.5.3
Pablo Neira Ayuso
maintainerQuoted 24 lines · Patrick McHardy
We currently have a limit of 8 *
PAGE_SIZEanonymous sets. Lift that limit by continuing the scan if the entire page is exhausted.Signed-off-by Patrick McHardy <[email protected]>--- net/netfilter/nf_tables_api.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)net/netfilter/nf_tables_api.c +1
-1@@ -2004,7 +2004,7 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set,const struct nft_set *i;const char *p;unsigned long *inuse; -unsigned int n =0 ; +unsigned int n =0 , min =0 ; p =strnchr (name,IFNAMSIZ ,'%' );if (p !=NULL ) {@@ -2014,23 +2014,28 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set, inuse = (unsigned long *)get_zeroed_page (GFP_KERNEL );if (inuse ==NULL )
net/netfilter/nf_tables_api.c static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set, · line 2023
Quoted 10 lines
net/netfilter/nf_tables_api.c +2
-2return -ENOMEM ; - +cont:list_for_each_entry (i, &ctx->table->sets, list) {int tmp;if (!sscanf (i->name, name, &tmp))continue ; -if (tmp <0 || tmp >=BITS_PER_BYTE *PAGE_SIZE ) +if (tmp < min || tmp >= min +BITS_PER_BYTE *PAGE_SIZE )
I think we can break looping if tmp >= min + BITS_PER_BYTE * PAGE_SIZE fulfills (assuming the list of sets is ordered).
net/netfilter/nf_tables_api.c static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set, · line 2033
Quoted 11 lines
net/netfilter/nf_tables_api.c +5
-1continue ; -set_bit (tmp, inuse); +set_bit (tmp - min, inuse); } n =find_first_zero_bit (inuse,BITS_PER_BYTE *PAGE_SIZE ); +if (n >=BITS_PER_BYTE *PAGE_SIZE ) { + min +=BITS_PER_BYTE *PAGE_SIZE ; +memset (inuse,0 ,PAGE_SIZE ); + goto cont;
If the page is full, we start iterating over the set list from the beginning.
Quoted 12 lines
net/netfilter/nf_tables_api.c +2
-1+ }free_page ((unsigned long )inuse); } -snprintf (set->name,sizeof (set->name), name, n); +snprintf (set->name,sizeof (set->name), name, min + n);list_for_each_entry (i, &ctx->table->sets, list) {if (!strcmp (set->name, i->name))return -ENFILE ;Signature · 1 line
1.8.5.3
Quoted 31 lines · Pablo Neira Ayuso
Quoted 30 lines · Patrick McHardy
We currently have a limit of 8 *
PAGE_SIZEanonymous sets. Lift that limit by continuing the scan if the entire page is exhausted.Signed-off-by Patrick McHardy <[email protected]>--- net/netfilter/nf_tables_api.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)net/netfilter/nf_tables_api.c +2
-2@@ -2004,7 +2004,7 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set,const struct nft_set *i;const char *p;unsigned long *inuse; -unsigned int n =0 ; +unsigned int n =0 , min =0 ; p =strnchr (name,IFNAMSIZ ,'%' );if (p !=NULL ) {@@ -2014,23 +2014,28 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set, inuse = (unsigned long *)get_zeroed_page (GFP_KERNEL );if (inuse ==NULL )return -ENOMEM ; - +cont:list_for_each_entry (i, &ctx->table->sets, list) {int tmp;
Quoted 7 lines
net/netfilter/nf_tables_api.c static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set, · line 2023
Quoted 4 lines
net/netfilter/nf_tables_api.c +1
-1if (!sscanf (i->name, name, &tmp))continue ; -if (tmp <0 || tmp >=BITS_PER_BYTE *PAGE_SIZE ) +if (tmp < min || tmp >= min +BITS_PER_BYTE *PAGE_SIZE )I think we can break looping if tmp >= min +
BITS_PER_BYTE*PAGE_SIZEfulfills (assuming the list of sets is ordered).
It's not, we really need to continue here.
Quoted 7 lines
Quoted 7 lines
net/netfilter/nf_tables_api.c +1
-1continue ; -set_bit (tmp, inuse); +set_bit (tmp - min, inuse); }
Quoted 8 lines
net/netfilter/nf_tables_api.c static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set, · line 2033
Quoted 5 lines
net/netfilter/nf_tables_api.c +4
-0n =find_first_zero_bit (inuse,BITS_PER_BYTE *PAGE_SIZE ); +if (n >=BITS_PER_BYTE *PAGE_SIZE ) { + min +=BITS_PER_BYTE *PAGE_SIZE ; +memset (inuse,0 ,PAGE_SIZE ); + goto cont;If the page is full, we start iterating over the set list from the beginning.
Yes, also necessary since the list is not ordered. We always pick the first free set name and add it at the end.
Quoted 13 lines
Quoted 13 lines
net/netfilter/nf_tables_api.c +2
-1+ }free_page ((unsigned long )inuse); } -snprintf (set->name,sizeof (set->name), name, n); +snprintf (set->name,sizeof (set->name), name, min + n);list_for_each_entry (i, &ctx->table->sets, list) {if (!strcmp (set->name, i->name))return -ENFILE ;Signature · 1 line
1.8.5.3
Pablo Neira Ayuso
maintainerQuoted 58 lines · Patrick McHardy
Quoted 31 lines · Pablo Neira Ayuso
Quoted 30 lines · Patrick McHardy
We currently have a limit of 8 *
PAGE_SIZEanonymous sets. Lift that limit by continuing the scan if the entire page is exhausted.Signed-off-by Patrick McHardy <[email protected]>--- net/netfilter/nf_tables_api.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-)net/netfilter/nf_tables_api.c +2
-2@@ -2004,7 +2004,7 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set,const struct nft_set *i;const char *p;unsigned long *inuse; -unsigned int n =0 ; +unsigned int n =0 , min =0 ; p =strnchr (name,IFNAMSIZ ,'%' );if (p !=NULL ) {@@ -2014,23 +2014,28 @@ static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set, inuse = (unsigned long *)get_zeroed_page (GFP_KERNEL );if (inuse ==NULL )return -ENOMEM ; - +cont:list_for_each_entry (i, &ctx->table->sets, list) {int tmp;Quoted 7 lines
net/netfilter/nf_tables_api.c static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set, · line 2023
Quoted 4 lines
net/netfilter/nf_tables_api.c +1
-1if (!sscanf (i->name, name, &tmp))continue ; -if (tmp <0 || tmp >=BITS_PER_BYTE *PAGE_SIZE ) +if (tmp < min || tmp >= min +BITS_PER_BYTE *PAGE_SIZE )I think we can break looping if tmp >= min +
BITS_PER_BYTE*PAGE_SIZEfulfills (assuming the list of sets is ordered).It's not, we really need to continue here.
Quoted 7 lines
Quoted 7 lines
net/netfilter/nf_tables_api.c +1
-1continue ; -set_bit (tmp, inuse); +set_bit (tmp - min, inuse); }Quoted 8 lines
net/netfilter/nf_tables_api.c static int nf_tables_set_alloc_name(struct nft_ctx *ctx, struct nft_set *set, · line 2033
Quoted 5 lines
net/netfilter/nf_tables_api.c +4
-0n =find_first_zero_bit (inuse,BITS_PER_BYTE *PAGE_SIZE ); +if (n >=BITS_PER_BYTE *PAGE_SIZE ) { + min +=BITS_PER_BYTE *PAGE_SIZE ; +memset (inuse,0 ,PAGE_SIZE ); + goto cont;If the page is full, we start iterating over the set list from the beginning.
Quoted 2 lines
Yes, also necessary since the list is not ordered. We always pick the first free set name and add it at the end.
Right, I misunderstood the logic behind the patch. I'll push this patch, thanks Patrick.