LKML Archive on lore.kernel.org
help / color / mirror / Atom feed
* [RFC][PATCH] n_tty : Loss of sync following a buffer overflow
@ 2008-03-11 18:06 gmail
0 siblings, 0 replies; 3+ messages in thread
From: gmail @ 2008-03-11 18:06 UTC (permalink / raw)
To: linux-kernel
From: Rupesh Sugathan <Rupesh.Sugathan@gmail.com>
There seems to be a synchronization issue with the n_tty.c driver when
working in canonical mode.
The n_tty rightly discards data received following a buffer overflow and
hence the tty->read_cnt is not updated. However, the newline characters
received following a buffer overflow seems to increment the tty-
>canon_data index. This may result in a loss of sync between the tty-
>canon_data & tty->read_cnt while processing read in the read_chan().
This loss of sync might be irrecoverable even when the data is later
received at a slower rate.
----
I am not very sure if there is any deliberate rationale to process the
newlines even when the buffer has overflown. Please comment and review
the patch
diff -pu a/drivers/char/n_tty.c b/drivers/char/n_tty.c
--- a/drivers/char/n_tty.c 2008-03-10 17:11:54.000000000 -0700
+++ b/drivers/char/n_tty.c 2008-03-10 16:49:23.000000000 -0700
@@ -838,15 +838,17 @@ send_signal:
put_tty_queue(c, tty);
handle_newline:
- spin_lock_irqsave(&tty->read_lock, flags);
- set_bit(tty->read_head, tty->read_flags);
- put_tty_queue_nolock(c, tty);
- tty->canon_head = tty->read_head;
- tty->canon_data++;
- spin_unlock_irqrestore(&tty->read_lock, flags);
- kill_fasync(&tty->fasync, SIGIO, POLL_IN);
- if (waitqueue_active(&tty->read_wait))
- wake_up_interruptible(&tty->read_wait);
+ if (tty->read_cnt < N_TTY_BUF_SIZE) {
+ spin_lock_irqsave(&tty->read_lock, flags);
+ set_bit(tty->read_head, tty->read_flags);
+ put_tty_queue_nolock(c, tty);
+ tty->canon_head = tty->read_head;
+ tty->canon_data++;
+ spin_unlock_irqrestore(&tty->read_lock, flags);
+ kill_fasync(&tty->fasync, SIGIO, POLL_IN);
+ if (waitqueue_active(&tty->read_wait))
+ wake_up_interruptible(&tty->read_wait);
+ }
return;
}
}
Signed-off-by: Rupesh Sugathan <Rupesh.Sugathan@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [RFC][PATCH] n_tty : Loss of sync following a buffer overflow
2008-03-11 20:42 Rupesh Sugathan
@ 2008-03-12 0:19 ` Paul Fulghum
0 siblings, 0 replies; 3+ messages in thread
From: Paul Fulghum @ 2008-03-12 0:19 UTC (permalink / raw)
To: rupesh.sugathan; +Cc: linux-kernel, Alan Cox
Rupesh Sugathan wrote:
> There seems to be a synchronization issue with the n_tty.c driver when
> working in canonical mode.
> The n_tty rightly discards data received following a buffer overflow and
> hence the tty->read_cnt is not updated. However, the newline characters
> received following a buffer overflow seems to increment the tty-
> canon_data index. This may result in a loss of sync between the tty-
> canon_data & tty->read_cnt while processing read in the read_chan().
> This loss of sync might be irrecoverable even when the data is later
> received at a slower rate.
>
> ----
> I am not very sure if there is any deliberate rationale to process the
> newlines even when the buffer has overflown. Please comment and review
> the patch
>
> diff -pu a/drivers/char/n_tty.c b/drivers/char/n_tty.c
Some more information:
This is not purely theoretical. Rupesh is actually
working a problem where he has seen the N_TTY buffer overflow
and the canonical state variables get out of sync with read_cnt, etc.
This patch seems obviously correct, if N_TTY drops a
char due to a full buffer the rest of the character
processing should not take place. Particularly in this
case where the extra processing leaves the tty structure
in an inconsistent state.
--
Paul Fulghum
Microgate Systems, Ltd
^ permalink raw reply [flat|nested] 3+ messages in thread
* [RFC][PATCH] n_tty : Loss of sync following a buffer overflow
@ 2008-03-11 20:42 Rupesh Sugathan
2008-03-12 0:19 ` Paul Fulghum
0 siblings, 1 reply; 3+ messages in thread
From: Rupesh Sugathan @ 2008-03-11 20:42 UTC (permalink / raw)
To: linux-kernel
From: Rupesh Sugathan <Rupesh.Sugathan@gmail.com>
There seems to be a synchronization issue with the n_tty.c driver when
working in canonical mode.
The n_tty rightly discards data received following a buffer overflow and
hence the tty->read_cnt is not updated. However, the newline characters
received following a buffer overflow seems to increment the tty-
>canon_data index. This may result in a loss of sync between the tty-
>canon_data & tty->read_cnt while processing read in the read_chan().
This loss of sync might be irrecoverable even when the data is later
received at a slower rate.
----
I am not very sure if there is any deliberate rationale to process the
newlines even when the buffer has overflown. Please comment and review
the patch
diff -pu a/drivers/char/n_tty.c b/drivers/char/n_tty.c
--- a/drivers/char/n_tty.c 2008-03-10 17:11:54.000000000 -0700
+++ b/drivers/char/n_tty.c 2008-03-10 16:49:23.000000000 -0700
@@ -838,15 +838,17 @@ send_signal:
put_tty_queue(c, tty);
handle_newline:
- spin_lock_irqsave(&tty->read_lock, flags);
- set_bit(tty->read_head, tty->read_flags);
- put_tty_queue_nolock(c, tty);
- tty->canon_head = tty->read_head;
- tty->canon_data++;
- spin_unlock_irqrestore(&tty->read_lock, flags);
- kill_fasync(&tty->fasync, SIGIO, POLL_IN);
- if (waitqueue_active(&tty->read_wait))
- wake_up_interruptible(&tty->read_wait);
+ if (tty->read_cnt < N_TTY_BUF_SIZE) {
+ spin_lock_irqsave(&tty->read_lock, flags);
+ set_bit(tty->read_head, tty->read_flags);
+ put_tty_queue_nolock(c, tty);
+ tty->canon_head = tty->read_head;
+ tty->canon_data++;
+ spin_unlock_irqrestore(&tty->read_lock, flags);
+ kill_fasync(&tty->fasync, SIGIO, POLL_IN);
+ if (waitqueue_active(&tty->read_wait))
+ wake_up_interruptible(&tty->read_wait);
+ }
return;
}
}
Signed-off-by: Rupesh Sugathan <Rupesh.Sugathan@gmail.com>
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2008-03-11 23:20 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-03-11 18:06 [RFC][PATCH] n_tty : Loss of sync following a buffer overflow gmail
2008-03-11 20:42 Rupesh Sugathan
2008-03-12 0:19 ` Paul Fulghum
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).