mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Jiri Slaby <jslaby@suse.com>
To: Xiyu Yang <xiyuyang19@fudan.edu.cn>,
	Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	linux-serial@vger.kernel.org, linux-kernel@vger.kernel.org
Cc: yuanxzhang@fudan.edu.cn, kjlu@umn.edu, Xin Tan <tanxin.ctf@gmail.com>
Subject: Re: [PATCH] tty: serial_core: Fix uart_state leak when port shutdown
Date: Mon, 15 Jun 2020 06:56:11 +0200	[thread overview]
Message-ID: <bf6c1e7b-3dc6-aba6-955a-fee351a6d800@suse.com> (raw)
In-Reply-To: <1592052665-95042-1-git-send-email-xiyuyang19@fudan.edu.cn>

On 13. 06. 20, 14:51, Xiyu Yang wrote:
> 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.

uport should be valid at that point and both the returned one and the
used one should be the same.

> Fix this issue by update the "uport" object to the return value of
> uart_port_lock() when invoking uart_port_lock().

Do you actually encounter the issue or is this some static analyzer result?

> Signed-off-by: Xiyu Yang <xiyuyang19@fudan.edu.cn>
> Signed-off-by: Xin Tan <tanxin.ctf@gmail.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);
> 

thanks,
-- 
js
suse labs

      reply	other threads:[~2020-06-15  4:56 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2020-06-13 12:51 Xiyu Yang
2020-06-15  4:56 ` Jiri Slaby [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bf6c1e7b-3dc6-aba6-955a-fee351a6d800@suse.com \
    --to=jslaby@suse.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=kjlu@umn.edu \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    --cc=tanxin.ctf@gmail.com \
    --cc=xiyuyang19@fudan.edu.cn \
    --cc=yuanxzhang@fudan.edu.cn \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®