From 3d7fae761e65e9d0f16d7247ee8a464d4fe002da Mon Sep 17 00:00:00 2001 From: Daiki Ueno Date: Tue, 2 Jun 2020 21:45:17 +0200 Subject: valgrind: check if session ticket key is used without initialization This adds a valgrind client request for session->key.session_ticket_key to make sure that it is not used without initialization. Signed-off-by: Daiki Ueno --- lib/state.c | 5 ++++- lib/stek.c | 8 ++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/state.c b/lib/state.c index 8ba2cc4a32..7d0a77dc95 100644 --- a/lib/state.c +++ b/lib/state.c @@ -578,9 +578,12 @@ int gnutls_init(gnutls_session_t * session, unsigned int flags) if (flags & GNUTLS_CLIENT) VALGRIND_MAKE_MEM_UNDEFINED((*session)->security_parameters.client_random, GNUTLS_RANDOM_SIZE); - if (flags & GNUTLS_SERVER) + if (flags & GNUTLS_SERVER) { VALGRIND_MAKE_MEM_UNDEFINED((*session)->security_parameters.server_random, GNUTLS_RANDOM_SIZE); + VALGRIND_MAKE_MEM_UNDEFINED((*session)->key.session_ticket_key, + TICKET_MASTER_KEY_SIZE); + } } #endif handshake_internal_state_clear1(*session); diff --git a/lib/stek.c b/lib/stek.c index 5ab9e7d2d1..316555b49a 100644 --- a/lib/stek.c +++ b/lib/stek.c @@ -21,6 +21,9 @@ */ #include "gnutls_int.h" #include "stek.h" +#ifdef HAVE_VALGRIND_MEMCHECK_H +#include +#endif #define NAME_POS (0) #define KEY_POS (TICKET_KEY_NAME_SIZE) @@ -143,6 +146,11 @@ static int rotate(gnutls_session_t session) call_rotation_callback(session, key, t); session->key.totp.last_result = t; memcpy(session->key.session_ticket_key, key, sizeof(key)); +#ifdef HAVE_VALGRIND_MEMCHECK_H + if (RUNNING_ON_VALGRIND) + VALGRIND_MAKE_MEM_DEFINED(session->key.session_ticket_key, + TICKET_MASTER_KEY_SIZE); +#endif session->key.totp.was_rotated = 1; } else if (t < 0) { -- cgit v1.2.1