From 053e11f397f3f890c52a1add6aa4e75a9178eba0 Mon Sep 17 00:00:00 2001 From: John Brooks Date: Sat, 25 Apr 2015 22:52:35 -0600 Subject: [PATCH 1/3] Fix out-of-bounds read in INTRODUCE2 client auth The length of auth_data from an INTRODUCE2 cell is checked when the auth_type is recognized (1 or 2), but not for any other non-zero auth_type. Later, auth_data is assumed to have at least REND_DESC_COOKIE_LEN bytes, leading to a client-triggered out of bounds read. Fixed by checking auth_len before comparing the descriptor cookie against known clients. Fixes #15823; bugfix on 0.2.1.6-alpha. --- changes/bug15823 | 4 ++++ src/or/rendservice.c | 18 ++++++++++++++---- 2 files changed, 18 insertions(+), 4 deletions(-) create mode 100644 changes/bug15823 diff --git a/changes/bug15823 b/changes/bug15823 new file mode 100644 index 000000000..987de5d9a --- /dev/null +++ b/changes/bug15823 @@ -0,0 +1,4 @@ + o Minor bugfixes (hidden service): + - Fix an out-of-bounds read when parsing invalid INTRODUCE2 cells + on a client authorized hidden service. Fixes bug 15823; bugfix + on 0.2.1.6-alpha. diff --git a/src/or/rendservice.c b/src/or/rendservice.c index 436f2f4b6..0a5456739 100644 --- a/src/or/rendservice.c +++ b/src/or/rendservice.c @@ -939,11 +939,13 @@ rend_service_requires_uptime(rend_service_t *service) return 0; } -/** Check client authorization of a given descriptor_cookie for - * service. Return 1 for success and 0 for failure. */ +/** Check client authorization of a given descriptor_cookie of + * length cookie_len for service. Return 1 for success + * and 0 for failure. */ static int rend_check_authorization(rend_service_t *service, - const char *descriptor_cookie) + const char *descriptor_cookie, + size_t cookie_len) { rend_authorized_client_t *auth_client = NULL; tor_assert(service); @@ -954,6 +956,13 @@ rend_check_authorization(rend_service_t *service, return 0; } + if (cookie_len != REND_DESC_COOKIE_LEN) { + log_info(LD_REND, "Descriptor cookie is %lu bytes, but we expected " + "%lu bytes. Dropping cell.", + (unsigned long)cookie_len, (unsigned long)REND_DESC_COOKIE_LEN); + return 0; + } + /* Look up client authorization by descriptor cookie. */ SMARTLIST_FOREACH(service->clients, rend_authorized_client_t *, client, { if (tor_memeq(client->descriptor_cookie, descriptor_cookie, @@ -1300,7 +1309,8 @@ rend_service_introduce(origin_circuit_t *circuit, const uint8_t *request, if (service->clients) { if (parsed_req->version == 3 && parsed_req->u.v3.auth_len > 0) { if (rend_check_authorization(service, - (const char*)parsed_req->u.v3.auth_data)) { + (const char*)parsed_req->u.v3.auth_data, + parsed_req->u.v3.auth_len)) { log_info(LD_REND, "Authorization data in INTRODUCE2 cell are valid."); } else { log_info(LD_REND, "The authorization data that are contained in " From fb7d1f41b409761be3381efaeec0f56d2a470a9f Mon Sep 17 00:00:00 2001 From: "teor (Tim Wilson-Brown)" Date: Tue, 19 Jan 2016 11:22:58 +1100 Subject: [PATCH 2/3] Make memwipe() do nothing when passed a NULL pointer or zero size Check size argument to memwipe() for underflow. Closes bug #18089. Reported by "gk", patch by "teor". Bugfix on 0.2.3.25 and 0.2.4.6-alpha (#7352), commit 49dd5ef3 on 7 Nov 2012. --- changes/bug18089 | 6 ++++++ src/common/crypto.c | 8 ++++++++ 2 files changed, 14 insertions(+) create mode 100644 changes/bug18089 diff --git a/changes/bug18089 b/changes/bug18089 new file mode 100644 index 000000000..c1fb342f7 --- /dev/null +++ b/changes/bug18089 @@ -0,0 +1,6 @@ + o Minor fixes (security): + - Make memwipe() do nothing when passed a NULL pointer + or zero size. Check size argument to memwipe() for underflow. + Closes bug #18089. Reported by "gk", patch by "teor". + Bugfix on 0.2.3.25 and 0.2.4.6-alpha (#7352), + commit 49dd5ef3 on 7 Nov 2012. diff --git a/src/common/crypto.c b/src/common/crypto.c index 925beb352..f91391780 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -2972,6 +2972,7 @@ secret_to_key(char *key_out, size_t key_out_len, const char *secret, /** * Destroy the sz bytes of data stored at mem, setting them to * the value byte. + * If mem is NULL or sz is zero, nothing happens. * * This function is preferable to memset, since many compilers will happily * optimize out memset() when they can convince themselves that the data being @@ -2989,6 +2990,13 @@ secret_to_key(char *key_out, size_t key_out_len, const char *secret, void memwipe(void *mem, uint8_t byte, size_t sz) { + if (mem == NULL || sz == 0) { + return; + } + + /* Data this large is likely to be an underflow. */ + tor_assert(sz < SIZE_T_CEILING); + /* Because whole-program-optimization exists, we may not be able to just * have this function call "memset". A smart compiler could inline it, then * eliminate dead memsets, and declare itself to be clever. */ From 6cb8c0fd4e9c544710b1ad72a695feb87a1d7ee7 Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Tue, 19 Jan 2016 08:28:58 -0500 Subject: [PATCH 3/3] Refine the memwipe() arguments check for 18089 a little more. We still silently ignore memwipe(NULL, ch, 0); and memwipe(ptr, ch, 0); /* for ptr != NULL */ But we now assert on: memwipe(NULL, ch, 30); --- src/common/crypto.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/common/crypto.c b/src/common/crypto.c index f91391780..522c1375c 100644 --- a/src/common/crypto.c +++ b/src/common/crypto.c @@ -2990,9 +2990,11 @@ secret_to_key(char *key_out, size_t key_out_len, const char *secret, void memwipe(void *mem, uint8_t byte, size_t sz) { - if (mem == NULL || sz == 0) { + if (sz == 0) { return; } + /* If sz is nonzero, then mem must not be NULL. */ + tor_assert(mem != NULL); /* Data this large is likely to be an underflow. */ tor_assert(sz < SIZE_T_CEILING);