linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: "He, Bo" <bo.he@intel.com>, "Zhang, Jun" <jun.zhang@intel.com>,
	Jiri Kosina <jkosina@suse.cz>, Sasha Levin <sashal@kernel.org>,
	linux-input@vger.kernel.org
Subject: [PATCH AUTOSEL 5.0 04/66] HID: debug: fix race condition with between rdesc_show() and device removal
Date: Wed, 24 Apr 2019 10:32:38 -0400	[thread overview]
Message-ID: <20190424143341.27665-4-sashal@kernel.org> (raw)
In-Reply-To: <20190424143341.27665-1-sashal@kernel.org>

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 (Microsoft) <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 ac9fda1b5a72..1384e57182af 100644
--- a/drivers/hid/hid-debug.c
+++ b/drivers/hid/hid-debug.c
@@ -1060,10 +1060,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


  parent reply	other threads:[~2019-04-24 14:33 UTC|newest]

Thread overview: 76+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-04-24 14:32 [PATCH AUTOSEL 5.0 01/66] arm64: dts: rockchip: fix rk3328-roc-cc gmac2io tx/rx_delay Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 02/66] HID: Increase maximum report size allowed by hid_field_extract() Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 03/66] HID: logitech: check the return value of create_singlethread_workqueue Sasha Levin
2019-04-24 14:32 ` Sasha Levin [this message]
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 05/66] rtc: cros-ec: Fail suspend/resume if wake IRQ can't be configured Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 06/66] rtc: sh: Fix invalid alarm warning for non-enabled alarm Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 07/66] ARM: OMAP2+: add missing of_node_put after of_device_is_available Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 08/66] batman-adv: Reduce claim hash refcnt only for removed entry Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 09/66] batman-adv: Reduce tt_local " Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 10/66] batman-adv: Reduce tt_global " Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 11/66] batman-adv: fix warning in function batadv_v_elp_get_throughput Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 12/66] ARM: dts: rockchip: Fix gpu opp node names for rk3288 Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 13/66] reset: meson-audio-arb: Fix missing .owner setting of reset_controller_dev Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 14/66] ARM: dts: Fix dcan clkctrl clock for am3 Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 15/66] i40e: fix i40e_ptp_adjtime when given a negative delta Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 16/66] igb: Fix WARN_ONCE on runtime suspend Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 17/66] ixgbe: fix mdio bus registration Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 18/66] i40e: fix WoL support check Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 19/66] fm10k: Fix a potential NULL pointer dereference Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 20/66] riscv: fix accessing 8-byte variable from RV32 Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 21/66] HID: quirks: Fix keyboard + touchpad on Lenovo Miix 630 Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 22/66] net: hns3: fix compile error Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 23/66] xdp: fix cpumap redirect SKB creation bug Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 24/66] net/mlx5: E-Switch, Protect from invalid memory access in offload fdb table Sasha Levin
2019-04-24 14:32 ` [PATCH AUTOSEL 5.0 25/66] net/mlx5: E-Switch, Fix esw manager vport indication for more vport commands Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 26/66] bonding: show full hw address in sysfs for slave entries Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 27/66] net: stmmac: use correct DMA buffer size in the RX descriptor Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 28/66] net: stmmac: ratelimit RX error logs Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 29/66] net: stmmac: don't stop NAPI processing when dropping a packet Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 30/66] net: stmmac: don't overwrite discard_frame status Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 31/66] net: stmmac: fix dropping of multi-descriptor RX frames Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 32/66] net: stmmac: don't log oversized frames Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 33/66] jffs2: fix use-after-free on symlink traversal Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 34/66] debugfs: " Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 35/66] mfd: twl-core: Disable IRQ while suspended Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 36/66] block: use blk_free_flush_queue() to free hctx->fq in blk_mq_init_hctx Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 37/66] rtc: da9063: set uie_unsupported when relevant Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 38/66] HID: input: add mapping for Assistant key Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 39/66] vfio/pci: use correct format characters Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 40/66] vfio/type1: Limit DMA mappings per container Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 41/66] scsi: core: add new RDAC LENOVO/DE_Series device Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 42/66] scsi: storvsc: Fix calculation of sub-channel count Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 43/66] arm/mach-at91/pm : fix possible object reference leak Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 44/66] blk-mq: do not reset plug->rq_count before the list is sorted Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 45/66] arm64: fix wrong check of on_sdei_stack in nmi context Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 46/66] net: hns: fix KASAN: use-after-free in hns_nic_net_xmit_hw() Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 47/66] net: hns: Use NAPI_POLL_WEIGHT for hns driver Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 48/66] net: hns: Fix probabilistic memory overwrite when HNS driver initialized Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 49/66] net: hns: fix ICMP6 neighbor solicitation messages discard problem Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 50/66] net: hns: Fix WARNING when remove HNS driver with SMMU enabled Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 51/66] libcxgb: fix incorrect ppmax calculation Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 52/66] KVM: SVM: prevent DBG_DECRYPT and DBG_ENCRYPT overflow Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 53/66] kmemleak: powerpc: skip scanning holes in the .bss section Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 54/66] hugetlbfs: fix memory leak for resv_map Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 55/66] sh: fix multiple function definition build errors Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 56/66] kernel/sysctl.c: fix out-of-bounds access when setting file-max Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 57/66] null_blk: prevent crash from bad home_node value Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 58/66] xsysace: Fix error handling in ace_setup Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 59/66] fs: stream_open - opener for stream-like files so that read and write can run simultaneously without deadlock Sasha Levin
2019-04-24 16:34   ` Greg Kroah-Hartman
2019-04-24 16:40     ` Linus Torvalds
2019-04-24 17:02       ` Greg Kroah-Hartman
2019-04-24 17:19       ` Sasha Levin
2019-04-24 17:26         ` Linus Torvalds
2019-04-24 18:30           ` Kirill Smelkov
2019-04-25 10:04             ` David Laight
2019-04-26  7:45               ` Kirill Smelkov
2019-04-26 11:00                 ` David Laight
2019-04-26 18:20                   ` Kirill Smelkov
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 60/66] ARM: orion: don't use using 64-bit DMA masks Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 61/66] ARM: iop: " Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 62/66] pin iocb through aio Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 63/66] aio: fold lookup_kiocb() into its sole caller Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 64/66] aio: keep io_event in aio_kiocb Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 65/66] aio: store event at final iocb_put() Sasha Levin
2019-04-24 14:33 ` [PATCH AUTOSEL 5.0 66/66] Fix aio_poll() races Sasha Levin

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190424143341.27665-4-sashal@kernel.org \
    --to=sashal@kernel.org \
    --cc=bo.he@intel.com \
    --cc=jkosina@suse.cz \
    --cc=jun.zhang@intel.com \
    --cc=linux-input@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=stable@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).