Skip to content

Commit 47ccc8f

Browse files
shuahkhgregkh
authored andcommitted
usbip: fix stub_dev to check for stream socket
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 <penguin-kernel@I-love.SAKURA.ne.jp> Signed-off-by: Shuah Khan <skhan@linuxfoundation.org> Link: https://lore.kernel.org/r/e942d2bd03afb8e8552bd2a5d84e18d17670d521.1615171203.git.skhan@linuxfoundation.org Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 1cffb1c commit 47ccc8f

1 file changed

Lines changed: 11 additions & 1 deletion

File tree

drivers/usb/usbip/stub_dev.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,16 @@ static ssize_t usbip_sockfd_store(struct device *dev, struct device_attribute *a
6969
}
7070

7171
socket = sockfd_lookup(sockfd, &err);
72-
if (!socket)
72+
if (!socket) {
73+
dev_err(dev, "failed to lookup sock");
7374
goto err;
75+
}
76+
77+
if (socket->type != SOCK_STREAM) {
78+
dev_err(dev, "Expecting SOCK_STREAM - found %d",
79+
socket->type);
80+
goto sock_err;
81+
}
7482

7583
sdev->ud.tcp_socket = socket;
7684
sdev->ud.sockfd = sockfd;
@@ -100,6 +108,8 @@ static ssize_t usbip_sockfd_store(struct device *dev, struct device_attribute *a
100108

101109
return count;
102110

111+
sock_err:
112+
sockfd_put(socket);
103113
err:
104114
spin_unlock_irq(&sdev->ud.lock);
105115
return -EINVAL;

0 commit comments

Comments
 (0)