<feed xmlns='http://www.w3.org/2005/Atom'>
<title>linux-toradex.git/drivers/usb/gadget/function/f_fs.c, branch v4.4.78</title>
<subtitle>Linux kernel for Apalis and Colibri modules</subtitle>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/'/>
<entry>
<title>usb: gadget: f_fs: Fix possibe deadlock</title>
<updated>2017-07-05T12:37:16+00:00</updated>
<author>
<name>Baolin Wang</name>
<email>baolin.wang@linaro.org</email>
</author>
<published>2016-12-08T11:55:22+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=1e0f216195a6d106ed50c386abffdf60f496d518'/>
<id>1e0f216195a6d106ed50c386abffdf60f496d518</id>
<content type='text'>
commit b3ce3ce02d146841af012d08506b4071db8ffde3 upstream.

When system try to close /dev/usb-ffs/adb/ep0 on one core, at the same
time another core try to attach new UDC, which will cause deadlock as
below scenario. Thus we should release ffs lock before issuing
unregister_gadget_item().

[   52.642225] c1 ======================================================
[   52.642228] c1 [ INFO: possible circular locking dependency detected ]
[   52.642236] c1 4.4.6+ #1 Tainted: G        W  O
[   52.642241] c1 -------------------------------------------------------
[   52.642245] c1 usb ffs open/2808 is trying to acquire lock:
[   52.642270] c0  (udc_lock){+.+.+.}, at: [&lt;ffffffc00065aeec&gt;]
		usb_gadget_unregister_driver+0x3c/0xc8
[   52.642272] c1  but task is already holding lock:
[   52.642283] c0  (ffs_lock){+.+.+.}, at: [&lt;ffffffc00066b244&gt;]
		ffs_data_clear+0x30/0x140
[   52.642285] c1 which lock already depends on the new lock.
[   52.642287] c1
               the existing dependency chain (in reverse order) is:
[   52.642295] c0
	       -&gt; #1 (ffs_lock){+.+.+.}:
[   52.642307] c0        [&lt;ffffffc00012340c&gt;] __lock_acquire+0x20f0/0x2238
[   52.642314] c0        [&lt;ffffffc000123b54&gt;] lock_acquire+0xe4/0x298
[   52.642322] c0        [&lt;ffffffc000aaf6e8&gt;] mutex_lock_nested+0x7c/0x3cc
[   52.642328] c0        [&lt;ffffffc00066f7bc&gt;] ffs_func_bind+0x504/0x6e8
[   52.642334] c0        [&lt;ffffffc000654004&gt;] usb_add_function+0x84/0x184
[   52.642340] c0        [&lt;ffffffc000658ca4&gt;] configfs_composite_bind+0x264/0x39c
[   52.642346] c0        [&lt;ffffffc00065b348&gt;] udc_bind_to_driver+0x58/0x11c
[   52.642352] c0        [&lt;ffffffc00065b49c&gt;] usb_udc_attach_driver+0x90/0xc8
[   52.642358] c0        [&lt;ffffffc0006598e0&gt;] gadget_dev_desc_UDC_store+0xd4/0x128
[   52.642369] c0        [&lt;ffffffc0002c14e8&gt;] configfs_write_file+0xd0/0x13c
[   52.642376] c0        [&lt;ffffffc00023c054&gt;] vfs_write+0xb8/0x214
[   52.642381] c0        [&lt;ffffffc00023cad4&gt;] SyS_write+0x54/0xb0
[   52.642388] c0        [&lt;ffffffc000085ff0&gt;] el0_svc_naked+0x24/0x28
[   52.642395] c0
              -&gt; #0 (udc_lock){+.+.+.}:
[   52.642401] c0        [&lt;ffffffc00011e3d0&gt;] print_circular_bug+0x84/0x2e4
[   52.642407] c0        [&lt;ffffffc000123454&gt;] __lock_acquire+0x2138/0x2238
[   52.642412] c0        [&lt;ffffffc000123b54&gt;] lock_acquire+0xe4/0x298
[   52.642420] c0        [&lt;ffffffc000aaf6e8&gt;] mutex_lock_nested+0x7c/0x3cc
[   52.642427] c0        [&lt;ffffffc00065aeec&gt;] usb_gadget_unregister_driver+0x3c/0xc8
[   52.642432] c0        [&lt;ffffffc00065995c&gt;] unregister_gadget_item+0x28/0x44
[   52.642439] c0        [&lt;ffffffc00066b34c&gt;] ffs_data_clear+0x138/0x140
[   52.642444] c0        [&lt;ffffffc00066b374&gt;] ffs_data_reset+0x20/0x6c
[   52.642450] c0        [&lt;ffffffc00066efd0&gt;] ffs_data_closed+0xac/0x12c
[   52.642454] c0        [&lt;ffffffc00066f070&gt;] ffs_ep0_release+0x20/0x2c
[   52.642460] c0        [&lt;ffffffc00023dbe4&gt;] __fput+0xb0/0x1f4
[   52.642466] c0        [&lt;ffffffc00023dd9c&gt;] ____fput+0x20/0x2c
[   52.642473] c0        [&lt;ffffffc0000ee944&gt;] task_work_run+0xb4/0xe8
[   52.642482] c0        [&lt;ffffffc0000cd45c&gt;] do_exit+0x360/0xb9c
[   52.642487] c0        [&lt;ffffffc0000cf228&gt;] do_group_exit+0x4c/0xb0
[   52.642494] c0        [&lt;ffffffc0000dd3c8&gt;] get_signal+0x380/0x89c
[   52.642501] c0        [&lt;ffffffc00008a8f0&gt;] do_signal+0x154/0x518
[   52.642507] c0        [&lt;ffffffc00008af00&gt;] do_notify_resume+0x70/0x78
[   52.642512] c0        [&lt;ffffffc000085ee8&gt;] work_pending+0x1c/0x20
[   52.642514] c1
              other info that might help us debug this:
