OSDN Git Service

HID: roccat: Use struct_group() to zero kone_mouse_event
authorKees Cook <keescook@chromium.org>
Fri, 21 May 2021 02:56:15 +0000 (19:56 -0700)
committerKees Cook <keescook@chromium.org>
Sat, 25 Sep 2021 15:20:48 +0000 (08:20 -0700)
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>
drivers/hid/hid-roccat-kone.c
drivers/hid/hid-roccat-kone.h

index 1ca6448..ea17abc 100644 (file)
@@ -857,7 +857,7 @@ static int kone_raw_event(struct hid_device *hdev, struct hid_report *report,
                memcpy(&kone->last_mouse_event, event,
                                sizeof(struct kone_mouse_event));
        else
-               memset(&event->tilt, 0, 5);
+               memset(&event->wipe, 0, sizeof(event->wipe));
 
        kone_keep_values_up_to_date(kone, event);
 
index 4a1a9cb..65c800e 100644 (file)
@@ -152,11 +152,13 @@ struct kone_mouse_event {
        uint16_t x;
        uint16_t y;
        uint8_t wheel; /* up = 1, down = -1 */
-       uint8_t tilt; /* right = 1, left = -1 */
-       uint8_t unknown;
-       uint8_t event;
-       uint8_t value; /* press = 0, release = 1 */
-       uint8_t macro_key; /* 0 to 8 */
+       struct_group(wipe,
+               uint8_t tilt; /* right = 1, left = -1 */
+               uint8_t unknown;
+               uint8_t event;
+               uint8_t value; /* press = 0, release = 1 */
+               uint8_t macro_key; /* 0 to 8 */
+       );
 } __attribute__ ((__packed__));
 
 enum kone_mouse_events {