@@ -463,3 +463,6 @@ LSM_HOOK(int, 0, bdev_alloc_security, struct block_device *bdev)
LSM_HOOK(void, LSM_RET_VOID, bdev_free_security, struct block_device *bdev)
LSM_HOOK(int, 0, bdev_setintegrity, struct block_device *bdev,
enum lsm_integrity_type type, const void *value, size_t size)
+
+LSM_HOOK(void, 0, memfd_created, struct file *file)
+
@@ -2386,4 +2386,12 @@ static inline void security_initramfs_populated(void)
}
#endif /* CONFIG_SECURITY */
+#ifdef CONFIG_SECURITY
+extern void security_memfd_created(struct file *file);
+#else
+static inline void security_memfd_created(struct file *file)
+{
+}
+#endif /* CONFIG_SECURITY */
+
#endif /* ! __LINUX_SECURITY_H */
@@ -19,6 +19,7 @@
#include <linux/shmem_fs.h>
#include <linux/memfd.h>
#include <linux/pid_namespace.h>
+#include <linux/security.h>
#include <uapi/linux/memfd.h>
/*
@@ -483,6 +484,7 @@ SYSCALL_DEFINE2(memfd_create,
goto err_fd;
}
+ security_memfd_created(file);
fd_install(fd, file);
kfree(name);
return fd;
@@ -6010,3 +6010,14 @@ void security_initramfs_populated(void)
{
call_void_hook(initramfs_populated);
}
+
+/**
+ * security_memfd_created() - Notify LSMs that a memfd has been created
+ *
+ * Tells the LSMs that a memfd has been created.
+ */
+void security_memfd_created(struct file *file)
+{
+ call_void_hook(memfd_created, file);
+}
+