linux-kernel.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, Michael Wu <michael@allwinnertech.com>,
	John Keeping <john@metanate.com>,
	Linyu Yuan <quic_linyyuan@quicinc.com>
Subject: [PATCH 5.15 090/106] usb: gadget: f_fs: change ep->status safe in ffs_epfile_io()
Date: Mon, 20 Jun 2022 14:51:49 +0200	[thread overview]
Message-ID: <20220620124727.050996609@linuxfoundation.org> (raw)
In-Reply-To: <20220620124724.380838401@linuxfoundation.org>

From: Linyu Yuan <quic_linyyuan@quicinc.com>

commit fb1f16d74e263baa4ad11e31e28b68f144aa55ed upstream.

If a task read/write data in blocking mode, it will wait the completion
in ffs_epfile_io(), if function unbind occurs, ffs_func_unbind() will
kfree ffs ep, once the task wake up, it still dereference the ffs ep to
obtain the request status.

Fix it by moving the request status to io_data which is stack-safe.

Cc: <stable@vger.kernel.org> # 5.15
Reported-by: Michael Wu <michael@allwinnertech.com>
Tested-by: Michael Wu <michael@allwinnertech.com>
Reviewed-by: John Keeping <john@metanate.com>
Signed-off-by: Linyu Yuan <quic_linyyuan@quicinc.com>
Link: https://lore.kernel.org/r/1654863478-26228-2-git-send-email-quic_linyyuan@quicinc.com
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
---
 drivers/usb/gadget/function/f_fs.c |   34 +++++++++++++++++++---------------
 1 file changed, 19 insertions(+), 15 deletions(-)

