isdn: i4l: isdn_tty: Fix some concurrency double-free bugs
Subsystems (2)
PATCH 1/1 isdn: i4l: isdn_tty: Fix some concurrency double-free bugs
The functions isdn_tty_tiocmset() and isdn_tty_set_termios() may be concurrently executed.
isdn_tty_tiocmset
isdn_tty_modem_hup
line 719: kfree(info->dtmf_state);
line 721: kfree(info->silence_state);
line 723: kfree(info->adpcms);
line 725: kfree(info->adpcmr);isdn_tty_set_termios
isdn_tty_modem_hup
line 719: kfree(info->dtmf_state);
line 721: kfree(info->silence_state);
line 723: kfree(info->adpcms);
line 725: kfree(info->adpcmr);Thus, some concurrency double-free bugs may occur.
These possible bugs are found by a static tool written by myself and my manual code review.
To fix these possible bugs, the mutex lock "modem_info_mutex" used in isdn_tty_tiocmset() is added in isdn_tty_set_termios().
--- drivers/isdn/i4l/isdn_tty.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-)
drivers/isdn/i4l/isdn_tty.c +5 -1
@@ -1437,15 +1437,19 @@ isdn_tty_set_termios(struct tty_struct *tty, struct ktermios *old_termios) {modem_info *info = (modem_info *) tty->driver_data; +mutex_lock (&modem_info_mutex);if (!old_termios)isdn_tty_change_speed (info);else {if (tty->termios.c_cflag == old_termios->c_cflag && tty->termios.c_ispeed == old_termios->c_ispeed && - tty->termios.c_ospeed == old_termios->c_ospeed) + tty->termios.c_ospeed == old_termios->c_ospeed) { +mutex_unlock (&modem_info_mutex);return ; + }isdn_tty_change_speed (info); } +mutex_unlock (&modem_info_mutex); }/*
Signature · 1 line
2.17.0
From: Jia-Ju Bai <[email protected]>
Date: Tue, 8 Jan 2019 21:04:48 +0800
Quoted 2 lines
The functions
isdn_tty_tiocmset()andisdn_tty_set_termios()may be concurrently executed.
...
Quoted 7 lines
These possible bugs are found by a static tool written by myself and my manual code review.
To fix these possible bugs, the mutex lock "
modem_info_mutex" used inisdn_tty_tiocmset()is added inisdn_tty_set_termios().Signed-off-by Jia-Ju Bai <[email protected]>
Applied.