HID: debug: fix the ring buffer implementation
commit 13054abbaa4f1fd4e6f3b4b63439ec033b4c8035 upstream.
Ring buffer implementation in hid_debug_event() and hid_debug_events_read()
is strange allowing lost or corrupted data. After commit 717adfdaf147
("HID: debug: check length before copy_to_user()") it is possible to enter
an infinite loop in hid_debug_events_read() by providing 0 as count, this
locks up a system. Fix this by rewriting the ring buffer implementation
with kfifo and simplify the code.
This fixes CVE-2019-3819.
v2: fix an execution logic and add a comment
v3: use __set_current_state() instead of set_current_state()
Backport to v4.9: some tree-wide patches are missing in v4.9 so
cherry-pick relevant pieces from:
* 6396bb22151 ("treewide: kzalloc() -> kcalloc()")
* a9a08845e9ac ("vfs: do bulk POLL* -> EPOLL* replacement")
* 174cd4b1e5fb ("sched/headers: Prepare to move signal wakeup & sigpending
methods from <linux/sched.h> into <linux/sched/signal.h>")
Link: https://bugzilla.redhat.com/show_bug.cgi?id=1669187
Cc: stable@vger.kernel.org # v4.18+
Fixes: cd667ce247
("HID: use debugfs for events/reports dumping")
Fixes: 717adfdaf147 ("HID: debug: check length before copy_to_user()")
Signed-off-by: Vladis Dronov <vdronov@redhat.com>
Reviewed-by: Oleg Nesterov <oleg@redhat.com>
Signed-off-by: Benjamin Tissoires <benjamin.tissoires@redhat.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
877362fd15
commit
64a9f5f2e4
2 changed files with 53 additions and 80 deletions
|
@ -24,7 +24,10 @@
|
|||
|
||||
#ifdef CONFIG_DEBUG_FS
|
||||
|
||||
#include <linux/kfifo.h>
|
||||
|
||||
#define HID_DEBUG_BUFSIZE 512
|
||||
#define HID_DEBUG_FIFOSIZE 512
|
||||
|
||||
void hid_dump_input(struct hid_device *, struct hid_usage *, __s32);
|
||||
void hid_dump_report(struct hid_device *, int , u8 *, int);
|
||||
|
@ -37,11 +40,8 @@ void hid_debug_init(void);
|
|||
void hid_debug_exit(void);
|
||||
void hid_debug_event(struct hid_device *, char *);
|
||||
|
||||
|
||||
struct hid_debug_list {
|
||||
char *hid_debug_buf;
|
||||
int head;
|
||||
int tail;
|
||||
DECLARE_KFIFO_PTR(hid_debug_fifo, char);
|
||||
struct fasync_struct *fasync;
|
||||
struct hid_device *hdev;
|
||||
struct list_head node;
|
||||
|
@ -64,4 +64,3 @@ struct hid_debug_list {
|
|||
#endif
|
||||
|
||||
#endif
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue