<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel.git/drivers/usb/gadget/function/f_fs.c, branch linux-6.3.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.
</subtitle>
<id>https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-6.3.y</id>
<link rel='self' href='https://git.0xinfinity.dev/distro/kernel.git/atom?h=linux-6.3.y'/>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/'/>
<updated>2023-06-09T08:48:15Z</updated>
<entry>
<title>usb: gadget: f_fs: Add unbind event before functionfs_unbind</title>
<updated>2023-06-09T08:48:15Z</updated>
<author>
<name>Uttkarsh Aggarwal</name>
</author>
<published>2023-05-25T09:28:54Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=7d4d05d3b15bf005c4e82981e7b0ba0455c5b024'/>
<id>urn:sha1:7d4d05d3b15bf005c4e82981e7b0ba0455c5b024</id>
<content type='text'>
commit efb6b535207395a5c7317993602e2503ca8cb4b3 upstream.

While exercising the unbind path, with the current implementation
the functionfs_unbind would be calling which waits for the ffs-&gt;mutex
to be available, however within the same time ffs_ep0_read is invoked
&amp; if no setup packets are pending, it will invoke function
wait_event_interruptible_exclusive_locked_irq which by definition waits
for the ev.count to be increased inside the same mutex for which
functionfs_unbind is waiting.
This creates deadlock situation because the functionfs_unbind won't
get the lock until ev.count is increased which can only happen if
the caller ffs_func_unbind can proceed further.

Following is the illustration:

	CPU1				CPU2

ffs_func_unbind()		ffs_ep0_read()
				mutex_lock(ffs-&gt;mutex)
				wait_event(ffs-&gt;ev.count)
functionfs_unbind()
  mutex_lock(ffs-&gt;mutex)
  mutex_unlock(ffs-&gt;mutex)

ffs_event_add()

&lt;deadlock&gt;

Fix this by moving the event unbind before functionfs_unbind
to ensure the ev.count is incrased properly.

Fixes: 6a19da111057 ("usb: gadget: f_fs: Prevent race during ffs_ep0_queue_wait")
Cc: stable &lt;stable@kernel.org&gt;
Signed-off-by: Uttkarsh Aggarwal &lt;quic_uaggarwa@quicinc.com&gt;
Link: https://lore.kernel.org/r/20230525092854.7992-1-quic_uaggarwa@quicinc.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: gadget: f_fs: Fix ffs_epfile_read_iter to handle ITER_UBUF</title>
<updated>2023-04-05T17:24:01Z</updated>
<author>
<name>Sandeep Dhavale</name>
</author>
<published>2023-04-01T06:05:08Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=d356b3cdd00cae4508be566a47c0cfb74e14862a'/>
<id>urn:sha1:d356b3cdd00cae4508be566a47c0cfb74e14862a</id>
<content type='text'>
iov_iter for ffs_epfile_read_iter can be ITER_UBUF with io_uring.
In that case dup_iter() does not have to allocate anything and it
can return NULL. ffs_epfile_read_iter treats this as a failure and
returns -ENOMEM. Fix it by checking if iter_is_ubuf().

Fixes: 1e23db450cff ("io_uring: use iter_ubuf for single range imports")
Signed-off-by: Sandeep Dhavale &lt;dhavale@google.com&gt;
Acked-by: Jens Axboe &lt;axboe@kernel.dk&gt;
Link: https://lore.kernel.org/r/20230401060509.3608259-2-dhavale@google.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>Merge 6.2-rc7 into usb-next</title>
<updated>2023-02-06T07:33:30Z</updated>
<author>
<name>Greg Kroah-Hartman</name>
</author>
<published>2023-02-06T07:33:30Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=924fb3ec50f5156d21e4f484358fb36f75b91ca8'/>
<id>urn:sha1:924fb3ec50f5156d21e4f484358fb36f75b91ca8</id>
<content type='text'>
We need the USB fixes in here, and this resolves a merge conflict with
the i915 driver as reported in linux-next

Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: gadget: f_fs: Fix unbalanced spinlock in __ffs_ep0_queue_wait</title>
<updated>2023-01-24T17:19:39Z</updated>
<author>
<name>Udipto Goswami</name>
</author>
<published>2023-01-24T09:11:49Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=921deb9da15851425ccbb6ee409dc2fd8fbdfe6b'/>
<id>urn:sha1:921deb9da15851425ccbb6ee409dc2fd8fbdfe6b</id>
<content type='text'>
__ffs_ep0_queue_wait executes holding the spinlock of &amp;ffs-&gt;ev.waitq.lock
and unlocks it after the assignments to usb_request are done.
However in the code if the request is already NULL we bail out returning
-EINVAL but never unlocked the spinlock.

Fix this by adding spin_unlock_irq &amp;ffs-&gt;ev.waitq.lock before returning.

Fixes: 6a19da111057 ("usb: gadget: f_fs: Prevent race during ffs_ep0_queue_wait")
Reviewed-by: John Keeping &lt;john@metanate.com&gt;
Signed-off-by: Udipto Goswami &lt;quic_ugoswami@quicinc.com&gt;
Link: https://lore.kernel.org/r/20230124091149.18647-1-quic_ugoswami@quicinc.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>Merge 6.2-rc5 into usb-next</title>
<updated>2023-01-23T14:38:08Z</updated>
<author>
<name>Greg Kroah-Hartman</name>
</author>
<published>2023-01-23T14:38:08Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=e3e9fc7fa7ad221cc2e7b207d514cc84ed393251'/>
<id>urn:sha1:e3e9fc7fa7ad221cc2e7b207d514cc84ed393251</id>
<content type='text'>
We need the USB fixes in here and this resolves merge conflicts as
reported in linux-next in the following files:
	drivers/usb/host/xhci.c
	drivers/usb/host/xhci.h
	drivers/usb/typec/ucsi/ucsi.c

Reported-by: Stephen Rothwell &lt;sfr@canb.auug.org.au&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: gadget: f_fs: Ensure ep0req is dequeued before free_request</title>
<updated>2023-01-17T16:07:06Z</updated>
<author>
<name>Udipto Goswami</name>
</author>
<published>2022-12-15T05:29:06Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=ce405d561b020e5a46340eb5146805a625dcacee'/>
<id>urn:sha1:ce405d561b020e5a46340eb5146805a625dcacee</id>
<content type='text'>
As per the documentation, function usb_ep_free_request guarantees
the request will not be queued or no longer be re-queued (or
otherwise used). However, with the current implementation it
doesn't make sure that the request in ep0 isn't reused.

Fix this by dequeuing the ep0req on functionfs_unbind before
freeing the request to align with the definition.

Fixes: ddf8abd25994 ("USB: f_fs: the FunctionFS driver")
Signed-off-by: Udipto Goswami &lt;quic_ugoswami@quicinc.com&gt;
Tested-by: Krishna Kurapati &lt;quic_kriskura@quicinc.com&gt;
Link: https://lore.kernel.org/r/20221215052906.8993-3-quic_ugoswami@quicinc.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: gadget: f_fs: Prevent race during ffs_ep0_queue_wait</title>
<updated>2023-01-17T16:07:06Z</updated>
<author>
<name>Udipto Goswami</name>
</author>
<published>2022-12-15T05:29:05Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=6a19da111057f69214b97c62fb0ac59023970850'/>
<id>urn:sha1:6a19da111057f69214b97c62fb0ac59023970850</id>
<content type='text'>
While performing fast composition switch, there is a possibility that the
process of ffs_ep0_write/ffs_ep0_read get into a race condition
due to ep0req being freed up from functionfs_unbind.

Consider the scenario that the ffs_ep0_write calls the ffs_ep0_queue_wait
by taking a lock &amp;ffs-&gt;ev.waitq.lock. However, the functionfs_unbind isn't
bounded so it can go ahead and mark the ep0req to NULL, and since there
is no NULL check in ffs_ep0_queue_wait we will end up in use-after-free.

Fix this by making a serialized execution between the two functions using
a mutex_lock(ffs-&gt;mutex).

Fixes: ddf8abd25994 ("USB: f_fs: the FunctionFS driver")
Signed-off-by: Udipto Goswami &lt;quic_ugoswami@quicinc.com&gt;
Tested-by: Krishna Kurapati &lt;quic_kriskura@quicinc.com&gt;
Link: https://lore.kernel.org/r/20221215052906.8993-2-quic_ugoswami@quicinc.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: gadget: f_fs: use io_data-&gt;status consistently</title>
<updated>2023-01-06T15:36:52Z</updated>
<author>
<name>John Keeping</name>
</author>
<published>2022-11-24T17:04:28Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b566d38857fcb6777f25b674b90a831eec0817a2'/>
<id>urn:sha1:b566d38857fcb6777f25b674b90a831eec0817a2</id>
<content type='text'>
Commit fb1f16d74e26 ("usb: gadget: f_fs: change ep-&gt;status safe in
ffs_epfile_io()") added a new ffs_io_data::status field to fix lifetime
issues in synchronous requests.

While there are no similar lifetime issues for asynchronous requests
(the separate ep member in ffs_io_data avoids them) using the status
field means the USB request can be freed earlier and that there is more
consistency between the synchronous and asynchronous I/O paths.

Cc: Linyu Yuan &lt;quic_linyyuan@quicinc.com&gt;
Signed-off-by: John Keeping &lt;john@metanate.com&gt;
Reviewed-by: Linyu Yuan &lt;quic_linyyuan@quicinc.com&gt;
Link: https://lore.kernel.org/r/20221124170430.3998755-1-john@metanate.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: gadget: f_fs: stricter integer overflow checks</title>
<updated>2022-09-07T14:23:22Z</updated>
<author>
<name>Dan Carpenter</name>
</author>
<published>2022-09-01T14:59:42Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=f57004b9d96755cd6a243b51c267be4016b4563c'/>
<id>urn:sha1:f57004b9d96755cd6a243b51c267be4016b4563c</id>
<content type='text'>
This from static analysis.  The vla_item() takes a size and adds it to
the total.  It has a built in integer overflow check so if it encounters
an integer overflow anywhere then it records the total as SIZE_MAX.

However there is an issue here because the "lang_count*(needed_count+1)"
multiplication can overflow.  Technically the "lang_count + 1" addition
could overflow too, but that would be detected and is harmless.  Fix
both using the new size_add() and size_mul() functions.

Fixes: e6f3862fa1ec ("usb: gadget: FunctionFS: Remove VLAIS usage from gadget code")
Signed-off-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Link: https://lore.kernel.org/r/YxDI3lMYomE7WCjn@kili
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usb: move from strlcpy with unused retval to strscpy</title>
<updated>2022-08-19T09:08:54Z</updated>
<author>
<name>Wolfram Sang</name>
</author>
<published>2022-08-18T21:01:15Z</published>
<link rel='alternate' type='text/html' href='https://git.0xinfinity.dev/distro/kernel.git/commit/?id=b7db5733a5ace9acc1f3104c9050c5aa1363f13b'/>
<id>urn:sha1:b7db5733a5ace9acc1f3104c9050c5aa1363f13b</id>
<content type='text'>
Follow the advice of the below link and prefer 'strscpy' in this
subsystem. Conversion is 1:1 because the return value is not used.
Generated by a coccinelle script.

Link: https://lore.kernel.org/r/CAHk-=wgfRnXz0W3D37d01q3JFkr_i_uTL=V6A6G1oUZcprmknw@mail.gmail.com/
Reviewed-by: Richard Leitner &lt;richard.leitner@skidata.com&gt;
Reviewed-by: Laurent Pinchart &lt;laurent.pinchart+renesas@ideasonboard.com&gt;
Acked-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
Signed-off-by: Wolfram Sang &lt;wsa+renesas@sang-engineering.com&gt;
Link: https://lore.kernel.org/r/20220818210116.7517-1-wsa+renesas@sang-engineering.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
</feed>
