linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH AUTOSEL 4.4 01/15] HID: debug: fix race condition with between rdesc_show() and device removal
@ 2019-04-24 14:51 Sasha Levin
  2019-04-24 14:51 ` [PATCH AUTOSEL 4.4 02/15] rtc: sh: Fix invalid alarm warning for non-enabled alarm Sasha Levin
                   ` (13 more replies)
  0 siblings, 14 replies; 15+ messages in thread
From: Sasha Levin @ 2019-04-24 14:51 UTC (permalink / raw)
  To: linux-kernel, stable
  Cc: He, Bo, Zhang, Jun, Jiri Kosina, Sasha Levin, linux-input

From: "He, Bo" <bo.he@intel.com>

[ Upstream commit cef0d4948cb0a02db37ebfdc320e127c77ab1637 ]

There is a race condition that could happen if hid_debug_rdesc_show()
is running while hdev is in the process of going away (device removal,
system suspend, etc) which could result in NULL pointer dereference:

	 BUG: unable to handle kernel paging request at 0000000783316040
	 CPU: 1 PID: 1512 Comm: getevent Tainted: G     U     O 4.19.20-quilt-2e5dc0ac-00029-gc455a447dd55 #1
	 RIP: 0010:hid_dump_device+0x9b/0x160
	 Call Trace:
	  hid_debug_rdesc_show+0x72/0x1d0
	  seq_read+0xe0/0x410
	  full_proxy_read+0x5f/0x90
	  __vfs_read+0x3a/0x170
	  vfs_read+0xa0/0x150
	  ksys_read+0x58/0xc0
	  __x64_sys_read+0x1a/0x20
	  do_syscall_64+0x55/0x110
	  entry_SYSCALL_64_after_hwframe+0x49/0xbe

Grab driver_input_lock to make sure the input device exists throughout the
whole process of dumping the rdesc.

[jkosina@suse.cz: update changelog a bit]
Signed-off-by: "he, bo" <bo.he@intel.com>
Signed-off-by: "Zhang, Jun" <jun.zhang@intel.com>
Signed-off-by: Jiri Kosina <jkosina@suse.cz>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
 drivers/hid/hid-debug.c | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/drivers/hid/hid-debug.c b/drivers/hid/hid-debug.c
index d7179dd3c9ef..3cafa1d28fed 100644
--- a/drivers/hid/hid-debug.c
+++ b/drivers/hid/hid-debug.c
@@ -1058,10 +1058,15 @@ static int hid_debug_rdesc_show(struct seq_file *f, void *p)
 	seq_printf(f, "\n\n");
 
 	/* dump parsed data and input mappings */
+	if (down_interruptible(&hdev->driver_input_lock))
+		return 0;
+
 	hid_dump_device(hdev, f);
 	seq_printf(f, "\n");
 	hid_dump_input_mapping(hdev, f);
 
+	up(&hdev->driver_input_lock);
+
 	return 0;
 }
 
-- 
2.19.1


^ permalink raw reply related	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2019-04-24 14:54 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-04-24 14:51 [PATCH AUTOSEL 4.4 01/15] HID: debug: fix race condition with between rdesc_show() and device removal Sasha Levin
2019-04-24 14:51 ` [PATCH AUTOSEL 4.4 02/15] rtc: sh: Fix invalid alarm warning for non-enabled alarm Sasha Levin
2019-04-24 14:51 ` [PATCH AUTOSEL 4.4 03/15] igb: Fix WARN_ONCE on runtime suspend Sasha Levin
2019-04-24 14:51 ` [PATCH AUTOSEL 4.4 04/15] bonding: show full hw address in sysfs for slave entries Sasha Levin
2019-04-24 14:51 ` [PATCH AUTOSEL 4.4 05/15] jffs2: fix use-after-free on symlink traversal Sasha Levin
2019-04-24 14:51 ` [PATCH AUTOSEL 4.4 06/15] debugfs: " Sasha Levin
2019-04-24 14:51 ` [PATCH AUTOSEL 4.4 07/15] rtc: da9063: set uie_unsupported when relevant Sasha Levin
2019-04-24 14:51 ` [PATCH AUTOSEL 4.4 08/15] vfio/pci: use correct format characters Sasha Levin
2019-04-24 14:51 ` [PATCH AUTOSEL 4.4 09/15] scsi: storvsc: Fix calculation of sub-channel count Sasha Levin
2019-04-24 14:51 ` [PATCH AUTOSEL 4.4 10/15] net: hns: Use NAPI_POLL_WEIGHT for hns driver Sasha Levin
2019-04-24 14:51 ` [PATCH AUTOSEL 4.4 11/15] net: hns: Fix WARNING when remove HNS driver with SMMU enabled Sasha Levin
2019-04-24 14:51 ` [PATCH AUTOSEL 4.4 12/15] hugetlbfs: fix memory leak for resv_map Sasha Levin
2019-04-24 14:51 ` [PATCH AUTOSEL 4.4 13/15] xsysace: Fix error handling in ace_setup Sasha Levin
2019-04-24 14:51 ` [PATCH AUTOSEL 4.4 14/15] ARM: orion: don't use using 64-bit DMA masks Sasha Levin
2019-04-24 14:51 ` [PATCH AUTOSEL 4.4 15/15] ARM: iop: " Sasha Levin

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).