json: reject too long interface names
Florian Westphal
maintainerPATCH 1/1 json: reject too long interface names
Blamed commit added a length check on ifnames to the bison parser. Unfortunately that wasn't enough, json parser has the same issue.
Bogon results in:
BUG: Interface length 44 exceeds limit
nft: src/mnl.c:742: nft_dev_add: Assertion `0' failed.
After patch, included bogon results in:
Error: Invalid device at index 0. name d2345678999999999999999999999999999999012345 too long
I intentionally did not extend evaluate.c to catch this, past sentiment was that frontends should not send garbage.
I'll send a followup patch to also catch this from eval stage in case there are further reports for frontends passing in such long names.
--- src/parser_json.c | 17 +++- .../nft-j-f/dev_name_parser_overflow_crash | 90 +++++++++++++++++++ 2 files changed, 105 insertions(+), 2 deletions(-) create mode 100644 tests/shell/testcases/bogons/nft-j-f/dev_name_parser_overflow_crash
src/parser_json.c +15 -2
@@ -2951,7 +2951,13 @@ static struct expr *json_parse_devs(struct json_ctx *ctx, json_t *root)size_t index;if (!json_unpack (root,"s" , &dev)) { - tmp =constant_expr_alloc (int_loc, &string_type, +if (strlen (dev) >=IFNAMSIZ ) { +json_error (ctx,"Device name %s too long" , dev); +expr_free (expr); +return NULL ; + } + + tmp =constant_expr_alloc (int_loc, &ifname_type,BYTEORDER_HOST_ENDIAN ,strlen (dev) *BITS_PER_BYTE , dev);compound_expr_add (expr, tmp);
@@ -2969,7 +2975,14 @@ static struct expr *json_parse_devs(struct json_ctx *ctx, json_t *root)expr_free (expr);return NULL ; } - tmp =constant_expr_alloc (int_loc, &string_type, + +if (strlen (dev) >=IFNAMSIZ ) { +json_error (ctx,"Device name %s too long at index %zu" , dev, index); +expr_free (expr); +return NULL ; + } + + tmp =constant_expr_alloc (int_loc, &ifname_type,BYTEORDER_HOST_ENDIAN ,strlen (dev) *BITS_PER_BYTE , dev);compound_expr_add (expr, tmp);
tests/shell/testcases/bogons/nft-j-f/dev_name_parser_overflow_crash new file +90 -0
90 lines not on this page · raw message
Signature · 1 line
2.49.0
Quoted 10 lines · Florian Westphal
Blamed commit added a length check on ifnames to the bison parser. Unfortunately that wasn't enough, json parser has the same issue.
Bogon results in:
BUG: Interface length 44 exceeds limitnft:
src/mnl.c:742:nft_dev_add: Assertion `0' failed.After patch, included bogon results in:
Error: Invalid device at index 0. named2345678999999999999999999999999999999012345too long
Quoted 8 lines
I intentionally did not extend
evaluate.cto catch this, past sentiment was that frontends should not send garbage.I'll send a followup patch to also catch this from eval stage in case there are further reports for frontends passing in such long names.
Fixes fa52bc225806 ("parser: reject zero-length interface names")Signed-off-by Florian Westphal <[email protected]>