]> git.ipfire.org Git - thirdparty/freeradius-server.git/commitdiff
Hack in stack over-allocation for OpenSSL async contexts
authorArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 28 Mar 2022 17:28:37 +0000 (11:28 -0600)
committerArran Cudbard-Bell <a.cudbardb@freeradius.org>
Mon, 28 Mar 2022 17:28:37 +0000 (11:28 -0600)
src/lib/tls/base.c

index fe5f8624e873a7cd5e410201a4abfe913befc344..c577c2f15b1e3bf9ffd1110105bdb6cc25e53695 100644 (file)
@@ -204,10 +204,37 @@ int fr_tls_max_threads = 1;
  * @param len to alloc.
  * @return realloc.
  */
-static void *fr_openssl_talloc(size_t len, NDEBUG_UNUSED char const *file, NDEBUG_UNUSED int line)
+static void *fr_openssl_talloc(size_t len, char const *file, NDEBUG_UNUSED int line)
 {
+       static char const *async_file;
        void *chunk;
 
+       /*
+        *      Cache the filename pointer for the async_posix.c
+        *      source file, so we can figure out when we're
+        *      being asked for stack memory.
+        *
+        *      This is terrible, we're basically guessing at the
+        *      stack size.  OpenSSL 3.1.0 will have proper
+        *      allocation functions so we can something more
+        *      sensible.
+        */
+       if (!async_file) {
+               char const *sep;
+
+               sep = strrchr(file, '/');
+               if (!sep) {
+                       sep = file;
+               } else {
+                       sep++;
+               }
+               if (strcmp(sep, "async_posix.c") == 0) {
+                       async_file = file;
+               alloc_stack:
+                       len *= 4;
+               }
+       } else if (file == async_file) goto alloc_stack;
+
        chunk = talloc_array(ssl_talloc_ctx, uint8_t, len);
 #ifndef NDEBUG
        talloc_set_name(chunk, "%s:%u", file, line);