History

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.

Kees Cook committed 5 years ago

Commit 86100471 parent c92a08c1 file · +4 −5Browse files

Unified · Split

drivers/char/pcmcia/cm4000_cs.c+4−5
@@ -116,8 +116,9 @@ struct cm4000_dev { · 115 unmodified lines
116 wait_queue_head_t atrq; /* wait for ATR valid */116 wait_queue_head_t atrq; /* wait for ATR valid */
117 wait_queue_head_t readq; /* used by write to wake blk.read */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 * initialising to zero depends on it - see ZERO_DEV below. */120 * initialising to zero depends on it - see ZERO_DEV below. */
121 struct_group(init,
121 unsigned char atr_csum;122 unsigned char atr_csum;
122 unsigned char atr_len_retry;123 unsigned char atr_len_retry;
123 unsigned short atr_len;124 unsigned short atr_len;
@@ -140,12 +141,10 @@ struct cm4000_dev { · 16 unmodified lines
140 141
141 struct timer_list timer; /* used to keep monitor running */142 struct timer_list timer; /* used to keep monitor running */
142 int monitor_running;143 int monitor_running;
144 );
143};145};
144 146
145#define ZERO_DEV(dev) \147#define ZERO_DEV(dev) memset(&((dev)->init), 0, sizeof((dev)->init))
146 memset(&dev->atr_csum,0, \
147 sizeof(struct cm4000_dev) - \
148 offsetof(struct cm4000_dev, atr_csum))
149 148
150static struct pcmcia_device *dev_table[CM4000_MAX_DEV];149static struct pcmcia_device *dev_table[CM4000_MAX_DEV];
151static struct class *cmm_class;150static struct class *cmm_class;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t