Skip to content

Commit b401f8c

Browse files
Anthony Malletgregkh
authored andcommitted
USB: cdc-acm: fix rounding error in TIOCSSERIAL
By default, tty_port_init() initializes those parameters to a multiple of HZ. For instance in line 69 of tty_port.c: port->close_delay = (50 * HZ) / 100; https://github.com/torvalds/linux/blob/master/drivers/tty/tty_port.c#L69 With e.g. CONFIG_HZ = 250 (as this is the case for Ubuntu 18.04 linux-image-4.15.0-37-generic), the default setting for close_delay is thus 125. When ioctl(fd, TIOCGSERIAL, &s) is executed, the setting returned in user space is '12' (125/10). When ioctl(fd, TIOCSSERIAL, &s) is then executed with the same setting '12', the value is interpreted as '120' which is different from the current setting and a EPERM error may be raised by set_serial_info() if !CAP_SYS_ADMIN. https://github.com/torvalds/linux/blob/master/drivers/usb/class/cdc-acm.c#L919 Fixes: ba2d8ce ("cdc-acm: implement TIOCSSERIAL to avoid blocking close(2)") Signed-off-by: Anthony Mallet <[email protected]> Cc: stable <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 633e2b2 commit b401f8c

File tree

1 file changed

+16
-9
lines changed

1 file changed

+16
-9
lines changed

drivers/usb/class/cdc-acm.c

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -907,25 +907,32 @@ static int set_serial_info(struct tty_struct *tty, struct serial_struct *ss)
907907
{
908908
struct acm *acm = tty->driver_data;
909909
unsigned int closing_wait, close_delay;
910+
unsigned int old_closing_wait, old_close_delay;
910911
int retval = 0;
911912

912913
close_delay = msecs_to_jiffies(ss->close_delay * 10);
913914
closing_wait = ss->closing_wait == ASYNC_CLOSING_WAIT_NONE ?
914915
ASYNC_CLOSING_WAIT_NONE :
915916
msecs_to_jiffies(ss->closing_wait * 10);
916917

918+
/* we must redo the rounding here, so that the values match */
919+
old_close_delay = jiffies_to_msecs(acm->port.close_delay) / 10;
920+
old_closing_wait = acm->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
921+
ASYNC_CLOSING_WAIT_NONE :
922+
jiffies_to_msecs(acm->port.closing_wait) / 10;
923+
917924
mutex_lock(&acm->port.mutex);
918925

919-
if (!capable(CAP_SYS_ADMIN)) {
920-
if ((close_delay != acm->port.close_delay) ||
921-
(closing_wait != acm->port.closing_wait))
926+
if ((ss->close_delay != old_close_delay) ||
927+
(ss->closing_wait != old_closing_wait)) {
928+
if (!capable(CAP_SYS_ADMIN))
922929
retval = -EPERM;
923-
else
924-
retval = -EOPNOTSUPP;
925-
} else {
926-
acm->port.close_delay = close_delay;
927-
acm->port.closing_wait = closing_wait;
928-
}
930+
else {
931+
acm->port.close_delay = close_delay;
932+
acm->port.closing_wait = closing_wait;
933+
}
934+
} else
935+
retval = -EOPNOTSUPP;
929936

930937
mutex_unlock(&acm->port.mutex);
931938
return retval;

0 commit comments

Comments
 (0)