json: make sure timeout list is initialised
Florian Westphal
maintainerPATCH 1/1 json: make sure timeout list is initialised
On parser error, obj_free will iterate this list. Included json bogon crashes due to null deref because list head initialisation did not yet happen.
Fixes c82a26ebf7e9 ("json: Add ct timeout support")
Signed-off-by Florian Westphal <[email protected]>
--- src/parser_json.c | 2 +- tests/shell/testcases/bogons/assert_failures | 35 +++++++++--- .../bogons/nft-j-f/ct_timeout_null_crash | 54 +++++++++++++++++++ 3 files changed, 84 insertions(+), 7 deletions(-) create mode 100644 tests/shell/testcases/bogons/nft-j-f/ct_timeout_null_crash
src/parser_json.c +1 -1
@@ -3722,6 +3722,7 @@ static struct cmd *json_parse_cmd_add_object(struct json_ctx *ctx,break ;case NFT_OBJECT_CT_TIMEOUT : cmd_obj =CMD_OBJ_CT_TIMEOUT ; +init_list_head (&obj->ct_timeout.timeout_list); obj->type =NFT_OBJECT_CT_TIMEOUT ;if (!json_unpack (root,"{s:s}" ,"protocol" , &tmp)) {if (!strcmp (tmp,"tcp" )) {
@@ -3740,7 +3741,6 @@ static struct cmd *json_parse_cmd_add_object(struct json_ctx *ctx, } obj->ct_timeout.l3proto = l3proto; -init_list_head (&obj->ct_timeout.timeout_list);if (json_parse_ct_timeout_policy (ctx, root, obj)) goto err_free_obj;break ;
tests/shell/testcases/bogons/assert_failures +29 -6
@@ -1,6 +1,8 @@ #!/bin/bash dir=$(dirname $0)/nft-f/ +jsondir=$(dirname $0)/nft-j-f/ + tmpfile=$(mktemp) cleanup()
@@ -10,18 +12,39 @@ cleanup() trap cleanup EXIT -for f in $dir/*; do - echo "Check $f" - $NFT --check -f "$f" 2> "$tmpfile" +die_on_error() +{ + local rv="$1" + local fname="$2" - if [ $? -ne 1 ]; then - echo "Bogus input file $f did not cause expected error code" 1>&2 + if [ $rv -ne 1 ]; then + echo "Bogus input file $fname did not cause expected error code" 1>&2 exit 111 fi if grep AddressSanitizer "$tmpfile"; then - echo "Address sanitizer splat for $f" 1>&2 + echo "Address sanitizer splat for $fname" 1>&2 cat "$tmpfile" exit 111 fi +} + +for f in $dir/*; do + echo "Check $f" + $NFT --check -f "$f" 2> "$tmpfile" + + die_on_error $? "$f" +done + +if [ "$NFT_TEST_HAVE_json" = "n" ];then + # Intentionally do not skip if we lack json input, + # we ran all the tests that we could. + exit 0 +fi + +for f in $jsondir/*; do + echo "Check json input $f" + $NFT --check -j -f "$f" 2> "$tmpfile" + + die_on_error $? done
tests/shell/testcases/bogons/nft-j-f/ct_timeout_null_crash new file +54 -0
54 lines not on this page · raw message
Signature · 1 line
2.48.1
Quoted 6 lines · Florian Westphal
On parser error,
obj_freewill iterate this list. Included json bogon crashes due to null deref because list head initialisation did not yet happen.Fixes c82a26ebf7e9 ("json: Add ct timeout support")Signed-off-by Florian Westphal <[email protected]>
Reviewed-by Pablo Neira Ayuso <[email protected]>
Thanks