misc: binary api fuzz test fixes

Add a hook to src/vlibapi/api_shared.c to fuzz (screw up) binary API
messages, e.g. by xoring random data into them before processing. We
specifically exempt client connection messages, and inband debug CLI
messages. We step over msg_id, client index, client context, and
sw_if_index. Otherwise, "make test" vectors fail too rapidly to learn
anything.

The goal is to reduce the number of crashes caused to zero. We're
fairly close with this patch.

Add vl_msg_api_max_length(void *mp), which returns the maximum
plausible length for a binary API message.

Use it to hardern vl_api_from_api_to_new_vec(...) which takes an
additional argument - message pointer - so it can verify that
astr->length is sane. If it's not sane, return a u8 *vector of the
form "insane astr->length nnnn\0".

Verify array lengths in vl_api_dhcp6_send_client_message_t_handler(...)
and vl_api_dhcp6_pd_send_client_message_t_handler(...).

Add a fairly effective binary API fuzz hook to the unittest plugin,
and modify the "make test" framework.py to pass "api-fuzz { on|off }"
to enable API fuzzing: "make API_FUZZ=on TEST=xxx test-debug" or similar

Type: improvement

Signed-off-by: Dave Barach <dave@barachs.net>
Change-Id: I0157267652a163c01553d5267620f719cc6c3bde
This commit is contained in:
Dave Barach
2020-04-29 17:04:10 -04:00
committed by Florin Coras
parent d88fc0fced
commit 7784140f2b
19 changed files with 259 additions and 23 deletions

View File

@@ -1165,7 +1165,7 @@ vl_api_cli_inband_reply_t_handler (vl_api_cli_inband_reply_t * mp)
vam->retval = retval;
if (retval == 0)
vam->cmd_reply = vl_api_from_api_to_new_vec (&mp->reply);
vam->cmd_reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
vam->result_ready = 1;
}
@@ -1176,7 +1176,7 @@ vl_api_cli_inband_reply_t_handler_json (vl_api_cli_inband_reply_t * mp)
vat_json_node_t node;
u8 *reply = 0; /* reply vector */
reply = vl_api_from_api_to_new_vec (&mp->reply);
reply = vl_api_from_api_to_new_vec (mp, &mp->reply);
vec_reset_length (vam->cmd_reply);
vat_json_init_object (&node);