From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796388409; b=Q9nEj50qRgkOwKg7LuIMRIzztlFvTawaSl5StpUwQFy9hguK9sKLGIiWdLJCDP7vvFXM WETkD95wZ0vfHlHeaHVDdN6lPw+hdJ3Hh6GrbPnjsYI7J+2YQgiHyr72Bn6b72bfqXyZ8 hhxC2rT0qFi8+EGV9NrGDgDlSSqaVNkT4NBUEOjJQMmpag/loI4dDdvX8pSGccVp8A+Kl IlNFEKA0IKkdYufTtnuK4eQP6W0mtuud4ZCArqOteCEyspheiDguRLo6NlZxOSr/Au/1G pKaTa6DapW/WW24qjISCByOBYgNenTyLQx7X0KMq+OxKSlHIksS9f//9bSqpnTkEodQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796388409; h=Received:DKIM-Signature:From:To:Cc:Subject:Date:Message-ID:X-Mailer: In-Reply-To:References:User-Agent:X-stable:X-Patchwork-Hint: MIME-Version:Content-Transfer-Encoding; bh=yTWE/648lVQ16onNmN0ZCJv7iDHZUlBb2poQvMaA7XE=; b=BXelxZ6c6Qs3QgfbLcHkYozpnihvDRcPlGLbSLnRc/CZc18oSniTRjxswS5/jVfHfQPs sWDlHO7e9nHl9x5KUvkxtF7/bP5e9xLP9f2nf5XcOYGQVgNbKl7uDDysX93ED1lsZweC+ yWuGLKotiCphtBPEYWtIOaUFfmTG9LoGRAR9pR+zfyUt+rk11LI1WlgWPiRtcxD2walTE Umiu4bhdt3gukcpOTbqIKgCw3vYwGYWWsZxiGw2eRh8nK0hymuyj1SfufogCTUb4FvQh5 38c5+Fd+bfL8x0kh4I1nJFLhcaGp/hKOsbwV0phtkIVAt+4jJorNJOfW/W3ziykPcqg== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=wCPy738u; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 36BAE606A322; Fri, 4 Dec 2026 12:46:48 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.a=rsa-sha256 header.s=korg header.b=wCPy738u Received: by smtp.kernel.org (Postfix) with ESMTPSA id 516311F000CE; Fri, 4 Dec 2026 12:46:48 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linuxfoundation.org; s=korg; t=1796388408; bh=yTWE/648lVQ16onNmN0ZCJv7iDHZUlBb2poQvMaA7XE=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=wCPy738u0FmtqqSKNcVVt7wRUjYKMFjCgDRWvAFxIvtMIww15alEb05MDs17itZDV qjEfeki6qlqzKcdlXNnFh1r7IrgQXTowPCU/5WiYkEL6bZyy3NAf2qOij9Blriu6i0 /IUqsZdIcB55F4Z/Z28eAMaCbiT/iRw7eArWUeXk= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, syzbot+782b2f1063e38ba8fa6e@syzkaller.appspotmail.com, stable , Brian Ellis Subject: [PATCH 6.1 0601/1059] usb: gadget: u_serial: fix NULL deref in gs_close() after failed open Date: Fri, 4 Dec 2026 19:02:12 +0900 Message-ID: <20261204100659.694872385@linuxfoundation.org> X-Mailer: git-send-email 2.56.1 In-Reply-To: <20261204100643.980430235@linuxfoundation.org> References: <20261204100643.980430235@linuxfoundation.org> User-Agent: quilt/0.69 X-stable: review X-Patchwork-Hint: ignore X-Mailing-List: patches@lists.linux.dev List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Brian Ellis commit ea6cf69ad03c8d85138830c0d2c3b946b5ae231d upstream. gs_close() opens with struct gs_port *port = tty->driver_data; ... spin_lock_irq(&port->port_lock); and never checks port. gs_open() assigns tty->driver_data only on the port.count 0 -> 1 edge, so any failure earlier in gs_open() leaves it NULL, and tty_open() calls tty_release(), and hence ->close(), when ->open() fails. syzbot hit exactly this on arm64. Fault injection failed the kfifo_alloc() of the write buffer in gs_open(): __kfifo_alloc_node+0x10c/0x208 lib/kfifo.c:44 gs_open+0x144/0x514 drivers/usb/gadget/function/u_serial.c:636 tty_open+0x404/0x89c drivers/tty/tty_io.c:2137 and the tty core's close of the failed open then took port_lock through the NULL port: BUG: unable to handle kernel paging request in gs_close KASAN: null-ptr-deref in range [0x00000000000003a0-0x00000000000003a7] Call trace: spin_lock_irq include/linux/spinlock.h:372 [inline] gs_close+0xac/0x65c drivers/usb/gadget/function/u_serial.c:698 tty_release+0x2c4/0xffc drivers/tty/tty_io.c:1745 tty_open+0x46c/0x89c drivers/tty/tty_io.c:2146 Return early instead. There is nothing to release when the open never got far enough to claim the port. Unlike the check reverted by commit f6c7bc4a6823 ("Revert "usb: gadget: u_serial: Add null pointer check in gs_start_io""), this is not hiding a race: the tty core calls ->close() for an ->open() that failed by design, so driver_data is legitimately unset on that path. Fixes: c1dca562be8a ("usb gadget: split out serial core") Reported-by: syzbot+782b2f1063e38ba8fa6e@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?extid=782b2f1063e38ba8fa6e Cc: stable Assisted-by: LLM Signed-off-by: Brian Ellis Link: https://patch.msgid.link/20261013-u_serial-gs-close-null-v4-1-9ea038501994@gotenna.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Greg Kroah-Hartman --- drivers/usb/gadget/function/u_serial.c | 3 +++ 1 file changed, 3 insertions(+) --- a/drivers/usb/gadget/function/u_serial.c +++ b/drivers/usb/gadget/function/u_serial.c @@ -678,6 +678,9 @@ static void gs_close(struct tty_struct * struct gs_port *port = tty->driver_data; struct gserial *gser; + if (!port) + return; + spin_lock_irq(&port->port_lock); if (port->port.count != 1) {