Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753001AbcDUQrv (ORCPT ); Thu, 21 Apr 2016 12:47:51 -0400 Received: from mail-wm0-f51.google.com ([74.125.82.51]:36069 "EHLO mail-wm0-f51.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752506AbcDUQrs (ORCPT ); Thu, 21 Apr 2016 12:47:48 -0400 MIME-Version: 1.0 In-Reply-To: <1461245188.6620.316.camel@linux.intel.com> References: <1461192388-13900-1-git-send-email-keescook@chromium.org> <1461192388-13900-6-git-send-email-keescook@chromium.org> <1461245188.6620.316.camel@linux.intel.com> Date: Thu, 21 Apr 2016 09:47:46 -0700 X-Google-Sender-Auth: PFcvFNL_Ol80qj1lx-TUiQt9Br0 Message-ID: Subject: Re: [PATCH 5/6] fs: define a string representation of the kernel_read_file_id enumeration From: Kees Cook To: Andy Shevchenko Cc: James Morris , Mimi Zohar , Joe Perches , Andrew Morton , "Serge E. Hallyn" , Jonathan Corbet , Kalle Valo , Mauro Carvalho Chehab , Guenter Roeck , Jiri Slaby , Paul Moore , Stephen Smalley , Casey Schaufler , Andreas Gruenbacher , Rasmus Villemoes , Ulf Hansson , Vitaly Kuznetsov , linux-security-module , LKML , "linux-doc@vger.kernel.org" Content-Type: text/plain; charset=UTF-8 Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 3582 Lines: 105 On Thu, Apr 21, 2016 at 6:26 AM, Andy Shevchenko wrote: > On Wed, 2016-04-20 at 15:46 -0700, Kees Cook wrote: >> From: Mimi Zohar >> >> 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 >> [kees: removed removal of my old version, constified pointer values] >> Signed-off-by: Kees Cook > > > I got this > > In file included from /home/andy/prj/linux- > topic/include/linux/seq_file.h:10:0, > from /home/andy/prj/linux- > topic/include/linux/pinctrl/consumer.h:17, > from /home/andy/prj/linux- > topic/include/linux/pinctrl/devinfo.h:21, > from /home/andy/prj/linux- > topic/include/linux/device.h:24, > from /home/andy/prj/linux- > topic/include/linux/dmaengine.h:20, > from /home/andy/prj/linux- > topic/drivers/dma/dw/core.c:15: > /home/andy/prj/linux-topic/include/linux/fs.h:2627:74: warning: type > qualifiers ignored on function return type [-Wignored-qualifiers] > static inline const char * const kernel_read_file_id_str(enum > kernel_read_file_id id) What gcc version are you using? Seems like I need to drop the added "const" on the return? -Kees > >> --- >> include/linux/fs.h | 31 +++++++++++++++++++++++++------ >> 1 file changed, 25 insertions(+), 6 deletions(-) >> >> diff --git a/include/linux/fs.h b/include/linux/fs.h >> index 70e61b58baaf..518716b4834e 100644 >> --- a/include/linux/fs.h >> +++ b/include/linux/fs.h >> @@ -2590,15 +2590,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); > > -- > Andy Shevchenko > Intel Finland Oy > -- Kees Cook Chrome OS & Brillo Security