Skip to content

Commit 4842ed5

Browse files
gregkhjhovold
authored andcommitted
USB: serial: visor: handle potential invalid device configuration
If we get an invalid device configuration from a palm 3 type device, we might incorrectly parse things, and we have the potential to crash in "interesting" ways. Fix this up by verifying the size of the configuration passed to us by the device, and only if it is correct, will we handle it. Note that this also fixes an information leak of slab data. Reported-by: Andrey Konovalov <[email protected]> Reviewed-by: Andrey Konovalov <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> [ johan: add comment about the info leak ] Cc: stable <[email protected]> Signed-off-by: Johan Hovold <[email protected]>
1 parent 4205cb0 commit 4842ed5

File tree

1 file changed

+35
-34
lines changed

1 file changed

+35
-34
lines changed

drivers/usb/serial/visor.c

Lines changed: 35 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -335,47 +335,48 @@ static int palm_os_3_probe(struct usb_serial *serial,
335335
goto exit;
336336
}
337337

338-
if (retval == sizeof(*connection_info)) {
339-
connection_info = (struct visor_connection_info *)
340-
transfer_buffer;
341-
342-
num_ports = le16_to_cpu(connection_info->num_ports);
343-
for (i = 0; i < num_ports; ++i) {
344-
switch (
345-
connection_info->connections[i].port_function_id) {
346-
case VISOR_FUNCTION_GENERIC:
347-
string = "Generic";
348-
break;
349-
case VISOR_FUNCTION_DEBUGGER:
350-
string = "Debugger";
351-
break;
352-
case VISOR_FUNCTION_HOTSYNC:
353-
string = "HotSync";
354-
break;
355-
case VISOR_FUNCTION_CONSOLE:
356-
string = "Console";
357-
break;
358-
case VISOR_FUNCTION_REMOTE_FILE_SYS:
359-
string = "Remote File System";
360-
break;
361-
default:
362-
string = "unknown";
363-
break;
364-
}
365-
dev_info(dev, "%s: port %d, is for %s use\n",
366-
serial->type->description,
367-
connection_info->connections[i].port, string);
368-
}
338+
if (retval != sizeof(*connection_info)) {
339+
dev_err(dev, "Invalid connection information received from device\n");
340+
retval = -ENODEV;
341+
goto exit;
369342
}
370-
/*
371-
* Handle devices that report invalid stuff here.
372-
*/
343+
344+
connection_info = (struct visor_connection_info *)transfer_buffer;
345+
346+
num_ports = le16_to_cpu(connection_info->num_ports);
347+
348+
/* Handle devices that report invalid stuff here. */
373349
if (num_ports == 0 || num_ports > 2) {
374350
dev_warn(dev, "%s: No valid connect info available\n",
375351
serial->type->description);
376352
num_ports = 2;
377353
}
378354

355+
for (i = 0; i < num_ports; ++i) {
356+
switch (connection_info->connections[i].port_function_id) {
357+
case VISOR_FUNCTION_GENERIC:
358+
string = "Generic";
359+
break;
360+
case VISOR_FUNCTION_DEBUGGER:
361+
string = "Debugger";
362+
break;
363+
case VISOR_FUNCTION_HOTSYNC:
364+
string = "HotSync";
365+
break;
366+
case VISOR_FUNCTION_CONSOLE:
367+
string = "Console";
368+
break;
369+
case VISOR_FUNCTION_REMOTE_FILE_SYS:
370+
string = "Remote File System";
371+
break;
372+
default:
373+
string = "unknown";
374+
break;
375+
}
376+
dev_info(dev, "%s: port %d, is for %s use\n",
377+
serial->type->description,
378+
connection_info->connections[i].port, string);
379+
}
379380
dev_info(dev, "%s: Number of ports: %d\n", serial->type->description,
380381
num_ports);
381382

0 commit comments

Comments
 (0)