memfd-util: add wrapper for memfd_create

The wrapper removes the flags MFD_EXEC and MFD_NOEXEC_SEAL when running
on kernels not understanding those flags.
This commit is contained in:
Thomas Weißschuh
2023-03-15 01:18:59 +00:00
parent 8cb0a001d8
commit ad62530ebb
2 changed files with 18 additions and 0 deletions
+16
View File
@@ -20,6 +20,22 @@
#include "string-util.h"
#include "utf8.h"
int memfd_create_wrapper(const char *name, unsigned mode) {
unsigned mode_compat;
int mfd;
mfd = RET_NERRNO(memfd_create(name, mode));
if (mfd != -EINVAL)
return mfd;
mode_compat = mode & ~(MFD_EXEC | MFD_NOEXEC_SEAL);
if (mode == mode_compat)
return mfd;
return RET_NERRNO(memfd_create(name, mode_compat));
}
int memfd_new(const char *name) {
_cleanup_free_ char *g = NULL;
+2
View File
@@ -6,6 +6,8 @@
#include <stdint.h>
#include <sys/types.h>
int memfd_create_wrapper(const char *name, unsigned mode);
int memfd_new(const char *name);
int memfd_new_and_map(const char *name, size_t sz, void **p);
int memfd_new_and_seal(const char *name, const void *data, size_t sz);