evaluate: fix crash when set name is null
Florian Westphal
maintainerPATCH 1/1 evaluate: fix crash when set name is null
Bogon provides a handle but not a name.
--- src/cache.c | 3 +++ src/evaluate.c | 3 +++ tests/shell/testcases/bogons/nft-f/null_set_name_crash | 2 ++ 3 files changed, 8 insertions(+) create mode 100644 tests/shell/testcases/bogons/nft-f/null_set_name_crash
src/cache.c +3 -0
@@ -840,6 +840,9 @@ struct set *set_cache_find(const struct table *table, const char *name)struct set *set;uint32_t hash; +if (!name) +return NULL ; + hash =djb_hash (name) %NFT_CACHE_HSIZE ;list_for_each_entry (set, &table->set_cache.ht[hash], cache.hlist) {if (!strcmp (set->handle.set.name, name))
src/evaluate.c +3 -0
@@ -284,6 +284,9 @@ static int set_not_found(struct eval_ctx *ctx, const struct location *loc,const struct table *table;struct set *set; +if (!set_name) + set_name ="" ; + set =set_lookup_fuzzy (set_name, &ctx->nft->cache, &table);if (set ==NULL )return cmd_error (ctx, loc,"%s" ,strerror (ENOENT ));
tests/shell/testcases/bogons/nft-f/null_set_name_crash new file +2 -0
@@ -0,0 +1,2 @@ +table y { } +reset set y handle 6
Signature · 1 line
2.49.0
Pablo Neira Ayuso
maintainerQuoted 1 line · Florian Westphal
Bogon provides a handle but not a name.
No handle for delete map command:
| SET set_or_id_spec
{
$$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SET, &$2, &@$, NULL);
}
| MAP set_spec
^^^^^^^^This is incomplete:
f4a34d25f6d5 ("src: list set handle and delete set via set handle")
but this is also lacking handle support:
745e51d0b8f0 ("evaluate: remove set from cache on delete set command")
Then, reset command parser looks consistent:
83e0f4402fb7 ("Implement 'reset {set,map,element}' commands")
but cmd_evaluate_reset() calls cmd_evaluate_list() which cannot deal with the handle.
Looking at delete command for other objects, same issue, eg. chain_del_cache() also does not deal with this handle.
I think the way to go is to add another hashtable to look up for object handles, I can post a patch for this purpose.
Quoted 48 lines
Signed-off-by Florian Westphal <[email protected]>--- src/cache.c | 3 +++ src/evaluate.c | 3 +++ tests/shell/testcases/bogons/nft-f/null_set_name_crash | 2 ++ 3 files changed, 8 insertions(+) create mode 100644 tests/shell/testcases/bogons/nft-f/null_set_name_crashsrc/cache.c +3
-0@@ -840,6 +840,9 @@ struct set *set_cache_find(const struct table *table, const char *name)struct set *set;uint32_t hash; +if (!name) +return NULL ; + hash =djb_hash (name) %NFT_CACHE_HSIZE ;list_for_each_entry (set, &table->set_cache.ht[hash], cache.hlist) {if (!strcmp (set->handle.set.name, name))src/evaluate.c +3
-0@@ -284,6 +284,9 @@ static int set_not_found(struct eval_ctx *ctx, const struct location *loc,const struct table *table;struct set *set; +if (!set_name) + set_name ="" ; + set =set_lookup_fuzzy (set_name, &ctx->nft->cache, &table);if (set ==NULL )return cmd_error (ctx, loc,"%s" ,strerror (ENOENT ));tests/shell/testcases/bogons/nft-f/null_set_name_crash new file +2
-0@@ -0,0 +1,2 @@ +table y { } +reset set y handle 6Signature · 1 line
2.49.0
Pablo Neira Ayuso
maintainerQuoted 24 lines · Pablo Neira Ayuso
Quoted 1 line · Florian Westphal
Bogon provides a handle but not a name.
No handle for delete map command:
| SET set_or_id_spec { $$ = cmd_alloc(CMD_DELETE, CMD_OBJ_SET, &$2, &@$, NULL); } | MAP set_spec ^^^^^^^^This is incomplete:
f4a34d25f6d5("src: list set handle and delete set via set handle")but this is also lacking handle support:
745e51d0b8f0("evaluate: remove set from cache on delete set command")Then, reset command parser looks consistent:
83e0f4402fb7("Implement 'reset {set,map,element}' commands")
Quoted 8 lines
but
cmd_evaluate_reset()callscmd_evaluate_list()which cannot deal with the handle.Looking at delete command for other objects, same issue, eg.
chain_del_cache()also does not deal with this handle.I think the way to go is to add another hashtable to look up for object handles, I can post a patch for this purpose.
I started extending userspace to improve support for handles but it turns out that kernel is missing a few bits for lookup by handle in get/reset commands.
So I am only fixing this in a series by now.