stable.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: linux-kernel@vger.kernel.org
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	stable@vger.kernel.org, Shuah Khan <skhan@linuxfoundation.org>,
	syzbot+a93fba6d384346a761e3@syzkaller.appspotmail.com
Subject: [PATCH 5.4 037/111] usbip: stub-dev synchronize sysfs code paths
Date: Mon, 12 Apr 2021 10:40:15 +0200	[thread overview]
Message-ID: <20210412084005.495831126@linuxfoundation.org> (raw)
In-Reply-To: <20210412084004.200986670@linuxfoundation.org>

From: Shuah Khan <skhan@linuxfoundation.org>

commit 9dbf34a834563dada91366c2ac266f32ff34641a upstream.

Fuzzing uncovered race condition between sysfs code paths in usbip
drivers. Device connect/disconnect code paths initiated through
sysfs interface are prone to races if disconnect happens during
connect and vice versa.

Use sysfs_lock to protect sysfs paths in stub-dev.

Cc: stable@vger.kernel.org
Reported-and-tested-by: syzbot+a93fba6d384346a761e3@syzkaller.appspotmail.com
Signed-off-by: Shuah Khan <skhan@linuxfoundation.org>
Link: https://lore.kernel.org/r/2b182f3561b4a065bf3bf6dce3b0e9944ba17b3f.1616807117.git.skhan@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/usbip/stub_dev.c |   11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

