The Linux Kernel Mailing List
 help / color / mirror / Atom feed
From: gmail <rupesh.sugathan@gmail.com>
To: linux-kernel@vger.kernel.org
Subject: [RFC][PATCH] n_tty : Loss of sync following a buffer overflow
Date: Tue, 11 Mar 2008 11:06:01 -0700	[thread overview]
Message-ID: <1205258761.28851.14.camel@estonia> (raw)

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>




             reply	other threads:[~2008-03-11 18:32 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-11 18:06 gmail [this message]
  -- strict thread matches above, loose matches on Subject: below --
2008-03-11 20:42 [RFC][PATCH] n_tty : Loss of sync following a buffer overflow Rupesh Sugathan
2008-03-12  0:19 ` Paul Fulghum

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1205258761.28851.14.camel@estonia \
    --to=rupesh.sugathan@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox