Re: Output truncated in ssh session after d2b6f44779d3 ("n_tty: Fix signal handling flushes")

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi Filipe,

On 07/07/2015 05:28 PM, Filipe Brandenburger wrote:
> On Wed, Jun 10, 2015 at 10:11 AM, Peter Hurley <peter@xxxxxxxxxxxxxxxxxx> wrote:
>> Well, I still couldn't repro this bug but I have a hypothesis that
>> the bash sig handler is executing before the flush occurs, perhaps
>> because the flush is stalled waiting for the write lock.
>>
>> Would you please try the patch below?
> 
> I just wanted to get back to you to say I've been testing your patch
> for a few weeks and with the patch applied I have never reproduced the
> problem with Ctrl+C truncating the output (while I've been able to
> consistently reproduce it without the patch.)
> 
> I tested it on top of 4.0.4, 4.0.5, 4.1-rc6, 4.1-rc8, 4.1, 4.1.y and 4.2-rc1.
> 
> Do you think you could send this patch for inclusion in kernel 4.2?

I missed the initial merge window for 4.2, but Greg already has this patch
so will be included in linux-next, probably by the weekend.

[I see now that the patch I sent to Greg wasn't cc'd to you. Sorry about that;
I overlooked that the Reported-by tag didn't add you to the send list. My bad.
I'll forward you Greg's upstream notification when I get it.]

> Feel free to include:
> 
> Reported-by: Filipe Brandenburger <filbranden@xxxxxxxxxx>
> Tested-by: Filipe Brandenburger <filbranden@xxxxxxxxxx>
> Acked-by: Filipe Brandenburger <filbranden@xxxxxxxxxx>
> (whichever ones you find more appropriate)

Already done.
 
> Ideally also a reference to the Bugzilla:
> https://bugzilla.kernel.org/show_bug.cgi?id=99351

Yep, already done.

> And possibly one to this mail thread:
> http://www.spinics.net/lists/linux-serial/msg17791.html

Typically, things like this aren't added unless there was a lot of
time in between the problem and the solution (months).

> BTW, perhaps this also belongs in stable kernels 4.0.y and 4.1.y, if
> you feel that's appropriate perhaps forward it to stable when you push
> it upstream.

I added a Fixes tag so this patch will make it's way to those
kernels eventually (probably during this rc cycle). At that time,
this patch will likely also be added to 4.2-rcX as well.

Regards,
Peter Hurley


> 
> Cheers!
> Filipe
> 
> 
>> --- >% ---
>> Subject: [PATCH] n_tty: signal and flush atomically
>>
>> When handling signalling char, claim the termios write lock before
>> signalling waiting readers and writers to prevent further i/o
>> before flushing the echo and output buffers. This prevents a
>> userspace signal handler which may output from racing the terminal
>> flush.
>>
>> Reference: Bugzilla #99351 ("Output truncated in ssh session after...")
>> Fixes: commit d2b6f44779d3 ("n_tty: Fix signal handling flushes")
>> Reported-by: Filipe Brandenburger <filbranden@xxxxxxxxxx>
>> Signed-off-by: Peter Hurley <peter@xxxxxxxxxxxxxxxxxx>
>> ---
>>  drivers/tty/n_tty.c | 16 +++++++++++++---
>>  1 file changed, 13 insertions(+), 3 deletions(-)
>>
>> diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
>> index c9c27f6..ee8bfac 100644
>> --- a/drivers/tty/n_tty.c
>> +++ b/drivers/tty/n_tty.c
>> @@ -1108,19 +1108,29 @@ static void eraser(unsigned char c, struct tty_struct *tty)
>>   *     Locking: ctrl_lock
>>   */
>>
>> -static void isig(int sig, struct tty_struct *tty)
>> +static void __isig(int sig, struct tty_struct *tty)
>>  {
>> -       struct n_tty_data *ldata = tty->disc_data;
>>         struct pid *tty_pgrp = tty_get_pgrp(tty);
>>         if (tty_pgrp) {
>>                 kill_pgrp(tty_pgrp, sig, 1);
>>                 put_pid(tty_pgrp);
>>         }
>> +}
>>
>> -       if (!L_NOFLSH(tty)) {
>> +static void isig(int sig, struct tty_struct *tty)
>> +{
>> +       struct n_tty_data *ldata = tty->disc_data;
>> +
>> +       if (L_NOFLSH(tty)) {
>> +               /* signal only */
>> +               __isig(sig, tty);
>> +
>> +       } else { /* signal and flush */
>>                 up_read(&tty->termios_rwsem);
>>                 down_write(&tty->termios_rwsem);
>>
>> +               __isig(sig, tty);
>> +
>>                 /* clear echo buffer */
>>                 mutex_lock(&ldata->output_lock);
>>                 ldata->echo_head = ldata->echo_tail = 0;
>> --
>> 2.4.3

--
To unsubscribe from this list: send the line "unsubscribe linux-serial" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html



[Index of Archives]     [Kernel Newbies]     [Security]     [Netfilter]     [Bugtraq]     [Linux PPP]     [Linux FS]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Samba]     [Video 4 Linux]     [Linmodem]     [Device Mapper]     [Linux Kernel for ARM]

  Powered by Linux