linux/drivers/usb/gadget/function
Lars-Peter Clausen aa8141daf0 usb: gadget: ffs: Execute copy_to_user() with USER_DS set
[ Upstream commit 4058ebf33c ]

When using a AIO read() operation on the function FS gadget driver a URB is
submitted asynchronously and on URB completion the received data is copied
to the userspace buffer associated with the read operation.

This is done from a kernel worker thread invoking copy_to_user() (through
copy_to_iter()). And while the user space process memory is made available
to the kernel thread using use_mm(), some architecture require in addition
to this that the operation runs with USER_DS set. Otherwise the userspace
memory access will fail.

For example on ARM64 with Privileged Access Never (PAN) and User Access
Override (UAO) enabled the following crash occurs.

	Internal error: Accessing user space memory with fs=KERNEL_DS: 9600004f [#1] SMP
	Modules linked in:
	CPU: 2 PID: 1636 Comm: kworker/2:1 Not tainted 4.9.0-04081-g8ab2dfb-dirty #487
	Hardware name: ZynqMP ZCU102 Rev1.0 (DT)
	Workqueue: events ffs_user_copy_worker
	task: ffffffc87afc8080 task.stack: ffffffc87a00c000
	PC is at __arch_copy_to_user+0x190/0x220
	LR is at copy_to_iter+0x78/0x3c8
	[...]
	[<ffffff800847b790>] __arch_copy_to_user+0x190/0x220
	[<ffffff80086f25d8>] ffs_user_copy_worker+0x70/0x130
	[<ffffff80080b8c64>] process_one_work+0x1dc/0x460
	[<ffffff80080b8f38>] worker_thread+0x50/0x4b0
	[<ffffff80080bf5a0>] kthread+0xd8/0xf0
	[<ffffff8008083680>] ret_from_fork+0x10/0x50

Address this by placing a set_fs(USER_DS) before of the copy operation
and revert it again once the copy operation has finished.

This patch is analogous to commit d7ffde35e3 ("vhost: use USER_DS in
vhost_worker thread") which addresses the same underlying issue.

Signed-off-by: Lars-Peter Clausen <lars@metafoo.de>
Signed-off-by: Felipe Balbi <felipe.balbi@linux.intel.com>
Signed-off-by: Sasha Levin <alexander.levin@microsoft.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2018-05-30 07:49:12 +02:00
..
f_acm.c ACM gadget: fix endianness in notifications 2017-03-30 09:35:16 +02:00
f_ecm.c Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending 2015-11-13 20:04:17 -08:00
f_eem.c Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending 2015-11-13 20:04:17 -08:00
f_fs.c usb: gadget: ffs: Execute copy_to_user() with USER_DS set 2018-05-30 07:49:12 +02:00
f_hid.c usb: gadget: f_hid: fix: Prevent accessing released memory 2018-04-08 11:51:56 +02:00
f_loopback.c usb: gadget: f_loopback: fix the warning during the enumeration 2015-11-17 11:35:47 -06:00
f_mass_storage.c USB: g_mass_storage: Fix deadlock when driver is unbound 2017-10-12 11:27:32 +02:00
f_mass_storage.h USB: g_mass_storage: Fix deadlock when driver is unbound 2017-10-12 11:27:32 +02:00
f_midi.c usb: gadget: define free_ep_req as universal function 2018-04-08 11:51:56 +02:00
f_ncm.c Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending 2015-11-13 20:04:17 -08:00
f_obex.c Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending 2015-11-13 20:04:17 -08:00
f_phonet.c Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending 2015-11-13 20:04:17 -08:00
f_printer.c Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending 2015-11-13 20:04:17 -08:00
f_rndis.c Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending 2015-11-13 20:04:17 -08:00
f_serial.c Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending 2015-11-13 20:04:17 -08:00
f_sourcesink.c usb: gadget: define free_ep_req as universal function 2018-04-08 11:51:56 +02:00
f_subset.c Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending 2015-11-13 20:04:17 -08:00
f_uac1.c Merge branch 'for-next' of git://git.kernel.org/pub/scm/linux/kernel/git/nab/target-pending 2015-11-13 20:04:17 -08:00
f_uac2.c usb: gadget: f_uac2: fix bFirstInterface in composite gadget 2018-05-30 07:48:58 +02:00
f_uvc.c usb: gadget: f_uvc: Sanity check wMaxPacketSize for SuperSpeed 2017-12-25 14:22:10 +01:00
f_uvc.h
g_zero.h usb: gadget: define free_ep_req as universal function 2018-04-08 11:51:56 +02:00
Makefile
ndis.h
rndis.c usb: gadget: rndis: use signed type for a signed value 2015-05-21 16:29:14 -05:00
rndis.h usb: gadget: rndis: use signed type for a signed value 2015-05-21 16:29:14 -05:00
storage_common.c vfs: add file_path() helper 2015-06-23 18:00:05 -04:00
storage_common.h usb: gadget: storage-common: Set FSG_MAX_LUNS to 16 2015-07-29 09:59:19 -05:00
u_ecm.h
u_eem.h
u_ether_configfs.h usb-gadget/ether: use per-attribute show and store methods 2015-10-13 22:14:18 -07:00
u_ether.c usb: gadget: u_ether: remove interrupt throttling 2016-11-18 10:48:35 +01:00
u_ether.h usb: gadget: remove gadget_chips.h 2015-08-06 09:35:20 -05:00
u_fs.h
u_gether.h
u_hid.h
u_midi.h
u_ncm.h
u_phonet.h
u_printer.h
u_rndis.h usb: gadget: rndis: remove the limit of available rndis connections 2015-05-07 13:47:17 -05:00
u_serial.c TTY/Serial driver patches for 4.4-rc1 2015-11-04 21:35:12 -08:00
u_serial.h
u_uac1.c
u_uac1.h usb: gadget: remove gadget_chips.h 2015-08-06 09:35:20 -05:00
u_uac2.h
u_uvc.h
uvc_configfs.c usb: gadget: uvc: Missing files for configfs interface 2018-02-16 20:09:40 +01:00
uvc_configfs.h
uvc_queue.c [media] media: videobuf2: Change queue_setup argument 2015-10-20 14:48:39 -02:00
uvc_queue.h [media] media: videobuf2: Restructure vb2_buffer 2015-10-01 09:04:43 -03:00
uvc_v4l2.c
uvc_v4l2.h
uvc_video.c usb: gadget: composite: always set ep->mult to a sensible value 2017-01-12 11:22:51 +01:00
uvc_video.h
uvc.h