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
116116 wait_queue_head_t atrq; /* wait for ATR valid */
117117 wait_queue_head_t readq; /* used by write to wake blk.read */
118118
119− /* warning: do not move this fields.
119+ /* warning: do not move this struct group.
120120 * initialising to zero depends on it - see ZERO_DEV below. */
121+ struct_group(init,
121122 unsigned char atr_csum;
122123 unsigned char atr_len_retry;
123124 unsigned short atr_len;
@@ -140,12 +141,10 @@ struct cm4000_dev { · 16 unmodified lines
140141
141142 struct timer_list timer; /* used to keep monitor running */
142143 int monitor_running;
144+ );
143145 };
144146
145−#define ZERO_DEV(dev) \
146− memset(&dev->atr_csum,0, \
147− sizeof(struct cm4000_dev) - \
148− offsetof(struct cm4000_dev, atr_csum))
147+#define ZERO_DEV(dev) memset(&((dev)->init), 0, sizeof((dev)->init))
149148
150149 static struct pcmcia_device *dev_table[CM4000_MAX_DEV];
151150 static 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