[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-Id: <1592052665-95042-1-git-send-email-xiyuyang19@fudan.edu.cn>
Date: Sat, 13 Jun 2020 20:51:04 +0800
From: Xiyu Yang <xiyuyang19@...an.edu.cn>
To: Greg Kroah-Hartman <gregkh@...uxfoundation.org>,
Jiri Slaby <jslaby@...e.com>, linux-serial@...r.kernel.org,
linux-kernel@...r.kernel.org
Cc: yuanxzhang@...an.edu.cn, kjlu@....edu,
Xiyu Yang <xiyuyang19@...an.edu.cn>,
Xin Tan <tanxin.ctf@...il.com>
Subject: [PATCH] tty: serial_core: Fix uart_state leak when port shutdown
uart_shutdown() invokes uart_port_lock(), which returns a reference of
the uart_port object if increases the refcount of the uart_state object
successfully or returns NULL if fails.
However, uart_shutdown() don't take the return value of uart_port_lock()
as the new uart_port object to "uport" and use the old "uport" instead
to balance refcount in uart_port_unlock(), which may cause a redundant
decrement of refcount occurred when the new "uport" equals to NULL and
then cause a potential memory leak.
Fix this issue by update the "uport" object to the return value of
uart_port_lock() when invoking uart_port_lock().
Signed-off-by: Xiyu Yang <xiyuyang19@...an.edu.cn>
Signed-off-by: Xin Tan <tanxin.ctf@...il.com>
---
drivers/tty/serial/serial_core.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
index 57840cf90388..ab8756ef2b60 100644
--- a/drivers/tty/serial/serial_core.c
+++ b/drivers/tty/serial/serial_core.c
@@ -313,7 +313,7 @@ static void uart_shutdown(struct tty_struct *tty, struct uart_state *state)
* console driver may need to allocate/free a debug object, which
* can endup in printk() recursion.
*/
- uart_port_lock(state, flags);
+ uport = uart_port_lock(state, flags);
xmit_buf = state->xmit.buf;
state->xmit.buf = NULL;
uart_port_unlock(uport, flags);
--
2.7.4
Powered by blists - more mailing lists