Skip to contentSkip to conversation

tls-crypt: don't leak memory for incorrect tls-crypt messages

PATCH In review Steffan Karger 2 participants 2 messages Aug 16, 2017 – Sep 6, 2017

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tls-crypt: don't leak memory for incorrect tls-crypt messages

If tls_crypt_unwrap() failed, we would jump to cleanup and forget to free the buffer. Instead, allocate the buffer through gc, which is free'd in the cleanup section.

---
 src/openvpn/ssl.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
src/openvpn/ssl.c +2 -2
index 2a476800..806172ea 100644
@@ -1534,7 +1534,7 @@ read_control_auth(struct buffer *buf,
     }
     else if (ctx->mode == TLS_WRAP_CRYPT)
     {
-        struct buffer tmp = alloc_buf(buf_forward_capacity_total(buf));
+        struct buffer tmp = alloc_buf_gc(buf_forward_capacity_total(buf), &gc);
         if (!tls_crypt_unwrap(buf, &tmp, &ctx->opt))
         {
             msg(D_TLS_ERRORS, "TLS Error: tls-crypt unwrapping failed from %s",
@@ -1543,7 +1543,7 @@ read_control_auth(struct buffer *buf,
         }
         ASSERT(buf_init(buf, buf->offset));
         ASSERT(buf_copy(buf, &tmp));
-        free_buf(&tmp);
+        buf_clear(&tmp);
     }
 
     if (ctx->mode == TLS_WRAP_NONE || ctx->mode == TLS_WRAP_AUTH)
Signature · 1 line
2.11.0
#1 lore raw

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA512

ACK. This code looks good. Hard to trigger to fully test it, but it follows the usual coding paterns we have.

Your patch has been applied to the following branches

commit fca89379c53fe2c145db96a5bcd32327c4bcfa78 (master) commit db52b6df6915d38a269bf68767faefd9cebf33bb (release/2.4)

Author: Steffan Karger
Date:   Wed Aug 16 19:04:50 2017 +0200
     tls-crypt: don't leak memory for incorrect tls-crypt messages

     Signed-off-by: Steffan Karger <[email protected]...>
     Acked-by: David Sommerseth <[email protected]...>
     Message-Id: <[email protected]...>
     URL: https://www.mail-archive.com/[email protected]/msg15282.html
     Signed-off-by: David Sommerseth <[email protected]...>

- --
kind regards,

David Sommerseth

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2.0.22 (GNU/Linux)

iQIcBAEBCgAGBQJZsH8VAAoJEIbPlEyWcf3yEPkP/iJBHppjZLB98538ylLYRXZg QaT6ElLrbKr2fI6glC5dc63KUCNRv/oov1hR6RWfmWSEyjjaVj4xwzAt5eXq4us5 kiDvaqdWKQZORaPLMlYm46CC2+UJycgpgm0Nqi71GftSuJ6nbSVhGb/G7FFLkZHK eqeTXq8ApE3XI2cL2DOE8jw6z8l4wYop8EMt4eXRcOJAcc2paby55LdlGkleuqG3 iDD+bF7KNinme5XLgR2ujyOhwJJg+EUycEnwsKB6w3tRK+kfdG0/UG/AoXJiBebX cA5zFBgu5lXIJ1Dhtw8opvjpbt/x2FoVczMiAxNw7hHSv0e6UlNHUhkLHki3xxnj Lhv3/2Zz228VIWkofv41bBNmyXxWaRlNeved9XJNZdGq/flLXEnZYZfxBi5T8UEz gZDRv/k8NeYpgo3rPuwbtQUQ2oBRU0QF15Excm1qmG+7EMWt5/NowOjVD8N5QS9K PQlT4TfkCbTj6BIlCY9ZoMgC3LlM68Jwen/X54/Pa0Nty+BUX+sKxGUYkjWNrt/A E6FhVH+sh4YYdP9942qbXfqpoVgx49puoZVsUGvi+fblc8OtvOfjh4kxKS5JKWDl ozfFJ4kdFJG4LVyniZqm6wCeKOl8G9dULchOcLulKysN0nCGme98XsQogZIwhwWk vko0BRTINgNBTppWMM3W
=KYjg
-----END PGP SIGNATURE-----