#############################################################################*/
#include <errno.h>
+#include <fcntl.h>
#include <stdlib.h>
#include <sys/mman.h>
#include <sys/queue.h>
const char* path = pakfire_file_get_path(file);
// Allocate a new buffer
- fd = memfd_create(path, MFD_CLOEXEC);
+ fd = memfd_create(path, MFD_ALLOW_SEALING|MFD_CLOEXEC);
if (fd < 0) {
CTX_ERROR(linter->ctx, "memfd_create() failed: %m\n");
r = -errno;
goto ERROR;
}
+ // Seal the file so that nothing can be changed
+ r = fcntl(fd, F_ADD_SEALS,
+ F_SEAL_SEAL|F_SEAL_SHRINK|F_SEAL_GROW|F_SEAL_WRITE|F_SEAL_FUTURE_WRITE);
+ if (r < 0) {
+ CTX_ERROR(linter->ctx, "Could not seal the file: %m\n");
+ r = -errno;
+ goto ERROR;
+ }
+
return fd;
ERROR: