aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMimi Zohar <zohar@linux.vnet.ibm.com>2016-04-20 18:46:27 -0400
committerJames Morris <james.l.morris@oracle.com>2016-04-20 20:47:26 -0400
commit1284ab5b2dcb927d38e4f3fbc2e307f3d1af9262 (patch)
tree732acec00e94c88cbb11eb0a41384c64208facc1
parent8a56038c2aef97a9d4b9dd608b912b9d9a4a2d68 (diff)
fs: define a string representation of the kernel_read_file_id enumeration
A string representation of the kernel_read_file_id enumeration is needed for displaying messages (eg. pr_info, auditing) that can be used by multiple LSMs and the integrity subsystem. To simplify keeping the list of strings up to date with the enumeration, this patch defines two new preprocessing macros named __fid_enumify and __fid_stringify to create the enumeration and an array of strings. kernel_read_file_id_str() returns a string based on the enumeration. Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com> [kees: removed removal of my old version, constified pointer values] Signed-off-by: Kees Cook <keescook@chromium.org> Signed-off-by: James Morris <james.l.morris@oracle.com>
-rw-r--r--include/linux/fs.h31
1 files changed, 25 insertions, 6 deletions
diff --git a/include/linux/fs.h b/include/linux/fs.h
index 14a97194b34b..90477550b935 100644
--- a/include/linux/fs.h
+++ b/include/linux/fs.h
@@ -2580,15 +2580,34 @@ static inline void i_readcount_inc(struct inode *inode)
2580#endif 2580#endif
2581extern int do_pipe_flags(int *, int); 2581extern int do_pipe_flags(int *, int);
2582 2582
2583#define __kernel_read_file_id(id) \
2584 id(UNKNOWN, unknown) \
2585 id(FIRMWARE, firmware) \
2586 id(MODULE, kernel-module) \
2587 id(KEXEC_IMAGE, kexec-image) \
2588 id(KEXEC_INITRAMFS, kexec-initramfs) \
2589 id(POLICY, security-policy) \
2590 id(MAX_ID, )
2591
2592#define __fid_enumify(ENUM, dummy) READING_ ## ENUM,
2593#define __fid_stringify(dummy, str) #str,
2594
2583enum kernel_read_file_id { 2595enum kernel_read_file_id {
2584 READING_FIRMWARE = 1, 2596 __kernel_read_file_id(__fid_enumify)
2585 READING_MODULE, 2597};
2586 READING_KEXEC_IMAGE, 2598
2587 READING_KEXEC_INITRAMFS, 2599static const char * const kernel_read_file_str[] = {
2588 READING_POLICY, 2600 __kernel_read_file_id(__fid_stringify)
2589 READING_MAX_ID
2590}; 2601};
2591 2602
2603static inline const char * const kernel_read_file_id_str(enum kernel_read_file_id id)
2604{
2605 if (id < 0 || id >= READING_MAX_ID)
2606 return kernel_read_file_str[READING_UNKNOWN];
2607
2608 return kernel_read_file_str[id];
2609}
2610
2592extern int kernel_read(struct file *, loff_t, char *, unsigned long); 2611extern int kernel_read(struct file *, loff_t, char *, unsigned long);
2593extern int kernel_read_file(struct file *, void **, loff_t *, loff_t, 2612extern int kernel_read_file(struct file *, void **, loff_t *, loff_t,
2594 enum kernel_read_file_id); 2613 enum kernel_read_file_id);