Skip to content

Commit 3c4f833

Browse files
Yi Yanggregkh
authored andcommitted
tty: n_gsm: fix the UAF caused by race condition in gsm_cleanup_mux
In commit 9b9c819 ("tty: n_gsm: fix UAF in gsm_cleanup_mux"), the UAF problem is not completely fixed. There is a race condition in gsm_cleanup_mux(), which caused this UAF. The UAF problem is triggered by the following race: task[5046] task[5054] ----------------------- ----------------------- gsm_cleanup_mux(); dlci = gsm->dlci[0]; mutex_lock(&gsm->mutex); gsm_cleanup_mux(); dlci = gsm->dlci[0]; //Didn't take the lock gsm_dlci_release(gsm->dlci[i]); gsm->dlci[i] = NULL; mutex_unlock(&gsm->mutex); mutex_lock(&gsm->mutex); dlci->dead = true; //UAF Fix it by assigning values after mutex_lock(). Link: https://syzkaller.appspot.com/text?tag=CrashReport&x=176188b5a80000 Cc: stable <stable@kernel.org> Fixes: 9b9c819 ("tty: n_gsm: fix UAF in gsm_cleanup_mux") Fixes: aa371e9 ("tty: n_gsm: fix restart handling via CLD command") Signed-off-by: Yi Yang <yiyang13@huawei.com> Co-developed-by: Qiumiao Zhang <zhangqiumiao1@huawei.com> Signed-off-by: Qiumiao Zhang <zhangqiumiao1@huawei.com> Link: https://lore.kernel.org/r/20230811031121.153237-1-yiyang13@huawei.com Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent a4a79e0 commit 3c4f833

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

drivers/tty/n_gsm.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3042,12 +3042,13 @@ static void gsm_error(struct gsm_mux *gsm)
30423042
static void gsm_cleanup_mux(struct gsm_mux *gsm, bool disc)
30433043
{
30443044
int i;
3045-
struct gsm_dlci *dlci = gsm->dlci[0];
3045+
struct gsm_dlci *dlci;
30463046
struct gsm_msg *txq, *ntxq;
30473047

30483048
gsm->dead = true;
30493049
mutex_lock(&gsm->mutex);
30503050

3051+
dlci = gsm->dlci[0];
30513052
if (dlci) {
30523053
if (disc && dlci->state != DLCI_CLOSED) {
30533054
gsm_dlci_begin_close(dlci);

0 commit comments

Comments
 (0)