Commit 0b29f967 authored by Shuah Khan's avatar Shuah Khan Committed by Kleber Sacilotto de Souza

usbip: prevent vhci_hcd driver from leaking a socket pointer address

BugLink: http://bugs.launchpad.net/bugs/1754592

commit 2f2d0088 upstream.

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: default avatarSecunia Research <vuln@secunia.com>
Signed-off-by: default avatarShuah Khan <shuahkh@osg.samsung.com>
Signed-off-by: default avatarGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Signed-off-by: default avatarStefan Bader <stefan.bader@canonical.com>
Signed-off-by: default avatarKleber Sacilotto de Souza <kleber.souza@canonical.com>
parent 0d2d6856
...@@ -261,6 +261,7 @@ struct usbip_device { ...@@ -261,6 +261,7 @@ struct usbip_device {
/* lock for status */ /* lock for status */
spinlock_t lock; spinlock_t lock;
int sockfd;
struct socket *tcp_socket; struct socket *tcp_socket;
struct task_struct *tcp_rx; struct task_struct *tcp_rx;
......
...@@ -39,16 +39,20 @@ static ssize_t status_show(struct device *dev, struct device_attribute *attr, ...@@ -39,16 +39,20 @@ static ssize_t status_show(struct device *dev, struct device_attribute *attr,
/* /*
* output example: * output example:
* prt sta spd dev socket local_busid * port sta spd dev sockfd local_busid
* 000 004 000 000 c5a7bb80 1-2.3 * 0000 004 000 00000000 000003 1-2.3
* 001 004 000 000 d8cee980 2-3.4 * 0001 004 000 00000000 000004 2-3.4
* *
* IP address can be retrieved from a socket pointer address by looking * Output includes socket fd instead of socket pointer address to
* up /proc/net/{tcp,tcp6}. Also, a userland program may remember a * avoid leaking kernel memory address in:
* port number and its peer IP address. * /sys/devices/platform/vhci_hcd.0/status and in debug output.
* 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 change is made to use sockfd instead.
*/ */
out += sprintf(out, out += sprintf(out,
"prt sta spd bus dev socket local_busid\n"); "prt sta spd bus dev sockfd local_busid\n");
for (i = 0; i < VHCI_NPORTS; i++) { for (i = 0; i < VHCI_NPORTS; i++) {
struct vhci_device *vdev = port_to_vdev(i); struct vhci_device *vdev = port_to_vdev(i);
...@@ -60,11 +64,11 @@ static ssize_t status_show(struct device *dev, struct device_attribute *attr, ...@@ -60,11 +64,11 @@ static ssize_t status_show(struct device *dev, struct device_attribute *attr,
out += sprintf(out, "%03u %08x ", out += sprintf(out, "%03u %08x ",
vdev->speed, vdev->devid); vdev->speed, vdev->devid);
out += sprintf(out, "%16p ", vdev->ud.tcp_socket); out += sprintf(out, "%16p ", vdev->ud.tcp_socket);
out += sprintf(out, "%06u", vdev->ud.sockfd);
out += sprintf(out, "%s", dev_name(&vdev->udev->dev)); out += sprintf(out, "%s", dev_name(&vdev->udev->dev));
} else { } else
out += sprintf(out, "000 000 000 0000000000000000 0-0"); out += sprintf(out, "000 000 000 000000 0-0");
}
out += sprintf(out, "\n"); out += sprintf(out, "\n");
spin_unlock(&vdev->ud.lock); spin_unlock(&vdev->ud.lock);
...@@ -223,6 +227,7 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr, ...@@ -223,6 +227,7 @@ static ssize_t store_attach(struct device *dev, struct device_attribute *attr,
vdev->devid = devid; vdev->devid = devid;
vdev->speed = speed; vdev->speed = speed;
vdev->ud.sockfd = sockfd;
vdev->ud.tcp_socket = socket; vdev->ud.tcp_socket = socket;
vdev->ud.status = VDEV_ST_NOTASSIGNED; vdev->ud.status = VDEV_ST_NOTASSIGNED;
......
...@@ -55,12 +55,12 @@ static int parse_status(const char *value) ...@@ -55,12 +55,12 @@ static int parse_status(const char *value)
while (*c != '\0') { while (*c != '\0') {
int port, status, speed, devid; int port, status, speed, devid;
unsigned long socket; int sockfd;
char lbusid[SYSFS_BUS_ID_SIZE]; char lbusid[SYSFS_BUS_ID_SIZE];
ret = sscanf(c, "%d %d %d %x %lx %31s\n", ret = sscanf(c, "%d %d %d %x %u %31s\n",
&port, &status, &speed, &port, &status, &speed,
&devid, &socket, lbusid); &devid, &sockfd, lbusid);
if (ret < 5) { if (ret < 5) {
dbg("sscanf failed: %d", ret); dbg("sscanf failed: %d", ret);
...@@ -69,7 +69,7 @@ static int parse_status(const char *value) ...@@ -69,7 +69,7 @@ static int parse_status(const char *value)
dbg("port %d status %d speed %d devid %x", dbg("port %d status %d speed %d devid %x",
port, status, speed, devid); port, status, speed, devid);
dbg("socket %lx lbusid %s", socket, lbusid); dbg("sockfd %u lbusid %s", sockfd, lbusid);
/* if a device is connected, look at it */ /* if a device is connected, look at it */
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment