mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: "Michał Mirosław" <mirq-linux@rere.qmqm.pl>
To: fabricioakio@gmail.com
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
	Neill Kapron <nkapron@google.com>,
	Krystian Kaniewski <krystianmkaniewski@gmail.com>,
	Brian Ellis <brianellis@gotenna.com>, Ai Chao <aichao@kylinos.cn>,
	Prashanth K <prashanth.k@oss.qualcomm.com>,
	linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
	stable@vger.kernel.org
Subject: Re: [PATCH v2 1/2] usb: gadget: u_serial: Publish the console only under port_lock
Date: Mon, 23 Nov 2026 09:55:07 +0100	[thread overview]
Message-ID: <awP_a5IqlYHPvx-G@qmqm.qmqm.pl> (raw)
In-Reply-To: <20261122-u-serial-console-dequeue-v2-1-820f355827e6@gmail.com>

On Sun, Nov 22, 2026 at 10:48:34PM -0300, Fabricio Akio via B4 Relay wrote:
> From: Fabricio Akio <fabricioakio@gmail.com>
> 
> gserial_connect() and gserial_disconnect() find the console through
> port->console under port_lock, but gs_console_init() sets it before
> taking the lock, and gs_console_exit() clears it after dropping it.
> A host connect while the console is being turned on through configfs
> can then connect it twice, leaking the first request. While it is
> being turned off, a connect can attach a request to the console being
> freed and schedule its work after cancel_work_sync().
> 
> Set and clear port->console under port_lock, together with connecting
> and disconnecting the console.
> 
> Fixes: d7cb8fb7aa7d ("usb: gadget: u_serial: allow more console gadget ports")
> Cc: stable@vger.kernel.org
> Signed-off-by: Fabricio Akio <fabricioakio@gmail.com>
> ---
>  drivers/usb/gadget/function/u_serial.c | 4 ++--
>  1 file changed, 2 insertions(+), 2 deletions(-)
> 
> diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
> index 0a304f508bc3..1f0110ea7f6a 100644
> --- a/drivers/usb/gadget/function/u_serial.c
> +++ b/drivers/usb/gadget/function/u_serial.c
> @@ -1173,10 +1173,10 @@ static int gs_console_init(struct gs_port *port)
>  		return err;
>  	}
>  
> -	port->console = cons;
>  	register_console(&cons->console);

Note that there is `if (port->console) return` just at the start of this
function. If there is indeed a race here, that should be taken into
account.

-- 
Michał Mirosław

  reply	other threads:[~2026-11-23  8:55 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-23  1:48 [PATCH v2 0/2] usb: gadget: u_serial: Fix the console request's lifetime Fabricio Akio via B4 Relay
2026-11-23  1:48 ` [PATCH v2 1/2] usb: gadget: u_serial: Publish the console only under port_lock Fabricio Akio via B4 Relay
2026-11-23  8:55   ` Michał Mirosław [this message]
2026-11-23  1:48 ` [PATCH v2 2/2] usb: gadget: u_serial: Free the console request only once it is back Fabricio Akio via B4 Relay

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=awP_a5IqlYHPvx-G@qmqm.qmqm.pl \
    --to=mirq-linux@rere.qmqm.pl \
    --cc=aichao@kylinos.cn \
    --cc=brianellis@gotenna.com \
    --cc=fabricioakio@gmail.com \
    --cc=gregkh@linuxfoundation.org \
    --cc=krystianmkaniewski@gmail.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-usb@vger.kernel.org \
    --cc=nkapron@google.com \
    --cc=prashanth.k@oss.qualcomm.com \
    --cc=stable@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®