<feed xmlns='http://www.w3.org/2005/Atom'>
<title>kernel/drivers/usb/usbip/vudc_sysfs.c, branch linux-6.9.y</title>
<subtitle>Hosts the 0x221E linux distro kernel.</subtitle>
<id>https://universe.0xinfinity.dev/distro/kernel/atom?h=linux-6.9.y</id>
<link rel='self' href='https://universe.0xinfinity.dev/distro/kernel/atom?h=linux-6.9.y'/>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/'/>
<updated>2022-10-22T11:20:49Z</updated>
<entry>
<title>usbip: vudc: Convert snprintf() to sysfs_emit()</title>
<updated>2022-10-22T11:20:49Z</updated>
<author>
<name>Jules Irenge</name>
<email>jbi.octave@gmail.com</email>
</author>
<published>2022-10-01T14:56:33Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=13cc02f115d010d078851fac7f347890e62c097d'/>
<id>urn:sha1:13cc02f115d010d078851fac7f347890e62c097d</id>
<content type='text'>
Coccinnelle reports a warning
Warning: Use scnprintf or sprintf

Following the advice on kernel documentation
https://www.kernel.org/doc/html/latest/filesystems/sysfs.html

For show(device *...) functions we should only use sysfs_emit() or sysfs_emit_at()
especially when formatting the value to be returned to user space.
Convert snprintf() to sysfs_emit()

Signed-off-by: Jules Irenge &lt;jules.irenge@postgrad.manchester.ac.uk&gt;
Reviewed-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
Link: https://lore.kernel.org/r/YzhVIaNGdM33pcts@octinomon
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usbip: vudc: Don't enable IRQs prematurely</title>
<updated>2022-06-10T09:48:19Z</updated>
<author>
<name>Dan Carpenter</name>
<email>dan.carpenter@oracle.com</email>
</author>
<published>2022-05-25T12:30:13Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=62e4efe3375eb30292dabaec4481dc04550d3644'/>
<id>urn:sha1:62e4efe3375eb30292dabaec4481dc04550d3644</id>
<content type='text'>
This code does:

	spin_unlock_irq(&amp;udc-&gt;ud.lock);
	spin_unlock_irqrestore(&amp;udc-&gt;lock, flags);

which does not make sense.  In theory, the first unlock could enable
IRQs and then the second _irqrestore could disable them again.  There
would be a brief momemt where IRQs were enabled improperly.

In real life, however, this function is always called with IRQs enabled
and the bug does not affect runtime.

Reviewed-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
Signed-off-by: Dan Carpenter &lt;dan.carpenter@oracle.com&gt;
Link: https://lore.kernel.org/r/Yo4hVWcZNYzKEkIQ@kili
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usbip: vudc: fix missing unlock on error in usbip_sockfd_store()</title>
<updated>2021-04-12T08:29:50Z</updated>
<author>
<name>Ye Bin</name>
<email>yebin10@huawei.com</email>
</author>
<published>2021-04-08T11:23:05Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=1d08ed588c6a85a35a24c82eb4cf0807ec2b366a'/>
<id>urn:sha1:1d08ed588c6a85a35a24c82eb4cf0807ec2b366a</id>
<content type='text'>
Add the missing unlock before return from function usbip_sockfd_store()
in the error handling case.

Fixes: bd8b82042269 ("usbip: vudc synchronize sysfs code paths")
Reported-by: Hulk Robot &lt;hulkci@huawei.com&gt;
Acked-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
Signed-off-by: Ye Bin &lt;yebin10@huawei.com&gt;
Link: https://lore.kernel.org/r/20210408112305.1022247-1-yebin10@huawei.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usbip: vudc synchronize sysfs code paths</title>
<updated>2021-04-05T07:05:42Z</updated>
<author>
<name>Shuah Khan</name>
<email>skhan@linuxfoundation.org</email>
</author>
<published>2021-03-30T01:36:50Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=bd8b82042269a95db48074b8bb400678dbac1815'/>
<id>urn:sha1:bd8b82042269a95db48074b8bb400678dbac1815</id>
<content type='text'>
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 vudc.

Cc: stable@vger.kernel.org
Reported-and-tested-by: syzbot+a93fba6d384346a761e3@syzkaller.appspotmail.com
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
Link: https://lore.kernel.org/r/caabcf3fc87bdae970509b5ff32d05bb7ce2fb15.1616807117.git.skhan@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usbip: Fix incorrect double assignment to udc-&gt;ud.tcp_rx</title>
<updated>2021-03-17T20:27:48Z</updated>
<author>
<name>Colin Ian King</name>
<email>colin.king@canonical.com</email>
</author>
<published>2021-03-11T10:44:45Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=9858af27e69247c5d04c3b093190a93ca365f33d'/>
<id>urn:sha1:9858af27e69247c5d04c3b093190a93ca365f33d</id>
<content type='text'>
Currently udc-&gt;ud.tcp_rx is being assigned twice, the second assignment
is incorrect, it should be to udc-&gt;ud.tcp_tx instead of rx. Fix this.

Fixes: 46613c9dfa96 ("usbip: fix vudc usbip_sockfd_store races leading to gpf")
Acked-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
Signed-off-by: Colin Ian King &lt;colin.king@canonical.com&gt;
Cc: stable &lt;stable@vger.kernel.org&gt;
Addresses-Coverity: ("Unused value")
Link: https://lore.kernel.org/r/20210311104445.7811-1-colin.king@canonical.com
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usbip: fix vudc usbip_sockfd_store races leading to gpf</title>
<updated>2021-03-10T18:32:34Z</updated>
<author>
<name>Shuah Khan</name>
<email>skhan@linuxfoundation.org</email>
</author>
<published>2021-03-08T03:53:31Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=46613c9dfa964c0c60b5385dbdf5aaa18be52a9c'/>
<id>urn:sha1:46613c9dfa964c0c60b5385dbdf5aaa18be52a9c</id>
<content type='text'>
usbip_sockfd_store() is invoked when user requests attach (import)
detach (unimport) usb gadget device from usbip host. vhci_hcd sends
import request and usbip_sockfd_store() exports the device if it is
free for export.

Export and unexport are governed by local state and shared state
- Shared state (usbip device status, sockfd) - sockfd and Device
  status are used to determine if stub should be brought up or shut
  down. Device status is shared between host and client.
- Local state (tcp_socket, rx and tx thread task_struct ptrs)
  A valid tcp_socket controls rx and tx thread operations while the
  device is in exported state.
- While the device is exported, device status is marked used and socket,
  sockfd, and thread pointers are valid.

Export sequence (stub-up) includes validating the socket and creating
receive (rx) and transmit (tx) threads to talk to the client to provide
access to the exported device. rx and tx threads depends on local and
shared state to be correct and in sync.

Unexport (stub-down) sequence shuts the socket down and stops the rx and
tx threads. Stub-down sequence relies on local and shared states to be
in sync.

There are races in updating the local and shared status in the current
stub-up sequence resulting in crashes. These stem from starting rx and
tx threads before local and global state is updated correctly to be in
sync.

1. Doesn't handle kthread_create() error and saves invalid ptr in local
   state that drives rx and tx threads.
2. Updates tcp_socket and sockfd,  starts stub_rx and stub_tx threads
   before updating usbip_device status to SDEV_ST_USED. This opens up a
   race condition between the threads and usbip_sockfd_store() stub up
   and down handling.

Fix the above problems:
- Stop using kthread_get_run() macro to create/start threads.
- Create threads and get task struct reference.
- Add kthread_create() failure handling and bail out.
- Hold usbip_device lock to update local and shared states after
  creating rx and tx threads.
- Update usbip_device status to SDEV_ST_USED.
- Update usbip_device tcp_socket, sockfd, tcp_rx, and tcp_tx
- Start threads after usbip_device (tcp_socket, sockfd, tcp_rx, tcp_tx,
  and status) is complete.

Credit goes to syzbot and Tetsuo Handa for finding and root-causing the
kthread_get_run() improper error handling problem and others. This is a
hard problem to find and debug since the races aren't seen in a normal
case. Fuzzing forces the race window to be small enough for the
kthread_get_run() error path bug and starting threads before updating the
local and shared state bug in the stub-up sequence.

Fixes: 9720b4bc76a83807 ("staging/usbip: convert to kthread")
Cc: stable@vger.kernel.org
Reported-by: syzbot &lt;syzbot+a93fba6d384346a761e3@syzkaller.appspotmail.com&gt;
Reported-by: syzbot &lt;syzbot+bf1a360e305ee719e364@syzkaller.appspotmail.com&gt;
Reported-by: syzbot &lt;syzbot+95ce4b142579611ef0a9@syzkaller.appspotmail.com&gt;
Reported-by: Tetsuo Handa &lt;penguin-kernel@I-love.SAKURA.ne.jp&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
Link: https://lore.kernel.org/r/b1c08b983ffa185449c9f0f7d1021dc8c8454b60.1615171203.git.skhan@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usbip: fix vudc to check for stream socket</title>
<updated>2021-03-10T18:32:34Z</updated>
<author>
<name>Shuah Khan</name>
<email>skhan@linuxfoundation.org</email>
</author>
<published>2021-03-08T03:53:28Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=6801854be94fe8819b3894979875ea31482f5658'/>
<id>urn:sha1:6801854be94fe8819b3894979875ea31482f5658</id>
<content type='text'>
Fix usbip_sockfd_store() to validate the passed in file descriptor is
a stream socket. If the file descriptor passed was a SOCK_DGRAM socket,
sock_recvmsg() can't detect end of stream.