--- a/drivers/usb/gadget/function/f_fs.c
+++ b/drivers/usb/gadget/function/f_fs.c
@@ -122,8 +122,6 @@ struct ffs_ep {
 	struct usb_endpoint_descriptor	*descs[3];
 
 	u8				num;
-
-	int				status;	/* P: epfile->mutex */
 };
 
 struct ffs_epfile {
@@ -227,6 +225,9 @@ struct ffs_io_data {
 	bool use_sg;
 
 	struct ffs_data *ffs;
+
+	int status;
+	struct completion done;
 };
 
 struct ffs_desc_helper {
@@ -707,12 +708,15 @@ static const struct file_operations ffs_
 
 static void ffs_epfile_io_complete(struct usb_ep *_ep, struct usb_request *req)
 {
+	struct ffs_io_data *io_data = req->context;
+
 	ENTER();
-	if (req->context) {
-		struct ffs_ep *ep = _ep->driver_data;
-		ep->status = req->status ? req->status : req->actual;
-		complete(req->context);
-	}
+	if (req->status)
+		io_data->status = req->status;
+	else
+		io_data->status = req->actual;
+
+	complete(&io_data->done);
 }
 
 static ssize_t ffs_copy_to_iter(void *data, int data_len, struct iov_iter *iter)
@@ -1050,7 +1054,6 @@ static ssize_t ffs_epfile_io(struct file
 		WARN(1, "%s: data_len == -EINVAL\n", __func__);
 		ret = -EINVAL;
 	} else if (!io_data->aio) {
-		DECLARE_COMPLETION_ONSTACK(done);
 		bool interrupted = false;
 
 		req = ep->req;
@@ -1066,7 +1069,8 @@ static ssize_t ffs_epfile_io(struct file
 
 		io_data->buf = data;
 
-		req->context  = &done;
+		init_completion(&io_data->done);
+		req->context  = io_data;
 		req->complete = ffs_epfile_io_complete;
 
 		ret = usb_ep_queue(ep->ep, req, GFP_ATOMIC);
@@ -1075,7 +1079,7 @@ static ssize_t ffs_epfile_io(struct file
 
 		spin_unlock_irq(&epfile->ffs->eps_lock);
 
-		if (wait_for_completion_interruptible(&done)) {
+		if (wait_for_completion_interruptible(&io_data->done)) {
 			/*
 			 * To avoid race condition with ffs_epfile_io_complete,
 			 * dequeue the request first then check
@@ -1083,17 +1087,17 @@ static ssize_t ffs_epfile_io(struct file
 			 * condition with req->complete callback.
 			 */
 			usb_ep_dequeue(ep->ep, req);
-			wait_for_completion(&done);
-			interrupted = ep->status < 0;
+			wait_for_completion(&io_data->done);
+			interrupted = io_data->status < 0;
 		}
 
 		if (interrupted)
 			ret = -EINTR;
-		else if (io_data->read && ep->status > 0)
-			ret = __ffs_epfile_read_data(epfile, data, ep->status,
+		else if (io_data->read && io_data->status > 0)
+			ret = __ffs_epfile_read_data(epfile, data, io_data->status,
 						     &io_data->data);
 		else
-			ret = ep->status;
+			ret = io_data->status;
 		goto error_mutex;
 	} else if (!(req = usb_ep_alloc_request(ep->ep, GFP_ATOMIC))) {
 		ret = -ENOMEM;



  parent reply	other threads:[~2022-06-20 13:29 UTC|newest]

Thread overview: 121+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-06-20 12:50 [PATCH 5.15 000/106] 5.15.49-rc1 review Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 001/106] Revert "drm/amd/display: Fix DCN3 B0 DP Alt Mapping" Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 002/106] nfsd: Replace use of rwsem with errseq_t Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 003/106] arm64: dts: imx8mm-beacon: Enable RTS-CTS on UART3 Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 004/106] arm64: dts: imx8mn-beacon: " Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 005/106] powerpc/kasan: Silence KASAN warnings in __get_wchan() Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 006/106] ASoC: nau8822: Add operation for internal PLL off and on Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 007/106] drm/amd/display: Read Golden Settings Table from VBIOS Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 008/106] drm/amdkfd: Use mmget_not_zero in MMU notifier Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 009/106] dma-debug: make things less spammy under memory pressure Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 010/106] ASoC: cs42l52: Fix TLV scales for mixer controls Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 011/106] ASoC: cs35l36: Update digital volume TLV Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 012/106] ASoC: cs53l30: Correct number of volume levels on SX controls Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 013/106] ASoC: cs42l52: Correct TLV for Bypass Volume Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 014/106] ASoC: cs42l56: Correct typo in minimum level for SX volume controls Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 015/106] ASoC: cs42l51: Correct minimum value for SX volume control Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 016/106] drm/amdkfd: add pinned BOs to kfd_bo_list Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 017/106] ata: libata-core: fix NULL pointer deref in ata_host_alloc_pinfo() Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 018/106] quota: Prevent memory allocation recursion while holding dq_lock Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 019/106] ASoC: wm8962: Fix suspend while playing music Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 020/106] ASoC: es8328: Fix event generation for deemphasis control Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 021/106] ASoC: wm_adsp: Fix event generation for wm_adsp_fw_put() Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 022/106] Input: soc_button_array - also add Lenovo Yoga Tablet2 1051F to dmi_use_low_level_irq Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 023/106] scsi: vmw_pvscsi: Expand vcpuHint to 16 bits Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 024/106] scsi: lpfc: Resolve NULL ptr dereference after an ELS LOGO is aborted Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 025/106] scsi: lpfc: Fix port stuck in bypassed state after LIP in PT2PT topology Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 026/106] scsi: lpfc: Allow reduced polling rate for nvme_admin_async_event cmd completion Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 027/106] scsi: mpt3sas: Fix out-of-bounds compiler warning Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 028/106] scsi: ipr: Fix missing/incorrect resource cleanup in error case Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 029/106] scsi: pmcraid: Fix missing " Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 030/106] ALSA: hda/realtek - Add HW8326 support Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 031/106] virtio-mmio: fix missing put_device() when vm_cmdline_parent registration failed Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 032/106] nfc: nfcmrvl: Fix memory leak in nfcmrvl_play_deferred Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 033/106] ipv6: Fix signed integer overflow in l2tp_ip6_sendmsg Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 034/106] net: ethernet: mtk_eth_soc: fix misuse of mem alloc interface netdev[napi]_alloc_frag Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 035/106] gcc-12: disable -Wdangling-pointer warning for now Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 036/106] mellanox: mlx5: avoid uninitialized variable warning with gcc-12 Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 037/106] netfs: gcc-12: temporarily disable -Wattribute-warning for now Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 038/106] MIPS: Loongson-3: fix compile mips cpu_hwmon as module build error Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 039/106] random: credit cpu and bootloader seeds by default Greg Kroah-Hartman
2022-06-20 12:50 ` [PATCH 5.15 040/106] gpio: dwapb: Dont print error on -EPROBE_DEFER Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 041/106] platform/x86: gigabyte-wmi: Add Z690M AORUS ELITE AX DDR4 support Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 042/106] platform/x86: gigabyte-wmi: Add support for B450M DS3H-CF Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 043/106] platform/x86/intel: hid: Add Surface Go to VGBS allow list Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 044/106] staging: r8188eu: fix rtw_alloc_hwxmits error detection for now Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 045/106] staging: r8188eu: Use zeroing allocator in wpa_set_encryption() Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 046/106] staging: r8188eu: Fix warning of array overflow in ioctl_linux.c Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 047/106] pNFS: Dont keep retrying if the server replied NFS4ERR_LAYOUTUNAVAILABLE Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 048/106] pNFS: Avoid a live lock condition in pnfs_update_layout() Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 049/106] sunrpc: set cl_max_connect when cloning an rpc_clnt Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 050/106] clocksource: hyper-v: unexport __init-annotated hv_init_clocksource() Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 051/106] i40e: Fix adding ADQ filter to TC0 Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 052/106] i40e: Fix calculating the number of queue pairs Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 053/106] i40e: Fix call trace in setup_tx_descriptors Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 054/106] Drivers: hv: vmbus: Release cpu lock in error case Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 055/106] tty: goldfish: Fix free_irq() on remove Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 056/106] misc: atmel-ssc: Fix IRQ check in ssc_probe Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 057/106] io_uring: fix races with file table unregister Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 058/106] io_uring: fix races with buffer " Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 059/106] drm/i915/reset: Fix error_state_read ptr + offset use Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 060/106] net: hns3: split function hclge_update_port_base_vlan_cfg() Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 061/106] net: hns3: set port base vlan tbl_sta to false before removing old vlan Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 062/106] net: hns3: dont push link state to VF if unalive Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 063/106] net: hns3: fix tm port shapping of fibre port is incorrect after driver initialization Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 064/106] nvme: add device name to warning in uuid_show() Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 065/106] mlxsw: spectrum_cnt: Reorder counter pools Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 066/106] net: bgmac: Fix an erroneous kfree() in bgmac_remove() Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 067/106] net: ax25: Fix deadlock caused by skb_recv_datagram in ax25_recvmsg Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 068/106] arm64: ftrace: fix branch range checks Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 069/106] arm64: ftrace: consistently handle PLTs Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 070/106] certs/blacklist_hashes.c: fix const confusion in certs blacklist Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 071/106] init: Initialize noop_backing_dev_info early Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 072/106] block: Fix handling of offline queues in blk_mq_alloc_request_hctx() Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 073/106] faddr2line: Fix overlapping text section failures, the sequel Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 074/106] i2c: npcm7xx: Add check for platform_driver_register Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 075/106] irqchip/gic/realview: Fix refcount leak in realview_gic_of_init Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 076/106] irqchip/gic-v3: Fix error handling in gic_populate_ppi_partitions Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 077/106] irqchip/gic-v3: Fix refcount leak " Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 078/106] irqchip/realtek-rtl: Fix refcount leak in map_interrupts Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 079/106] sched: Fix balance_push() vs __sched_setscheduler() Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 080/106] i2c: designware: Use standard optional ref clock implementation Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 081/106] mei: hbm: drop capability response on early shutdown Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 082/106] mei: me: add raptor lake point S DID Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 083/106] comedi: vmk80xx: fix expression for tx buffer size Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 084/106] crypto: memneq - move into lib/ Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 085/106] USB: serial: option: add support for Cinterion MV31 with new baseline Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 086/106] USB: serial: io_ti: add Agilent E5805A support Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 087/106] usb: dwc2: Fix memory leak in dwc2_hcd_init Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 088/106] usb: cdnsp: Fixed setting last_trb incorrectly Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 089/106] usb: gadget: lpc32xx_udc: Fix refcount leak in lpc32xx_udc_probe Greg Kroah-Hartman
2022-06-20 12:51 ` Greg Kroah-Hartman [this message]
2022-06-20 12:51 ` [PATCH 5.15 091/106] usb: gadget: f_fs: change ep->ep safe in ffs_epfile_io() Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 092/106] tty: n_gsm: Debug output allocation must use GFP_ATOMIC Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 093/106] serial: 8250: Store to lsr_save_flags after lsr read Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 094/106] bus: fsl-mc-bus: fix KASAN use-after-free in fsl_mc_bus_remove() Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 095/106] dm mirror log: round up region bitmap size to BITS_PER_LONG Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 096/106] drm/amd/display: Cap OLED brightness per max frame-average luminance Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 097/106] cfi: Fix __cfi_slowpath_diag RCU usage with cpuidle Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 098/106] ext4: fix super block checksum incorrect after mount Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 099/106] ext4: fix bug_on ext4_mb_use_inode_pa Greg Kroah-Hartman
2022-06-20 12:51 ` [PATCH 5.15 100/106] ext4: make variable "count" signed Greg Kroah-Hartman
2022-06-20 12:52 ` [PATCH 5.15 101/106] ext4: add reserved GDT blocks check Greg Kroah-Hartman
2022-06-20 12:52 ` [PATCH 5.15 102/106] KVM: arm64: Dont read a HW interrupt pending state in user context Greg Kroah-Hartman
2022-06-20 12:52 ` [PATCH 5.15 103/106] ALSA: hda/realtek: fix right sounds and mute/micmute LEDs for HP machine Greg Kroah-Hartman
2022-06-20 12:52 ` [PATCH 5.15 104/106] virtio-pci: Remove wrong address verification in vp_del_vqs() Greg Kroah-Hartman
2022-06-20 12:52 ` [PATCH 5.15 105/106] powerpc/book3e: get rid of #include <generated/compile.h> Greg Kroah-Hartman
2022-06-20 12:52 ` [PATCH 5.15 106/106] clk: imx8mp: fix usb_root_clk parent Greg Kroah-Hartman
2022-06-20 16:38 ` [PATCH 5.15 000/106] 5.15.49-rc1 review Fox Chen
2022-06-20 18:13 ` Florian Fainelli
2022-06-21  0:47 ` Guenter Roeck
2022-06-21  3:29 ` Bagas Sanjaya
2022-06-21  8:20 ` Ron Economos
2022-06-21  8:36 ` Naresh Kamboju
2022-06-21  8:55   ` Greg Kroah-Hartman
2022-06-21  9:45     ` Jason A. Donenfeld
2022-06-21 10:35       ` Greg Kroah-Hartman
2022-06-21 11:36         ` Naresh Kamboju
2022-06-21 15:12           ` Greg Kroah-Hartman
2022-06-21  9:40 ` Sudip Mukherjee
2022-06-21  9:59 ` Jon Hunter
2022-06-21 21:48 ` Shuah Khan

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=20220620124727.050996609@linuxfoundation.org \
    --to=gregkh@linuxfoundation.org \
    --cc=john@metanate.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=michael@allwinnertech.com \
    --cc=quic_linyyuan@quicinc.com \
    --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).