public inbox for linux-kernel@vger.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/1] tty : fix tty_line must not be equal to number of allocated tty pointers in tty driver
@ 2010-09-02 14:06 Nathael Pajani
  0 siblings, 0 replies; only message in thread
From: Nathael Pajani @ 2010-09-02 14:06 UTC (permalink / raw)
  To: gregkh, linux-kernel; +Cc: torvalds

[-- Attachment #1: Type: text/plain, Size: 1599 bytes --]

Hi,

I found a bug "by chance" in drivers/char/tty_io.c

I mean "by chance" because I was just reading the code of the tty_find_polling_driver() to 
make a new tty_find_by_name() function.

---
In tty_find_polling_driver() the driver actually test "tty_line <= p->num" while num 
refers to the number of struct tty_struct pointers allocated for the p->ttys (p is a 
tty_driver), and tty_line is scanned in a tty name, which can be for example ttyS2. Then 
tty_line equals 2. And if p->num is 2, we have only p->ttys[0] and p->ttys[1], but no 
p->ttys[2].

This is actually unharmful, for tty_find_polling_driver() is used only in 
drivers/serial/kgdboc.c, and there's a test over there to find a console with a matching 
index, which will never happen.

This is still a bug anyway.

Signed-off-by: Nathael Pajani <nathael.pajani@ed3l.fr>
---

patch against 2bfc96a127bc1cc94d26bfaa40159966064f9c8c (Linux 2.6.36-rc3) :


diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 949067a..613c852 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -355,7 +355,7 @@ struct tty_driver *tty_find_polling_driver(char *name, int *line)
         if (*stp == '\0')
             stp = NULL;

-       if (tty_line >= 0 && tty_line <= p->num && p->ops &&
+       if (tty_line >= 0 && tty_line < p->num && p->ops &&
             p->ops->poll_init && !p->ops->poll_init(p, tty_line, stp)) {
             res = tty_driver_kref_get(p);
             *line = tty_line;



Have fun.
+++

-- 
Nathaël PAJANI
ED3L - Etude et Développement - Linux et Logiciels Libres
Internet : http://www.ed3l.fr

[-- Attachment #2: patch_tty_io_tty_line_cannot_equal_allocated_tty_num.patch --]
[-- Type: text/x-diff, Size: 505 bytes --]

diff --git a/drivers/char/tty_io.c b/drivers/char/tty_io.c
index 949067a..613c852 100644
--- a/drivers/char/tty_io.c
+++ b/drivers/char/tty_io.c
@@ -355,7 +355,7 @@ struct tty_driver *tty_find_polling_driver(char *name, int *line)
 		if (*stp == '\0')
 			stp = NULL;
 
-		if (tty_line >= 0 && tty_line <= p->num && p->ops &&
+		if (tty_line >= 0 && tty_line < p->num && p->ops &&
 		    p->ops->poll_init && !p->ops->poll_init(p, tty_line, stp)) {
 			res = tty_driver_kref_get(p);
 			*line = tty_line;

^ permalink raw reply related	[flat|nested] only message in thread

only message in thread, other threads:[~2010-09-02 14:16 UTC | newest]

Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2010-09-02 14:06 [PATCH 1/1] tty : fix tty_line must not be equal to number of allocated tty pointers in tty driver Nathael Pajani

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