Merge pull request #26800 from t-8ch/memfd_create

memfd: add support for exec flags
This commit is contained in:
Lennart Poettering
2023-03-15 09:28:09 +01:00
committed by GitHub
6 changed files with 46 additions and 11 deletions
+17 -1
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;
@@ -49,7 +65,7 @@ int memfd_new(const char *name) {
}
}
return RET_NERRNO(memfd_create(name, MFD_ALLOW_SEALING | MFD_CLOEXEC));
return memfd_create_wrapper(name, MFD_ALLOW_SEALING | MFD_CLOEXEC | MFD_NOEXEC_SEAL);
}
int memfd_map(int fd, uint64_t offset, size_t size, void **p) {
+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);
+8
View File
@@ -10,3 +10,11 @@
#ifndef MFD_CLOEXEC
#define MFD_CLOEXEC 0x0001U
#endif
#ifndef MFD_NOEXEC_SEAL
#define MFD_NOEXEC_SEAL 0x0008U
#endif
#ifndef MFD_EXEC
#define MFD_EXEC 0x0010U
#endif