Skip to contentSkip to conversation

n_tty: Protect minimum_to_wake reset for concurrent readers

PATCH In review Peter Hurley 2 participants 6 messages Nov 7, 2013 – Nov 25, 2013 TTY layer and serial drivers

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 n_tty: Protect minimum_to_wake reset for concurrent readers

With multiple, concurrent readers (each waiting to acquire the atomic_read_lock mutex), a departing reader may mistakenly reset minimum_to_wake after a new reader has already set a new value.

Protect the minimum_to_wake reset with the atomic_read_lock critical section.

---
 drivers/tty/n_tty.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
drivers/tty/n_tty.c +2 -2
index ce11cd5..bf9650d 100644
@@ -2253,12 +2253,12 @@ static ssize_t n_tty_read(struct tty_struct *tty, struct file *file,
 	n_tty_set_room(tty);
 	up_read(&tty->termios_rwsem);
 
-	mutex_unlock(&ldata->atomic_read_lock);
 	remove_wait_queue(&tty->read_wait, &wait);
-
 	if (!waitqueue_active(&tty->read_wait))
 		ldata->minimum_to_wake = minimum;
 
+	mutex_unlock(&ldata->atomic_read_lock);
+
 	__set_current_state(TASK_RUNNING);
 	if (b - buf)
 		retval = b - buf;
Signature · 1 line
1.8.1.2
#1 lore raw
Quoted 11 lines · Peter Hurley

With multiple, concurrent readers (each waiting to acquire the atomic_read_lock mutex), a departing reader may mistakenly reset minimum_to_wake after a new reader has already set a new value.

Protect the minimum_to_wake reset with the atomic_read_lock critical section.

---
 drivers/tty/n_tty.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

This patch doesn't apply to Linus's tree anymore (and hence, mine.) Is it needed for 3.13-final? Or just 3.14-rc1? Either way, can you refresh it and resend?

thanks,

greg k-h

#2 lore raw
Quoted 8 lines · Greg Kroah-Hartman
Quoted 7 lines · Peter Hurley

With multiple, concurrent readers (each waiting to acquire the atomic_read_lock mutex), a departing reader may mistakenly reset minimum_to_wake after a new reader has already set a new value.

Protect the minimum_to_wake reset with the atomic_read_lock critical section.

Quoted 8 lines
Quoted 4 lines
---
  drivers/tty/n_tty.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

This patch doesn't apply to Linus's tree anymore (and hence, mine.) Is it needed for 3.13-final? Or just 3.14-rc1? Either way, can you refresh it and resend?

Hmmm, for me this applies cleanly to your tty-linus branch:

peter@thor:~/src/kernels/tty$ git tree -10
* c7df628 (HEAD, tty-linus) n_tty: Protect minimum_to_wake reset for concurrent readers
* 3dcf344 (origin/tty-linus) TTY: amiserial, add missing platform check
* dc1dc2f TTY: pmac_zilog, check existence of ports in pmz_console_init()
* c284ee2 n_gsm: race between ld close and gsmtty open
* f301412 tty/serial/8250: fix typo in help text
* c77569d n_tty: Fix 4096-byte canonical reads
* 6f22253 n_tty: Fix echo overrun tail computation
* 42458f4 n_tty: Ensure reader restarts worker for next reader
* 6ce4eac (tag: v3.13-rc1, origin/tty-next, origin/master, origin/HEAD) Linux 3.13-rc1

I'll just resend it.

Regards,
Peter Hurley

#3 lore raw
Quoted 31 lines · Peter Hurley
Quoted 8 lines · Greg Kroah-Hartman
Quoted 7 lines · Peter Hurley

With multiple, concurrent readers (each waiting to acquire the atomic_read_lock mutex), a departing reader may mistakenly reset minimum_to_wake after a new reader has already set a new value.

Protect the minimum_to_wake reset with the atomic_read_lock critical section.

Quoted 8 lines
Quoted 4 lines
---
 drivers/tty/n_tty.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

This patch doesn't apply to Linus's tree anymore (and hence, mine.) Is it needed for 3.13-final? Or just 3.14-rc1? Either way, can you refresh it and resend?

Hmmm, for me this applies cleanly to your tty-linus branch:

peter@thor:~/src/kernels/tty$ git tree -10
* c7df628 (HEAD, tty-linus) n_tty: Protect minimum_to_wake reset for concurrent readers
* 3dcf344 (origin/tty-linus) TTY: amiserial, add missing platform check
* dc1dc2f TTY: pmac_zilog, check existence of ports in pmz_console_init()
* c284ee2 n_gsm: race between ld close and gsmtty open
* f301412 tty/serial/8250: fix typo in help text
* c77569d n_tty: Fix 4096-byte canonical reads
* 6f22253 n_tty: Fix echo overrun tail computation
* 42458f4 n_tty: Ensure reader restarts worker for next reader
* 6ce4eac (tag: v3.13-rc1, origin/tty-next, origin/master, origin/HEAD) Linux 3.13-rc1
Quoted 1 line

I'll just resend it.

Oh nevermind, it has leading extra spaces, which something added, I'll go edit it by hand and fix it up, sorry for not noticing.

greg k-h

#4 lore raw
Quoted 32 lines · Greg Kroah-Hartman
Quoted 31 lines · Peter Hurley
Quoted 8 lines · Greg Kroah-Hartman
Quoted 7 lines · Peter Hurley

With multiple, concurrent readers (each waiting to acquire the atomic_read_lock mutex), a departing reader may mistakenly reset minimum_to_wake after a new reader has already set a new value.

Protect the minimum_to_wake reset with the atomic_read_lock critical section.

Quoted 8 lines
Quoted 4 lines
---
 drivers/tty/n_tty.c | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

This patch doesn't apply to Linus's tree anymore (and hence, mine.) Is it needed for 3.13-final? Or just 3.14-rc1? Either way, can you refresh it and resend?

Hmmm, for me this applies cleanly to your tty-linus branch:

peter@thor:~/src/kernels/tty$ git tree -10
* c7df628 (HEAD, tty-linus) n_tty: Protect minimum_to_wake reset for concurrent readers
* 3dcf344 (origin/tty-linus) TTY: amiserial, add missing platform check
* dc1dc2f TTY: pmac_zilog, check existence of ports in pmz_console_init()
* c284ee2 n_gsm: race between ld close and gsmtty open
* f301412 tty/serial/8250: fix typo in help text
* c77569d n_tty: Fix 4096-byte canonical reads
* 6f22253 n_tty: Fix echo overrun tail computation
* 42458f4 n_tty: Ensure reader restarts worker for next reader
* 6ce4eac (tag: v3.13-rc1, origin/tty-next, origin/master, origin/HEAD) Linux 3.13-rc1
Quoted 4 lines
Quoted 1 line

I'll just resend it.

Oh nevermind, it has leading extra spaces, which something added, I'll go edit it by hand and fix it up, sorry for not noticing.

And 'git am' handles this just fine, I was just testing it out first using 'patch' which didn't like the extra spaces, my fault.

sorry for the noise,

greg k-h

#5 lore raw
Quoted 35 lines · Greg Kroah-Hartman
Quoted 34 lines · Greg Kroah-Hartman
Quoted 32 lines · Peter Hurley
Quoted 8 lines · Greg Kroah-Hartman
Quoted 7 lines · Peter Hurley

With multiple, concurrent readers (each waiting to acquire the atomic_read_lock mutex), a departing reader may mistakenly reset minimum_to_wake after a new reader has already set a new value.

Protect the minimum_to_wake reset with the atomic_read_lock critical section.

Quoted 8 lines
Quoted 4 lines
---
  drivers/tty/n_tty.c | 4 ++--
  1 file changed, 2 insertions(+), 2 deletions(-)

This patch doesn't apply to Linus's tree anymore (and hence, mine.) Is it needed for 3.13-final? Or just 3.14-rc1? Either way, can you refresh it and resend?

Hmmm, for me this applies cleanly to your tty-linus branch:

peter@thor:~/src/kernels/tty$ git tree -10
* c7df628 (HEAD, tty-linus) n_tty: Protect minimum_to_wake reset for concurrent readers
* 3dcf344 (origin/tty-linus) TTY: amiserial, add missing platform check
* dc1dc2f TTY: pmac_zilog, check existence of ports in pmz_console_init()
* c284ee2 n_gsm: race between ld close and gsmtty open
* f301412 tty/serial/8250: fix typo in help text
* c77569d n_tty: Fix 4096-byte canonical reads
* 6f22253 n_tty: Fix echo overrun tail computation
* 42458f4 n_tty: Ensure reader restarts worker for next reader
* 6ce4eac (tag: v3.13-rc1, origin/tty-next, origin/master, origin/HEAD) Linux 3.13-rc1

I'll just resend it.

Quoted 7 lines
Quoted 2 lines

Oh nevermind, it has leading extra spaces, which something added, I'll go edit it by hand and fix it up, sorry for not noticing.

And 'git am' handles this just fine, I was just testing it out first using 'patch' which didn't like the extra spaces, my fault.

sorry for the noise,

Not a problem.

In fact, the interruption was fortuitous because I was testing an unsubmitted patch which I'd hoped would fix the readline() paste bug & bugzilla #55991. When I tried to resend this patch with git send-email, the 'Password:' prompt looped until I killed it.

Thanks for the test vector :)

Regards,
Peter Hurley