Skip to content

Commit 2f2d008

Browse files
Shuah Khangregkh
authored andcommitted
usbip: prevent vhci_hcd driver from leaking a socket pointer address
When a client has a USB device attached over IP, the vhci_hcd driver is locally leaking a socket pointer address via the /sys/devices/platform/vhci_hcd/status file (world-readable) and in debug output when "usbip --debug port" is run. Fix it to not leak. The socket pointer address is not used at the moment and it was made visible as a convenient way to find IP address from socket pointer address by looking up /proc/net/{tcp,tcp6}. As this opens a security hole, the fix replaces socket pointer address with sockfd. Reported-by: Secunia Research <vuln@secunia.com> Cc: stable <stable@vger.kernel.org> Signed-off-by: Shuah Khan <shuahkh@osg.samsung.com> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent c6688ef commit 2f2d008

3 files changed

Lines changed: 21 additions & 13 deletions

File tree

‎drivers/usb/usbip/usbip_common.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ struct usbip_device {
256256
/* lock for status */
257257
spinlock_t lock;
258258

259+
int sockfd;
259260
struct socket *tcp_socket;
260261

261262
struct task_struct *tcp_rx;

‎drivers/usb/usbip/vhci_sysfs.c‎

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,20 @@
1717

1818
/*
1919
* output example:
20-
* hub port sta spd dev socket local_busid
21-
* hs 0000 004 000 00000000 c5a7bb80 1-2.3
20+
* hub port sta spd dev sockfd local_busid
21+
* hs 0000 004 000 00000000 3 1-2.3
2222
* ................................................
23-
* ss 0008 004 000 00000000 d8cee980 2-3.4
23+
* ss 0008 004 000 00000000 4 2-3.4
2424
* ................................................
2525
*
26-
* IP address can be retrieved from a socket pointer address by looking
27-
* up /proc/net/{tcp,tcp6}. Also, a userland program may remember a
28-
* port number and its peer IP address.
26+
* Output includes socket fd instead of socket pointer address to avoid
27+
* leaking kernel memory address in:
28+
* /sys/devices/platform/vhci_hcd.0/status and in debug output.
29+
* The socket pointer address is not used at the moment and it was made
30+
* visible as a convenient way to find IP address from socket pointer
31+
* address by looking up /proc/net/{tcp,tcp6}. As this opens a security
32+
* hole, the change is made to use sockfd instead.
33+
*
2934
*/
3035
static void port_show_vhci(char **out, int hub, int port, struct vhci_device *vdev)
3136
{
@@ -39,8 +44,8 @@ static void port_show_vhci(char **out, int hub, int port, struct vhci_device *vd
3944
if (vdev->ud.status == VDEV_ST_USED) {
4045
*out += sprintf(*out, "%03u %08x ",
4146
vdev->speed, vdev->devid);
42-
*out += sprintf(*out, "%16p %s",
43-
vdev->ud.tcp_socket,
47+
*out += sprintf(*out, "%u %s",
48+
vdev->ud.sockfd,
4449
dev_name(&vdev->udev->dev));
4550

4651
} else {
@@ -160,7 +165,8 @@ static ssize_t nports_show(struct device *dev, struct device_attribute *attr,
160165
char *s = out;
161166

162167
/*
163-
* Half the ports are for SPEED_HIGH and half for SPEED_SUPER, thus the * 2.
168+
* Half the ports are for SPEED_HIGH and half for SPEED_SUPER,
169+
* thus the * 2.
164170
*/
165171
out += sprintf(out, "%d\n", VHCI_PORTS * vhci_num_controllers);
166172
return out - s;
@@ -366,6 +372,7 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,
366372

367373
vdev->devid = devid;
368374
vdev->speed = speed;
375+
vdev->ud.sockfd = sockfd;
369376
vdev->ud.tcp_socket = socket;
370377
vdev->ud.status = VDEV_ST_NOTASSIGNED;
371378

‎tools/usb/usbip/libsrc/vhci_driver.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -50,14 +50,14 @@ static int parse_status(const char *value)
5050

5151
while (*c != '\0') {
5252
int port, status, speed, devid;
53-
unsigned long socket;
53+
int sockfd;
5454
char lbusid[SYSFS_BUS_ID_SIZE];
5555
struct usbip_imported_device *idev;
5656
char hub[3];
5757

58-
ret = sscanf(c, "%2s %d %d %d %x %lx %31s\n",
58+
ret = sscanf(c, "%2s %d %d %d %x %u %31s\n",
5959
hub, &port, &status, &speed,
60-
&devid, &socket, lbusid);
60+
&devid, &sockfd, lbusid);
6161

6262
if (ret < 5) {
6363
dbg("sscanf failed: %d", ret);
@@ -66,7 +66,7 @@ static int parse_status(const char *value)
6666

6767
dbg("hub %s port %d status %d speed %d devid %x",
6868
hub, port, status, speed, devid);
69-
dbg("socket %lx lbusid %s", socket, lbusid);
69+
dbg("sockfd %u lbusid %s", sockfd, lbusid);
7070

7171
/* if a device is connected, look at it */
7272
idev = &vhci_driver->idev[port];

0 commit comments

Comments
 (0)