[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <20200624093407.GB1751086@kroah.com>
Date: Wed, 24 Jun 2020 11:34:07 +0200
From: Greg Kroah-Hartman <gregkh@...uxfoundation.org>
To: Xiyu Yang <xiyuyang19@...an.edu.cn>
Cc: Jiri Slaby <jslaby@...e.com>, linux-serial@...r.kernel.org,
linux-kernel@...r.kernel.org, yuanxzhang@...an.edu.cn,
kjlu@....edu, Xin Tan <tanxin.ctf@...il.com>
Subject: Re: [PATCH] tty: serial_core: Fix uart_state refcnt leak when the
port startup
On Sat, Jun 13, 2020 at 08:52:18PM +0800, Xiyu Yang wrote:
> uart_port_startup() 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_port_startup() 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..968fd619aec0 100644
> --- a/drivers/tty/serial/serial_core.c
> +++ b/drivers/tty/serial/serial_core.c
> @@ -205,7 +205,7 @@ static int uart_port_startup(struct tty_struct *tty, struct uart_state *state,
> if (!page)
> return -ENOMEM;
>
> - uart_port_lock(state, flags);
> + uport = uart_port_lock(state, flags);
How is this a different pointer than you originally had?
And if it is a different pointer, shouldn't you be calling this function
and using the pointer much earlier in the function instead of just here?
Can you trigger a problem that this patch solves? If so, how?
thanks,
greg k-h
Powered by blists - more mailing lists