Re: [PATCH v2 1/2] usb: gadget: u_serial: Publish the console only under port_lock
From: Michał Mirosław
Date: Mon Nov 23 2026 - 03:55:25 EST
On Sun, Nov 22, 2026 at 10:48:34PM -0300, Fabricio Akio via B4 Relay wrote:
> From: Fabricio Akio <fabricioakio@xxxxxxxxx>
>
> 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@xxxxxxxxxxxxxxx
> Signed-off-by: Fabricio Akio <fabricioakio@xxxxxxxxx>
> ---
> 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