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

HID: roccat: Use struct_group() to zero kone_mouse_event

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 kone_mouse_event that should
be initialized to zero.

Cc: Stefan Achatz <erazor_de@users.sourceforge.net>
Cc: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Cc: linux-input@vger.kernel.org
Acked-by: Jiri Kosina <jikos@kernel.org>
Link: https://lore.kernel.org/lkml/nycvar.YFH.7.76.2108201810560.15313@cbobk.fhfr.pm
Signed-off-by: Kees Cook <keescook@chromium.org>

+8 -6
+1 -1
drivers/hid/hid-roccat-kone.c
··· 857 857 memcpy(&kone->last_mouse_event, event, 858 858 sizeof(struct kone_mouse_event)); 859 859 else 860 - memset(&event->tilt, 0, 5); 860 + memset(&event->wipe, 0, sizeof(event->wipe)); 861 861 862 862 kone_keep_values_up_to_date(kone, event); 863 863
+7 -5
drivers/hid/hid-roccat-kone.h
··· 152 152 uint16_t x; 153 153 uint16_t y; 154 154 uint8_t wheel; /* up = 1, down = -1 */ 155 - uint8_t tilt; /* right = 1, left = -1 */ 156 - uint8_t unknown; 157 - uint8_t event; 158 - uint8_t value; /* press = 0, release = 1 */ 159 - uint8_t macro_key; /* 0 to 8 */ 155 + struct_group(wipe, 156 + uint8_t tilt; /* right = 1, left = -1 */ 157 + uint8_t unknown; 158 + uint8_t event; 159 + uint8_t value; /* press = 0, release = 1 */ 160 + uint8_t macro_key; /* 0 to 8 */ 161 + ); 160 162 } __attribute__ ((__packed__)); 161 163 162 164 enum kone_mouse_events {