Skip to content

eBPF-based security platform

otel: hold the S3 snapshot in a memfd rather than a file in TMPDIR

Daniel Borkmannf5cdc5b3ca68
diff --git a/Documentation/architecture.rst b/Documentation/architecture.rst
index 8200af37..407f35d4 100644
--- a/Documentation/architecture.rst
+++ b/Documentation/architecture.rst
@@ -250,9 +250,7 @@ set-user-ID program does. The dynamic loader then ignores
variables glibc treats as unsafe, and libraries ignore what they read
with ``secure_getenv()``, among them OpenSSL's ``OPENSSL_CONF`` and
``OPENSSL_MODULES``. The hook runs on every binary handler pass, so
-a script that names shirudo as its interpreter gets the same. glibc
-drops ``TMPDIR`` in this mode too, so the map export's snapshot file
-goes to ``/tmp`` on a target.
+a script that names shirudo as its interpreter gets the same.
``lsm/bpf_prog_load`` runs after the kernel's signature check and admits
a program only when the verdict is ``BPF_SIG_VERIFIED`` and the
diff --git a/util/upatch_maps_otel.c b/util/upatch_maps_otel.c
index 7c262651..80cecc7d 100644
--- a/util/upatch_maps_otel.c
+++ b/util/upatch_maps_otel.c
@@ -16,6 +16,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <sys/mman.h>
#include <sys/random.h>
#include <sys/stat.h>
#include <time.h>
@@ -1985,33 +1986,13 @@ struct snapshot_writer {
static int snapshot_temp_file(FILE **out)
{
- const char *tmpdir = getenv("TMPDIR");
- char path[PATH_MAX];
FILE *file;
- int fd, n;
+ int fd;
- if (!tmpdir || !tmpdir[0])
- tmpdir = "/tmp";
- n = strsprintf(path, sizeof(path), "%s/%s", tmpdir,
- "shirudo-map-snapshot.XXXXXX");
- if (n < 0)
- return -ENAMETOOLONG;
- fd = mkstemp(path);
+ fd = memfd_create("shirudo-map-snapshot",
+ MFD_CLOEXEC | MFD_NOEXEC_SEAL);
if (fd < 0)
return -errno;
- if (fchmod(fd, 0600) != 0) {
- int rc = -errno;
-
- unlink(path);
- close(fd);
- return rc;
- }
- if (unlink(path) != 0) {
- int rc = -errno;
-
- close(fd);
- return rc;
- }
file = fdopen(fd, "w+b");
if (!file) {
int rc = -errno;