mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
To: Sang-Hoon Choi <csh0052@gmail.com>
Cc: Arnaud Pouliquen <arnaud.pouliquen@foss.st.com>,
	Jiri Slaby <jirislaby@kernel.org>,
	linux-remoteproc@vger.kernel.org, linux-serial@vger.kernel.org,
	linux-kernel@vger.kernel.org, Changyul Lee <lcy8047@gmail.com>
Subject: Re: [RFC] tty: rpmsg: possible lookup-to-reference lifetime race
Date: Mon, 21 Sep 2026 20:50:19 +0200	[thread overview]
Message-ID: <2026092154-anger-sensually-aae8@gregkh> (raw)
In-Reply-To: <179000811428.1227592.8003229121862460039.idr-bug-84@gmail.com>

On Tue, Sep 22, 2026 at 01:28:34AM +0900, Sang-Hoon Choi wrote:
> Hi,
> 
> I would like to report a possible lifetime gap between looking up a port
> in tty_idr and acquiring its reference in rpmsg_tty_install().
> 
> The source reviewed is mainline commit
> 5dd1818b15d98d4a20806cd00b1b40320b06004f.
> 
> The install path calls idr_find() without idr_lock, stores the result in
> tty->driver_data, and calls tty_port_get(&cport->port). The port destructor
> removes the IDR entry under idr_lock, drops the mutex, and frees cport.
> 
> If the last reference is dropped during that lookup-to-get interval, the
> following order appears possible:
> 
>     rpmsg_tty_install()              rpmsg_tty_destruct_port()
>     -------------------              -------------------------

Why would these ever run at the same time?  How can that happen?


>     cport = idr_find(...)
>                                      take idr_lock
>                                      idr_remove(...)
>                                      drop idr_lock
>                                      kfree(cport)
>     tty_port_get(&cport->port)
> 
> tty_port_get() uses kref_get_unless_zero(), but this cannot protect memory
> that has already been freed. The install path also does not check for a
> missing ID or a failed reference acquisition before tty_port_install().
> 
> TTY installation is serialized by tty_mutex, but the RPMsg remove path
> does not explicitly take that mutex around its final tty_port_put().
> The destructor can consequently run from RPMsg removal, not just from
> TTY cleanup. I have not established all cross-subsystem ordering rules.
> 
> A draft takes idr_lock across idr_find() and tty_port_get(), and returns
> -ENODEV if no live reference is obtained. This uses the mutex already
> taken by the destructor before removing the entry. Its scope is this
> lookup/destruction gap; it does not establish safety of every probe or
> remove interaction.
> 
> The draft was compile-checked as rpmsg_tty.o with W=1 in an x86
> allmodconfig build at the commit above and passed checkpatch. There is
> no runtime reproducer with an RPMsg endpoint or sanitizer trace. Device
> permissions and the ability to remove the endpoint also remain relevant
> to any security assessment.
> 
> Does another TTY or RPMsg lifetime rule prevent this particular overlap?
> 
> Reported-by: Changyul Lee <lcy8047@gmail.com>
> Assisted-by: LLM

Why not have your LLM make a patch for this that you can test and get
credit for the fix if there really is an issue?

And again, how can those two things ever run at the same time in a real
system controlled by a normal user (i.e. not root permissions)?

thanks,

greg k-h

      reply	other threads:[~2026-09-21 18:50 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-09-21 16:28 Sang-Hoon Choi
2026-09-21 18:50 ` Greg Kroah-Hartman [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=2026092154-anger-sensually-aae8@gregkh \
    --to=gregkh@linuxfoundation.org \
    --cc=arnaud.pouliquen@foss.st.com \
    --cc=csh0052@gmail.com \
    --cc=jirislaby@kernel.org \
    --cc=lcy8047@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-remoteproc@vger.kernel.org \
    --cc=linux-serial@vger.kernel.org \
    /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®