[   52.642517] c1  Possible unsafe locking scenario:
[   52.642518] c1        CPU0                    CPU1
[   52.642520] c1        ----                    ----
[   52.642525] c0   lock(ffs_lock);
[   52.642529] c0                                lock(udc_lock);
[   52.642533] c0                                lock(ffs_lock);
[   52.642537] c0   lock(udc_lock);
[   52.642539] c1
                      *** DEADLOCK ***
[   52.642543] c1 1 lock held by usb ffs open/2808:
[   52.642555] c0  #0:  (ffs_lock){+.+.+.}, at: [&lt;ffffffc00066b244&gt;]
		ffs_data_clear+0x30/0x140
[   52.642557] c1 stack backtrace:
[   52.642563] c1 CPU: 1 PID: 2808 Comm: usb ffs open Tainted: G
[   52.642565] c1 Hardware name: Spreadtrum SP9860g Board (DT)
[   52.642568] c1 Call trace:
[   52.642573] c1 [&lt;ffffffc00008b430&gt;] dump_backtrace+0x0/0x170
[   52.642577] c1 [&lt;ffffffc00008b5c0&gt;] show_stack+0x20/0x28
[   52.642583] c1 [&lt;ffffffc000422694&gt;] dump_stack+0xa8/0xe0
[   52.642587] c1 [&lt;ffffffc00011e548&gt;] print_circular_bug+0x1fc/0x2e4
[   52.642591] c1 [&lt;ffffffc000123454&gt;] __lock_acquire+0x2138/0x2238
[   52.642595] c1 [&lt;ffffffc000123b54&gt;] lock_acquire+0xe4/0x298
[   52.642599] c1 [&lt;ffffffc000aaf6e8&gt;] mutex_lock_nested+0x7c/0x3cc
[   52.642604] c1 [&lt;ffffffc00065aeec&gt;] usb_gadget_unregister_driver+0x3c/0xc8
[   52.642608] c1 [&lt;ffffffc00065995c&gt;] unregister_gadget_item+0x28/0x44
[   52.642613] c1 [&lt;ffffffc00066b34c&gt;] ffs_data_clear+0x138/0x140
[   52.642618] c1 [&lt;ffffffc00066b374&gt;] ffs_data_reset+0x20/0x6c
[   52.642621] c1 [&lt;ffffffc00066efd0&gt;] ffs_data_closed+0xac/0x12c
[   52.642625] c1 [&lt;ffffffc00066f070&gt;] ffs_ep0_release+0x20/0x2c
[   52.642629] c1 [&lt;ffffffc00023dbe4&gt;] __fput+0xb0/0x1f4
[   52.642633] c1 [&lt;ffffffc00023dd9c&gt;] ____fput+0x20/0x2c
[   52.642636] c1 [&lt;ffffffc0000ee944&gt;] task_work_run+0xb4/0xe8
[   52.642640] c1 [&lt;ffffffc0000cd45c&gt;] do_exit+0x360/0xb9c
[   52.642644] c1 [&lt;ffffffc0000cf228&gt;] do_group_exit+0x4c/0xb0
[   52.642647] c1 [&lt;ffffffc0000dd3c8&gt;] get_signal+0x380/0x89c
[   52.642651] c1 [&lt;ffffffc00008a8f0&gt;] do_signal+0x154/0x518
[   52.642656] c1 [&lt;ffffffc00008af00&gt;] do_notify_resume+0x70/0x78
[   52.642659] c1 [&lt;ffffffc000085ee8&gt;] work_pending+0x1c/0x20

Acked-by: Michal Nazarewicz &lt;mina86@mina86.com&gt;
Signed-off-by: Baolin Wang &lt;baolin.wang@linaro.org&gt;
Signed-off-by: Felipe Balbi &lt;felipe.balbi@linux.intel.com&gt;
Cc: Jerry Zhang &lt;zhangjerry@google.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit b3ce3ce02d146841af012d08506b4071db8ffde3 upstream.

When system try to close /dev/usb-ffs/adb/ep0 on one core, at the same
time another core try to attach new UDC, which will cause deadlock as
below scenario. Thus we should release ffs lock before issuing
unregister_gadget_item().

[   52.642225] c1 ======================================================
[   52.642228] c1 [ INFO: possible circular locking dependency detected ]
[   52.642236] c1 4.4.6+ #1 Tainted: G        W  O
[   52.642241] c1 -------------------------------------------------------
[   52.642245] c1 usb ffs open/2808 is trying to acquire lock:
[   52.642270] c0  (udc_lock){+.+.+.}, at: [&lt;ffffffc00065aeec&gt;]
		usb_gadget_unregister_driver+0x3c/0xc8