Cc: stable@vger.kernel.org
Suggested-by: Tetsuo Handa &lt;penguin-kernel@I-love.SAKURA.ne.jp&gt;
Signed-off-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
Link: https://lore.kernel.org/r/387a670316002324113ac7ea1e8b53f4085d0c95.1615171203.git.skhan@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>USB: usbip: convert platform driver to use dev_groups</title>
<updated>2019-08-06T07:40:47Z</updated>
<author>
<name>Greg Kroah-Hartman</name>
<email>gregkh@linuxfoundation.org</email>
</author>
<published>2019-08-05T19:36:35Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=91148dbad80bb6024389287be4aefcbf20b2d0e4'/>
<id>urn:sha1:91148dbad80bb6024389287be4aefcbf20b2d0e4</id>
<content type='text'>
Platform drivers now have the option to have the platform core create
and remove any needed sysfs attribute files.  So take advantage of that
and do not register "by hand" any sysfs files.

Cc: Valentina Manea &lt;valentina.manea.m@gmail.com&gt;
Acked-by: Shuah Khan &lt;skhan@linuxfoundation.org&gt;
Link: https://lore.kernel.org/r/20190805193636.25560-5-gregkh@linuxfoundation.org
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>usbip: vudc: fix null pointer dereference on udc-&gt;lock</title>
<updated>2018-03-09T18:01:07Z</updated>
<author>
<name>Colin Ian King</name>
<email>colin.king@canonical.com</email>
</author>
<published>2018-02-22T17:39:17Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=df3334c223a033f562645712e832ca4cbb326bbf'/>
<id>urn:sha1:df3334c223a033f562645712e832ca4cbb326bbf</id>
<content type='text'>
Currently the driver attempts to spin lock on udc-&gt;lock before a NULL
pointer check is performed on udc, hence there is a potential null
pointer dereference on udc-&gt;lock.  Fix this by moving the null check
on udc before the lock occurs.

Fixes: ea6873a45a22 ("usbip: vudc: Add SysFS infrastructure for VUDC")
Signed-off-by: Colin Ian King &lt;colin.king@canonical.com&gt;
Acked-by: Shuah Khan &lt;shuahkh@osg.samsung.com&gt;
Reviewed-by: Krzysztof Opasiak &lt;k.opasiak@samsung.com&gt;
Cc: stable &lt;stable@vger.kernel.org&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
<entry>
<title>USB: move many drivers to use DEVICE_ATTR_WO</title>
<updated>2018-01-24T07:49:52Z</updated>
<author>
<name>Greg Kroah-Hartman</name>
<email>gregkh@linuxfoundation.org</email>
</author>
<published>2018-01-23T10:24:07Z</published>
<link rel='alternate' type='text/html' href='https://universe.0xinfinity.dev/distro/kernel/commit/?id=ca35910a1ba21e45368640ac4d884536649966d9'/>
<id>urn:sha1:ca35910a1ba21e45368640ac4d884536649966d9</id>
<content type='text'>
Instead of "open coding" a DEVICE_ATTR() define, use the
DEVICE_ATTR_WO() macro instead, which does everything properly instead.

This does require a few static functions to be renamed to work properly,
but thanks to a script from Joe Perches, this was easily done.

Reported-by: Joe Perches &lt;joe@perches.com&gt;
Cc: Peter Chen &lt;Peter.Chen@nxp.com&gt;
Cc: Valentina Manea &lt;valentina.manea.m@gmail.com&gt;
Acked-by: Felipe Balbi &lt;felipe.balbi@linux.intel.com&gt;
Acked-by: Johan Hovold &lt;johan@kernel.org&gt;
Acked-by: Shuah Khan &lt;shuahkh@osg.samsung.com&gt;
Signed-off-by: Greg Kroah-Hartman &lt;gregkh@linuxfoundation.org&gt;
</content>
</entry>
</feed>
