linux-usb.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH v2 0/3] TIOCSSERIAL fixes
@ 2021-04-08 13:15 Johan Hovold
  2021-04-08 13:16 ` [PATCH v2 1/3] Revert "USB: cdc-acm: fix rounding error in TIOCSSERIAL" Johan Hovold
                   ` (2 more replies)
  0 siblings, 3 replies; 7+ messages in thread
From: Johan Hovold @ 2021-04-08 13:15 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Oliver Neukum, linux-usb, linux-kernel, Johan Hovold, Anthony Mallet

This series fixes up a few issues with cdc-acm TIOCSSERIAL
implementation.

Johan

Changes in v2
 - amend commit message to clarify that the 12 cs close_delay bug had
   already been fixed by an earlier patch (1/3)

 - amend commit message to clarify that the base clock rate isn't known
   for CDC and that the current line speed can still be retrieved
   through the standard termios interfaces (3/3)

Johan Hovold (3):
  Revert "USB: cdc-acm: fix rounding error in TIOCSSERIAL"
  USB: cdc-acm: fix unprivileged TIOCCSERIAL
  USB: cdc-acm: fix TIOCGSERIAL implementation

 drivers/usb/class/cdc-acm.c | 16 +++-------------
 1 file changed, 3 insertions(+), 13 deletions(-)

-- 
2.26.3


^ permalink raw reply	[flat|nested] 7+ messages in thread

* [PATCH v2 1/3] Revert "USB: cdc-acm: fix rounding error in TIOCSSERIAL"
  2021-04-08 13:15 [PATCH v2 0/3] TIOCSSERIAL fixes Johan Hovold
@ 2021-04-08 13:16 ` Johan Hovold
  2021-04-08 13:31   ` Oliver Neukum
  2021-04-08 13:16 ` [PATCH v2 2/3] USB: cdc-acm: fix unprivileged TIOCCSERIAL Johan Hovold
  2021-04-08 13:16 ` [PATCH v2 3/3] USB: cdc-acm: fix TIOCGSERIAL implementation Johan Hovold
  2 siblings, 1 reply; 7+ messages in thread
From: Johan Hovold @ 2021-04-08 13:16 UTC (permalink / raw)
  To: Greg Kroah-Hartman
  Cc: Oliver Neukum, linux-usb, linux-kernel, Johan Hovold,
	Anthony Mallet, stable

This reverts commit b401f8c4f492cbf74f3f59c9141e5be3071071bb.

The offending commit claimed that trying to set the values reported back
by TIOCGSERIAL as a regular user could result in an -EPERM error when HZ
is 250, but that was never the case.

With HZ=250, the default 0.5 second value of close_delay is converted to
125 jiffies when set and is converted back to 50 centiseconds by
TIOCGSERIAL as expected (not 12 cs as was claimed, even if that was the
case before an earlier fix).

Comparing the internal current and new jiffies values is just fine to
determine if the value is about to change so drop the bogus workaround
(which was also backported to stable).

For completeness: With different default values for these parameters or
with a HZ value not divisible by two, the lack of rounding when setting
the default values in tty_port_init() could result in an -EPERM being
returned, but this is hardly something we need to worry about.

Cc: Anthony Mallet <anthony.mallet@laas.fr>
Cc: stable@vger.kernel.org
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/class/cdc-acm.c | 11 ++---------
 1 file changed, 2 insertions(+), 9 deletions(-)

diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 3fda1ec961d7..96e221803fa6 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -942,7 +942,6 @@ static int set_serial_info(struct tty_struct *tty, struct serial_struct *ss)
 {
 	struct acm *acm = tty->driver_data;
 	unsigned int closing_wait, close_delay;
-	unsigned int old_closing_wait, old_close_delay;
 	int retval = 0;
 
 	close_delay = msecs_to_jiffies(ss->close_delay * 10);
@@ -950,17 +949,11 @@ static int set_serial_info(struct tty_struct *tty, struct serial_struct *ss)
 			ASYNC_CLOSING_WAIT_NONE :
 			msecs_to_jiffies(ss->closing_wait * 10);
 
-	/* we must redo the rounding here, so that the values match */
-	old_close_delay	= jiffies_to_msecs(acm->port.close_delay) / 10;
-	old_closing_wait = acm->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
-				ASYNC_CLOSING_WAIT_NONE :
-				jiffies_to_msecs(acm->port.closing_wait) / 10;
-
 	mutex_lock(&acm->port.mutex);
 
 	if (!capable(CAP_SYS_ADMIN)) {
-		if ((ss->close_delay != old_close_delay) ||
-		    (ss->closing_wait != old_closing_wait))
+		if ((close_delay != acm->port.close_delay) ||
+		    (closing_wait != acm->port.closing_wait))
 			retval = -EPERM;
 		else
 			retval = -EOPNOTSUPP;
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 2/3] USB: cdc-acm: fix unprivileged TIOCCSERIAL
  2021-04-08 13:15 [PATCH v2 0/3] TIOCSSERIAL fixes Johan Hovold
  2021-04-08 13:16 ` [PATCH v2 1/3] Revert "USB: cdc-acm: fix rounding error in TIOCSSERIAL" Johan Hovold
@ 2021-04-08 13:16 ` Johan Hovold
  2021-04-08 13:32   ` Oliver Neukum
  2021-04-08 13:16 ` [PATCH v2 3/3] USB: cdc-acm: fix TIOCGSERIAL implementation Johan Hovold
  2 siblings, 1 reply; 7+ messages in thread
From: Johan Hovold @ 2021-04-08 13:16 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Oliver Neukum, linux-usb, linux-kernel, Johan Hovold

TIOCSSERIAL is a horrid, underspecified, legacy interface which for most
serial devices is only useful for setting the close_delay and
closing_wait parameters.

A non-privileged user has only ever been able to set the since long
deprecated ASYNC_SPD flags and trying to change any other *supported*
feature should result in -EPERM being returned. Setting the current
values for any supported features should return success.

Fix the cdc-acm implementation which instead indicated that the
TIOCSSERIAL ioctl was not even implemented when a non-privileged user
set the current values.

Fixes: ba2d8ce9db0a ("cdc-acm: implement TIOCSSERIAL to avoid blocking close(2)")
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/class/cdc-acm.c | 2 --
 1 file changed, 2 deletions(-)

diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 96e221803fa6..43e31dad4831 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -955,8 +955,6 @@ static int set_serial_info(struct tty_struct *tty, struct serial_struct *ss)
 		if ((close_delay != acm->port.close_delay) ||
 		    (closing_wait != acm->port.closing_wait))
 			retval = -EPERM;
-		else
-			retval = -EOPNOTSUPP;
 	} else {
 		acm->port.close_delay  = close_delay;
 		acm->port.closing_wait = closing_wait;
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* [PATCH v2 3/3] USB: cdc-acm: fix TIOCGSERIAL implementation
  2021-04-08 13:15 [PATCH v2 0/3] TIOCSSERIAL fixes Johan Hovold
  2021-04-08 13:16 ` [PATCH v2 1/3] Revert "USB: cdc-acm: fix rounding error in TIOCSSERIAL" Johan Hovold
  2021-04-08 13:16 ` [PATCH v2 2/3] USB: cdc-acm: fix unprivileged TIOCCSERIAL Johan Hovold
@ 2021-04-08 13:16 ` Johan Hovold
  2021-04-08 13:33   ` Oliver Neukum
  2 siblings, 1 reply; 7+ messages in thread
From: Johan Hovold @ 2021-04-08 13:16 UTC (permalink / raw)
  To: Greg Kroah-Hartman; +Cc: Oliver Neukum, linux-usb, linux-kernel, Johan Hovold

TIOCSSERIAL is a horrid, underspecified, legacy interface which for most
serial devices is only useful for setting the close_delay and
closing_wait parameters.

The xmit_fifo_size parameter could be used to set the hardware transmit
fifo size of a legacy UART when it could not be detected, but the
interface is limited to eight bits and should be left unset when it is
not used.

Similarly, baud_base could be used to set the UART base clock when it
could not be detected, but might as well be left unset when it is not
known (which is the case for CDC).

Fix the cdc-acm TIOCGSERIAL implementation by dropping its custom
interpretation of the unused xmit_fifo_size and baud_base fields, which
overflowed the former with the URB buffer size and set the latter to the
current line speed. Also return the port line number, which is the only
other value used besides the close parameters.

Note that the current line speed can still be retrieved through the
standard termios interfaces.

Fixes: 18c75720e667 ("USB: allow users to run setserial with cdc-acm")
Signed-off-by: Johan Hovold <johan@kernel.org>
---
 drivers/usb/class/cdc-acm.c | 3 +--
 1 file changed, 1 insertion(+), 2 deletions(-)

diff --git a/drivers/usb/class/cdc-acm.c b/drivers/usb/class/cdc-acm.c
index 43e31dad4831..b74713518b3a 100644
--- a/drivers/usb/class/cdc-acm.c
+++ b/drivers/usb/class/cdc-acm.c
@@ -929,8 +929,7 @@ static int get_serial_info(struct tty_struct *tty, struct serial_struct *ss)
 {
 	struct acm *acm = tty->driver_data;
 
-	ss->xmit_fifo_size = acm->writesize;
-	ss->baud_base = le32_to_cpu(acm->line.dwDTERate);
+	ss->line = acm->minor;
 	ss->close_delay	= jiffies_to_msecs(acm->port.close_delay) / 10;
 	ss->closing_wait = acm->port.closing_wait == ASYNC_CLOSING_WAIT_NONE ?
 				ASYNC_CLOSING_WAIT_NONE :
-- 
2.26.3


^ permalink raw reply related	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 1/3] Revert "USB: cdc-acm: fix rounding error in TIOCSSERIAL"
  2021-04-08 13:16 ` [PATCH v2 1/3] Revert "USB: cdc-acm: fix rounding error in TIOCSSERIAL" Johan Hovold
@ 2021-04-08 13:31   ` Oliver Neukum
  0 siblings, 0 replies; 7+ messages in thread
From: Oliver Neukum @ 2021-04-08 13:31 UTC (permalink / raw)
  To: Johan Hovold, Greg Kroah-Hartman
  Cc: linux-usb, linux-kernel, Anthony Mallet, stable

Am Donnerstag, den 08.04.2021, 15:16 +0200 schrieb Johan Hovold:
> This reverts commit b401f8c4f492cbf74f3f59c9141e5be3071071bb.
> 
> The offending commit claimed that trying to set the values reported back
> by TIOCGSERIAL as a regular user could result in an -EPERM error when HZ
> is 250, but that was never the case.
> 
> With HZ=250, the default 0.5 second value of close_delay is converted to
> 125 jiffies when set and is converted back to 50 centiseconds by
> TIOCGSERIAL as expected (not 12 cs as was claimed, even if that was the
> case before an earlier fix).
> 
> Comparing the internal current and new jiffies values is just fine to
> determine if the value is about to change so drop the bogus workaround
> (which was also backported to stable).
> 
> For completeness: With different default values for these parameters or
> with a HZ value not divisible by two, the lack of rounding when setting
> the default values in tty_port_init() could result in an -EPERM being
> returned, but this is hardly something we need to worry about.
> 
> Cc: Anthony Mallet <anthony.mallet@laas.fr>
> Cc: stable@vger.kernel.org
> Signed-off-by: Johan Hovold <johan@kernel.org>
Acked-by: Oliver Neukum <oneukum@suse.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 2/3] USB: cdc-acm: fix unprivileged TIOCCSERIAL
  2021-04-08 13:16 ` [PATCH v2 2/3] USB: cdc-acm: fix unprivileged TIOCCSERIAL Johan Hovold
@ 2021-04-08 13:32   ` Oliver Neukum
  0 siblings, 0 replies; 7+ messages in thread
From: Oliver Neukum @ 2021-04-08 13:32 UTC (permalink / raw)
  To: Johan Hovold, Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel

Am Donnerstag, den 08.04.2021, 15:16 +0200 schrieb Johan Hovold:
> TIOCSSERIAL is a horrid, underspecified, legacy interface which for most
> serial devices is only useful for setting the close_delay and
> closing_wait parameters.
> 
> A non-privileged user has only ever been able to set the since long
> deprecated ASYNC_SPD flags and trying to change any other *supported*
> feature should result in -EPERM being returned. Setting the current
> values for any supported features should return success.
> 
> Fix the cdc-acm implementation which instead indicated that the
> TIOCSSERIAL ioctl was not even implemented when a non-privileged user
> set the current values.
> 
> Fixes: ba2d8ce9db0a ("cdc-acm: implement TIOCSSERIAL to avoid blocking close(2)")
> Signed-off-by: Johan Hovold <johan@kernel.org>
Acked-by: Oliver Neukum <oneukum@suse.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: [PATCH v2 3/3] USB: cdc-acm: fix TIOCGSERIAL implementation
  2021-04-08 13:16 ` [PATCH v2 3/3] USB: cdc-acm: fix TIOCGSERIAL implementation Johan Hovold
@ 2021-04-08 13:33   ` Oliver Neukum
  0 siblings, 0 replies; 7+ messages in thread
From: Oliver Neukum @ 2021-04-08 13:33 UTC (permalink / raw)
  To: Johan Hovold, Greg Kroah-Hartman; +Cc: linux-usb, linux-kernel

Am Donnerstag, den 08.04.2021, 15:16 +0200 schrieb Johan Hovold:
> TIOCSSERIAL is a horrid, underspecified, legacy interface which for most
> serial devices is only useful for setting the close_delay and
> closing_wait parameters.
> 
> The xmit_fifo_size parameter could be used to set the hardware transmit
> fifo size of a legacy UART when it could not be detected, but the
> interface is limited to eight bits and should be left unset when it is
> not used.
> 
> Similarly, baud_base could be used to set the UART base clock when it
> could not be detected, but might as well be left unset when it is not
> known (which is the case for CDC).
> 
> Fix the cdc-acm TIOCGSERIAL implementation by dropping its custom
> interpretation of the unused xmit_fifo_size and baud_base fields, which
> overflowed the former with the URB buffer size and set the latter to the
> current line speed. Also return the port line number, which is the only
> other value used besides the close parameters.
> 
> Note that the current line speed can still be retrieved through the
> standard termios interfaces.
> 
> Fixes: 18c75720e667 ("USB: allow users to run setserial with cdc-acm")
> Signed-off-by: Johan Hovold <johan@kernel.org>
Acked-by: Oliver Neukum <oneukum@suse.com>


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2021-04-08 13:33 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-04-08 13:15 [PATCH v2 0/3] TIOCSSERIAL fixes Johan Hovold
2021-04-08 13:16 ` [PATCH v2 1/3] Revert "USB: cdc-acm: fix rounding error in TIOCSSERIAL" Johan Hovold
2021-04-08 13:31   ` Oliver Neukum
2021-04-08 13:16 ` [PATCH v2 2/3] USB: cdc-acm: fix unprivileged TIOCCSERIAL Johan Hovold
2021-04-08 13:32   ` Oliver Neukum
2021-04-08 13:16 ` [PATCH v2 3/3] USB: cdc-acm: fix TIOCGSERIAL implementation Johan Hovold
2021-04-08 13:33   ` Oliver Neukum

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).