[   52.642272] c1  but task is already holding lock:
[   52.642283] c0  (ffs_lock){+.+.+.}, at: [&lt;ffffffc00066b244&gt;]
		ffs_data_clear+0x30/0x140
[   52.642285] c1 which lock already depends on the new lock.
[   52.642287] c1
               the existing dependency chain (in reverse order) is:
[   52.642295] c0
	       -&gt; #1 (ffs_lock){+.+.+.}:
[   52.642307] c0        [&lt;ffffffc00012340c&gt;] __lock_acquire+0x20f0/0x2238
[   52.642314] c0        [&lt;ffffffc000123b54&gt;] lock_acquire+0xe4/0x298
[   52.642322] c0        [&lt;ffffffc000aaf6e8&gt;] mutex_lock_nested+0x7c/0x3cc
[   52.642328] c0        [&lt;ffffffc00066f7bc&gt;] ffs_func_bind+0x504/0x6e8
[   52.642334] c0        [&lt;ffffffc000654004&gt;] usb_add_function+0x84/0x184
[   52.642340] c0        [&lt;ffffffc000658ca4&gt;] configfs_composite_bind+0x264/0x39c
[   52.642346] c0        [&lt;ffffffc00065b348&gt;] udc_bind_to_driver+0x58/0x11c
[   52.642352] c0        [&lt;ffffffc00065b49c&gt;] usb_udc_attach_driver+0x90/0xc8
[   52.642358] c0        [&lt;ffffffc0006598e0&gt;] gadget_dev_desc_UDC_store+0xd4/0x128
[   52.642369] c0        [&lt;ffffffc0002c14e8&gt;] configfs_write_file+0xd0/0x13c
[   52.642376] c0        [&lt;ffffffc00023c054&gt;] vfs_write+0xb8/0x214
[   52.642381] c0        [&lt;ffffffc00023cad4&gt;] SyS_write+0x54/0xb0
[   52.642388] c0        [&lt;ffffffc000085ff0&gt;] el0_svc_naked+0x24/0x28
[   52.642395] c0
              -&gt; #0 (udc_lock){+.+.+.}:
[   52.642401] c0        [&lt;ffffffc00011e3d0&gt;] print_circular_bug+0x84/0x2e4
[   52.642407] c0        [&lt;ffffffc000123454&gt;] __lock_acquire+0x2138/0x2238
[   52.642412] c0        [&lt;ffffffc000123b54&gt;] lock_acquire+0xe4/0x298
[   52.642420] c0        [&lt;ffffffc000aaf6e8&gt;] mutex_lock_nested+0x7c/0x3cc
[   52.642427] c0        [&lt;ffffffc00065aeec&gt;] usb_gadget_unregister_driver+0x3c/0xc8
[   52.642432] c0        [&lt;ffffffc00065995c&gt;] unregister_gadget_item+0x28/0x44
[   52.642439] c0        [&lt;ffffffc00066b34c&gt;] ffs_data_clear+0x138/0x140
[   52.642444] c0        [&lt;ffffffc00066b374&gt;] ffs_data_reset+0x20/0x6c
[   52.642450] c0        [&lt;ffffffc00066efd0&gt;] ffs_data_closed+0xac/0x12c
[   52.642454] c0        [&lt;ffffffc00066f070&gt;] ffs_ep0_release+0x20/0x2c
[   52.642460] c0        [&lt;ffffffc00023dbe4&gt;] __fput+0xb0/0x1f4
[   52.642466] c0        [&lt;ffffffc00023dd9c&gt;] ____fput+0x20/0x2c
[   52.642473] c0        [&lt;ffffffc0000ee944&gt;] task_work_run+0xb4/0xe8
[   52.642482] c0        [&lt;ffffffc0000cd45c&gt;] do_exit+0x360/0xb9c
[   52.642487] c0        [&lt;ffffffc0000cf228&gt;] do_group_exit+0x4c/0xb0
[   52.642494] c0        [&lt;ffffffc0000dd3c8&gt;] get_signal+0x380/0x89c
[   52.642501] c0        [&lt;ffffffc00008a8f0&gt;] do_signal+0x154/0x518
[   52.642507] c0        [&lt;ffffffc00008af00&gt;] do_notify_resume+0x70/0x78
[   52.642512] c0        [&lt;ffffffc000085ee8&gt;] work_pending+0x1c/0x20
[   52.642514] c1
              other info that might help us debug this:
[   52.642517] c1  Possible unsafe locking scenario:
[   52.642518] c1        CPU0                    CPU1
[   52.642520] c1        ----                    ----
[   52.642525] c0   lock(ffs_lock);
[   52.642529] c0                                lock(udc_lock);
[   52.642533] c0                                lock(ffs_lock);
[   52.642537] c0   lock(udc_lock);
[   52.642539] c1
                      *** DEADLOCK ***
[   52.642543] c1 1 lock held by usb ffs open/2808:
[   52.642555] c0  #0:  (ffs_lock){+.+.+.}, at: [&lt;ffffffc00066b244&gt;]
		ffs_data_clear+0x30/0x140
[   52.642557] c1 stack backtrace:
[   52.642563] c1 CPU: 1 PID: 2808 Comm: usb ffs open Tainted: G
[   52.642565] c1 Hardware name: Spreadtrum SP9860g Board (DT)
[   52.642568] c1 Call trace:
[   52.642573] c1 [&lt;ffffffc00008b430&gt;] dump_backtrace+0x0/0x170
[   52.642577] c1 [&lt;ffffffc00008b5c0&gt;] show_stack+0x20/0x28
[   52.642583] c1 [&lt;ffffffc000422694&gt;] dump_stack+0xa8/0xe0
[   52.642587] c1 [&lt;ffffffc00011e548&gt;] print_circular_bug+0x1fc/0x2e4
[   52.642591] c1 [&lt;ffffffc000123454&gt;] __lock_acquire+0x2138/0x2238
[   52.642595] c1 [&lt;ffffffc000123b54&gt;] lock_acquire+0xe4/0x298
[   52.642599] c1 [&lt;ffffffc000aaf6e8&gt;] mutex_lock_nested+0x7c/0x3cc
[   52.642604] c1 [&lt;ffffffc00065aeec&gt;] usb_gadget_unregister_driver+0x3c/0xc8
[   52.642608] c1 [&lt;ffffffc00065995c&gt;] unregister_gadget_item+0x28/0x44
[   52.642613] c1 [&lt;ffffffc00066b34c&gt;] ffs_data_clear+0x138/0x140
[   52.642618] c1 [&lt;ffffffc00066b374&gt;] ffs_data_reset+0x20/0x6c
[   52.642621] c1 [&lt;ffffffc00066efd0&gt;] ffs_data_closed+0xac/0x12c
[   52.642625] c1 [&lt;ffffffc00066f070&gt;] ffs_ep0_release+0x20/0x2c
[   52.642629] c1 [&lt;ffffffc00023dbe4&gt;] __fput+0xb0/0x1f4
[   52.642633] c1 [&lt;ffffffc00023dd9c&gt;] ____fput+0x20/0x2c
[   52.642636] c1 [&lt;ffffffc0000ee944&gt;] task_work_run+0xb4/0xe8
[   52.642640] c1 [&lt;ffffffc0000cd45c&gt;] do_exit+0x360/0xb9c
[   52.642644] c1 [&lt;ffffffc0000cf228&gt;] do_group_exit+0x4c/0xb0
[   52.642647] c1 [&lt;ffffffc0000dd3c8&gt;] get_signal+0x380/0x89c
[   52.642651] c1 [&lt;ffffffc00008a8f0&gt;] do_signal+0x154/0x518
[   52.642656] c1 [&lt;ffffffc00008af00&gt;] do_notify_resume+0x70/0x78
[   52.642659] c1 [&lt;ffffffc000085ee8&gt;] work_pending+0x1c/0x20

Acked-by: Michal Nazarewicz &lt;mina86@mina86.com&gt;
Signed-off-by: Baolin Wang &lt;baolin.wang@linaro.org&gt;
Signed-off-by: Felipe Balbi &lt;felipe.balbi@linux.intel.com&gt;
Cc: Jerry Zhang &lt;zhangjerry@google.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>usb: gadget: f_fs: avoid out of bounds access on comp_desc</title>
<updated>2017-06-29T10:48:53+00:00</updated>
<author>
<name>William Wu</name>
<email>william.wu@rock-chips.com</email>
</author>
<published>2017-04-25T09:45:48+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=889caad4fbe49e3a612ccb971e40c50912f90ace'/>
<id>889caad4fbe49e3a612ccb971e40c50912f90ace</id>
<content type='text'>
commit b7f73850bb4fac1e2209a4dd5e636d39be92f42c upstream.

Companion descriptor is only used for SuperSpeed endpoints,
if the endpoints are HighSpeed or FullSpeed, the Companion
descriptor will not allocated, so we can only access it if
gadget is SuperSpeed.

I can reproduce this issue on Rockchip platform rk3368 SoC
which supports USB 2.0, and use functionfs for ADB. Kernel
build with CONFIG_KASAN=y and CONFIG_SLUB_DEBUG=y report
the following BUG:

==================================================================
BUG: KASAN: slab-out-of-bounds in ffs_func_set_alt+0x224/0x3a0 at addr ffffffc0601f6509
Read of size 1 by task swapper/0/0
============================================================================
BUG kmalloc-256 (Not tainted): kasan: bad access detected
----------------------------------------------------------------------------

