Skip to content

Commit bc3bd59

Browse files
committed
netfilter: nf_tables: fix out of memory error handling
jira VULN-597 subsystem-sync netfilter:nf_tables 4.18.0-534 commit-author Florian Westphal <fw@strlen.de> commit 5e1be4c upstream-diff Using the 4.18.0-534 code as an example. Several instances of pipapo_resize() don't propagate allocation failures, this causes a crash when fault injection is enabled for gfp_kernel slabs. Fixes: 3c4287f ("nf_tables: Add set type for arbitrary concatenation of ranges") Signed-off-by: Florian Westphal <fw@strlen.de> Reviewed-by: Stefano Brivio <sbrivio@redhat.com> (cherry picked from commit 5e1be4c) Signed-off-by: Greg Rose <g.v.rose@ciq.com>
1 parent 873d89f commit bc3bd59

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

net/netfilter/nft_set_pipapo.c

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -850,12 +850,14 @@ static void pipapo_bucket_set(struct nft_pipapo_field *f, int rule, int group,
850850
static int pipapo_insert(struct nft_pipapo_field *f, const uint8_t *k,
851851
int mask_bits)
852852
{
853-
int rule = f->rules++, group, ret;
853+
int rule = f->rules, group, ret;
854854

855-
ret = pipapo_resize(f, f->rules - 1, f->rules);
855+
ret = pipapo_resize(f, f->rules, f->rules + 1);
856856
if (ret)
857857
return ret;
858858

859+
f->rules++;
860+
859861
for (group = 0; group < f->groups; group++) {
860862
int i, v;
861863
u8 mask;
@@ -995,7 +997,9 @@ static int pipapo_expand(struct nft_pipapo_field *f,
995997
step++;
996998
if (step >= len) {
997999
if (!masks) {
998-
pipapo_insert(f, base, 0);
1000+
err = pipapo_insert(f, base, 0);
1001+
if (err < 0)
1002+
return err;
9991003
masks = 1;
10001004
}
10011005
goto out;
@@ -1151,6 +1155,9 @@ static int nft_pipapo_insert(const struct net *net, const struct nft_set *set,
11511155
f->groups * NFT_PIPAPO_GROUP_BITS);
11521156
}
11531157

1158+
if (ret < 0)
1159+
return ret;
1160+
11541161
if (f->bsize > bsize_max)
11551162
bsize_max = f->bsize;
11561163

0 commit comments

Comments
 (0)