memfd-util: introduce memfd_new_full() helper
This is just like memfd_new(), but allows fine grained control of the sealing flags. This switches over all uses of memfd_new() where we actually want sealing to use memfd_new_full(). This then allows use to use memfd_new() for two further calls, where we previously used the more lowlevel memfd_create_wrapper().
This commit is contained in:
@@ -41,7 +41,7 @@ int memfd_create_wrapper(const char *name, unsigned mode) {
|
||||
return RET_NERRNO(memfd_create(name, mode_compat));
|
||||
}
|
||||
|
||||
int memfd_new(const char *name) {
|
||||
int memfd_new_full(const char *name, unsigned extra_flags) {
|
||||
_cleanup_free_ char *g = NULL;
|
||||
|
||||
if (!name) {
|
||||
@@ -70,7 +70,9 @@ int memfd_new(const char *name) {
|
||||
}
|
||||
}
|
||||
|
||||
return memfd_create_wrapper(name, MFD_ALLOW_SEALING | MFD_CLOEXEC | MFD_NOEXEC_SEAL);
|
||||
return memfd_create_wrapper(
|
||||
name,
|
||||
MFD_CLOEXEC | MFD_NOEXEC_SEAL | extra_flags);
|
||||
}
|
||||
|
||||
int memfd_add_seals(int fd, unsigned int seals) {
|
||||
@@ -183,7 +185,7 @@ int memfd_new_and_seal(const char *name, const void *data, size_t sz) {
|
||||
if (sz == SIZE_MAX)
|
||||
sz = strlen(data);
|
||||
|
||||
fd = memfd_new(name);
|
||||
fd = memfd_new_full(name, MFD_ALLOW_SEALING);
|
||||
if (fd < 0)
|
||||
return fd;
|
||||
|
||||
|
||||
@@ -8,8 +8,13 @@
|
||||
|
||||
int memfd_create_wrapper(const char *name, unsigned mode);
|
||||
|
||||
int memfd_new(const char *name);
|
||||
int memfd_new_full(const char *name, unsigned extra_flags);
|
||||
static inline int memfd_new(const char *name) {
|
||||
return memfd_new_full(name, 0);
|
||||
}
|
||||
|
||||
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);
|
||||
static inline int memfd_new_and_seal_string(const char *name, const char *s) {
|
||||
return memfd_new_and_seal(name, s, SIZE_MAX);
|
||||
|
||||
Reference in New Issue
Block a user