From 7784140f2bd2d5ae44f2be1507ac25f102006155 Mon Sep 17 00:00:00 2001 From: Dave Barach Date: Wed, 29 Apr 2020 17:04:10 -0400 Subject: 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 Change-Id: I0157267652a163c01553d5267620f719cc6c3bde --- src/plugins/dhcp/dhcp_api.c | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'src/plugins/dhcp') diff --git a/src/plugins/dhcp/dhcp_api.c b/src/plugins/dhcp/dhcp_api.c index a5163ca2e95..d2e423572fb 100644 --- a/src/plugins/dhcp/dhcp_api.c +++ b/src/plugins/dhcp/dhcp_api.c @@ -549,6 +549,12 @@ void params.T1 = ntohl (mp->T1); params.T2 = ntohl (mp->T2); n_addresses = ntohl (mp->n_addresses); + /* Make sure that the number of addresses is sane */ + if (n_addresses * sizeof (params.addresses) > vl_msg_api_max_length (mp)) + { + rv = VNET_API_ERROR_INVALID_VALUE; + goto bad_sw_if_index; + } params.addresses = 0; if (n_addresses > 0) vec_validate (params.addresses, n_addresses - 1); @@ -593,6 +599,14 @@ void params.T1 = ntohl (mp->T1); params.T2 = ntohl (mp->T2); n_prefixes = ntohl (mp->n_prefixes); + + /* Minimal check to see that the number of prefixes is sane */ + if (n_prefixes * sizeof (params.prefixes) > vl_msg_api_max_length (mp)) + { + rv = VNET_API_ERROR_INVALID_VALUE; + goto bad_sw_if_index; + } + params.prefixes = 0; if (n_prefixes > 0) vec_validate (params.prefixes, n_prefixes - 1); -- cgit 1.2.3-korg