Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cm4000_cs: Use struct_group() to zero struct cm4000_dev region

In preparation for FORTIFY_SOURCE performing compile-time and run-time
field bounds checking for memset(), avoid intentionally writing across
neighboring fields.

Add struct_group() to mark region of struct cm4000_dev that should be
initialized to zero.

Cc: Harald Welte <laforge@gnumonks.org>
Cc: Arnd Bergmann <arnd@arndb.de>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: Kees Cook <keescook@chromium.org>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Link: https://lore.kernel.org/lkml/YQDvxAofJlI1JoGZ@kroah.com

+4 -5
+4 -5
drivers/char/pcmcia/cm4000_cs.c
··· 116 116 wait_queue_head_t atrq; /* wait for ATR valid */ 117 117 wait_queue_head_t readq; /* used by write to wake blk.read */ 118 118 119 - /* warning: do not move this fields. 119 + /* warning: do not move this struct group. 120 120 * initialising to zero depends on it - see ZERO_DEV below. */ 121 + struct_group(init, 121 122 unsigned char atr_csum; 122 123 unsigned char atr_len_retry; 123 124 unsigned short atr_len; ··· 141 140 142 141 struct timer_list timer; /* used to keep monitor running */ 143 142 int monitor_running; 143 + ); 144 144 }; 145 145 146 - #define ZERO_DEV(dev) \ 147 - memset(&dev->atr_csum,0, \ 148 - sizeof(struct cm4000_dev) - \ 149 - offsetof(struct cm4000_dev, atr_csum)) 146 + #define ZERO_DEV(dev) memset(&((dev)->init), 0, sizeof((dev)->init)) 150 147 151 148 static struct pcmcia_device *dev_table[CM4000_MAX_DEV]; 152 149 static struct class *cmm_class;