Disabling lock debugging due to kernel taint
INFO: Allocated in ffs_func_bind+0x52c/0x99c age=1275 cpu=0 pid=1
alloc_debug_processing+0x128/0x17c
___slab_alloc.constprop.58+0x50c/0x610
__slab_alloc.isra.55.constprop.57+0x24/0x34
__kmalloc+0xe0/0x250
ffs_func_bind+0x52c/0x99c
usb_add_function+0xd8/0x1d4
configfs_composite_bind+0x48c/0x570
udc_bind_to_driver+0x6c/0x170
usb_udc_attach_driver+0xa4/0xd0
gadget_dev_desc_UDC_store+0xcc/0x118
configfs_write_file+0x1a0/0x1f8
__vfs_write+0x64/0x174
vfs_write+0xe4/0x200
SyS_write+0x68/0xc8
el0_svc_naked+0x24/0x28
INFO: Freed in inode_doinit_with_dentry+0x3f0/0x7c4 age=1275 cpu=7 pid=247
...
Call trace:
[&lt;ffffff900808aab4&gt;] dump_backtrace+0x0/0x230
[&lt;ffffff900808acf8&gt;] show_stack+0x14/0x1c
[&lt;ffffff90084ad420&gt;] dump_stack+0xa0/0xc8
[&lt;ffffff90082157cc&gt;] print_trailer+0x188/0x198
[&lt;ffffff9008215948&gt;] object_err+0x3c/0x4c
[&lt;ffffff900821b5ac&gt;] kasan_report+0x324/0x4dc
[&lt;ffffff900821aa38&gt;] __asan_load1+0x24/0x50
[&lt;ffffff90089eb750&gt;] ffs_func_set_alt+0x224/0x3a0
[&lt;ffffff90089d3760&gt;] composite_setup+0xdcc/0x1ac8
[&lt;ffffff90089d7394&gt;] android_setup+0x124/0x1a0
[&lt;ffffff90089acd18&gt;] _setup+0x54/0x74
[&lt;ffffff90089b6b98&gt;] handle_ep0+0x3288/0x4390
[&lt;ffffff90089b9b44&gt;] dwc_otg_pcd_handle_out_ep_intr+0x14dc/0x2ae4
[&lt;ffffff90089be85c&gt;] dwc_otg_pcd_handle_intr+0x1ec/0x298
[&lt;ffffff90089ad680&gt;] dwc_otg_pcd_irq+0x10/0x20
[&lt;ffffff9008116328&gt;] handle_irq_event_percpu+0x124/0x3ac
[&lt;ffffff9008116610&gt;] handle_irq_event+0x60/0xa0
[&lt;ffffff900811af30&gt;] handle_fasteoi_irq+0x10c/0x1d4
[&lt;ffffff9008115568&gt;] generic_handle_irq+0x30/0x40
[&lt;ffffff90081159b4&gt;] __handle_domain_irq+0xac/0xdc
[&lt;ffffff9008080e9c&gt;] gic_handle_irq+0x64/0xa4
...
Memory state around the buggy address:
  ffffffc0601f6400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  ffffffc0601f6480: 00 00 00 00 00 00 00 00 00 00 06 fc fc fc fc fc
 &gt;ffffffc0601f6500: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
                       ^
  ffffffc0601f6580: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
  ffffffc0601f6600: fc fc fc fc fc fc fc fc 00 00 00 00 00 00 00 00
==================================================================

Signed-off-by: William Wu &lt;william.wu@rock-chips.com&gt;
Signed-off-by: Felipe Balbi &lt;felipe.balbi@linux.intel.com&gt;
Cc: Jerry Zhang &lt;zhangjerry@google.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit b7f73850bb4fac1e2209a4dd5e636d39be92f42c upstream.

Companion descriptor is only used for SuperSpeed endpoints,
if the endpoints are HighSpeed or FullSpeed, the Companion
descriptor will not allocated, so we can only access it if
gadget is SuperSpeed.

I can reproduce this issue on Rockchip platform rk3368 SoC
which supports USB 2.0, and use functionfs for ADB. Kernel
build with CONFIG_KASAN=y and CONFIG_SLUB_DEBUG=y report
the following BUG:

==================================================================
BUG: KASAN: slab-out-of-bounds in ffs_func_set_alt+0x224/0x3a0 at addr ffffffc0601f6509
Read of size 1 by task swapper/0/0
============================================================================
BUG kmalloc-256 (Not tainted): kasan: bad access detected
----------------------------------------------------------------------------

Disabling lock debugging due to kernel taint
INFO: Allocated in ffs_func_bind+0x52c/0x99c age=1275 cpu=0 pid=1
alloc_debug_processing+0x128/0x17c
___slab_alloc.constprop.58+0x50c/0x610
__slab_alloc.isra.55.constprop.57+0x24/0x34
__kmalloc+0xe0/0x250
ffs_func_bind+0x52c/0x99c
usb_add_function+0xd8/0x1d4
configfs_composite_bind+0x48c/0x570
udc_bind_to_driver+0x6c/0x170
usb_udc_attach_driver+0xa4/0xd0
gadget_dev_desc_UDC_store+0xcc/0x118
configfs_write_file+0x1a0/0x1f8
__vfs_write+0x64/0x174
vfs_write+0xe4/0x200
SyS_write+0x68/0xc8
el0_svc_naked+0x24/0x28
INFO: Freed in inode_doinit_with_dentry+0x3f0/0x7c4 age=1275 cpu=7 pid=247
...
Call trace:
[&lt;ffffff900808aab4&gt;] dump_backtrace+0x0/0x230
[&lt;ffffff900808acf8&gt;] show_stack+0x14/0x1c
[&lt;ffffff90084ad420&gt;] dump_stack+0xa0/0xc8
[&lt;ffffff90082157cc&gt;] print_trailer+0x188/0x198
[&lt;ffffff9008215948&gt;] object_err+0x3c/0x4c
[&lt;ffffff900821b5ac&gt;] kasan_report+0x324/0x4dc
[&lt;ffffff900821aa38&gt;] __asan_load1+0x24/0x50
[&lt;ffffff90089eb750&gt;] ffs_func_set_alt+0x224/0x3a0
[&lt;ffffff90089d3760&gt;] composite_setup+0xdcc/0x1ac8
[&lt;ffffff90089d7394&gt;] android_setup+0x124/0x1a0
[&lt;ffffff90089acd18&gt;] _setup+0x54/0x74
[&lt;ffffff90089b6b98&gt;] handle_ep0+0x3288/0x4390
[&lt;ffffff90089b9b44&gt;] dwc_otg_pcd_handle_out_ep_intr+0x14dc/0x2ae4
[&lt;ffffff90089be85c&gt;] dwc_otg_pcd_handle_intr+0x1ec/0x298
[&lt;ffffff90089ad680&gt;] dwc_otg_pcd_irq+0x10/0x20
[&lt;ffffff9008116328&gt;] handle_irq_event_percpu+0x124/0x3ac
[&lt;ffffff9008116610&gt;] handle_irq_event+0x60/0xa0
[&lt;ffffff900811af30&gt;] handle_fasteoi_irq+0x10c/0x1d4
[&lt;ffffff9008115568&gt;] generic_handle_irq+0x30/0x40
[&lt;ffffff90081159b4&gt;] __handle_domain_irq+0xac/0xdc
[&lt;ffffff9008080e9c&gt;] gic_handle_irq+0x64/0xa4
...
Memory state around the buggy address:
  ffffffc0601f6400: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
  ffffffc0601f6480: 00 00 00 00 00 00 00 00 00 00 06 fc fc fc fc fc
 &gt;ffffffc0601f6500: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
                       ^
  ffffffc0601f6580: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
  ffffffc0601f6600: fc fc fc fc fc fc fc fc 00 00 00 00 00 00 00 00
==================================================================

Signed-off-by: William Wu &lt;william.wu@rock-chips.com&gt;
Signed-off-by: Felipe Balbi &lt;felipe.balbi@linux.intel.com&gt;
Cc: Jerry Zhang &lt;zhangjerry@google.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>usb: gadget: function: f_fs: pass companion descriptor along</title>
<updated>2017-03-18T11:09:57+00:00</updated>
<author>
<name>Felipe Balbi</name>
<email>felipe.balbi@linux.intel.com</email>
</author>
<published>2017-01-31T12:54:45+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=4a1a3bb70fb4255a9f6052eb86db1ff2140255a6'/>
<id>4a1a3bb70fb4255a9f6052eb86db1ff2140255a6</id>
<content type='text'>
commit 2bfa0719ac2a9b2f3c91345873d3cdebd0296ba9 upstream.

If we're dealing with SuperSpeed endpoints, we need
to make sure to pass along the companion descriptor
and initialize fields needed by the Gadget
API. Eventually, f_fs.c should be converted to use
config_ep_by_speed() like all other functions,
though.

Signed-off-by: Felipe Balbi &lt;felipe.balbi@linux.intel.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 2bfa0719ac2a9b2f3c91345873d3cdebd0296ba9 upstream.

If we're dealing with SuperSpeed endpoints, we need
to make sure to pass along the companion descriptor
and initialize fields needed by the Gadget
API. Eventually, f_fs.c should be converted to use
config_ep_by_speed() like all other functions,
though.

Signed-off-by: Felipe Balbi &lt;felipe.balbi@linux.intel.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>usb: gadget: f_fs: Assorted buffer overflow checks.</title>
<updated>2017-02-09T07:02:46+00:00</updated>
<author>
<name>Vincent Pelletier</name>
<email>plr.vincent@gmail.com</email>
</author>
<published>2017-01-18T00:57:44+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=9cf89ade1afd450a5ff25ee65acbebb94b011287'/>
<id>9cf89ade1afd450a5ff25ee65acbebb94b011287</id>
<content type='text'>
commit 83e526f2a2fa4b2e82b6bd3ddbb26b70acfa8947 upstream.

OS descriptor head, when flagged as provided, is accessed without
checking if it fits in provided buffer. Verify length before access.
Also, there are other places where buffer length it checked
after accessing offsets which are potentially past the end. Check
buffer length before as well to fail cleanly.

Signed-off-by: Vincent Pelletier &lt;plr.vincent@gmail.com&gt;
Acked-by: Felipe Balbi &lt;felipe.balbi@linux.intel.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 83e526f2a2fa4b2e82b6bd3ddbb26b70acfa8947 upstream.

OS descriptor head, when flagged as provided, is accessed without
checking if it fits in provided buffer. Verify length before access.
Also, there are other places where buffer length it checked
after accessing offsets which are potentially past the end. Check
buffer length before as well to fail cleanly.

