fs/kernel_read_file: Split into separate include file
authorScott Branden <scott.branden@broadcom.com>
Fri, 2 Oct 2020 17:38:15 +0000 (10:38 -0700)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Mon, 5 Oct 2020 11:34:18 +0000 (13:34 +0200)
Move kernel_read_file* out of linux/fs.h to its own linux/kernel_read_file.h
include file. That header gets pulled in just about everywhere
and doesn't really need functions not related to the general fs interface.

Suggested-by: Christoph Hellwig <hch@lst.de>
Signed-off-by: Scott Branden <scott.branden@broadcom.com>
Signed-off-by: Kees Cook <keescook@chromium.org>
Reviewed-by: Christoph Hellwig <hch@lst.de>
Reviewed-by: Mimi Zohar <zohar@linux.ibm.com>
Reviewed-by: Luis Chamberlain <mcgrof@kernel.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Acked-by: James Morris <jamorris@linux.microsoft.com>
Link: https://lore.kernel.org/r/20200706232309.12010-2-scott.branden@broadcom.com
Link: https://lore.kernel.org/r/20201002173828.2099543-4-keescook@chromium.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
15 files changed:
drivers/base/firmware_loader/main.c
fs/exec.c
include/linux/fs.h
include/linux/ima.h
include/linux/kernel_read_file.h [new file with mode: 0644]
include/linux/security.h
kernel/kexec_file.c
kernel/module.c
security/integrity/digsig.c
security/integrity/ima/ima_fs.c
security/integrity/ima/ima_main.c
security/integrity/ima/ima_policy.c
security/loadpin/loadpin.c
security/security.c
security/selinux/hooks.c

index b0ec2721f55ded62892791d53f7dadbfc8fb4dd6..8c6ea389afcf109890a9a4afc69100a0a575d3ae 100644 (file)
@@ -12,6 +12,7 @@
 
 #include <linux/capability.h>
 #include <linux/device.h>
+#include <linux/kernel_read_file.h>
 #include <linux/module.h>
 #include <linux/init.h>
 #include <linux/timer.h>
index 9233cd50dc4ca310ee8cbe2ca4a07d9299d5e91b..c454af329413264b2c27c949567fa9b7431068a1 100644 (file)
--- a/fs/exec.c
+++ b/fs/exec.c
@@ -23,6 +23,7 @@
  * formats.
  */
 
+#include <linux/kernel_read_file.h>
 #include <linux/slab.h>
 #include <linux/file.h>
 #include <linux/fdtable.h>
index 3fb7af12d0339404ea9a3bcc3f9a8d0909c5688d..0885d53afb118ed9dd93371b725e68d7b66817c4 100644 (file)
@@ -2858,44 +2858,6 @@ static inline void i_readcount_inc(struct inode *inode)
 #endif
 extern int do_pipe_flags(int *, int);
 
-/* This is a list of *what* is being read, not *how* nor *where*. */
-#define __kernel_read_file_id(id) \
-       id(UNKNOWN, unknown)            \
-       id(FIRMWARE, firmware)          \
-       id(MODULE, kernel-module)               \
-       id(KEXEC_IMAGE, kexec-image)            \
-       id(KEXEC_INITRAMFS, kexec-initramfs)    \
-       id(POLICY, security-policy)             \
-       id(X509_CERTIFICATE, x509-certificate)  \
-       id(MAX_ID, )
-
-#define __fid_enumify(ENUM, dummy) READING_ ## ENUM,
-#define __fid_stringify(dummy, str) #str,
-
-enum kernel_read_file_id {
-       __kernel_read_file_id(__fid_enumify)
-};
-
-static const char * const kernel_read_file_str[] = {
-       __kernel_read_file_id(__fid_stringify)
-};
-
-static inline const char *kernel_read_file_id_str(enum kernel_read_file_id id)
-{
-       if ((unsigned)id >= READING_MAX_ID)
-               return kernel_read_file_str[READING_UNKNOWN];
-
-       return kernel_read_file_str[id];
-}
-
-extern int kernel_read_file(struct file *, void **, loff_t *, loff_t,
-                           enum kernel_read_file_id);
-extern int kernel_read_file_from_path(const char *, void **, loff_t *, loff_t,
-                                     enum kernel_read_file_id);
-extern int kernel_read_file_from_path_initns(const char *, void **, loff_t *, loff_t,
-                                            enum kernel_read_file_id);
-extern int kernel_read_file_from_fd(int, void **, loff_t *, loff_t,
-                                   enum kernel_read_file_id);
 extern ssize_t kernel_read(struct file *, void *, size_t, loff_t *);
 ssize_t __kernel_read(struct file *file, void *buf, size_t count, loff_t *pos);
 extern ssize_t kernel_write(struct file *, const void *, size_t, loff_t *);
index d15100de6cdddd7101838a2803b978ccd4545d9b..64804f78408b8454b2130f8c5ea0c7d1a2c5434a 100644 (file)
@@ -7,6 +7,7 @@
 #ifndef _LINUX_IMA_H
 #define _LINUX_IMA_H
 
+#include <linux/kernel_read_file.h>
 #include <linux/fs.h>
 #include <linux/security.h>
 #include <linux/kexec.h>
diff --git a/include/linux/kernel_read_file.h b/include/linux/kernel_read_file.h
new file mode 100644 (file)
index 0000000..78cf3d7
--- /dev/null
@@ -0,0 +1,51 @@
+/* SPDX-License-Identifier: GPL-2.0 */
+#ifndef _LINUX_KERNEL_READ_FILE_H
+#define _LINUX_KERNEL_READ_FILE_H
+
+#include <linux/file.h>
+#include <linux/types.h>
+
+/* This is a list of *what* is being read, not *how* nor *where*. */
+#define __kernel_read_file_id(id) \
+       id(UNKNOWN, unknown)            \
+       id(FIRMWARE, firmware)          \
+       id(MODULE, kernel-module)               \
+       id(KEXEC_IMAGE, kexec-image)            \
+       id(KEXEC_INITRAMFS, kexec-initramfs)    \
+       id(POLICY, security-policy)             \
+       id(X509_CERTIFICATE, x509-certificate)  \
+       id(MAX_ID, )
+
+#define __fid_enumify(ENUM, dummy) READING_ ## ENUM,
+#define __fid_stringify(dummy, str) #str,
+
+enum kernel_read_file_id {
+       __kernel_read_file_id(__fid_enumify)
+};
+
+static const char * const kernel_read_file_str[] = {
+       __kernel_read_file_id(__fid_stringify)
+};
+
+static inline const char *kernel_read_file_id_str(enum kernel_read_file_id id)
+{
+       if ((unsigned int)id >= READING_MAX_ID)
+               return kernel_read_file_str[READING_UNKNOWN];
+
+       return kernel_read_file_str[id];
+}
+
+int kernel_read_file(struct file *file,
+                    void **buf, loff_t *size, loff_t max_size,
+                    enum kernel_read_file_id id);
+int kernel_read_file_from_path(const char *path,
+                              void **buf, loff_t *size, loff_t max_size,
+                              enum kernel_read_file_id id);
+int kernel_read_file_from_path_initns(const char *path,
+                                     void **buf, loff_t *size, loff_t max_size,
+                                     enum kernel_read_file_id id);
+int kernel_read_file_from_fd(int fd,
+                            void **buf, loff_t *size, loff_t max_size,
+                            enum kernel_read_file_id id);
+
+#endif /* _LINUX_KERNEL_READ_FILE_H */
index 0a0a03b36a3bb178c5ff62cfd96cc7973c4412cb..42df0d9b4c37b24f6036f3be5f3e0d5198b72cc7 100644 (file)
@@ -23,6 +23,7 @@
 #ifndef __LINUX_SECURITY_H
 #define __LINUX_SECURITY_H
 
+#include <linux/kernel_read_file.h>
 #include <linux/key.h>
 #include <linux/capability.h>
 #include <linux/fs.h>
index ca40bef75a6169c5a737be2c5857346c22a9e38e..1cc82557f4c10a1cfec2c665afae0ba71345e343 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/elf.h>
 #include <linux/elfcore.h>
 #include <linux/kernel.h>
+#include <linux/kernel_read_file.h>
 #include <linux/syscalls.h>
 #include <linux/vmalloc.h>
 #include "kexec_internal.h"
index b2808acac46b512209e44156241406cea1077437..4218abd272ee4241feba2998f99c7dc1a8bd7cc8 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/fs.h>
 #include <linux/sysfs.h>
 #include <linux/kernel.h>
+#include <linux/kernel_read_file.h>
 #include <linux/slab.h>
 #include <linux/vmalloc.h>
 #include <linux/elf.h>
index ac02b7632353e4f17865c8ac2363e3f4d1874370..f8869be45d8f2c3b952f9284518a7e169f1fd83c 100644 (file)
@@ -10,6 +10,7 @@
 #include <linux/sched.h>
 #include <linux/slab.h>
 #include <linux/cred.h>
+#include <linux/kernel_read_file.h>
 #include <linux/key-type.h>
 #include <linux/digsig.h>
 #include <linux/vmalloc.h>
index 15a44c5022f77f2272cc61b8e30c2113d2b5e26b..e13ffece3726cd19188e85b5fae9129cf34251f9 100644 (file)
@@ -13,6 +13,7 @@
  */
 
 #include <linux/fcntl.h>
+#include <linux/kernel_read_file.h>
 #include <linux/slab.h>
 #include <linux/init.h>
 #include <linux/seq_file.h>
index 2f187784c5bc557f4efc1a1703ebd5dbd38c38bf..5f89970c5ab7d0205972a72637fb6c07a98ffa62 100644 (file)
@@ -18,6 +18,7 @@
 #include <linux/module.h>
 #include <linux/file.h>
 #include <linux/binfmts.h>
+#include <linux/kernel_read_file.h>
 #include <linux/mount.h>
 #include <linux/mman.h>
 #include <linux/slab.h>
index b4de33074b37da402e4547aa6dd02bcb86a1edfe..3b0b43e18ecfa6676c7a45f5b1c3c450ad7c4ec6 100644 (file)
@@ -9,6 +9,7 @@
 
 #include <linux/init.h>
 #include <linux/list.h>
+#include <linux/kernel_read_file.h>
 #include <linux/fs.h>
 #include <linux/security.h>
 #include <linux/magic.h>
index 670a1aebb8a10fa097822edd2c77cb8367792da6..163c48216d13eadfe9bdf270e17079368309f98a 100644 (file)
@@ -11,6 +11,7 @@
 
 #include <linux/module.h>
 #include <linux/fs.h>
+#include <linux/kernel_read_file.h>
 #include <linux/lsm_hooks.h>
 #include <linux/mount.h>
 #include <linux/blkdev.h>
index 70a7ad357bc6ab35aa4c7b6f7616222a8b88c805..19d3150f68f483b6eed9d1462ada89c7e3cc28a2 100644 (file)
@@ -16,6 +16,7 @@
 #include <linux/export.h>
 #include <linux/init.h>
 #include <linux/kernel.h>
+#include <linux/kernel_read_file.h>
 #include <linux/lsm_hooks.h>
 #include <linux/integrity.h>
 #include <linux/ima.h>
index a340986aa92e1d9e2434f2aaf5c208930a8156cb..96f5f8b3b9f038b33bc8cc1900d09e83d807c0b8 100644 (file)
@@ -24,6 +24,7 @@
 #include <linux/init.h>
 #include <linux/kd.h>
 #include <linux/kernel.h>
+#include <linux/kernel_read_file.h>
 #include <linux/tracehook.h>
 #include <linux/errno.h>
 #include <linux/sched/signal.h>