Commit 79cec18086 for openssl.org

commit 79cec180862cec7e22c36aba1744b36e48e39e8e
Author: Daiki Ueno <dueno@redhat.com>
Date:   Sat Jul 11 21:36:43 2026 +0900

    Support USDT probes compatible with crypto-auditing

    This adds an infrastructure for instrumenting the library with USDT
    probes compatible with the crypto-auditing project[1], which enables
    real-time monitoring of cryptography-related events utilizing eBPF.

    1. https://github.com/latchset/crypto-auditing

    Signed-off-by: Daiki Ueno <dueno@redhat.com>
    Co-authored-by: Clemens Lang <cllang@redhat.com>

    Reviewed-by: Mounir Idrassi <mounir.idrassi@idrix.fr>
    Reviewed-by: Dmitry Belyavskiy <beldmit@gmail.com>
    MergeDate: Sat Nov 21 14:48:28 2026
    (Merged from https://github.com/openssl/openssl/pull/32538)

diff --git a/Configure b/Configure
index 63c98246d6..7996c92d05 100755
--- a/Configure
+++ b/Configure
@@ -524,6 +524,7 @@ my @disablables_features = (
     "buildtest-c++",
     "bulk",
     "cached-fetch",
+    "usdt",
     "dgram",
     "winstore",
     "crypto-mdebug",
@@ -2080,6 +2081,23 @@ unless ($disabled{"unit-tests"}) {
     }
 }

+unless ($disabled{usdt}) {
+    my $cc = $config{CROSS_COMPILE}.$config{CC};
+    # eBPF USDT probes are defined using the DTRACE_PROBE* macros
+    # defined in <sys/sdt.h>. Some platforms including macOS and
+    # FreeBSD have this header as well, though they are incompatible
+    # with USDT probes. Restrict the support for Linux only for now.
+    if ($target =~ m/^linux/) {
+	system("printf '#include <sys/sdt.h>\n' | $cc -E - >/dev/null 2>&1");
+	if ($? != 0) {
+	    disable('no-sys-sdt-h', 'usdt');
+	}
+    } else {
+	disable('not-linux', 'usdt');
+    }
+}
+push @{$config{openssl_other_defines}}, "OPENSSL_NO_USDT" if ($disabled{usdt});
+
 # Get the extra flags used when building shared libraries and modules.  We
 # do this late because some of them depend on %disabled.

diff --git a/include/internal/usdt.h b/include/internal/usdt.h
new file mode 100644
index 0000000000..6f9b121589
--- /dev/null
+++ b/include/internal/usdt.h
@@ -0,0 +1,96 @@
+/*
+ * Copyright 2026 The OpenSSL Project Authors. All Rights Reserved.
+ *
+ * Licensed under the Apache License 2.0 (the "License").  You may not use
+ * this file except in compliance with the License.  You can obtain a copy
+ * in the file LICENSE in the source distribution or at
+ * https://www.openssl.org/source/license.html
+ */
+
+#ifndef OSSL_USDT_H
+#define OSSL_USDT_H
+#pragma once
+
+#include <openssl/opensslconf.h>
+
+#ifndef OPENSSL_NO_USDT
+#include <stdint.h>
+#include <sys/sdt.h>
+#ifdef __cplusplus
+extern "C" {
+#endif
+
+typedef struct ossl_usdt_data_st {
+    const char *key;
+    const void *value;
+    unsigned long value_size;
+} OSSL_USDT_DATA;
+
+#define OSSL_USDT_STRING(s) s, (unsigned long)-1
+#define OSSL_USDT_WORD(w) (void *)(intptr_t)w, (unsigned long)-2
+#define OSSL_USDT_BLOB(b, s) b, s
+
+/*
+ * Emits a context event with the given |name|.
+ */
+#define OSSL_USDT_new_context(context, name)                                    \
+    do {                                                                        \
+        OSSL_USDT_DATA data_[] = { { "name", OSSL_USDT_STRING(name) } };        \
+        DTRACE_PROBE4(crypto_auditing, new_context_with_data, context, context, \
+            data_, sizeof(data_) / sizeof(data_[0]));                           \
+    } while (0)
+
+/*
+ * Combines OSSL_USDT_new_context() followed by OSSL_USDT_data() as a
+ * single probe.
+ */
+#define OSSL_USDT_new_context_with_data(context, name, ...)                           \
+    do {                                                                              \
+        OSSL_USDT_DATA data_[] = { { "name", OSSL_USDT_STRING(name) }, __VA_ARGS__ }; \
+        DTRACE_PROBE4(crypto_auditing, new_context_with_data, context, context,       \
+            data_, sizeof(data_) / sizeof(data_[0]));                                 \
+    } while (0)
+
+/*
+ * Emits multiple data events at once as a variadic array of
+ * OSSL_USDT_DATA in the current event context.
+ */
+#define OSSL_USDT_data(context, ...)                                                            \
+    do {                                                                                        \
+        OSSL_USDT_DATA data_[] = { __VA_ARGS__ };                                               \
+        DTRACE_PROBE3(crypto_auditing, data, context, data_, sizeof(data_) / sizeof(data_[0])); \
+    } while (0)
+
+/*
+ * Asserts an explicit parent-child relationship of context.
+ */
+#define OSSL_USDT_new_child(parent_context, context) \
+    DTRACE_PROBE2(crypto_auditing, new_context, context, parent_context)
+
+/*
+ * Declares that |context| is retired and its value may be reused for
+ * other purposes.  This should be emitted when an object used as a
+ * context is freed, before the memory can be recycled for another
+ * object.
+ */
+#define OSSL_USDT_release_context(context) \
+    DTRACE_PROBE1(crypto_auditing, release_context, context)
+
+#ifdef __cplusplus
+}
+#endif
+
+#else
+
+#define OSSL_USDT_STRING(s)
+#define OSSL_USDT_WORD(w)
+#define OSSL_USDT_BLOB(b, s)
+
+#define OSSL_USDT_new_context(context, name)
+#define OSSL_USDT_new_context_with_data(context, name, ...)
+#define OSSL_USDT_data(context, ...)
+#define OSSL_USDT_new_child(parent_context, context)
+#define OSSL_USDT_release_context(context)
+
+#endif
+#endif /* OSSL_USDT_H */