Signed-off-by: Vincent Pelletier &lt;plr.vincent@gmail.com&gt;
Acked-by: Felipe Balbi &lt;felipe.balbi@linux.intel.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>usb: f_fs: off by one bug in _ffs_func_bind()</title>
<updated>2016-08-20T16:09:16+00:00</updated>
<author>
<name>Dan Carpenter</name>
<email>dan.carpenter@oracle.com</email>
</author>
<published>2016-05-28T04:48:10+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=f1d7992894fafb62b790b5112630b4f081b3b454'/>
<id>f1d7992894fafb62b790b5112630b4f081b3b454</id>
<content type='text'>
commit 0015f9156092d07b3ec06d37d014328419d5832e upstream.

This loop is supposed to set all the .num[] values to -1 but it's off by
one so it skips the first element and sets one element past the end of
the array.

I've cleaned up the loop a little as well.

Fixes: ddf8abd25994 ('USB: f_fs: the FunctionFS driver')
Acked-by: Michal Nazarewicz &lt;mina86@mina86.com&gt;
Signed-off-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Signed-off-by: Felipe Balbi &lt;felipe.balbi@linux.intel.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 0015f9156092d07b3ec06d37d014328419d5832e upstream.

This loop is supposed to set all the .num[] values to -1 but it's off by
one so it skips the first element and sets one element past the end of
the array.

I've cleaned up the loop a little as well.

Fixes: ddf8abd25994 ('USB: f_fs: the FunctionFS driver')
Acked-by: Michal Nazarewicz &lt;mina86@mina86.com&gt;
Signed-off-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Signed-off-by: Felipe Balbi &lt;felipe.balbi@linux.intel.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>usb: gadget: f_fs: Fix EFAULT generation for async read operations</title>
<updated>2016-06-01T19:15:51+00:00</updated>
<author>
<name>Lars-Peter Clausen</name>
<email>lars@metafoo.de</email>
</author>
<published>2016-03-30T11:49:14+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=ed97f0d96dfad18989b922c4c4095e9d06230bf6'/>
<id>ed97f0d96dfad18989b922c4c4095e9d06230bf6</id>
<content type='text'>
commit 332a5b446b7916d272c2a659a3b20909ce34d2c1 upstream.

In the current implementation functionfs generates a EFAULT for async read
operations if the read buffer size is larger than the URB data size. Since
a application does not necessarily know how much data the host side is
going to send it typically supplies a buffer larger than the actual data,
which will then result in a EFAULT error.

