Skip to content

Commit 73029a4

Browse files
dstarke-siemensgregkh
authored andcommitted
tty: n_gsm: fix reset fifo race condition
gsmtty_write() and gsm_dlci_data_output() properly guard the fifo access. However, gsm_dlci_close() and gsmtty_flush_buffer() modifies the fifo but do not guard this. Add a guard here to prevent race conditions on parallel writes to the fifo. Fixes: e1eaea4 ("tty: n_gsm line discipline") Cc: [email protected] Signed-off-by: Daniel Starke <[email protected]> Link: https://lore.kernel.org/r/[email protected] Signed-off-by: Greg Kroah-Hartman <[email protected]>
1 parent 1adf6fe commit 73029a4

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

drivers/tty/n_gsm.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1442,13 +1442,17 @@ static int gsm_control_wait(struct gsm_mux *gsm, struct gsm_control *control)
14421442

14431443
static void gsm_dlci_close(struct gsm_dlci *dlci)
14441444
{
1445+
unsigned long flags;
1446+
14451447
del_timer(&dlci->t1);
14461448
if (debug & 8)
14471449
pr_debug("DLCI %d goes closed.\n", dlci->addr);
14481450
dlci->state = DLCI_CLOSED;
14491451
if (dlci->addr != 0) {
14501452
tty_port_tty_hangup(&dlci->port, false);
1453+
spin_lock_irqsave(&dlci->lock, flags);
14511454
kfifo_reset(&dlci->fifo);
1455+
spin_unlock_irqrestore(&dlci->lock, flags);
14521456
/* Ensure that gsmtty_open() can return. */
14531457
tty_port_set_initialized(&dlci->port, 0);
14541458
wake_up_interruptible(&dlci->port.open_wait);
@@ -3148,13 +3152,17 @@ static unsigned int gsmtty_chars_in_buffer(struct tty_struct *tty)
31483152
static void gsmtty_flush_buffer(struct tty_struct *tty)
31493153
{
31503154
struct gsm_dlci *dlci = tty->driver_data;
3155+
unsigned long flags;
3156+
31513157
if (dlci->state == DLCI_CLOSED)
31523158
return;
31533159
/* Caution needed: If we implement reliable transport classes
31543160
then the data being transmitted can't simply be junked once
31553161
it has first hit the stack. Until then we can just blow it
31563162
away */
3163+
spin_lock_irqsave(&dlci->lock, flags);
31573164
kfifo_reset(&dlci->fifo);
3165+
spin_unlock_irqrestore(&dlci->lock, flags);
31583166
/* Need to unhook this DLCI from the transmit queue logic */
31593167
}
31603168

0 commit comments

Comments
 (0)