public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH] n_tty: check for negative and zero space return from tty_write_room
@ 2019-03-28 17:10 Colin King
  2019-03-28 19:34 ` Mukesh Ojha
  2019-03-29  7:43 ` Dan Carpenter
  0 siblings, 2 replies; 3+ messages in thread
From: Colin King @ 2019-03-28 17:10 UTC (permalink / raw)
  To: Greg Kroah-Hartman, Jiri Slaby; +Cc: kernel-janitors, linux-kernel

From: Colin Ian King <colin.king@canonical.com>

The return from tty_write_room could potentially be negative if
a tty write_room driver returns an error number (not that any seem
to do). Rather than just check for a zero return, also check for
a -ve return. This avoids the unsigned nr being set to a large unsigned
value on the assignment from variable space and can lead to overflowing
the buffer buf.  Better to be safe than assume all write_room
implementations in tty drivers are going to do the right thing.

Signed-off-by: Colin Ian King <colin.king@canonical.com>
---
 drivers/tty/n_tty.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
index 9cdb0fa3c4bf..66630787fbf9 100644
--- a/drivers/tty/n_tty.c
+++ b/drivers/tty/n_tty.c
@@ -550,7 +550,7 @@ static ssize_t process_output_block(struct tty_struct *tty,
 	mutex_lock(&ldata->output_lock);
 
 	space = tty_write_room(tty);
-	if (!space) {
+	if (space <= 0) {
 		mutex_unlock(&ldata->output_lock);
 		return 0;
 	}
-- 
2.20.1


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

end of thread, other threads:[~2019-03-29  7:44 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2019-03-28 17:10 [PATCH] n_tty: check for negative and zero space return from tty_write_room Colin King
2019-03-28 19:34 ` Mukesh Ojha
2019-03-29  7:43 ` Dan Carpenter

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox