* [PATCH 1/5] net: irda: fix wait_until_sent poll timeout
[not found] <1425461947-15888-1-git-send-email-johan@kernel.org>
@ 2015-03-04 9:39 ` Johan Hovold
2015-03-04 9:39 ` [PATCH 3/5] USB: serial: fix infinite wait_until_sent timeout Johan Hovold
2015-03-04 9:39 ` [PATCH 4/5] TTY: fix tty_wait_until_sent on 64-bit machines Johan Hovold
2 siblings, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2015-03-04 9:39 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Jiri Slaby, Samuel Ortiz, David S. Miller, Peter Hurley, Alan Cox,
linux-kernel, linux-usb, linux-serial, netdev,
ZIV-Asier Llano Palacios, Johan Hovold, stable
In case an infinite timeout (0) is requested, the irda wait_until_sent
implementation would use a zero poll timeout rather than the default
200ms.
Note that wait_until_sent is currently never called with a 0-timeout
argument due to a bug in tty_wait_until_sent.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable <stable@vger.kernel.org> # v2.6.12
Signed-off-by: Johan Hovold <johan@kernel.org>
---
net/irda/ircomm/ircomm_tty.c | 4 +++-
1 file changed, 3 insertions(+), 1 deletion(-)
diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
index 40695b9751c1..4efe486baee6 100644
--- a/net/irda/ircomm/ircomm_tty.c
+++ b/net/irda/ircomm/ircomm_tty.c
@@ -798,7 +798,9 @@ static void ircomm_tty_wait_until_sent(struct tty_struct *tty, int timeout)
orig_jiffies = jiffies;
/* Set poll time to 200 ms */
- poll_time = IRDA_MIN(timeout, msecs_to_jiffies(200));
+ poll_time = msecs_to_jiffies(200);
+ if (timeout)
+ poll_time = min_t(unsigned long, timeout, poll_time);
spin_lock_irqsave(&self->spinlock, flags);
while (self->tx_skb && self->tx_skb->len) {
--
2.0.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 3/5] USB: serial: fix infinite wait_until_sent timeout
[not found] <1425461947-15888-1-git-send-email-johan@kernel.org>
2015-03-04 9:39 ` [PATCH 1/5] net: irda: fix wait_until_sent poll timeout Johan Hovold
@ 2015-03-04 9:39 ` Johan Hovold
2015-03-04 9:39 ` [PATCH 4/5] TTY: fix tty_wait_until_sent on 64-bit machines Johan Hovold
2 siblings, 0 replies; 4+ messages in thread
From: Johan Hovold @ 2015-03-04 9:39 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Jiri Slaby, Samuel Ortiz, David S. Miller, Peter Hurley, Alan Cox,
linux-kernel, linux-usb, linux-serial, netdev,
ZIV-Asier Llano Palacios, Johan Hovold, stable
Make sure to handle an infinite timeout (0).
Note that wait_until_sent is currently never called with a 0-timeout
argument due to a bug in tty_wait_until_sent.
Fixes: dcf010503966 ("USB: serial: add generic wait_until_sent
implementation")
Cc: stable <stable@vger.kernel.org> # v3.10
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/usb/serial/generic.c | 5 +++--
1 file changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/usb/serial/generic.c b/drivers/usb/serial/generic.c
index ccf1df7c4b80..54e170dd3dad 100644
--- a/drivers/usb/serial/generic.c
+++ b/drivers/usb/serial/generic.c
@@ -258,7 +258,8 @@ void usb_serial_generic_wait_until_sent(struct tty_struct *tty, long timeout)
* character or at least one jiffy.
*/
period = max_t(unsigned long, (10 * HZ / bps), 1);
- period = min_t(unsigned long, period, timeout);
+ if (timeout)
+ period = min_t(unsigned long, period, timeout);
dev_dbg(&port->dev, "%s - timeout = %u ms, period = %u ms\n",
__func__, jiffies_to_msecs(timeout),
@@ -268,7 +269,7 @@ void usb_serial_generic_wait_until_sent(struct tty_struct *tty, long timeout)
schedule_timeout_interruptible(period);
if (signal_pending(current))
break;
- if (time_after(jiffies, expire))
+ if (timeout && time_after(jiffies, expire))
break;
}
}
--
2.0.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* [PATCH 4/5] TTY: fix tty_wait_until_sent on 64-bit machines
[not found] <1425461947-15888-1-git-send-email-johan@kernel.org>
2015-03-04 9:39 ` [PATCH 1/5] net: irda: fix wait_until_sent poll timeout Johan Hovold
2015-03-04 9:39 ` [PATCH 3/5] USB: serial: fix infinite wait_until_sent timeout Johan Hovold
@ 2015-03-04 9:39 ` Johan Hovold
2015-03-05 14:31 ` Peter Hurley
2 siblings, 1 reply; 4+ messages in thread
From: Johan Hovold @ 2015-03-04 9:39 UTC (permalink / raw)
To: Greg Kroah-Hartman
Cc: Jiri Slaby, Samuel Ortiz, David S. Miller, Peter Hurley, Alan Cox,
linux-kernel, linux-usb, linux-serial, netdev,
ZIV-Asier Llano Palacios, Johan Hovold, stable
Fix overflow bug in tty_wait_until_sent on 64-bit machines, where an
infinite timeout (0) would be passed to the underlying tty-driver's
wait_until_sent-operation as a negative timeout (-1), causing it to
return immediately.
This manifests itself for example as tcdrain() returning immediately,
drivers not honouring the drain flags when setting terminal attributes,
or even dropped data on close as a requested infinite closing-wait
timeout would be ignored.
The first symptom was reported by Asier LLANO who noted that tcdrain()
returned prematurely when using the ftdi_sio usb-serial driver.
Fix this by passing 0 rather than MAX_SCHEDULE_TIMEOUT (LONG_MAX) to the
underlying tty driver.
Note that the serial-core wait_until_sent-implementation is not affected
by this bug due to a lucky chance (comparison to an unsigned maximum
timeout), and neither is the cyclades one that had an explicit check for
negative timeouts, but all other tty drivers appear to be affected.
Fixes: 1da177e4c3f4 ("Linux-2.6.12-rc2")
Cc: stable <stable@vger.kernel.org> # v2.6.12
Reported-by: ZIV-Asier Llano Palacios <asier.llano@cgglobal.com>
Signed-off-by: Johan Hovold <johan@kernel.org>
---
drivers/tty/tty_ioctl.c | 12 +++++++++---
1 file changed, 9 insertions(+), 3 deletions(-)
diff --git a/drivers/tty/tty_ioctl.c b/drivers/tty/tty_ioctl.c
index a5cf253b2544..89ae23ac9ae6 100644
--- a/drivers/tty/tty_ioctl.c
+++ b/drivers/tty/tty_ioctl.c
@@ -217,11 +217,17 @@ void tty_wait_until_sent(struct tty_struct *tty, long timeout)
#endif
if (!timeout)
timeout = MAX_SCHEDULE_TIMEOUT;
+
if (wait_event_interruptible_timeout(tty->write_wait,
- !tty_chars_in_buffer(tty), timeout) >= 0) {
- if (tty->ops->wait_until_sent)
- tty->ops->wait_until_sent(tty, timeout);
+ !tty_chars_in_buffer(tty), timeout) < 0) {
+ return;
}
+
+ if (timeout == MAX_SCHEDULE_TIMEOUT)
+ timeout = 0;
+
+ if (tty->ops->wait_until_sent)
+ tty->ops->wait_until_sent(tty, timeout);
}
EXPORT_SYMBOL(tty_wait_until_sent);
--
2.0.5
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH 4/5] TTY: fix tty_wait_until_sent on 64-bit machines
2015-03-04 9:39 ` [PATCH 4/5] TTY: fix tty_wait_until_sent on 64-bit machines Johan Hovold
@ 2015-03-05 14:31 ` Peter Hurley
0 siblings, 0 replies; 4+ messages in thread
From: Peter Hurley @ 2015-03-05 14:31 UTC (permalink / raw)
To: Johan Hovold, Greg Kroah-Hartman
Cc: Jiri Slaby, Samuel Ortiz, David S. Miller, Alan Cox, linux-kernel,
linux-usb, linux-serial, netdev, ZIV-Asier Llano Palacios, stable
On 03/04/2015 04:39 AM, Johan Hovold wrote:
> Fix overflow bug in tty_wait_until_sent on 64-bit machines, where an
> infinite timeout (0) would be passed to the underlying tty-driver's
> wait_until_sent-operation as a negative timeout (-1), causing it to
> return immediately.
Wow, that is a nasty bug.
> This manifests itself for example as tcdrain() returning immediately,
> drivers not honouring the drain flags when setting terminal attributes,
> or even dropped data on close as a requested infinite closing-wait
> timeout would be ignored.
>
> The first symptom was reported by Asier LLANO who noted that tcdrain()
> returned prematurely when using the ftdi_sio usb-serial driver.
>
> Fix this by passing 0 rather than MAX_SCHEDULE_TIMEOUT (LONG_MAX) to the
> underlying tty driver.
>
> Note that the serial-core wait_until_sent-implementation is not affected
> by this bug due to a lucky chance (comparison to an unsigned maximum
> timeout), and neither is the cyclades one that had an explicit check for
> negative timeouts, but all other tty drivers appear to be affected.
Reviewed-by: Peter Hurley <peter@hurleysoftware.com>
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2015-03-05 14:31 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
[not found] <1425461947-15888-1-git-send-email-johan@kernel.org>
2015-03-04 9:39 ` [PATCH 1/5] net: irda: fix wait_until_sent poll timeout Johan Hovold
2015-03-04 9:39 ` [PATCH 3/5] USB: serial: fix infinite wait_until_sent timeout Johan Hovold
2015-03-04 9:39 ` [PATCH 4/5] TTY: fix tty_wait_until_sent on 64-bit machines Johan Hovold
2015-03-05 14:31 ` Peter Hurley
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).