This behaviour was introduced while refactoring the code to use iov_iter
interface in commit c993c39b8639 ("gadget/function/f_fs.c: use put iov_iter
into io_data"). The original code took the minimum over the URB size and
the user buffer size and then attempted to copy that many bytes using
copy_to_user(). If copy_to_user() could not copy all data a EFAULT error
was generated. Restore the original behaviour by only generating a EFAULT
error when the number of bytes copied is not the size of the URB and the
target buffer has not been fully filled.

Commit 342f39a6c8d3 ("usb: gadget: f_fs: fix check in read operation")
already fixed the same problem for the synchronous read path.

Fixes: c993c39b8639 ("gadget/function/f_fs.c: use put iov_iter into io_data")
Acked-by: Michal Nazarewicz &lt;mina86@mina86.com&gt;
Signed-off-by: Lars-Peter Clausen &lt;lars@metafoo.de&gt;
Signed-off-by: Felipe Balbi &lt;felipe.balbi@linux.intel.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 332a5b446b7916d272c2a659a3b20909ce34d2c1 upstream.

In the current implementation functionfs generates a EFAULT for async read
operations if the read buffer size is larger than the URB data size. Since
a application does not necessarily know how much data the host side is
going to send it typically supplies a buffer larger than the actual data,
which will then result in a EFAULT error.

This behaviour was introduced while refactoring the code to use iov_iter
interface in commit c993c39b8639 ("gadget/function/f_fs.c: use put iov_iter
into io_data"). The original code took the minimum over the URB size and
the user buffer size and then attempted to copy that many bytes using
copy_to_user(). If copy_to_user() could not copy all data a EFAULT error
was generated. Restore the original behaviour by only generating a EFAULT
error when the number of bytes copied is not the size of the URB and the
target buffer has not been fully filled.

Commit 342f39a6c8d3 ("usb: gadget: f_fs: fix check in read operation")
already fixed the same problem for the synchronous read path.

Fixes: c993c39b8639 ("gadget/function/f_fs.c: use put iov_iter into io_data")
Acked-by: Michal Nazarewicz &lt;mina86@mina86.com&gt;
Signed-off-by: Lars-Peter Clausen &lt;lars@metafoo.de&gt;
Signed-off-by: Felipe Balbi &lt;felipe.balbi@linux.intel.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>usb: gadget: f_fs: Fix use-after-free</title>
<updated>2016-05-04T21:48:41+00:00</updated>
<author>
<name>Lars-Peter Clausen</name>
<email>lars@metafoo.de</email>
</author>
<published>2016-04-14T15:01:17+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=e4c7ab76586146820b394e0176f286f5a2e70cb3'/>
<id>e4c7ab76586146820b394e0176f286f5a2e70cb3</id>
<content type='text'>
commit 38740a5b87d53ceb89eb2c970150f6e94e00373a upstream.

When using asynchronous read or write operations on the USB endpoints the
issuer of the IO request is notified by calling the ki_complete() callback
of the submitted kiocb when the URB has been completed.

Calling this ki_complete() callback will free kiocb. Make sure that the
structure is no longer accessed beyond that point, otherwise undefined
behaviour might occur.

Fixes: 2e4c7553cd6f ("usb: gadget: f_fs: add aio support")
Signed-off-by: Lars-Peter Clausen &lt;lars@metafoo.de&gt;
Signed-off-by: Felipe Balbi &lt;felipe.balbi@linux.intel.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
commit 38740a5b87d53ceb89eb2c970150f6e94e00373a upstream.

When using asynchronous read or write operations on the USB endpoints the
issuer of the IO request is notified by calling the ki_complete() callback
of the submitted kiocb when the URB has been completed.

Calling this ki_complete() callback will free kiocb. Make sure that the
structure is no longer accessed beyond that point, otherwise undefined
behaviour might occur.

Fixes: 2e4c7553cd6f ("usb: gadget: f_fs: add aio support")
Signed-off-by: Lars-Peter Clausen &lt;lars@metafoo.de&gt;
Signed-off-by: Felipe Balbi &lt;felipe.balbi@linux.intel.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;

</pre>
</div>
</content>
</entry>
<entry>
<title>usb: gadget: functionfs: fix missing access_ok checks</title>
<updated>2015-11-18T21:09:26+00:00</updated>
<author>
<name>Daniel Walter</name>
<email>dwalter@sigma-star.at</email>
</author>
<published>2015-11-18T16:15:49+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=7fe9a937d5156761cf79dc354f616c726b5c09e2'/>
<id>7fe9a937d5156761cf79dc354f616c726b5c09e2</id>
<content type='text'>
use safe copy_*_user instead of unsafe __copy_*_user
functions when accessing userland memory.

Signed-off-by: Daniel Walter &lt;dwalter@sigma-star.at&gt;
Signed-off-by: Felipe Balbi &lt;balbi@ti.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
use safe copy_*_user instead of unsafe __copy_*_user
functions when accessing userland memory.

Signed-off-by: Daniel Walter &lt;dwalter@sigma-star.at&gt;
Signed-off-by: Felipe Balbi &lt;balbi@ti.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>usb: gadget: ffs: call functionfs_unbind() if _ffs_func_bind() fails</title>
<updated>2015-07-31T13:57:57+00:00</updated>
<author>
<name>Robert Baldyga</name>
<email>r.baldyga@samsung.com</email>
</author>
<published>2015-07-13T09:03:50+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=55d811211b139ed097ddaf40d173c258f133c130'/>
<id>55d811211b139ed097ddaf40d173c258f133c130</id>
<content type='text'>
Function ffs_do_functionfs_bind() calls functionfs_bind() which allocates
usb request and increments refcounts. These things needs to be cleaned
up by if further steps of initialization fail by calling functionfs_unbind().

Signed-off-by: Robert Baldyga &lt;r.baldyga@samsung.com&gt;
Acked-by: Michal Nazarewicz &lt;mina86@mina86.com&gt;
Signed-off-by: Felipe Balbi &lt;balbi@ti.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
Function ffs_do_functionfs_bind() calls functionfs_bind() which allocates
usb request and increments refcounts. These things needs to be cleaned
up by if further steps of initialization fail by calling functionfs_unbind().

Signed-off-by: Robert Baldyga &lt;r.baldyga@samsung.com&gt;
Acked-by: Michal Nazarewicz &lt;mina86@mina86.com&gt;
Signed-off-by: Felipe Balbi &lt;balbi@ti.com&gt;
</pre>
</div>
</content>
</entry>
<entry>
<title>usb: gadget: f_fs: do not set cancel function on synchronous {read,write}</title>
<updated>2015-07-06T17:34:08+00:00</updated>
<author>
<name>Rui Miguel Silva</name>
<email>rui.silva@linaro.org</email>
</author>
<published>2015-05-18T15:02:07+00:00</published>
<link rel='alternate' type='text/html' href='https://git.toradex.cn/cgit/linux-toradex.git/commit/?id=4088acf1e845aba35f30fb91dee10649edbd0e84'/>
<id>4088acf1e845aba35f30fb91dee10649edbd0e84</id>
<content type='text'>
do not try to set cancel function in synchronous operations in
ffs_epfile_{read,write}_iter.

Cc: &lt;stable@vger.kernel.org&gt; # v4.0+
Acked-by: Al Viro &lt;viro@ZenIV.linux.org.uk&gt;
Signed-off-by: Rui Miguel Silva &lt;rui.silva@linaro.org&gt;
Signed-off-by: Felipe Balbi &lt;balbi@ti.com&gt;
</content>
<content type='xhtml'>
<div xmlns='http://www.w3.org/1999/xhtml'>
<pre>
do not try to set cancel function in synchronous operations in
ffs_epfile_{read,write}_iter.

Cc: &lt;stable@vger.kernel.org&gt; # v4.0+
Acked-by: Al Viro &lt;viro@ZenIV.linux.org.uk&gt;
Signed-off-by: Rui Miguel Silva &lt;rui.silva@linaro.org&gt;
Signed-off-by: Felipe Balbi &lt;balbi@ti.com&gt;
</pre>
</div>
</content>
</entry>
</feed>
