Skip to content

Commit

Permalink
fs: define a string representation of the kernel_read_file_id enumera…
Browse files Browse the repository at this point in the history
…tion

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 <[email protected]>
[kees: removed removal of my old version, constified pointer values]
Signed-off-by: Kees Cook <[email protected]>
Signed-off-by: James Morris <[email protected]>
  • Loading branch information
Mimi Zohar authored and James Morris committed Apr 21, 2016
1 parent 8a56038 commit 1284ab5
Showing 1 changed file with 25 additions and 6 deletions.
31 changes: 25 additions & 6 deletions include/linux/fs.h
Original file line number Diff line number Diff line change
Expand Up @@ -2580,15 +2580,34 @@ static inline void i_readcount_inc(struct inode *inode)
#endif
extern int do_pipe_flags(int *, int);

#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(MAX_ID, )

#define __fid_enumify(ENUM, dummy) READING_ ## ENUM,
#define __fid_stringify(dummy, str) #str,

enum kernel_read_file_id {
READING_FIRMWARE = 1,
READING_MODULE,
READING_KEXEC_IMAGE,
READING_KEXEC_INITRAMFS,
READING_POLICY,
READING_MAX_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 * const kernel_read_file_id_str(enum kernel_read_file_id id)
{
if (id < 0 || id >= READING_MAX_ID)
return kernel_read_file_str[READING_UNKNOWN];

return kernel_read_file_str[id];
}

extern int kernel_read(struct file *, loff_t, char *, unsigned long);
extern int kernel_read_file(struct file *, void **, loff_t *, loff_t,
enum kernel_read_file_id);
Expand Down

0 comments on commit 1284ab5

Please sign in to comment.