From: Fabricio Akio <fabricioakio@gmail.com>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Neill Kapron <nkapron@google.com>
Cc: "Krystian Kaniewski" <krystianmkaniewski@gmail.com>,
"Brian Ellis" <brianellis@gotenna.com>,
"Ai Chao" <aichao@kylinos.cn>,
"Michał Mirosław" <mirq-linux@rere.qmqm.pl>,
"Prashanth K" <prashanth.k@oss.qualcomm.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
"Fabricio Akio" <fabricioakio@gmail.com>
Subject: [PATCH v3 1/2] usb: gadget: u_serial: Publish the console only under port_lock
Date: Wed, 25 Nov 2026 12:05:26 -0300 [thread overview]
Message-ID: <20261125-u-serial-console-dequeue-v3-1-b47f6e401dc1@gmail.com> (raw)
In-Reply-To: <20261125-u-serial-console-dequeue-v3-0-b47f6e401dc1@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);
spin_lock_irq(&port->port_lock);
+ port->console = cons;
if (port->port_usb)
gs_console_connect(port);
spin_unlock_irq(&port->port_lock);
@@ -1196,12 +1196,12 @@ static void gs_console_exit(struct gs_port *port)
spin_lock_irq(&port->port_lock);
if (cons->req)
gs_console_disconnect(port);
+ port->console = NULL;
spin_unlock_irq(&port->port_lock);
cancel_work_sync(&cons->work);
kfifo_free(&cons->buf);
kfree(cons);
- port->console = NULL;
}
ssize_t gserial_set_console(unsigned char port_num, const char *page, size_t count)
--
2.56.1
WARNING: multiple messages have this Message-ID (diff)
From: Fabricio Akio via B4 Relay <devnull+fabricioakio.gmail.com@kernel.org>
To: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Neill Kapron <nkapron@google.com>
Cc: "Krystian Kaniewski" <krystianmkaniewski@gmail.com>,
"Brian Ellis" <brianellis@gotenna.com>,
"Ai Chao" <aichao@kylinos.cn>,
"Michał Mirosław" <mirq-linux@rere.qmqm.pl>,
"Prashanth K" <prashanth.k@oss.qualcomm.com>,
linux-usb@vger.kernel.org, linux-kernel@vger.kernel.org,
"Fabricio Akio" <fabricioakio@gmail.com>
Subject: [PATCH v3 1/2] usb: gadget: u_serial: Publish the console only under port_lock
Date: Wed, 25 Nov 2026 12:05:26 -0300 [thread overview]
Message-ID: <20261125-u-serial-console-dequeue-v3-1-b47f6e401dc1@gmail.com> (raw)
In-Reply-To: <20261125-u-serial-console-dequeue-v3-0-b47f6e401dc1@gmail.com>
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);
spin_lock_irq(&port->port_lock);
+ port->console = cons;
if (port->port_usb)
gs_console_connect(port);
spin_unlock_irq(&port->port_lock);
@@ -1196,12 +1196,12 @@ static void gs_console_exit(struct gs_port *port)
spin_lock_irq(&port->port_lock);
if (cons->req)
gs_console_disconnect(port);
+ port->console = NULL;
spin_unlock_irq(&port->port_lock);
cancel_work_sync(&cons->work);
kfifo_free(&cons->buf);
kfree(cons);
- port->console = NULL;
}
ssize_t gserial_set_console(unsigned char port_num, const char *page, size_t count)
--
2.56.1
next prev parent reply other threads:[~2026-11-25 15:05 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-25 15:05 [PATCH v3 0/2] usb: gadget: u_serial: Fix the console request's lifetime Fabricio Akio
2026-11-25 15:05 ` Fabricio Akio via B4 Relay
2026-11-25 15:05 ` Fabricio Akio [this message]
2026-11-25 15:05 ` [PATCH v3 1/2] usb: gadget: u_serial: Publish the console only under port_lock Fabricio Akio via B4 Relay
2026-11-25 15:05 ` [PATCH v3 2/2] usb: gadget: u_serial: Free the console request only once it is back Fabricio Akio
2026-11-25 15:05 ` Fabricio Akio via B4 Relay
2026-11-25 15:30 ` [PATCH v3 0/2] usb: gadget: u_serial: Fix the console request's lifetime sashiko-bot
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=20261125-u-serial-console-dequeue-v3-1-b47f6e401dc1@gmail.com \
--to=fabricioakio@gmail.com \
--cc=aichao@kylinos.cn \
--cc=brianellis@gotenna.com \
--cc=gregkh@linuxfoundation.org \
--cc=krystianmkaniewski@gmail.com \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=mirq-linux@rere.qmqm.pl \
--cc=nkapron@google.com \
--cc=prashanth.k@oss.qualcomm.com \
/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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.