We're freeing the gsm->dlci[] array elements but leaving the freed
pointers hanging around.

My concern here is if we use the ioctl to change the config, it triggers
a restart in gsmld_config().  In that case, we would only reset the
first ->dlci[0] element and not the others so it does look to me like a
possible use after free.

Reported-by: Sun Peng <sun_p...@topsec.com.cn>
Signed-off-by: Dan Carpenter <dan.carpen...@oracle.com>

diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
index cc7f68814200..1f2fd9e76fe0 100644
--- a/drivers/tty/n_gsm.c
+++ b/drivers/tty/n_gsm.c
@@ -2075,9 +2075,11 @@ static void gsm_cleanup_mux(struct gsm_mux *gsm)
 
        /* Free up any link layer users */
        mutex_lock(&gsm->mutex);
-       for (i = 0; i < NUM_DLCI; i++)
+       for (i = 0; i < NUM_DLCI; i++) {
                if (gsm->dlci[i])
                        gsm_dlci_release(gsm->dlci[i]);
+               gsm->dlci[i] = NULL;
+       }
        mutex_unlock(&gsm->mutex);
        /* Now wipe the queues */
        list_for_each_entry_safe(txq, ntxq, &gsm->tx_list, list)

Reply via email to