--- a/drivers/usb/usbip/stub_dev.c
+++ b/drivers/usb/usbip/stub_dev.c
@@ -63,6 +63,7 @@ static ssize_t usbip_sockfd_store(struct
 
 		dev_info(dev, "stub up\n");
 
+		mutex_lock(&sdev->ud.sysfs_lock);
 		spin_lock_irq(&sdev->ud.lock);
 
 		if (sdev->ud.status != SDEV_ST_AVAILABLE) {
@@ -87,13 +88,13 @@ static ssize_t usbip_sockfd_store(struct
 		tcp_rx = kthread_create(stub_rx_loop, &sdev->ud, "stub_rx");
 		if (IS_ERR(tcp_rx)) {
 			sockfd_put(socket);
-			return -EINVAL;
+			goto unlock_mutex;
 		}
 		tcp_tx = kthread_create(stub_tx_loop, &sdev->ud, "stub_tx");
 		if (IS_ERR(tcp_tx)) {
 			kthread_stop(tcp_rx);
 			sockfd_put(socket);
-			return -EINVAL;
+			goto unlock_mutex;
 		}
 
 		/* get task structs now */
@@ -112,6 +113,8 @@ static ssize_t usbip_sockfd_store(struct
 		wake_up_process(sdev->ud.tcp_rx);
 		wake_up_process(sdev->ud.tcp_tx);
 
+		mutex_unlock(&sdev->ud.sysfs_lock);
+
 	} else {
 		dev_info(dev, "stub down\n");
 
@@ -122,6 +125,7 @@ static ssize_t usbip_sockfd_store(struct
 		spin_unlock_irq(&sdev->ud.lock);
 
 		usbip_event_add(&sdev->ud, SDEV_EVENT_DOWN);
+		mutex_unlock(&sdev->ud.sysfs_lock);
 	}
 
 	return count;
@@ -130,6 +134,8 @@ sock_err:
 	sockfd_put(socket);
 err:
 	spin_unlock_irq(&sdev->ud.lock);
+unlock_mutex:
+	mutex_unlock(&sdev->ud.sysfs_lock);
 	return -EINVAL;
 }
 static DEVICE_ATTR_WO(usbip_sockfd);
@@ -270,6 +276,7 @@ static struct stub_device *stub_device_a
 	sdev->ud.side		= USBIP_STUB;
 	sdev->ud.status		= SDEV_ST_AVAILABLE;
 	spin_lock_init(&sdev->ud.lock);
+	mutex_init(&sdev->ud.sysfs_lock);
 	sdev->ud.tcp_socket	= NULL;
 	sdev->ud.sockfd		= -1;
 



  parent reply	other threads:[~2021-04-12  8:47 UTC|newest]

Thread overview: 125+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-04-12  8:39 [PATCH 5.4 000/111] 5.4.112-rc1 review Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 001/111] counter: stm32-timer-cnt: fix ceiling miss-alignment with reload register Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 002/111] ALSA: aloop: Fix initialization of controls Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 003/111] ALSA: hda/realtek: Fix speaker amp setup on Acer Aspire E1 Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 004/111] ASoC: intel: atom: Stop advertising non working S24LE support Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 005/111] nfc: fix refcount leak in llcp_sock_bind() Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 006/111] nfc: fix refcount leak in llcp_sock_connect() Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 007/111] nfc: fix memory " Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 008/111] nfc: Avoid endless loops caused by repeated llcp_sock_connect() Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 009/111] xen/evtchn: Change irq_info lock to raw_spinlock_t Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 010/111] net: ipv6: check for validity before dereferencing cfg->fc_nlinfo.nlh Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 011/111] net: dsa: lantiq_gswip: Let GSWIP automatically set the xMII clock Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 012/111] drm/i915: Fix invalid access to ACPI _DSM objects Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 013/111] gcov: re-fix clang-11+ support Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 014/111] ia64: fix user_stack_pointer() for ptrace() Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 015/111] nds32: flush_dcache_page: use page_mapping_file to avoid races with swapoff Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 016/111] ocfs2: fix deadlock between setattr and dio_end_io_write Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 017/111] fs: direct-io: fix missing sdio->boundary Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 018/111] parisc: parisc-agp requires SBA IOMMU driver Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 019/111] parisc: avoid a warning on u8 cast for cmpxchg on u8 pointers Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 020/111] ARM: dts: turris-omnia: configure LED[2]/INTn pin as interrupt pin Greg Kroah-Hartman
2021-04-12  8:39 ` [PATCH 5.4 021/111] batman-adv: initialize "struct batadv_tvlv_tt_vlan_data"->reserved field Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 022/111] ice: Increase control queue timeout Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 023/111] ice: Fix for dereference of NULL pointer Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 024/111] ice: Cleanup fltr list in case of allocation issues Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 025/111] net: hso: fix null-ptr-deref during tty device unregistration Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 026/111] ethernet/netronome/nfp: Fix a use after free in nfp_bpf_ctrl_msg_rx Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 027/111] bpf, sockmap: Fix sk->prot unhash op reset Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 028/111] net: ensure mac header is set in virtio_net_hdr_to_skb() Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 029/111] i40e: Fix sparse warning: missing error code err Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 030/111] i40e: Fix sparse error: vsi->netdev could be null Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 031/111] net: sched: sch_teql: fix null-pointer dereference Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 032/111] mac80211: fix TXQ AC confusion Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 033/111] net: hsr: Reset MAC header for Tx path Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 034/111] net-ipv6: bugfix - raw & sctp - switch to ipv6_can_nonlocal_bind() Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 035/111] net: let skb_orphan_partial wake-up waiters Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 036/111] usbip: add sysfs_lock to synchronize sysfs code paths Greg Kroah-Hartman
2021-04-12  8:40 ` Greg Kroah-Hartman [this message]
2021-04-12  8:40 ` [PATCH 5.4 038/111] usbip: vudc " Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 039/111] usbip: synchronize event handler with " Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 040/111] i2c: turn recovery error on init to debug Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 041/111] virtio_net: Add XDP meta data support Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 042/111] virtio_net: Do not pull payload in skb->head Greg Kroah-Hartman
2021-04-12  9:12   ` Michael S. Tsirkin
2021-05-18 19:35     ` Eric Dumazet
2021-05-19  0:04       ` Sasha Levin
2021-04-12  8:40 ` [PATCH 5.4 043/111] net: dsa: lantiq_gswip: Dont use PHY auto polling Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 044/111] net: dsa: lantiq_gswip: Configure all remaining GSWIP_MII_CFG bits Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 045/111] xfrm: interface: fix ipv4 pmtu check to honor ip header df Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 046/111] regulator: bd9571mwv: Fix AVS and DVFS voltage range Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 047/111] net: xfrm: Localize sequence counter per network namespace Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 048/111] esp: delete NETIF_F_SCTP_CRC bit from features for esp offload Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 049/111] ASoC: SOF: Intel: hda: remove unnecessary parentheses Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 050/111] ASoC: SOF: Intel: HDA: fix core status verification Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 051/111] ASoC: wm8960: Fix wrong bclk and lrclk with pll enabled for some chips Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 052/111] xfrm: Fix NULL pointer dereference on policy lookup Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 053/111] i40e: Added Asym_Pause to supported link modes Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 054/111] i40e: Fix kernel oops when i40e driver removes VFs Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 055/111] hostfs: Use kasprintf() instead of fixed buffer formatting Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 056/111] hostfs: fix memory handling in follow_link() Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 057/111] amd-xgbe: Update DMA coherency values Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 058/111] sch_red: fix off-by-one checks in red_check_params() Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 059/111] arm64: dts: imx8mm/q: Fix pad control of SD1_DATA0 Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 060/111] can: bcm/raw: fix msg_namelen values depending on CAN_REQUIRED_SIZE Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 061/111] gianfar: Handle error code at MAC address change Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 062/111] cxgb4: avoid collecting SGE_QBASE regs during traffic Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 063/111] net:tipc: Fix a double free in tipc_sk_mcast_rcv Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 064/111] ARM: dts: imx6: pbab01: Set vmmc supply for both SD interfaces Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 065/111] net/ncsi: Avoid channel_monitor hrtimer deadlock Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 066/111] nfp: flower: ignore duplicate merge hints from FW Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 067/111] net: phy: broadcom: Only advertise EEE for supported modes Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 068/111] ASoC: sunxi: sun4i-codec: fill ASoC card owner Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 069/111] net/mlx5e: Fix ethtool indication of connector type Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 070/111] net/mlx5: Dont request more than supported EQs Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 071/111] net/rds: Fix a use after free in rds_message_map_pages Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 072/111] soc/fsl: qbman: fix conflicting alignment attributes Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 073/111] i40e: Fix display statistics for veb_tc Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 074/111] drm/msm: Set drvdata to NULL when msm_drm_init() fails Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 075/111] net: udp: Add support for getsockopt(..., ..., UDP_GRO, ..., ...); Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 076/111] scsi: ufs: Fix irq return code Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 077/111] scsi: ufs: Avoid busy-waiting by eliminating tag conflicts Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 078/111] scsi: ufs: Use blk_{get,put}_request() to allocate and free TMFs Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 079/111] scsi: ufs: core: Fix task management request completion timeout Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 080/111] scsi: ufs: core: Fix wrong Task Tag used in task management request UPIUs Greg Kroah-Hartman
2021-04-12  8:40 ` [PATCH 5.4 081/111] net: macb: restore cmp registers on resume path Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 082/111] clk: fix invalid usage of list cursor in register Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 083/111] clk: fix invalid usage of list cursor in unregister Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 084/111] workqueue: Move the position of debug_work_activate() in __queue_work() Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 085/111] s390/cpcmd: fix inline assembly register clobbering Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 086/111] perf inject: Fix repipe usage Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 087/111] net: openvswitch: conntrack: simplify the return expression of ovs_ct_limit_get_default_limit() Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 088/111] openvswitch: fix send of uninitialized stack memory in ct limit reply Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 089/111] net: hns3: clear VF down state bit before request link status Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 090/111] net/mlx5: Fix placement of log_max_flow_counter Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 091/111] net/mlx5: Fix PBMC register mapping Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 092/111] RDMA/cxgb4: check for ipv6 address properly while destroying listener Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 093/111] RDMA/addr: Be strict with gid size Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 094/111] RAS/CEC: Correct ce_add_elem()s returned values Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 095/111] clk: socfpga: fix iomem pointer cast on 64-bit Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 096/111] dt-bindings: net: ethernet-controller: fix typo in NVMEM Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 097/111] net: sched: bump refcount for new action in ACT replace mode Greg Kroah-Hartman
2021-04-13 10:36   ` Sudip Mukherjee
2021-04-13 10:51     ` Greg Kroah-Hartman
2021-04-13 12:40       ` Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 098/111] cfg80211: remove WARN_ON() in cfg80211_sme_connect Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 099/111] net: tun: set tun->dev->addr_len during TUNSETLINK processing Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 100/111] drivers: net: fix memory leak in atusb_probe Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 101/111] drivers: net: fix memory leak in peak_usb_create_dev Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 102/111] net: mac802154: Fix general protection fault Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 103/111] net: ieee802154: nl-mac: fix check on panid Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 104/111] net: ieee802154: fix nl802154 del llsec key Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 105/111] net: ieee802154: fix nl802154 del llsec dev Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 106/111] net: ieee802154: fix nl802154 add llsec key Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 107/111] net: ieee802154: fix nl802154 del llsec devkey Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 108/111] net: ieee802154: forbid monitor for set llsec params Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 109/111] net: ieee802154: forbid monitor for del llsec seclevel Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 110/111] net: ieee802154: stop dump llsec params for monitors Greg Kroah-Hartman
2021-04-12  8:41 ` [PATCH 5.4 111/111] Revert "cifs: Set CIFS_MOUNT_USE_PREFIX_PATH flag on setting cifs_sb->prepath." Greg Kroah-Hartman
2021-04-12 13:12 ` [PATCH 5.4 000/111] 5.4.112-rc1 review Jon Hunter
2021-04-12 18:57 ` Florian Fainelli
2021-04-12 22:08 ` Guenter Roeck
2021-04-13  1:35 ` Shuah Khan
2021-04-13  5:17 ` Naresh Kamboju
2021-04-13 10:31 ` Samuel Zou
2021-04-13 10:42 ` Sudip Mukherjee

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=20210412084005.495831126@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=skhan@linuxfoundation.org \
    --cc=stable@vger.kernel.org \
    --cc=syzbot+a93fba6d384346a761e3@syzkaller.appspotmail.com \
    /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).