| Seq | Timestamp | Type | Name | Duration |
|---|---|---|---|---|
| 0/0 | 2026/10/02 19:11 | flow | patch-triage |
2mArgs:null Results: {
"EnableConfigs": [
"USB_GADGET",
"USB_CONFIGFS",
"USB_CONFIGFS_SERIAL",
"USB_CONFIGFS_ACM",
"USB_U_SERIAL"
],
"FocusSymbols": [
"gs_install",
"gs_cleanup",
"gs_open",
"gs_close",
"gs_port_destruct",
"gs_port_alloc",
"gserial_free_port",
"gserial_free_line",
"gserial_alloc_line_no_console"
],
"KMSANReasoning": "The patch modifies the USB gadget serial driver (`u_serial.c`) to fix lifecycle and reference-counting issues between the TTY core and the gadget driver. It introduces `gs_install()`, `gs_cleanup()`, `gs_port_destruct()`, and tracks open failure counts (`open_close_failures`) and port slot reservations (`reserved`).\n\nAll modified and newly added struct fields belong either to `struct gs_port` (which is allocated with `kzalloc_obj`, ensuring zero-initialization) or to `struct portmaster` (which is stored in the zero-initialized static array `ports[]`). No uninitialized stack or heap variables are read, no buffer lengths or bounds are altered, and no kernel data is exposed or copied to user space. \n\nPotential defects in this patch involve object lifetimes, reference counting, use-after-free, or concurrency issues, which are covered by KASAN, LOCKDEP, and standard kernel runtime assertions. There is no risk of uninitialized memory usage, so a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false,
"Reasoning": "The patch reworks the lifetime, reference counting, and open/close state tracking for USB gadget serial devices (u_serial.c), introducing new tty driver operations (gs_install, gs_cleanup), a tty_port destructor (gs_port_destruct), and multiple WARN_ON assertions. The code is reachable in standard virtualized fuzzing setups via USB gadget configfs (e.g. using dummy_hcd) and accessible via /dev/ttyGS* device nodes. The concurrency between device teardown and concurrent TTY open/close calls makes this a high-value target for fuzzing.",
"WorthFuzzing": true
} |
| 1/1 | 2026/10/02 19:11 | action | read-patch-diff |
0mArgs:null Results: {
"PatchDiff": "commit d78810d9105851f29f9806c00f32094f2cf88a46\nAuthor: syz-cluster \u003ctriage@syzkaller.com\u003e\nDate: Fri Oct 2 19:11:06 2026 +0000\n\n syz-cluster: applied patch under review\n\ndiff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c\nindex cdd1dfc666c4f..aaad06fa5d050 100644\n--- a/drivers/usb/gadget/function/u_serial.c\n+++ b/drivers/usb/gadget/function/u_serial.c\n@@ -70,10 +70,28 @@\n *\tgserial-\u003eioport == usb_ep-\u003edriver_data ... gs_port\n *\tgs_port-\u003eport_usb ... gserial\n *\n- * gs_port \u003c---\u003e tty_struct ... links will be null when the TTY file\n- * isn't opened; managed by gs_open()/gs_close()\n- *\tgserial-\u003eport_tty ... tty_struct\n- *\ttty_struct-\u003edriver_data ... gserial\n+ * gs_port \u003c---\u003e tty_struct:\n+ *\ttty-\u003edriver_data refers to gs_port from install through cleanup,\n+ *\tpinning the port via tty_port reference counting.\n+ *\tgs_port-\u003eport.tty exists only while the port is open.\n+ *\n+ * Each entry in ports[] is guarded by ports[i].lock and models three states:\n+ * - Free: !port \u0026\u0026 !reserved\n+ * - Published: port \u0026\u0026 reserved\n+ * - Retiring or device registration in progress: !port \u0026\u0026 reserved\n+ *\n+ * A minor remains reserved until gs_port_destruct() runs upon final tty_port\n+ * release, preventing minor reuse while cleanup or termios saving is still\n+ * underway. The owner reference is retained through device unregister so the\n+ * destructor releases the reservation only after device teardown is complete.\n+ *\n+ * open_close_failures tracks failed gs_open() calls where port-\u003eport.count\n+ * was not incremented. The TTY core calls gs_close() on open failure to tear\n+ * down the tty; tracking failures as aggregate credits allows gs_close() to\n+ * consume a credit and exit without decrementing port-\u003eport.count. Credits\n+ * are aggregate rather than paired with individual files (another gs_close()\n+ * can consume a failed open's credit before that file's own close runs).\n+ * It is protected by tty_lock.\n */\n \n /* RX and TX queues can buffer QUEUE_SIZE packets before they hit the\n@@ -128,6 +146,7 @@ struct gs_port {\n \twait_queue_head_t\tclose_wait;\n \tbool\t\t\tsuspended;\t/* port suspended */\n \tbool\t\t\tstart_delayed;\t/* delay start when suspended */\n+\tunsigned int\t\topen_close_failures; /* protected by tty_lock */\n \tstruct async_icount\ticount;\n \n \t/* REVISIT this state ... */\n@@ -135,8 +154,9 @@ struct gs_port {\n };\n \n static struct portmaster {\n-\tstruct mutex\tlock;\t\t\t/* protect open/close */\n+\tstruct mutex\tlock;\t\t\t/* protect open/close and port slot */\n \tstruct gs_port\t*port;\n+\tbool\t\treserved;\n } ports[MAX_U_SERIAL_PORTS];\n \n #define GS_CLOSE_TIMEOUT\t\t15\t\t/* seconds */\n@@ -603,22 +623,63 @@ static int gserial_wakeup_host(struct gserial *gser)\n \n /* TTY Driver */\n \n+static int gs_install(struct tty_driver *driver, struct tty_struct *tty)\n+{\n+\tstruct gs_port *port;\n+\tstruct tty_port *tport;\n+\tint ret;\n+\n+\tmutex_lock(\u0026ports[tty-\u003eindex].lock);\n+\tport = ports[tty-\u003eindex].port;\n+\tif (!port) {\n+\t\tmutex_unlock(\u0026ports[tty-\u003eindex].lock);\n+\t\treturn -ENODEV;\n+\t}\n+\n+\ttport = tty_port_get(\u0026port-\u003eport);\n+\tif (!tport) {\n+\t\tmutex_unlock(\u0026ports[tty-\u003eindex].lock);\n+\t\treturn -ENODEV;\n+\t}\n+\n+\tret = tty_port_install(tport, driver, tty);\n+\tif (ret) {\n+\t\tmutex_unlock(\u0026ports[tty-\u003eindex].lock);\n+\t\ttty_port_put(tport);\n+\t\treturn ret;\n+\t}\n+\n+\ttty-\u003edriver_data = port;\n+\tmutex_unlock(\u0026ports[tty-\u003eindex].lock);\n+\n+\treturn 0;\n+}\n+\n+static void gs_cleanup(struct tty_struct *tty)\n+{\n+\ttty_port_put(tty-\u003eport);\n+}\n+\n /*\n- * gs_open sets up the link between a gs_port and its associated TTY.\n- * That link is broken *only* by TTY close(), and all driver methods\n- * know that.\n+ * gs_open associates an open TTY with its gs_port.\n+ *\n+ * There are two TTY-to-port relationships: port-\u003eport.tty exists from the\n+ * first successful open until final close, while tty-\u003edriver_data is assigned\n+ * during gs_install() and remains valid through gs_cleanup().\n */\n static int gs_open(struct tty_struct *tty, struct file *file)\n {\n \tint\t\tport_num = tty-\u003eindex;\n-\tstruct gs_port\t*port;\n+\tstruct gs_port\t*port = tty-\u003edriver_data;\n \tint\t\tstatus = 0;\n \n+\tif (!port)\n+\t\treturn -ENODEV;\n+\n \tmutex_lock(\u0026ports[port_num].lock);\n-\tport = ports[port_num].port;\n-\tif (!port) {\n+\tif (ports[port_num].port != port) {\n \t\tstatus = -ENODEV;\n-\t\tgoto out;\n+\t\tgoto fail_unlock;\n \t}\n \n \tspin_lock_irq(\u0026port-\u003eport_lock);\n@@ -638,7 +699,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)\n \t\tif (status) {\n \t\t\tpr_debug(\"gs_open: ttyGS%d (%p,%p) no buffer\\n\",\n \t\t\t\t port_num, tty, file);\n-\t\t\tgoto out;\n+\t\t\tgoto fail_unlock;\n \t\t}\n \n \t\tspin_lock_irq(\u0026port-\u003eport_lock);\n@@ -648,7 +709,6 @@ static int gs_open(struct tty_struct *tty, struct file *file)\n \tif (port-\u003eport.count++)\n \t\tgoto exit_unlock_port;\n \n-\ttty-\u003edriver_data = port;\n \tport-\u003eport.tty = tty;\n \n \t/* if connected, start the I/O stream */\n@@ -672,7 +732,11 @@ static int gs_open(struct tty_struct *tty, struct file *file)\n \n exit_unlock_port:\n \tspin_unlock_irq(\u0026port-\u003eport_lock);\n-out:\n+\tmutex_unlock(\u0026ports[port_num].lock);\n+\treturn status;\n+\n+fail_unlock:\n+\tport-\u003eopen_close_failures++;\n \tmutex_unlock(\u0026ports[port_num].lock);\n \treturn status;\n }\n@@ -695,6 +759,14 @@ static void gs_close(struct tty_struct *tty, struct file *file)\n \tstruct gs_port *port = tty-\u003edriver_data;\n \tstruct gserial\t*gser;\n \n+\tif (!port)\n+\t\treturn;\n+\n+\tif (port-\u003eopen_close_failures \u003e 0) {\n+\t\tport-\u003eopen_close_failures--;\n+\t\treturn;\n+\t}\n+\n \tspin_lock_irq(\u0026port-\u003eport_lock);\n \n \tif (port-\u003eport.count != 1) {\n@@ -909,8 +981,10 @@ static int gs_get_icount(struct tty_struct *tty,\n }\n \n static const struct tty_operations gs_tty_ops = {\n+\t.install =\t\tgs_install,\n \t.open =\t\t\tgs_open,\n \t.close =\t\tgs_close,\n+\t.cleanup =\t\tgs_cleanup,\n \t.write =\t\tgs_write,\n \t.put_char =\t\tgs_put_char,\n \t.flush_chars =\t\tgs_flush_chars,\n@@ -1203,14 +1277,41 @@ static void gs_console_exit(struct gs_port *port)\n \n #endif\n \n-static int\n+static void gs_port_destruct(struct tty_port *tport)\n+{\n+\tstruct gs_port *port = container_of(tport, struct gs_port, port);\n+\tunsigned int port_num = port-\u003eport_num;\n+\n+\tmutex_lock(\u0026ports[port_num].lock);\n+\tif (WARN_ON(ports[port_num].port))\n+\t\tports[port_num].port = NULL;\n+\tWARN_ON(!ports[port_num].reserved);\n+\tif (gs_tty_driver)\n+\t\tgs_tty_driver-\u003eports[port_num] = NULL;\n+\tports[port_num].reserved = false;\n+\tmutex_unlock(\u0026ports[port_num].lock);\n+\n+\tkfifo_free(\u0026port-\u003eport_write_buf);\n+\tkfree(port);\n+}\n+\n+static const struct tty_port_operations gs_port_ops = {\n+\t.destruct = gs_port_destruct,\n+};\n+\n+static struct gs_port *\n gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding)\n {\n \tstruct gs_port\t*port;\n \tint\t\tret = 0;\n \n \tmutex_lock(\u0026ports[port_num].lock);\n-\tif (ports[port_num].port) {\n+\tif (WARN_ON_ONCE(ports[port_num].port \u0026\u0026 !ports[port_num].reserved)) {\n+\t\tret = -EBUSY;\n+\t\tgoto out;\n+\t}\n+\n+\tif (ports[port_num].reserved) {\n \t\tret = -EBUSY;\n \t\tgoto out;\n \t}\n@@ -1222,6 +1323,7 @@ gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding)\n \t}\n \n \ttty_port_init(\u0026port-\u003eport);\n+\tport-\u003eport.ops = \u0026gs_port_ops;\n \tspin_lock_init(\u0026port-\u003eport_lock);\n \tinit_waitqueue_head(\u0026port-\u003edrain_wait);\n \tinit_waitqueue_head(\u0026port-\u003eclose_wait);\n@@ -1235,10 +1337,13 @@ gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding)\n \tport-\u003eport_num = port_num;\n \tport-\u003eport_line_coding = *coding;\n \n-\tports[port_num].port = port;\n+\tports[port_num].reserved = true;\n+\tmutex_unlock(\u0026ports[port_num].lock);\n+\treturn port;\n+\n out:\n \tmutex_unlock(\u0026ports[port_num].lock);\n-\treturn ret;\n+\treturn ERR_PTR(ret);\n }\n \n static int gs_closed(struct gs_port *port)\n@@ -1258,8 +1363,7 @@ static void gserial_free_port(struct gs_port *port)\n \t/* wait for old opens to finish */\n \twait_event(port-\u003eclose_wait, gs_closed(port));\n \tWARN_ON(port-\u003eport_usb != NULL);\n-\ttty_port_destroy(\u0026port-\u003eport);\n-\tkfree(port);\n+\ttty_port_put(\u0026port-\u003eport);\n }\n \n void gserial_free_line(unsigned char port_num)\n@@ -1276,15 +1380,15 @@ void gserial_free_line(unsigned char port_num)\n \tports[port_num].port = NULL;\n \tmutex_unlock(\u0026ports[port_num].lock);\n \n-\tgserial_free_port(port);\n \ttty_unregister_device(gs_tty_driver, port_num);\n+\tgserial_free_port(port);\n }\n EXPORT_SYMBOL_GPL(gserial_free_line);\n \n int gserial_alloc_line_no_console(unsigned char *line_num)\n {\n \tstruct usb_cdc_line_coding\tcoding;\n-\tstruct gs_port\t\t\t*port;\n+\tstruct gs_port\t\t\t*port = ERR_PTR(-EBUSY);\n \tstruct device\t\t\t*tty_dev;\n \tint\t\t\t\tret;\n \tint\t\t\t\tport_num;\n@@ -1295,19 +1399,20 @@ int gserial_alloc_line_no_console(unsigned char *line_num)\n \tcoding.bDataBits = USB_CDC_1_STOP_BITS;\n \n \tfor (port_num = 0; port_num \u003c MAX_U_SERIAL_PORTS; port_num++) {\n-\t\tret = gs_port_alloc(port_num, \u0026coding);\n-\t\tif (ret == -EBUSY)\n-\t\t\tcontinue;\n-\t\tif (ret)\n+\t\tport = gs_port_alloc(port_num, \u0026coding);\n+\t\tif (IS_ERR(port)) {\n+\t\t\tret = PTR_ERR(port);\n+\t\t\tif (ret == -EBUSY)\n+\t\t\t\tcontinue;\n \t\t\treturn ret;\n+\t\t}\n \t\tbreak;\n \t}\n-\tif (ret)\n-\t\treturn ret;\n+\tif (IS_ERR(port))\n+\t\treturn PTR_ERR(port);\n \n \t/* ... and sysfs class devices, so mdev/udev make /dev/ttyGS* */\n \n-\tport = ports[port_num].port;\n \ttty_dev = tty_port_register_device(\u0026port-\u003eport,\n \t\t\tgs_tty_driver, port_num, NULL);\n \tif (IS_ERR(tty_dev)) {\n@@ -1315,15 +1420,16 @@ int gserial_alloc_line_no_console(unsigned char *line_num)\n \t\t\t\t__func__, port_num, PTR_ERR(tty_dev));\n \n \t\tret = PTR_ERR(tty_dev);\n-\t\tmutex_lock(\u0026ports[port_num].lock);\n-\t\tports[port_num].port = NULL;\n-\t\tmutex_unlock(\u0026ports[port_num].lock);\n-\t\tgserial_free_port(port);\n-\t\tgoto err;\n+\t\ttty_port_put(\u0026port-\u003eport);\n+\t\treturn ret;\n \t}\n+\n+\tmutex_lock(\u0026ports[port_num].lock);\n+\tports[port_num].port = port;\n+\tmutex_unlock(\u0026ports[port_num].lock);\n+\n \t*line_num = port_num;\n-err:\n-\treturn ret;\n+\treturn 0;\n }\n EXPORT_SYMBOL_GPL(gserial_alloc_line_no_console);\n \n"
} |
| 2/1 | 2026/10/02 19:11 | agent | patch-evaluator |
1mModel:core Args: null Results: {
"EnableConfigs": [
"USB_GADGET",
"USB_CONFIGFS",
"USB_CONFIGFS_SERIAL",
"USB_CONFIGFS_ACM",
"USB_U_SERIAL"
],
"FocusSymbols": [
"gs_install",
"gs_cleanup",
"gs_open",
"gs_close",
"gs_port_destruct",
"gs_port_alloc",
"gserial_free_port",
"gserial_free_line",
"gserial_alloc_line_no_console"
],
"Reasoning": "The patch reworks the lifetime, reference counting, and open/close state tracking for USB gadget serial devices (u_serial.c), introducing new tty driver operations (gs_install, gs_cleanup), a tty_port destructor (gs_port_destruct), and multiple WARN_ON assertions. The code is reachable in standard virtualized fuzzing setups via USB gadget configfs (e.g. using dummy_hcd) and accessible via /dev/ttyGS* device nodes. The concurrency between device teardown and concurrent TTY open/close calls makes this a high-value target for fuzzing.",
"WorthFuzzing": true
}Instruction: You are an expert Linux kernel maintainer and security engineer.
Your job is to review a provided patch series and evaluate whether it warrants fuzzing with syzkaller.
IMPORTANT: The changes have ALREADY been applied and committed as the HEAD commit in
your workspace. Do NOT rely on internal assumptions. You must actively use your code access
tools to inspect the actual source code, callers, and surrounding context.
================================================================================
1. CORE TRIAGE PHILOSOPHY
================================================================================
The goal of patch fuzzing is to discover crashes, regressions, exposed latent bugs,
and newly triggered assertions introduced by the patch series.
- REACHABILITY IS THE PRIMARY GATE:
Fuzzing can only discover bugs in code that can actually execute in standard virtualized
environments (GCE or QEMU, utilizing software-emulated devices like USB gadgets, netdev, tun/tap).
If the modified code is structurally unreachable (see Section 2), it MUST NOT be fuzzed,
regardless of whether it adds assertions or complex logic.
- DO NOT BLINDLY TRUST "NO FUNCTIONAL CHANGE" (NFCI) OR "REFACTORING" CLAIMS:
Patch authors routinely label changes as "cleanups", "refactorings", or state
"No functional change intended". Do NOT take these claims at face value.
Code refactorings that rearrange logic, introduce helper functions, or alter state management
in core subsystems frequently introduce subtle semantic shifts or uncover latent kernel bugs.
If reachable executable code is modified or refactored, it MUST be fuzzed.
- NEW OR MODIFIED ASSERTIONS IN REACHABLE CODE MUST BE FUZZED:
When a patch introduces or modifies runtime checks or assertions (e.g., WARN_ON*, VM_WARN_ON*,
BUG_ON*, lockdep_assert*) in reachable code paths, it enforces new or stricter invariants.
Even if the author believes the invariant always holds, fuzzing is essential to verify whether
an unusual sequence of operations can violate it.
================================================================================
2. WHEN TO RETURN WorthFuzzing=false (NEGATIVE CRITERIA)
================================================================================
Return WorthFuzzing=false ONLY IF all modified code falls strictly into one or more of these categories:
- Non-kernel and non-executable changes:
* Modifications to Documentation/, comments, or spelling fixes.
* User-space directories, self-tests, samples, or scripts (e.g., tools/, samples/, scripts/, usr/)
that do not affect the compiled kernel image (vmlinux) or kernel modules.
* Purely decorative logging (e.g., message strings in pr_err, printk, dev_info) or tracepoints
that do not alter control flow or data structures.
* Build system or Kconfig changes that do not alter compiled C logic.
- Structurally unreachable hardware:
* Vendor-specific PCIe switches, SmartNICs, or GPU drivers (e.g., mlxsw, pds_core, qed,
ionic, amdgpu) requiring physical ASIC/PCIe cards not emulated in standard QEMU.
- Unreachable execution paths:
* Driver teardown callbacks (.remove, .shutdown, pci_unregister_driver) executed only during
physical PCI hot-unplug or manual sysfs driver unbinding.
* Code paths exclusive to architectures other than the target architecture.
================================================================================
3. WHEN TO RETURN WorthFuzzing=true (POSITIVE CRITERIA)
================================================================================
Return WorthFuzzing=true whenever the patch touches reachable executable code, including:
- Core Subsystems:
* Any logic modifications in memory management (mm/), synchronization/locking (kernel/locking/),
BPF, scheduler, core networking, VFS, or syscall handling.
- Refactorings and Code Cleanups:
* Any restructuring of reachable data structures, helper abstractions, or algorithm flows.
- Runtime Assertions and Defensive Checks:
* Any introduction or alteration of assertions (WARN_ON*, VM_WARN_ON*, BUG_ON*, etc.) in reachable paths.
- Reachable Drivers and Protocols:
* Drivers accessible via virtual buses (virtio, USB gadget, loopback, netlink, binder, sockets, etc.).
================================================================================
4. EXTRACTING FocusSymbols (PREVENTING DILUTION)
================================================================================
When WorthFuzzing=true, you must extract specific kernel functions into FocusSymbols to guide the fuzzer:
- AVOID UBIQUITOUS LIFECYCLE HOT-PATHS:
Do NOT list generic, ubiquitous functions called by almost every program in the corpus
(including, but not limited to: general memory allocators and deallocators, page fault
and trap handlers, or core synchronization primitives; this is not an exhaustive list).
Listing ubiquitous functions causes the fuzzer to classify thousands of unrelated tests as "focused",
which severely dilutes fuzzing effort away from the actual changes.
- TARGET SPECIFIC FEATURE LOGIC AND ENTRYPOINTS:
List functions that specifically implement the logic being added or altered, or direct API entrypoints
for the subsystem feature under review.
- HANDLING STATIC INLINE FUNCTIONS IN HEADERS (.h):
Compiler-inlined static functions (such as static inlines in mm/*.h or include/linux/*.h) lack
distinct symbol addresses in vmlinux and cannot be targeted directly by symbol coverage filters.
If the changes are primarily in static inline helpers, identify non-static, feature-specific caller
functions in .c files that exercise them (avoiding ubiquitous lifecycle wrappers).
================================================================================
5. IDENTIFYING EnableConfigs
================================================================================
Identify any specific CONFIG_ options required to properly compile and reach the modified code:
- Inspect Kconfig files and #ifdef guards; do not make assumptions.
- Check "depends on" lines in Kconfig to include any non-standard parent subsystem configs needed.
- Strip any 'CONFIG_' prefix (e.g., return "NET_IPV4" instead of "CONFIG_NET_IPV4").
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit d78810d9105851f29f9806c00f32094f2cf88a46
Author: syz-cluster <triage@syzkaller.com>
Date: Fri Oct 2 19:11:06 2026 +0000
syz-cluster: applied patch under review
diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index cdd1dfc666c4f..aaad06fa5d050 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -70,10 +70,28 @@
* gserial->ioport == usb_ep->driver_data ... gs_port
* gs_port->port_usb ... gserial
*
- * gs_port <---> tty_struct ... links will be null when the TTY file
- * isn't opened; managed by gs_open()/gs_close()
- * gserial->port_tty ... tty_struct
- * tty_struct->driver_data ... gserial
+ * gs_port <---> tty_struct:
+ * tty->driver_data refers to gs_port from install through cleanup,
+ * pinning the port via tty_port reference counting.
+ * gs_port->port.tty exists only while the port is open.
+ *
+ * Each entry in ports[] is guarded by ports[i].lock and models three states:
+ * - Free: !port && !reserved
+ * - Published: port && reserved
+ * - Retiring or device registration in progress: !port && reserved
+ *
+ * A minor remains reserved until gs_port_destruct() runs upon final tty_port
+ * release, preventing minor reuse while cleanup or termios saving is still
+ * underway. The owner reference is retained through device unregister so the
+ * destructor releases the reservation only after device teardown is complete.
+ *
+ * open_close_failures tracks failed gs_open() calls where port->port.count
+ * was not incremented. The TTY core calls gs_close() on open failure to tear
+ * down the tty; tracking failures as aggregate credits allows gs_close() to
+ * consume a credit and exit without decrementing port->port.count. Credits
+ * are aggregate rather than paired with individual files (another gs_close()
+ * can consume a failed open's credit before that file's own close runs).
+ * It is protected by tty_lock.
*/
/* RX and TX queues can buffer QUEUE_SIZE packets before they hit the
@@ -128,6 +146,7 @@ struct gs_port {
wait_queue_head_t close_wait;
bool suspended; /* port suspended */
bool start_delayed; /* delay start when suspended */
+ unsigned int open_close_failures; /* protected by tty_lock */
struct async_icount icount;
/* REVISIT this state ... */
@@ -135,8 +154,9 @@ struct gs_port {
};
static struct portmaster {
- struct mutex lock; /* protect open/close */
+ struct mutex lock; /* protect open/close and port slot */
struct gs_port *port;
+ bool reserved;
} ports[MAX_U_SERIAL_PORTS];
#define GS_CLOSE_TIMEOUT 15 /* seconds */
@@ -603,22 +623,63 @@ static int gserial_wakeup_host(struct gserial *gser)
/* TTY Driver */
+static int gs_install(struct tty_driver *driver, struct tty_struct *tty)
+{
+ struct gs_port *port;
+ struct tty_port *tport;
+ int ret;
+
+ mutex_lock(&ports[tty->index].lock);
+ port = ports[tty->index].port;
+ if (!port) {
+ mutex_unlock(&ports[tty->index].lock);
+ return -ENODEV;
+ }
+
+ tport = tty_port_get(&port->port);
+ if (!tport) {
+ mutex_unlock(&ports[tty->index].lock);
+ return -ENODEV;
+ }
+
+ ret = tty_port_install(tport, driver, tty);
+ if (ret) {
+ mutex_unlock(&ports[tty->index].lock);
+ tty_port_put(tport);
+ return ret;
+ }
+
+ tty->driver_data = port;
+ mutex_unlock(&ports[tty->index].lock);
+
+ return 0;
+}
+
+static void gs_cleanup(struct tty_struct *tty)
+{
+ tty_port_put(tty->port);
+}
+
/*
- * gs_open sets up the link between a gs_port and its associated TTY.
- * That link is broken *only* by TTY close(), and all driver methods
- * know that.
+ * gs_open associates an open TTY with its gs_port.
+ *
+ * There are two TTY-to-port relationships: port->port.tty exists from the
+ * first successful open until final close, while tty->driver_data is assigned
+ * during gs_install() and remains valid through gs_cleanup().
*/
static int gs_open(struct tty_struct *tty, struct file *file)
{
int port_num = tty->index;
- struct gs_port *port;
+ struct gs_port *port = tty->driver_data;
int status = 0;
+ if (!port)
+ return -ENODEV;
+
mutex_lock(&ports[port_num].lock);
- port = ports[port_num].port;
- if (!port) {
+ if (ports[port_num].port != port) {
status = -ENODEV;
- goto out;
+ goto fail_unlock;
}
spin_lock_irq(&port->port_lock);
@@ -638,7 +699,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
if (status) {
pr_debug("gs_open: ttyGS%d (%p,%p) no buffer\n",
port_num, tty, file);
- goto out;
+ goto fail_unlock;
}
spin_lock_irq(&port->port_lock);
@@ -648,7 +709,6 @@ static int gs_open(struct tty_struct *tty, struct file *file)
if (port->port.count++)
goto exit_unlock_port;
- tty->driver_data = port;
port->port.tty = tty;
/* if connected, start the I/O stream */
@@ -672,7 +732,11 @@ static int gs_open(struct tty_struct *tty, struct file *file)
exit_unlock_port:
spin_unlock_irq(&port->port_lock);
-out:
+ mutex_unlock(&ports[port_num].lock);
+ return status;
+
+fail_unlock:
+ port->open_close_failures++;
mutex_unlock(&ports[port_num].lock);
return status;
}
@@ -695,6 +759,14 @@ static void gs_close(struct tty_struct *tty, struct file *file)
struct gs_port *port = tty->driver_data;
struct gserial *gser;
+ if (!port)
+ return;
+
+ if (port->open_close_failures > 0) {
+ port->open_close_failures--;
+ return;
+ }
+
spin_lock_irq(&port->port_lock);
if (port->port.count != 1) {
@@ -909,8 +981,10 @@ static int gs_get_icount(struct tty_struct *tty,
}
static const struct tty_operations gs_tty_ops = {
+ .install = gs_install,
.open = gs_open,
.close = gs_close,
+ .cleanup = gs_cleanup,
.write = gs_write,
.put_char = gs_put_char,
.flush_chars = gs_flush_chars,
@@ -1203,14 +1277,41 @@ static void gs_console_exit(struct gs_port *port)
#endif
-static int
+static void gs_port_destruct(struct tty_port *tport)
+{
+ struct gs_port *port = container_of(tport, struct gs_port, port);
+ unsigned int port_num = port->port_num;
+
+ mutex_lock(&ports[port_num].lock);
+ if (WARN_ON(ports[port_num].port))
+ ports[port_num].port = NULL;
+ WARN_ON(!ports[port_num].reserved);
+ if (gs_tty_driver)
+ gs_tty_driver->ports[port_num] = NULL;
+ ports[port_num].reserved = false;
+ mutex_unlock(&ports[port_num].lock);
+
+ kfifo_free(&port->port_write_buf);
+ kfree(port);
+}
+
+static const struct tty_port_operations gs_port_ops = {
+ .destruct = gs_port_destruct,
+};
+
+static struct gs_port *
gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding)
{
struct gs_port *port;
int ret = 0;
mutex_lock(&ports[port_num].lock);
- if (ports[port_num].port) {
+ if (WARN_ON_ONCE(ports[port_num].port && !ports[port_num].reserved)) {
+ ret = -EBUSY;
+ goto out;
+ }
+
+ if (ports[port_num].reserved) {
ret = -EBUSY;
goto out;
}
@@ -1222,6 +1323,7 @@ gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding)
}
tty_port_init(&port->port);
+ port->port.ops = &gs_port_ops;
spin_lock_init(&port->port_lock);
init_waitqueue_head(&port->drain_wait);
init_waitqueue_head(&port->close_wait);
@@ -1235,10 +1337,13 @@ gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding)
port->port_num = port_num;
port->port_line_coding = *coding;
- ports[port_num].port = port;
+ ports[port_num].reserved = true;
+ mutex_unlock(&ports[port_num].lock);
+ return port;
+
out:
mutex_unlock(&ports[port_num].lock);
- return ret;
+ return ERR_PTR(ret);
}
static int gs_closed(struct gs_port *port)
@@ -1258,8 +1363,7 @@ static void gserial_free_port(struct gs_port *port)
/* wait for old opens to finish */
wait_event(port->close_wait, gs_closed(port));
WARN_ON(port->port_usb != NULL);
- tty_port_destroy(&port->port);
- kfree(port);
+ tty_port_put(&port->port);
}
void gserial_free_line(unsigned char port_num)
@@ -1276,15 +1380,15 @@ void gserial_free_line(unsigned char port_num)
ports[port_num].port = NULL;
mutex_unlock(&ports[port_num].lock);
- gserial_free_port(port);
tty_unregister_device(gs_tty_driver, port_num);
+ gserial_free_port(port);
}
EXPORT_SYMBOL_GPL(gserial_free_line);
int gserial_alloc_line_no_console(unsigned char *line_num)
{
struct usb_cdc_line_coding coding;
- struct gs_port *port;
+ struct gs_port *port = ERR_PTR(-EBUSY);
struct device *tty_dev;
int ret;
int port_num;
@@ -1295,19 +1399,20 @@ int gserial_alloc_line_no_console(unsigned char *line_num)
coding.bDataBits = USB_CDC_1_STOP_BITS;
for (port_num = 0; port_num < MAX_U_SERIAL_PORTS; port_num++) {
- ret = gs_port_alloc(port_num, &coding);
- if (ret == -EBUSY)
- continue;
- if (ret)
+ port = gs_port_alloc(port_num, &coding);
+ if (IS_ERR(port)) {
+ ret = PTR_ERR(port);
+ if (ret == -EBUSY)
+ continue;
return ret;
+ }
break;
}
- if (ret)
- return ret;
+ if (IS_ERR(port))
+ return PTR_ERR(port);
/* ... and sysfs class devices, so mdev/udev make /dev/ttyGS* */
- port = ports[port_num].port;
tty_dev = tty_port_register_device(&port->port,
gs_tty_driver, port_num, NULL);
if (IS_ERR(tty_dev)) {
@@ -1315,15 +1420,16 @@ int gserial_alloc_line_no_console(unsigned char *line_num)
__func__, port_num, PTR_ERR(tty_dev));
ret = PTR_ERR(tty_dev);
- mutex_lock(&ports[port_num].lock);
- ports[port_num].port = NULL;
- mutex_unlock(&ports[port_num].lock);
- gserial_free_port(port);
- goto err;
+ tty_port_put(&port->port);
+ return ret;
}
+
+ mutex_lock(&ports[port_num].lock);
+ ports[port_num].port = port;
+ mutex_unlock(&ports[port_num].lock);
+
*line_num = port_num;
-err:
- return ret;
+ return 0;
}
EXPORT_SYMBOL_GPL(gserial_alloc_line_no_console);
|
| 3/2 | 2026/10/02 19:11 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 6467 output: 29 thoughts: 124 Thoughts: **Analyzing the USB Serial Gadget Driver Patch** Alright, let's dive in. I see this patch is touching `drivers/usb/gadget/function/u_serial.c`. That's the USB serial gadget driver helper, if I recall correctly. Given how heavily syzkaller fuzzed USB Gadgets in the past, including those using raw-gadget, configfs USB gadget, and dummy_hcd, I'm already on high alert for potential issues. Time to understand these changes. I need to get a clear picture of *why* this file is being modified. First things first, I'll either check the associated Git commit message for context or just read through `u_serial.c` directly, paying close attention to its Kconfig dependencies. Understanding those dependencies is key to figuring out the impact of the changes. |
| 4/2 | 2026/10/02 19:11 | tool | grepper |
0mArgs:{
"Expression": "u_serial",
"PathPrefix": "drivers/usb/gadget"
}Results: {
"Output": "drivers/usb/gadget/function/Makefile=13=obj-$(CONFIG_USB_F_SS_LB)\t+= usb_f_ss_lb.o\ndrivers/usb/gadget/function/Makefile:14:obj-$(CONFIG_USB_U_SERIAL)\t+= u_serial.o\ndrivers/usb/gadget/function/Makefile-15-usb_f_serial-y\t\t\t:= f_serial.o\n--\ndrivers/usb/gadget/function/f_acm.c-22-\ndrivers/usb/gadget/function/f_acm.c:23:#include \"u_serial.h\"\ndrivers/usb/gadget/function/f_acm.c-24-\n--\ndrivers/usb/gadget/function/f_obex.c-17-\ndrivers/usb/gadget/function/f_obex.c:18:#include \"u_serial.h\"\ndrivers/usb/gadget/function/f_obex.c-19-\n--\ndrivers/usb/gadget/function/f_serial.c-14-\ndrivers/usb/gadget/function/f_serial.c:15:#include \"u_serial.h\"\ndrivers/usb/gadget/function/f_serial.c-16-\n--\ndrivers/usb/gadget/function/u_serial.c-2-/*\ndrivers/usb/gadget/function/u_serial.c:3: * u_serial.c - utilities for USB gadget \"serial port\"/TTY support\ndrivers/usb/gadget/function/u_serial.c-4- *\n--\ndrivers/usb/gadget/function/u_serial.c-33-\ndrivers/usb/gadget/function/u_serial.c:34:#include \"u_serial.h\"\ndrivers/usb/gadget/function/u_serial.c-35-\n--\ndrivers/usb/gadget/function/u_serial.h-2-/*\ndrivers/usb/gadget/function/u_serial.h:3: * u_serial.h - interface to USB gadget \"serial port\"/TTY utilities\ndrivers/usb/gadget/function/u_serial.h-4- *\n--\ndrivers/usb/gadget/function/u_serial.h=17=struct f_serial_opts {\n--\ndrivers/usb/gadget/function/u_serial.h-29- *\ndrivers/usb/gadget/function/u_serial.h:30: * The \"u_serial\" utility component exists to do one thing: manage TTY\ndrivers/usb/gadget/function/u_serial.h-31- * style I/O using the USB peripheral endpoints listed here, including\n--\ndrivers/usb/gadget/legacy/acm_ms.c-15-\ndrivers/usb/gadget/legacy/acm_ms.c:16:#include \"u_serial.h\"\ndrivers/usb/gadget/legacy/acm_ms.c-17-\n--\ndrivers/usb/gadget/legacy/cdc2.c-12-#include \"u_ether.h\"\ndrivers/usb/gadget/legacy/cdc2.c:13:#include \"u_serial.h\"\ndrivers/usb/gadget/legacy/cdc2.c-14-#include \"u_ecm.h\"\n--\ndrivers/usb/gadget/legacy/dbgp.c-16-\ndrivers/usb/gadget/legacy/dbgp.c:17:#include \"u_serial.h\"\ndrivers/usb/gadget/legacy/dbgp.c-18-\n--\ndrivers/usb/gadget/legacy/multi.c-15-\ndrivers/usb/gadget/legacy/multi.c:16:#include \"u_serial.h\"\ndrivers/usb/gadget/legacy/multi.c-17-#if defined USB_ETH_RNDIS\n--\ndrivers/usb/gadget/legacy/nokia.c-18-\ndrivers/usb/gadget/legacy/nokia.c:19:#include \"u_serial.h\"\ndrivers/usb/gadget/legacy/nokia.c-20-#include \"u_ether.h\"\n--\ndrivers/usb/gadget/legacy/serial.c-16-\ndrivers/usb/gadget/legacy/serial.c:17:#include \"u_serial.h\"\ndrivers/usb/gadget/legacy/serial.c-18-\n"
} |
| 5/2 | 2026/10/02 19:11 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 7874 output: 32 thoughts: 15 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Analyzing the Kconfig for CONFIG_USB_U_SERIAL** Alright, let's dive into the Kconfig for `CONFIG_USB_U_SERIAL`. My immediate thought process here is to quickly assess its dependencies and implications. I'm looking for the usual suspects: potential hardware dependencies (specific USB controllers or ports), any conflicting options, and the general placement within the overall USB subsystem hierarchy. I'll be mentally tracing the branching logic—does this option depend on a certain USB core being enabled first? Does it introduce any new modules or device drivers that I need to be aware of? I'm anticipating that `CONFIG_USB_U_SERIAL` probably enables a generic USB serial converter driver, which means I should be looking at how it integrates with other USB serial drivers. I'll need to remember any potential gotchas with different USB-to-serial chips (FTDI, Prolific, etc.) and if this Kconfig option handles those complexities. Also, are there any default values that need my attention? Furthermore, I'm expecting this configuration option to influence the build process; it might add specific source files or object files to the build, which could impact image size and linking. I'll mentally evaluate the implications for the target platform I'm working with – are there any resource constraints to be mindful of? This Kconfig option is critical because, for many embedded systems, serial communication through USB is essential for debugging, bootloading, and general device interaction. |
| 6/2 | 2026/10/02 19:11 | tool | grepper |
0mArgs:{
"Expression": "config USB_U_SERIAL",
"PathPrefix": "drivers/usb/gadget"
}Results: {
"Output": "drivers/usb/gadget/Kconfig=153=config USB_F_SS_LB\n--\ndrivers/usb/gadget/Kconfig-155-\ndrivers/usb/gadget/Kconfig:156:config USB_U_SERIAL\ndrivers/usb/gadget/Kconfig-157-\ttristate\n"
} |
| 7/2 | 2026/10/02 19:11 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 8339 output: 32 thoughts: 15 Thoughts: Okay, here's my attempt at summarizing that thought process, tailored for an expert audience: **Investigating the `CONFIG_USB_U_SERIAL` Dependency Chain** Right, let's dive into this `CONFIG_USB_U_SERIAL` thing. My immediate thought is to trace the dependencies. I need to understand what components in the kernel's USB subsystem rely on it, and *why*. I'm thinking specifically about how it fits into the broader picture of USB serial drivers. Is it a base component, a specific implementation detail, or something that's only pulled in under certain conditions? I need to figure out the context of its selection. Is it related to other modules I'm already familiar with, or is this new territory? Time to get the build system working. |
| 8/2 | 2026/10/02 19:11 | tool | grepper |
0mArgs:{
"Expression": "select USB_U_SERIAL",
"PathPrefix": "drivers/usb/gadget"
}Results: {
"Output": "drivers/usb/gadget/Kconfig=240=config USB_CONFIGFS_SERIAL\n--\ndrivers/usb/gadget/Kconfig-243-\tdepends on TTY\ndrivers/usb/gadget/Kconfig:244:\tselect USB_U_SERIAL\ndrivers/usb/gadget/Kconfig-245-\tselect USB_F_SERIAL\n--\ndrivers/usb/gadget/Kconfig=249=config USB_CONFIGFS_ACM\n--\ndrivers/usb/gadget/Kconfig-252-\tdepends on TTY\ndrivers/usb/gadget/Kconfig:253:\tselect USB_U_SERIAL\ndrivers/usb/gadget/Kconfig-254-\tselect USB_F_ACM\n--\ndrivers/usb/gadget/Kconfig=259=config USB_CONFIGFS_OBEX\n--\ndrivers/usb/gadget/Kconfig-262-\tdepends on TTY\ndrivers/usb/gadget/Kconfig:263:\tselect USB_U_SERIAL\ndrivers/usb/gadget/Kconfig-264-\tselect USB_F_OBEX\n--\ndrivers/usb/gadget/legacy/Kconfig=291=config USB_G_SERIAL\n--\ndrivers/usb/gadget/legacy/Kconfig-293-\tdepends on TTY\ndrivers/usb/gadget/legacy/Kconfig:294:\tselect USB_U_SERIAL\ndrivers/usb/gadget/legacy/Kconfig-295-\tselect USB_F_ACM\n--\ndrivers/usb/gadget/legacy/Kconfig=351=config USB_CDC_COMPOSITE\n--\ndrivers/usb/gadget/legacy/Kconfig-354-\tselect USB_LIBCOMPOSITE\ndrivers/usb/gadget/legacy/Kconfig:355:\tselect USB_U_SERIAL\ndrivers/usb/gadget/legacy/Kconfig-356-\tselect USB_U_ETHER\n--\ndrivers/usb/gadget/legacy/Kconfig=370=config USB_G_NOKIA\n--\ndrivers/usb/gadget/legacy/Kconfig-374-\tselect USB_LIBCOMPOSITE\ndrivers/usb/gadget/legacy/Kconfig:375:\tselect USB_U_SERIAL\ndrivers/usb/gadget/legacy/Kconfig-376-\tselect USB_U_ETHER\n--\ndrivers/usb/gadget/legacy/Kconfig=389=config USB_G_ACM_MS\n--\ndrivers/usb/gadget/legacy/Kconfig-392-\tselect USB_LIBCOMPOSITE\ndrivers/usb/gadget/legacy/Kconfig:393:\tselect USB_U_SERIAL\ndrivers/usb/gadget/legacy/Kconfig-394-\tselect USB_F_ACM\n--\ndrivers/usb/gadget/legacy/Kconfig=403=config USB_G_MULTI\n--\ndrivers/usb/gadget/legacy/Kconfig-407-\tselect USB_LIBCOMPOSITE\ndrivers/usb/gadget/legacy/Kconfig:408:\tselect USB_U_SERIAL\ndrivers/usb/gadget/legacy/Kconfig-409-\tselect USB_U_ETHER\n--\ndrivers/usb/gadget/legacy/Kconfig=490=config USB_G_DBGP_SERIAL\ndrivers/usb/gadget/legacy/Kconfig-491-\tdepends on USB_G_DBGP\ndrivers/usb/gadget/legacy/Kconfig:492:\tselect USB_U_SERIAL\ndrivers/usb/gadget/legacy/Kconfig-493-\tbool \"serial\"\n"
} |
| 9/2 | 2026/10/02 19:11 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 9436 output: 16 thoughts: 100 Thoughts: **Investigating USB Gadget Serial Support in Syzkaller** Okay, so I'm digging into how `u_serial.c` handles `/dev/ttyGS*` serial ports within the USB gadget configfs framework. We know that `USB_CONFIGFS_SERIAL`, `USB_CONFIGFS_ACM`, and even the older `USB_G_SERIAL` configurations all rely on this code to expose these serial interfaces. I need to see if Syzkaller, with its comprehensive understanding of kernel interfaces, has leveraged this. My immediate concern is whether syzkaller has existing descriptions or test cases for `/dev/ttyGS*` devices or even configfs gadget creation that involves serial functionality. If Syzkaller's coverage is good, it should have calls like `syz_open_dev$ttyGS` or equivalent mechanisms for describing and testing these gadget-serial interactions. If it does, that will be really useful. If not, I may have an area for contributing or enhancing its test suite. |
| 10/2 | 2026/10/02 19:11 | tool | grepper |
0mArgs:{
"Expression": "ttyGS"
}Results: {
"Output": "\nFull output is too long, showing 200 out of 326 lines.\nUse more precise expression if possible.\n\nDocumentation/ABI/testing/configfs-usb-gadget-acm=4=Description:\n--\nDocumentation/ABI/testing/configfs-usb-gadget-acm-6-\t\tThis item contains just one readonly attribute: port_num.\nDocumentation/ABI/testing/configfs-usb-gadget-acm:7:\t\tIt contains the port number of the /dev/ttyGS\u003cn\u003e device\nDocumentation/ABI/testing/configfs-usb-gadget-acm-8-\t\tassociated with acm function's instance \"name\".\n--\nDocumentation/ABI/testing/configfs-usb-gadget-obex=4=Description:\n--\nDocumentation/ABI/testing/configfs-usb-gadget-obex-6-\t\tThis item contains just one readonly attribute: port_num.\nDocumentation/ABI/testing/configfs-usb-gadget-obex:7:\t\tIt contains the port number of the /dev/ttyGS\u003cn\u003e device\nDocumentation/ABI/testing/configfs-usb-gadget-obex-8-\t\tassociated with obex function's instance \"name\".\n--\nDocumentation/ABI/testing/configfs-usb-gadget-serial=4=Description:\n--\nDocumentation/ABI/testing/configfs-usb-gadget-serial-6-\t\tThis item contains just one readonly attribute: port_num.\nDocumentation/ABI/testing/configfs-usb-gadget-serial:7:\t\tIt contains the port number of the /dev/ttyGS\u003cn\u003e device\nDocumentation/ABI/testing/configfs-usb-gadget-serial-8-\t\tassociated with gser function's instance \"name\".\n--\nDocumentation/usb/gadget-testing.rst=58=On the device::\nDocumentation/usb/gadget-testing.rst-59-\nDocumentation/usb/gadget-testing.rst:60:\tcat /dev/ttyGS\u003cY\u003e\nDocumentation/usb/gadget-testing.rst-61-\n--\nDocumentation/usb/gadget-testing.rst=64=On the device::\nDocumentation/usb/gadget-testing.rst-65-\nDocumentation/usb/gadget-testing.rst:66:\tcat \u003e /dev/ttyGS\u003cY\u003e\nDocumentation/usb/gadget-testing.rst-67-\n--\nDocumentation/usb/gadget-testing.rst=511=On device::\nDocumentation/usb/gadget-testing.rst-512-\nDocumentation/usb/gadget-testing.rst:513:\tseriald -f /dev/ttyGS\u003cY\u003e -s 1024\nDocumentation/usb/gadget-testing.rst-514-\n--\nDocumentation/usb/gadget-testing.rst=658=On target::\nDocumentation/usb/gadget-testing.rst-659-\nDocumentation/usb/gadget-testing.rst:660:\tcat /dev/ttyGS\u003cY\u003e\nDocumentation/usb/gadget-testing.rst-661-\n--\nDocumentation/usb/gadget-testing.rst=664=On target::\nDocumentation/usb/gadget-testing.rst-665-\nDocumentation/usb/gadget-testing.rst:666:\tcat \u003e /dev/ttyGS\u003cY\u003e\nDocumentation/usb/gadget-testing.rst-667-\n--\nDocumentation/usb/gadget_serial.rst=132=device nodes. After this gadget driver has been set up you should\nDocumentation/usb/gadget_serial.rst:133:then see a /dev/ttyGS0 node::\nDocumentation/usb/gadget_serial.rst-134-\nDocumentation/usb/gadget_serial.rst:135: # ls -l /dev/ttyGS0 | cat\nDocumentation/usb/gadget_serial.rst:136: crw-rw---- 1 root root 253, 0 May 8 14:10 /dev/ttyGS0\nDocumentation/usb/gadget_serial.rst-137- #\n--\nDocumentation/usb/gadget_serial.rst=140=you need to create /dev nodes by hand, the right numbers to use\nDocumentation/usb/gadget_serial.rst:141:will be in the /sys/class/tty/ttyGS0/dev file.\nDocumentation/usb/gadget_serial.rst-142-\n--\nDocumentation/usb/gadget_serial.rst=144=you may want to set up an /etc/inittab entry to run \"getty\" on it.\nDocumentation/usb/gadget_serial.rst:145:The /dev/ttyGS0 line should work like most any other serial port.\nDocumentation/usb/gadget_serial.rst-146-\n--\ndrivers/usb/gadget/Kconfig=259=config USB_CONFIGFS_OBEX\n--\ndrivers/usb/gadget/Kconfig-265-\thelp\ndrivers/usb/gadget/Kconfig:266:\t You will need a user space OBEX server talking to /dev/ttyGS*,\ndrivers/usb/gadget/Kconfig-267-\t since the kernel itself doesn't implement the OBEX protocol.\n--\ndrivers/usb/gadget/function/f_acm.c=299=static void acm_complete_set_line_coding(struct usb_ep *ep,\n--\ndrivers/usb/gadget/function/f_acm.c-305-\tif (req-\u003estatus != 0) {\ndrivers/usb/gadget/function/f_acm.c:306:\t\tdev_dbg(\u0026cdev-\u003egadget-\u003edev, \"acm ttyGS%d completion, err %d\\n\",\ndrivers/usb/gadget/function/f_acm.c-307-\t\t\tacm-\u003eport_num, req-\u003estatus);\n--\ndrivers/usb/gadget/function/f_acm.c-312-\tif (req-\u003eactual != sizeof(acm-\u003eport_line_coding)) {\ndrivers/usb/gadget/function/f_acm.c:313:\t\tdev_dbg(\u0026cdev-\u003egadget-\u003edev, \"acm ttyGS%d short resp, len %d\\n\",\ndrivers/usb/gadget/function/f_acm.c-314-\t\t\tacm-\u003eport_num, req-\u003eactual);\n--\ndrivers/usb/gadget/function/f_acm.c=332=static int acm_setup(struct usb_function *f, const struct usb_ctrlrequest *ctrl)\n--\ndrivers/usb/gadget/function/f_acm.c-408-\t\tdev_dbg(\u0026cdev-\u003egadget-\u003edev,\ndrivers/usb/gadget/function/f_acm.c:409:\t\t\t\"acm ttyGS%d req%02x.%02x v%04x i%04x l%d\\n\",\ndrivers/usb/gadget/function/f_acm.c-410-\t\t\tacm-\u003eport_num, ctrl-\u003ebRequestType, ctrl-\u003ebRequest,\n--\ndrivers/usb/gadget/function/f_acm.c-415-\t\tif (value \u003c 0)\ndrivers/usb/gadget/function/f_acm.c:416:\t\t\tERROR(cdev, \"acm response on ttyGS%d, err %d\\n\",\ndrivers/usb/gadget/function/f_acm.c-417-\t\t\t\t\tacm-\u003eport_num, value);\n--\ndrivers/usb/gadget/function/f_acm.c=424=static int acm_set_alt(struct usb_function *f, unsigned intf, unsigned alt)\n--\ndrivers/usb/gadget/function/f_acm.c-446-\t\t\tdev_dbg(\u0026cdev-\u003egadget-\u003edev,\ndrivers/usb/gadget/function/f_acm.c:447:\t\t\t\t\"reset acm ttyGS%d\\n\", acm-\u003eport_num);\ndrivers/usb/gadget/function/f_acm.c-448-\t\t\tgserial_disconnect(\u0026acm-\u003eport);\n--\ndrivers/usb/gadget/function/f_acm.c-451-\t\t\tdev_dbg(\u0026cdev-\u003egadget-\u003edev,\ndrivers/usb/gadget/function/f_acm.c:452:\t\t\t\t\"activate acm ttyGS%d\\n\", acm-\u003eport_num);\ndrivers/usb/gadget/function/f_acm.c-453-\t\t\tif (config_ep_by_speed(cdev-\u003egadget, f,\n--\ndrivers/usb/gadget/function/f_acm.c=470=static void acm_disable(struct usb_function *f)\n--\ndrivers/usb/gadget/function/f_acm.c-474-\ndrivers/usb/gadget/function/f_acm.c:475:\tdev_dbg(\u0026cdev-\u003egadget-\u003edev, \"acm ttyGS%d deactivated\\n\", acm-\u003eport_num);\ndrivers/usb/gadget/function/f_acm.c-476-\tgserial_disconnect(\u0026acm-\u003eport);\n--\ndrivers/usb/gadget/function/f_acm.c=496=static int acm_cdc_notify(struct f_acm *acm, u8 type, u16 value,\n--\ndrivers/usb/gadget/function/f_acm.c-528-\t\tERROR(acm-\u003eport.func.config-\u003ecdev,\ndrivers/usb/gadget/function/f_acm.c:529:\t\t\t\t\"acm ttyGS%d can't notify serial state, %d\\n\",\ndrivers/usb/gadget/function/f_acm.c-530-\t\t\t\tacm-\u003eport_num, status);\n--\ndrivers/usb/gadget/function/f_acm.c=537=static int acm_notify_serial_state(struct f_acm *acm)\n--\ndrivers/usb/gadget/function/f_acm.c-544-\tif (acm-\u003enotify_req) {\ndrivers/usb/gadget/function/f_acm.c:545:\t\tdev_dbg(\u0026cdev-\u003egadget-\u003edev, \"acm ttyGS%d serial state %04x\\n\",\ndrivers/usb/gadget/function/f_acm.c-546-\t\t\tacm-\u003eport_num, acm-\u003eserial_state);\n--\ndrivers/usb/gadget/function/f_acm.c=612=acm_bind(struct usb_configuration *c, struct usb_function *f)\n--\ndrivers/usb/gadget/function/f_acm.c-701-\tdev_dbg(\u0026cdev-\u003egadget-\u003edev,\ndrivers/usb/gadget/function/f_acm.c:702:\t\t\"acm ttyGS%d: IN/%s OUT/%s NOTIFY/%s\\n\",\ndrivers/usb/gadget/function/f_acm.c-703-\t\tacm-\u003eport_num,\n--\ndrivers/usb/gadget/function/f_obex.c=189=static int obex_set_alt(struct usb_function *f, unsigned intf, unsigned alt)\n--\ndrivers/usb/gadget/function/f_obex.c-198-\t\tdev_dbg(\u0026cdev-\u003egadget-\u003edev,\ndrivers/usb/gadget/function/f_obex.c:199:\t\t\t\"reset obex ttyGS%d control\\n\", obex-\u003eport_num);\ndrivers/usb/gadget/function/f_obex.c-200-\n--\ndrivers/usb/gadget/function/f_obex.c-206-\t\t\tdev_dbg(\u0026cdev-\u003egadget-\u003edev,\ndrivers/usb/gadget/function/f_obex.c:207:\t\t\t\t\"reset obex ttyGS%d\\n\", obex-\u003eport_num);\ndrivers/usb/gadget/function/f_obex.c-208-\t\t\tgserial_disconnect(\u0026obex-\u003eport);\n--\ndrivers/usb/gadget/function/f_obex.c-212-\t\t\tdev_dbg(\u0026cdev-\u003egadget-\u003edev,\ndrivers/usb/gadget/function/f_obex.c:213:\t\t\t\t\"init obex ttyGS%d\\n\", obex-\u003eport_num);\ndrivers/usb/gadget/function/f_obex.c-214-\t\t\tif (config_ep_by_speed(cdev-\u003egadget, f,\n--\ndrivers/usb/gadget/function/f_obex.c-225-\t\t\tdev_dbg(\u0026cdev-\u003egadget-\u003edev,\ndrivers/usb/gadget/function/f_obex.c:226:\t\t\t\t\"activate obex ttyGS%d\\n\", obex-\u003eport_num);\ndrivers/usb/gadget/function/f_obex.c-227-\t\t\tgserial_connect(\u0026obex-\u003eport, obex-\u003eport_num);\n--\ndrivers/usb/gadget/function/f_obex.c=248=static void obex_disable(struct usb_function *f)\n--\ndrivers/usb/gadget/function/f_obex.c-252-\ndrivers/usb/gadget/function/f_obex.c:253:\tdev_dbg(\u0026cdev-\u003egadget-\u003edev, \"obex ttyGS%d disable\\n\", obex-\u003eport_num);\ndrivers/usb/gadget/function/f_obex.c-254-\tgserial_disconnect(\u0026obex-\u003eport);\n--\ndrivers/usb/gadget/function/f_obex.c=259=static void obex_connect(struct gserial *g)\n--\ndrivers/usb/gadget/function/f_obex.c-267-\t\tdev_dbg(\u0026cdev-\u003egadget-\u003edev,\ndrivers/usb/gadget/function/f_obex.c:268:\t\t\t\"obex ttyGS%d function activate --\u003e %d\\n\",\ndrivers/usb/gadget/function/f_obex.c-269-\t\t\tobex-\u003eport_num, status);\n--\ndrivers/usb/gadget/function/f_obex.c=272=static void obex_disconnect(struct gserial *g)\n--\ndrivers/usb/gadget/function/f_obex.c-280-\t\tdev_dbg(\u0026cdev-\u003egadget-\u003edev,\ndrivers/usb/gadget/function/f_obex.c:281:\t\t\t\"obex ttyGS%d function deactivate --\u003e %d\\n\",\ndrivers/usb/gadget/function/f_obex.c-282-\t\t\tobex-\u003eport_num, status);\n--\ndrivers/usb/gadget/function/f_obex.c=302=static int obex_bind(struct usb_configuration *c, struct usb_function *f)\n--\ndrivers/usb/gadget/function/f_obex.c-367-\ndrivers/usb/gadget/function/f_obex.c:368:\tdev_dbg(\u0026cdev-\u003egadget-\u003edev, \"obex ttyGS%d: IN/%s OUT/%s\\n\",\ndrivers/usb/gadget/function/f_obex.c-369-\t\tobex-\u003eport_num,\n--\ndrivers/usb/gadget/function/f_serial.c=146=static int gser_set_alt(struct usb_function *f, unsigned intf, unsigned alt)\n--\ndrivers/usb/gadget/function/f_serial.c-154-\t\tdev_dbg(\u0026cdev-\u003egadget-\u003edev,\ndrivers/usb/gadget/function/f_serial.c:155:\t\t\t\"reset generic ttyGS%d\\n\", gser-\u003eport_num);\ndrivers/usb/gadget/function/f_serial.c-156-\t\tgserial_disconnect(\u0026gser-\u003eport);\n--\ndrivers/usb/gadget/function/f_serial.c-159-\t\tdev_dbg(\u0026cdev-\u003egadget-\u003edev,\ndrivers/usb/gadget/function/f_serial.c:160:\t\t\t\"activate generic ttyGS%d\\n\", gser-\u003eport_num);\ndrivers/usb/gadget/function/f_serial.c-161-\t\tif (config_ep_by_speed(cdev-\u003egadget, f, gser-\u003eport.in) ||\n--\ndrivers/usb/gadget/function/f_serial.c=172=static void gser_disable(struct usb_function *f)\n--\ndrivers/usb/gadget/function/f_serial.c-177-\tdev_dbg(\u0026cdev-\u003egadget-\u003edev,\ndrivers/usb/gadget/function/f_serial.c:178:\t\t\"generic ttyGS%d deactivated\\n\", gser-\u003eport_num);\ndrivers/usb/gadget/function/f_serial.c-179-\tgserial_disconnect(\u0026gser-\u003eport);\n--\ndrivers/usb/gadget/function/f_serial.c=186=static int gser_bind(struct usb_configuration *c, struct usb_function *f)\n--\ndrivers/usb/gadget/function/f_serial.c-238-\t\tgoto fail;\ndrivers/usb/gadget/function/f_serial.c:239:\tdev_dbg(\u0026cdev-\u003egadget-\u003edev, \"generic ttyGS%d: IN/%s OUT/%s\\n\",\ndrivers/usb/gadget/function/f_serial.c-240-\t\tgser-\u003eport_num,\n--\ndrivers/usb/gadget/function/u_serial.c-39- * \"serial port\" functionality through the USB gadget stack. Each such\ndrivers/usb/gadget/function/u_serial.c:40: * port is exposed through a /dev/ttyGS* node.\ndrivers/usb/gadget/function/u_serial.c-41- *\n--\ndrivers/usb/gadget/function/u_serial.c-49- * A given TTY port can be made available in multiple configurations.\ndrivers/usb/gadget/function/u_serial.c:50: * For example, each one might expose a ttyGS0 node which provides a\ndrivers/usb/gadget/function/u_serial.c-51- * login application. In one case that might use CDC ACM interface 0,\n--\ndrivers/usb/gadget/function/u_serial.c-56- * Configurations may expose more than one TTY port. For example, if\ndrivers/usb/gadget/function/u_serial.c:57: * ttyGS0 provides login service, then ttyGS1 might provide dialer access\ndrivers/usb/gadget/function/u_serial.c:58: * for a telephone or fax link. And ttyGS2 might be something that just\ndrivers/usb/gadget/function/u_serial.c-59- * needs a simple byte stream interface for some messaging protocol that\n--\ndrivers/usb/gadget/function/u_serial.c=256=__acquires(\u0026port-\u003eport_lock)\n--\ndrivers/usb/gadget/function/u_serial.c-288-\ndrivers/usb/gadget/function/u_serial.c:289:\t\tpr_vdebug(\"ttyGS%d: tx len=%d, %3ph ...\\n\", port-\u003eport_num, len, req-\u003ebuf);\ndrivers/usb/gadget/function/u_serial.c-290-\n\n"
} |
| 11/2 | 2026/10/02 19:11 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 14587 output: 30 thoughts: 1511 Thoughts: **Analyzing the USB Gadget Serial Driver Patch** Alright, let's dive into this patch for `drivers/usb/gadget/function/u_serial.c`. I see a significant reworking of the lifecycle and reference counting within the `u_serial` module. This is interesting. First, I note the addition of `open_close_failures` to `struct gs_port` and the `reserved` boolean within the `ports` array. These are clearly intended to manage port state and track potential errors during open/close operations. The implementation of `gs_install` and `gs_cleanup` tty operations, and more importantly, `gs_port_destruct` really catches my eye as a potential minefield. I'm seeing new lifecycle hooks being added. The changes in `gs_open` and `gs_close`, particularly around `open_close_failures`, suggest a more robust handling of open failures. It is important to notice the interactions with the tty core. The `gs_port_destruct` function is the destructor for the `tty_port` operations. The inclusion of `WARN_ON` macros here and within `gs_port_alloc` is a clear indication that the developers are aware of potential concurrency issues. I immediately recognize these as attempts to protect against double-frees, use-after-frees, or other memory corruption vulnerabilities, all of which are very concerning. The locking strategy with the `ports[port_num].lock` mutex is critical here. It is important to know if these are being used correctly! The changes in `gserial_free_port` and `gserial_free_line` reveal modifications to reference counting and the order of device unregistration, with a `tty_port_put(&port->port)` call replacing `tty_port_destroy`. The order change with `gserial_free_line` seems like it is a fix for a potential race. The new logic in `gserial_alloc_line_no_console` regarding port allocation and error handling further cements this focus on robust resource management. In essence, this patch introduces: * New assertions using `WARN_ON` and `WARN_ON_ONCE` to catch potential errors. * New lifecycle hooks: `gs_install`, `gs_cleanup`, and `gs_port_destruct` for proper object management. * State transition tracking with `reserved` and `open_close_failures`. * A shift to reference counting using `tty_port_get`/`tty_port_put`, which is an attempt to deal with the existing bugs. * Changes to locking and device unregistration order, which are likely aimed at fixing race conditions. My immediate question is about the reachability of this code in standard fuzzing environments. Can we actually trigger this code with syzkaller or other automated tools? Since the `u_serial` driver is selected by several configfs-related options like `CONFIG_USB_CONFIGFS_SERIAL`, `CONFIG_USB_G_SERIAL`, etc. and with `CONFIG_USB_DUMMY_HCD` or `CONFIG_USB_RAW_GADGET`, the answer is a resounding *yes*! My experience shows that these are quite regularly set up by syzkaller. Specifically, the use of USB gadget via configfs, which is common in syzkaller, will create `/dev/ttyGS0`, triggering execution of `gs_install`, `gs_open`, `gs_close`, and `gs_cleanup`. Furthermore, syzkaller tests often involve opening, reading, writing, and doing ioctls on `/dev/ttyGS%d` devices and destroying gadgets via configfs (e.g., `rmdir`). These tests concurrently exercise `gserial_free_line`, `gserial_free_port`, `gs_port_destruct`, `gs_install`, `gs_cleanup`, `gs_open`, and `gs_close`. That is very important, because it highlights the concurrent nature of these operations. The comment about `open_close_failures` is particularly relevant. The complex synchronization and lifetime management between tty core, port open/close, and gadget destruction, especially, is now a prime target for concurrency races and potential assertion failures. I'm going to want to focus testing efforts there. I must confirm these assumptions by checking the Kconfig dependencies in detail. |
| 12/2 | 2026/10/02 19:12 | tool | grepper |
0mArgs:{
"Expression": "USB_CONFIGFS",
"PathPrefix": "drivers/usb/gadget"
}Results: {
"Output": "drivers/usb/gadget/Kconfig=223=config USB_F_TCM\n--\ndrivers/usb/gadget/Kconfig-227-\ndrivers/usb/gadget/Kconfig:228:config USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-229-\ttristate \"USB Gadget functions configurable through configfs\"\n--\ndrivers/usb/gadget/Kconfig-239-\ndrivers/usb/gadget/Kconfig:240:config USB_CONFIGFS_SERIAL\ndrivers/usb/gadget/Kconfig-241-\tbool \"Generic serial bulk in/out\"\ndrivers/usb/gadget/Kconfig:242:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-243-\tdepends on TTY\n--\ndrivers/usb/gadget/Kconfig-248-\ndrivers/usb/gadget/Kconfig:249:config USB_CONFIGFS_ACM\ndrivers/usb/gadget/Kconfig-250-\tbool \"Abstract Control Model (CDC ACM)\"\ndrivers/usb/gadget/Kconfig:251:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-252-\tdepends on TTY\n--\ndrivers/usb/gadget/Kconfig-258-\ndrivers/usb/gadget/Kconfig:259:config USB_CONFIGFS_OBEX\ndrivers/usb/gadget/Kconfig-260-\tbool \"Object Exchange Model (CDC OBEX)\"\ndrivers/usb/gadget/Kconfig:261:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-262-\tdepends on TTY\n--\ndrivers/usb/gadget/Kconfig-268-\ndrivers/usb/gadget/Kconfig:269:config USB_CONFIGFS_NCM\ndrivers/usb/gadget/Kconfig-270-\tbool \"Network Control Model (CDC NCM)\"\ndrivers/usb/gadget/Kconfig:271:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-272-\tdepends on NET\n--\ndrivers/usb/gadget/Kconfig-280-\ndrivers/usb/gadget/Kconfig:281:config USB_CONFIGFS_ECM\ndrivers/usb/gadget/Kconfig-282-\tbool \"Ethernet Control Model (CDC ECM)\"\ndrivers/usb/gadget/Kconfig:283:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-284-\tdepends on NET\n--\ndrivers/usb/gadget/Kconfig-292-\ndrivers/usb/gadget/Kconfig:293:config USB_CONFIGFS_ECM_SUBSET\ndrivers/usb/gadget/Kconfig-294-\tbool \"Ethernet Control Model (CDC ECM) subset\"\ndrivers/usb/gadget/Kconfig:295:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-296-\tdepends on NET\n--\ndrivers/usb/gadget/Kconfig-302-\ndrivers/usb/gadget/Kconfig:303:config USB_CONFIGFS_RNDIS\ndrivers/usb/gadget/Kconfig-304-\tbool \"RNDIS\"\ndrivers/usb/gadget/Kconfig:305:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-306-\tdepends on NET\n--\ndrivers/usb/gadget/Kconfig-318-\ndrivers/usb/gadget/Kconfig:319:config USB_CONFIGFS_EEM\ndrivers/usb/gadget/Kconfig-320-\tbool \"Ethernet Emulation Model (EEM)\"\ndrivers/usb/gadget/Kconfig:321:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-322-\tdepends on NET\n--\ndrivers/usb/gadget/Kconfig-334-\ndrivers/usb/gadget/Kconfig:335:config USB_CONFIGFS_PHONET\ndrivers/usb/gadget/Kconfig-336-\tbool \"Phonet protocol\"\ndrivers/usb/gadget/Kconfig:337:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-338-\tdepends on NET\n--\ndrivers/usb/gadget/Kconfig-344-\ndrivers/usb/gadget/Kconfig:345:config USB_CONFIGFS_MASS_STORAGE\ndrivers/usb/gadget/Kconfig-346-\tbool \"Mass storage\"\ndrivers/usb/gadget/Kconfig:347:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-348-\tdepends on BLOCK\n--\ndrivers/usb/gadget/Kconfig-355-\ndrivers/usb/gadget/Kconfig:356:config USB_CONFIGFS_F_LB_SS\ndrivers/usb/gadget/Kconfig-357-\tbool \"Loopback and sourcesink function (for testing)\"\ndrivers/usb/gadget/Kconfig:358:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-359-\tselect USB_F_SS_LB\n--\ndrivers/usb/gadget/Kconfig-368-\ndrivers/usb/gadget/Kconfig:369:config USB_CONFIGFS_F_FS\ndrivers/usb/gadget/Kconfig-370-\tbool \"Function filesystem (FunctionFS)\"\ndrivers/usb/gadget/Kconfig:371:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-372-\tselect USB_F_FS\n--\ndrivers/usb/gadget/Kconfig-380-\ndrivers/usb/gadget/Kconfig:381:config USB_CONFIGFS_F_UAC1\ndrivers/usb/gadget/Kconfig-382-\tbool \"Audio Class 1.0\"\ndrivers/usb/gadget/Kconfig:383:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-384-\tdepends on SND\n--\ndrivers/usb/gadget/Kconfig-398-\ndrivers/usb/gadget/Kconfig:399:config USB_CONFIGFS_F_UAC1_LEGACY\ndrivers/usb/gadget/Kconfig-400-\tbool \"Audio Class 1.0 (legacy implementation)\"\ndrivers/usb/gadget/Kconfig:401:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-402-\tdepends on SND\n--\ndrivers/usb/gadget/Kconfig-411-\ndrivers/usb/gadget/Kconfig:412:config USB_CONFIGFS_F_UAC2\ndrivers/usb/gadget/Kconfig-413-\tbool \"Audio Class 2.0\"\ndrivers/usb/gadget/Kconfig:414:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-415-\tdepends on SND\n--\ndrivers/usb/gadget/Kconfig-430-\ndrivers/usb/gadget/Kconfig:431:config USB_CONFIGFS_F_MIDI\ndrivers/usb/gadget/Kconfig-432-\tbool \"MIDI function\"\ndrivers/usb/gadget/Kconfig:433:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-434-\tdepends on SND\n--\ndrivers/usb/gadget/Kconfig-444-\ndrivers/usb/gadget/Kconfig:445:config USB_CONFIGFS_F_MIDI2\ndrivers/usb/gadget/Kconfig-446-\tbool \"MIDI 2.0 function\"\ndrivers/usb/gadget/Kconfig:447:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-448-\tdepends on SND\n--\ndrivers/usb/gadget/Kconfig-457-\ndrivers/usb/gadget/Kconfig:458:config USB_CONFIGFS_F_HID\ndrivers/usb/gadget/Kconfig-459-\tbool \"HID function\"\ndrivers/usb/gadget/Kconfig:460:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-461-\tselect USB_F_HID\n--\ndrivers/usb/gadget/Kconfig-467-\ndrivers/usb/gadget/Kconfig:468:config USB_CONFIGFS_F_UVC\ndrivers/usb/gadget/Kconfig-469-\tbool \"USB Webcam function\"\ndrivers/usb/gadget/Kconfig:470:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-471-\tdepends on VIDEO_DEV\n--\ndrivers/usb/gadget/Kconfig-480-\ndrivers/usb/gadget/Kconfig:481:config USB_CONFIGFS_F_PRINTER\ndrivers/usb/gadget/Kconfig-482-\tbool \"Printer function\"\ndrivers/usb/gadget/Kconfig-483-\tselect USB_F_PRINTER\ndrivers/usb/gadget/Kconfig:484:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-485-\thelp\n--\ndrivers/usb/gadget/Kconfig-494-\ndrivers/usb/gadget/Kconfig:495:config USB_CONFIGFS_F_TCM\ndrivers/usb/gadget/Kconfig-496-\tbool \"USB Gadget Target Fabric\"\ndrivers/usb/gadget/Kconfig-497-\tdepends on TARGET_CORE\ndrivers/usb/gadget/Kconfig:498:\tdepends on USB_CONFIGFS\ndrivers/usb/gadget/Kconfig-499-\tselect USB_LIBCOMPOSITE\n"
} |
| 13/2 | 2026/10/02 19:12 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 19470 output: 39 thoughts: 1480 Thoughts: **Fuzzing Target Identification** Okay, let's break this down. First, I need to confirm the configuration space. I'm thinking, let's make sure the relevant USB gadget configurations are set. Specifically, I'm checking dependencies for `USB_CONFIGFS` which, as expected, depends on `USB_GADGET`. Then, I'm noting that `USB_CONFIGFS_SERIAL` (or `USB_CONFIGFS_ACM`) selects `USB_U_SERIAL`, as does `USB_G_SERIAL`. Since I want a full emulation for testing, I'll confirm that `CONFIG_USB_DUMMY_HCD` (software-emulated host and gadget controller) is available for virtualized environments like QEMU. Combining those, with `CONFIG_USB_GADGET`, `CONFIG_USB_CONFIGFS`, `CONFIG_USB_CONFIGFS_SERIAL` (or `CONFIG_USB_CONFIGFS_ACM` or `CONFIG_USB_G_SERIAL`), and `CONFIG_USB_DUMMY_HCD`, I can achieve a complete software-emulated USB gadget environment. I want to see if `USB_U_SERIAL` can be enabled directly or via configs. It is selected by a number of configs, including `USB_CONFIGFS_SERIAL`, `USB_CONFIGFS_ACM`, and `USB_G_SERIAL`, which are common in syzkaller. Now, considering the patch in question, I have to determine if this is a suitable target for fuzzing. I'll evaluate based on established guidelines. Key indicators for fuzzing targets include "Refactorings and Code Cleanups" touching reachable data structures, helper abstractions, or algorithm flows; "Runtime Assertions and Defensive Checks", involving the introduction or alteration of assertions; and "Reachable Drivers and Protocols", specifically mentioning USB gadget drivers as examples of reachability. This is where the core lies. This patch, crucially, modifies tty operations and introduces several assertions and changes locking semantics! Specifically, it introduces or modifies the following: * `gs_install`, `gs_cleanup`, `gs_open`, and `gs_close`. * A destructor `gs_port_destruct` for `tty_port_operations`. * Multiple `WARN_ON` / `WARN_ON_ONCE` assertions. * Changes to locking and reference counting via `tty_port_get`, `tty_port_put`, and aggregation credits. * Changes to the order of operations concerning `tty_unregister_device` and `gserial_free_port`. These changes clearly indicate `WorthFuzzing = true`. Now, I need to define the `FocusSymbols`. Let's identify the modified/added functions: `gs_install`, `gs_cleanup`, `gs_open`, `gs_close`, `gs_port_destruct`, `gs_port_alloc`, `gserial_free_port`, `gserial_free_line`, and `gserial_alloc_line_no_console`. The question becomes, which of these are actually exposed? `gs_install`, `gs_cleanup`, `gs_open`, and `gs_close` are part of `gs_tty_ops` and assigned to function pointers: they will not be inlined and are likely to have a symbol. Similarly, `gs_port_destruct` is assigned to `gs_port_ops.destruct` and will have a symbol. Moreover, `gserial_free_line` and `gserial_alloc_line_no_console` are `EXPORT_SYMBOL_GPL`. I will also check where `gserial_free_port` and `gs_port_alloc` are called to be certain about their reachability. I believe these are good candidates for fuzzing. |
| 14/2 | 2026/10/02 19:12 | tool | grepper |
0mArgs:{
"Expression": "gs_port_alloc",
"PathPrefix": "drivers/usb/gadget/function/u_serial.c"
}Results: {
"Output": "drivers/usb/gadget/function/u_serial.c=1302=static struct gs_port *\ndrivers/usb/gadget/function/u_serial.c:1303:gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding)\ndrivers/usb/gadget/function/u_serial.c-1304-{\n--\ndrivers/usb/gadget/function/u_serial.c=1388=int gserial_alloc_line_no_console(unsigned char *line_num)\n--\ndrivers/usb/gadget/function/u_serial.c-1401-\tfor (port_num = 0; port_num \u003c MAX_U_SERIAL_PORTS; port_num++) {\ndrivers/usb/gadget/function/u_serial.c:1402:\t\tport = gs_port_alloc(port_num, \u0026coding);\ndrivers/usb/gadget/function/u_serial.c-1403-\t\tif (IS_ERR(port)) {\n"
} |
| 15/2 | 2026/10/02 19:12 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 22068 output: 40 thoughts: 12 Thoughts: Okay, here's my take on those thoughts, tailored for an expert audience: **Analyzing the `gserial_free_port` Function** Alright, let's dive in. My immediate thought is to examine the `gserial_free_port` function. It's the lynchpin, the place where resources are released, and it’s critical for ensuring we don't leak memory or leave the system in a corrupted state. I want to understand its exact purpose and how it interacts with other modules, especially regarding potential race conditions or locking mechanisms it might use. I will evaluate the function's internal logic, considering how it handles the different scenarios such as port open/close states, ownership, and whether it properly releases all allocated structures like buffers or control blocks. I'll need to look at its interactions with any device-specific drivers, to see if there's potential for inconsistencies between the generic serial implementation and lower-level hardware operations. A close review of any error handling within the function is crucial, to see if there are missing or inadequate error paths that could lead to unexpected behavior or resource leaks. Overall, I need to confirm its robustness and correctness, particularly concerning memory management, locking, and proper deallocation of serial port resources. |
| 16/2 | 2026/10/02 19:12 | tool | grepper |
0mArgs:{
"Expression": "gserial_free_port",
"PathPrefix": "drivers/usb/gadget/function/u_serial.c"
}Results: {
"Output": "drivers/usb/gadget/function/u_serial.c=1349=static int gs_closed(struct gs_port *port)\n--\ndrivers/usb/gadget/function/u_serial.c-1359-\ndrivers/usb/gadget/function/u_serial.c:1360:static void gserial_free_port(struct gs_port *port)\ndrivers/usb/gadget/function/u_serial.c-1361-{\n--\ndrivers/usb/gadget/function/u_serial.c=1369=void gserial_free_line(unsigned char port_num)\n--\ndrivers/usb/gadget/function/u_serial.c-1383-\ttty_unregister_device(gs_tty_driver, port_num);\ndrivers/usb/gadget/function/u_serial.c:1384:\tgserial_free_port(port);\ndrivers/usb/gadget/function/u_serial.c-1385-}\n"
} |
| 17/2 | 2026/10/02 19:12 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 22636 output: 31 thoughts: 653 Thoughts: **Analyzing the Impact of the Code Changes** Okay, so `gserial_free_port` is only called by `gserial_free_line`, that's good to know. But let's get the full picture. I need to understand the scope of these changes. I see a bunch of functions have been modified or added in this diff. Let's list those out: `gs_install`, `gs_cleanup`, `gs_open`, `gs_close`, `gs_port_destruct`, `gs_port_alloc`, `gserial_free_port`, `gserial_free_line`, and `gserial_alloc_line_no_console`. This suggests a broader refactoring or feature implementation, not just a simple bug fix. And it looks like the underlying data structures, `gs_port` and `portmaster` have been updated. The addition of new operations `install`, `cleanup` and `destruct` points to a redesign around resource management. Now, let's consider the build environment. I see that `CONFIG_USB_U_SERIAL` is tristate. Tristate modules can be tricky, as they aren't always directly selectable in the menu. This prompts the question, can syzkaller influence `CONFIG_USB_U_SERIAL` through other means? I need to check the Kconfig files. Specifically, I'm trying to determine whether `syzkaller` can enable `CONFIG_USB_U_SERIAL` through setting other related configs, for example, `CONFIG_USB_CONFIGFS_SERIAL`, `CONFIG_USB_CONFIGFS_ACM`, or `CONFIG_USB_G_SERIAL`. Let's clarify, in the Linux kernel a configuration symbol like `USB_U_SERIAL` *does* exist, which can be selected using `kconfig`. The question is can `kconfig` set a symbol without a prompt, if the symbol is set in the `.config`? I know that normally symbols without prompts cannot be set unless selected (or their dependencies allow this), and that `.config` can set them directly. But, if `syzkaller` *does* enable these dependent prompt symbols, which symbols are the best to specify in `EnableConfigs`? I need to understand the dependencies of `USB_CONFIGFS_SERIAL` and `USB_CONFIGFS_ACM`. They depend on `USB_CONFIGFS` and `TTY`. `USB_CONFIGFS` itself depends on `USB_GADGET`. So I need to examine `USB_GADGET` in Kconfig to see what its dependencies are, and whether those dependencies could be enabled by `syzkaller` to indirectly enable this module. |
| 18/2 | 2026/10/02 19:12 | tool | grepper |
0mArgs:{
"Expression": "config USB_GADGET",
"PathPrefix": "drivers/usb/gadget"
}Results: {
"Output": "drivers/usb/gadget/Kconfig-16-\ndrivers/usb/gadget/Kconfig:17:menuconfig USB_GADGET\ndrivers/usb/gadget/Kconfig-18-\ttristate \"USB Gadget Support\"\n--\ndrivers/usb/gadget/Kconfig=47=if USB_GADGET\ndrivers/usb/gadget/Kconfig-48-\ndrivers/usb/gadget/Kconfig:49:config USB_GADGET_DEBUG\ndrivers/usb/gadget/Kconfig-50-\tbool \"Debugging messages (DEVELOPMENT)\"\n--\ndrivers/usb/gadget/Kconfig-62-\ndrivers/usb/gadget/Kconfig:63:config USB_GADGET_VERBOSE\ndrivers/usb/gadget/Kconfig-64-\tbool \"Verbose debugging Messages (DEVELOPMENT)\"\n--\ndrivers/usb/gadget/Kconfig-76-\ndrivers/usb/gadget/Kconfig:77:config USB_GADGET_DEBUG_FILES\ndrivers/usb/gadget/Kconfig-78-\tbool \"Debugging information files (DEVELOPMENT)\"\n--\ndrivers/usb/gadget/Kconfig-87-\ndrivers/usb/gadget/Kconfig:88:config USB_GADGET_DEBUG_FS\ndrivers/usb/gadget/Kconfig-89-\tbool \"Debugging information files in debugfs (DEVELOPMENT)\"\n--\ndrivers/usb/gadget/Kconfig-98-\ndrivers/usb/gadget/Kconfig:99:config USB_GADGET_VBUS_DRAW\ndrivers/usb/gadget/Kconfig-100-\tint \"Maximum VBUS Power usage (2-500 mA)\"\n--\ndrivers/usb/gadget/Kconfig-115-\ndrivers/usb/gadget/Kconfig:116:config USB_GADGET_STORAGE_NUM_BUFFERS\ndrivers/usb/gadget/Kconfig-117-\tint \"Number of storage pipeline buffers\"\n--\ndrivers/usb/gadget/legacy/Kconfig=190=config USB_G_NCM\n--\ndrivers/usb/gadget/legacy/Kconfig-205-\ndrivers/usb/gadget/legacy/Kconfig:206:config USB_GADGETFS\ndrivers/usb/gadget/legacy/Kconfig-207-\ttristate \"Gadget Filesystem\"\n--\ndrivers/usb/gadget/legacy/Kconfig=262=config USB_MASS_STORAGE\n--\ndrivers/usb/gadget/legacy/Kconfig-278-\ndrivers/usb/gadget/legacy/Kconfig:279:config USB_GADGET_TARGET\ndrivers/usb/gadget/legacy/Kconfig-280-\ttristate \"USB Gadget Target Fabric Module\"\n--\ndrivers/usb/gadget/udc/Kconfig=347=config USB_EG20T\n--\ndrivers/usb/gadget/udc/Kconfig-370-\ndrivers/usb/gadget/udc/Kconfig:371:config USB_GADGET_XILINX\ndrivers/usb/gadget/udc/Kconfig-372-\ttristate \"Xilinx USB Driver\"\n"
} |
| 19/2 | 2026/10/02 19:12 | llm | patch-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 24661 output: 270 thoughts: 911 Thoughts: **Fuzzing Verdict: USB Gadget Serial (u_serial.c)** Okay, let's break this down. First, I need to confirm the relevant Kconfig options are enabled for this to be fuzzable. I need to ensure that `USB_CONFIGFS_SERIAL` or `USB_CONFIGFS_ACM` (or `USB_G_SERIAL`) are set, which in turn will enable `USB_U_SERIAL` and compile `u_serial.o` into the kernel. I also need to verify that `USB_CONFIGFS`, `USB_GADGET`, and `TTY` are enabled and consider the need for virtualized environments, which I understand requires `USB_DUMMY_HCD` or `USB_RAW_GADGET`. So, my `EnableConfigs` list needs to include "USB_GADGET", "USB_CONFIGFS", "USB_CONFIGFS_SERIAL", "USB_CONFIGFS_ACM", and "USB_U_SERIAL". Next, I need to ensure the `FocusSymbols` are relevant. I've reviewed those symbols and they appear specific to the USB gadget serial utility (`u_serial.c`) and are not ubiquitous functions. Moreover, it appears they are either altered or added by the patch: `gs_install`, `gs_cleanup`, `gs_open`, `gs_close`, `gs_port_destruct`, `gs_port_alloc`, `gserial_free_port`, `gserial_free_line`, and `gserial_alloc_line_no_console`. The reasoning looks sound. This patch refactors the lifecycle management, open/close failure accounting, and tty_port reference counting in `u_serial.c`. It introduces new tty driver operations, a `tty_port_operations` destructor, alters open and close logic, and adds new assertions. These code paths *are* fully reachable in virtualized environments via USB gadget configfs (CDC ACM or generic serial over dummy_hcd) and exposed through the `/dev/ttyGS*` character devices. Specifically, concurrency issues between open/close and gadget tear-down *could* trigger latent races or the new assertions. This makes fuzzing warranted. Given all of this, I'm confident in the analysis. Let's call `set-results`. |
| 20/2 | 2026/10/02 19:12 | tool | set-results |
0mArgs:{
"EnableConfigs": [
"USB_GADGET",
"USB_CONFIGFS",
"USB_CONFIGFS_SERIAL",
"USB_CONFIGFS_ACM",
"USB_U_SERIAL"
],
"FocusSymbols": [
"gs_install",
"gs_cleanup",
"gs_open",
"gs_close",
"gs_port_destruct",
"gs_port_alloc",
"gserial_free_port",
"gserial_free_line",
"gserial_alloc_line_no_console"
],
"Reasoning": "The patch reworks the lifetime, reference counting, and open/close state tracking for USB gadget serial devices (u_serial.c), introducing new tty driver operations (gs_install, gs_cleanup), a tty_port destructor (gs_port_destruct), and multiple WARN_ON assertions. The code is reachable in standard virtualized fuzzing setups via USB gadget configfs (e.g. using dummy_hcd) and accessible via /dev/ttyGS* device nodes. The concurrency between device teardown and concurrent TTY open/close calls makes this a high-value target for fuzzing.",
"WorthFuzzing": true
}Results: {
"EnableConfigs": [
"USB_GADGET",
"USB_CONFIGFS",
"USB_CONFIGFS_SERIAL",
"USB_CONFIGFS_ACM",
"USB_U_SERIAL"
],
"FocusSymbols": [
"gs_install",
"gs_cleanup",
"gs_open",
"gs_close",
"gs_port_destruct",
"gs_port_alloc",
"gserial_free_port",
"gserial_free_line",
"gserial_alloc_line_no_console"
],
"Reasoning": "The patch reworks the lifetime, reference counting, and open/close state tracking for USB gadget serial devices (u_serial.c), introducing new tty driver operations (gs_install, gs_cleanup), a tty_port destructor (gs_port_destruct), and multiple WARN_ON assertions. The code is reachable in standard virtualized fuzzing setups via USB gadget configfs (e.g. using dummy_hcd) and accessible via /dev/ttyGS* device nodes. The concurrency between device teardown and concurrent TTY open/close calls makes this a high-value target for fuzzing.",
"WorthFuzzing": true
} |
| 21/1 | 2026/10/02 19:12 | action | If |
0mArgs:{
"WorthFuzzing": true
}Results: null |
| 22/2 | 2026/10/02 19:12 | agent | kmsan-evaluator |
0mModel:core Args: null Results: {
"KMSANReasoning": "The patch modifies the USB gadget serial driver (`u_serial.c`) to fix lifecycle and reference-counting issues between the TTY core and the gadget driver. It introduces `gs_install()`, `gs_cleanup()`, `gs_port_destruct()`, and tracks open failure counts (`open_close_failures`) and port slot reservations (`reserved`).\n\nAll modified and newly added struct fields belong either to `struct gs_port` (which is allocated with `kzalloc_obj`, ensuring zero-initialization) or to `struct portmaster` (which is stored in the zero-initialized static array `ports[]`). No uninitialized stack or heap variables are read, no buffer lengths or bounds are altered, and no kernel data is exposed or copied to user space. \n\nPotential defects in this patch involve object lifetimes, reference counting, use-after-free, or concurrency issues, which are covered by KASAN, LOCKDEP, and standard kernel runtime assertions. There is no risk of uninitialized memory usage, so a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Instruction: You are an expert Linux kernel security engineer specializing in kernel memory
error detectors (KASAN and KMSAN). Your job is to review the provided patch series and
determine if the code changes justify spawning a dedicated KMSAN (KernelMemorySanitizer)
fuzzing session in addition to standard KASAN fuzzing.
CRITICAL DISTINCTION BETWEEN KASAN AND KMSAN:
- Standard KASAN kernel builds (upstream-apparmor-kasan.config) already enable
a comprehensive suite of debugging tools and sanitizers, including KASAN
(out-of-bounds accesses, use-after-free, double free, invalid free), LOCKDEP
(locking bugs and deadlocks), UB-sanitizers, and memory corruption checks.
- KMSAN (KernelMemorySanitizer) detects reads of UNINITIALIZED memory (stack, heap,
or page allocations) and kernel-to-user memory info-leaks.
Rule: THERE IS NO SENSE IN RUNNING A KMSAN SESSION IF A BUG CAN BE CAUGHT BY KASAN,
LOCKDEP, OR OTHER STANDARD BUG DETECTORS.
A dedicated KMSAN fuzzing session incurs significant resource costs. You must ONLY
set NeedsKMSAN=true if the code changes introduce or expose UNINITIALIZED MEMORY risks
that are detected ONLY by KMSAN.
Look holistically at the patch series and surrounding code. Even if no direct
uninitialized field accesses or new buffer allocations are added in the diff itself,
a patch may alter control flow, bounds checking, or data length calculations in ways
that change how the rest of the code operates on existing buffers (e.g. allowing
uninitialized stack/heap memory to be read, copied to user space, or used in control
flow). Do not hesitate to use your code access tools to inspect the surrounding code,
called functions, and callers.
Set NeedsKMSAN=true ONLY IF the patch introduces or modifies:
1. Kernel structures sent to user space (via copy_to_user, put_user, netlink skb
attributes, ioctl output arguments, socket options, or BPF buffers) where fields
or structure padding might not be fully initialized/zeroed.
2. Conditional logic or branching that depends on potentially uninitialized variables
or struct fields.
3. Allocation or initialization of complex data structures where uninitialized fields
could be read later in reachable code paths.
4. Bounds checks, lengths, or logic in a way that allows surrounding code to access
uninitialized bytes of existing buffers.
Set NeedsKMSAN=false IF:
- The code changes primarily risk out-of-bounds access, array overflows, NULL pointer
dereferences, locking deadlocks, or use-after-free bugs (these are already caught
by KASAN, LOCKDEP, or standard bug detectors).
- All stack/heap structures touched or introduced by the patch are fully zeroed
or initialized (e.g. using = {0}, memset, kzalloc) before being read or copied.
- The patch does not introduce any risk of uninitialized memory usage or info-leaks.
Use your code access tools to inspect the surrounding code if necessary, then provide
detailed KMSANReasoning contrasting KASAN vs KMSAN applicability for this patch.
Prefer calling several tools at the same time to save round-trips.
Use set-results tool to provide results of the analysis.
It must be called exactly once before the final reply.
Ignore results of this tool.
Prompt: Target architecture: amd64
For your convenience, here is the diff of the changes:
commit d78810d9105851f29f9806c00f32094f2cf88a46
Author: syz-cluster <triage@syzkaller.com>
Date: Fri Oct 2 19:11:06 2026 +0000
syz-cluster: applied patch under review
diff --git a/drivers/usb/gadget/function/u_serial.c b/drivers/usb/gadget/function/u_serial.c
index cdd1dfc666c4f..aaad06fa5d050 100644
--- a/drivers/usb/gadget/function/u_serial.c
+++ b/drivers/usb/gadget/function/u_serial.c
@@ -70,10 +70,28 @@
* gserial->ioport == usb_ep->driver_data ... gs_port
* gs_port->port_usb ... gserial
*
- * gs_port <---> tty_struct ... links will be null when the TTY file
- * isn't opened; managed by gs_open()/gs_close()
- * gserial->port_tty ... tty_struct
- * tty_struct->driver_data ... gserial
+ * gs_port <---> tty_struct:
+ * tty->driver_data refers to gs_port from install through cleanup,
+ * pinning the port via tty_port reference counting.
+ * gs_port->port.tty exists only while the port is open.
+ *
+ * Each entry in ports[] is guarded by ports[i].lock and models three states:
+ * - Free: !port && !reserved
+ * - Published: port && reserved
+ * - Retiring or device registration in progress: !port && reserved
+ *
+ * A minor remains reserved until gs_port_destruct() runs upon final tty_port
+ * release, preventing minor reuse while cleanup or termios saving is still
+ * underway. The owner reference is retained through device unregister so the
+ * destructor releases the reservation only after device teardown is complete.
+ *
+ * open_close_failures tracks failed gs_open() calls where port->port.count
+ * was not incremented. The TTY core calls gs_close() on open failure to tear
+ * down the tty; tracking failures as aggregate credits allows gs_close() to
+ * consume a credit and exit without decrementing port->port.count. Credits
+ * are aggregate rather than paired with individual files (another gs_close()
+ * can consume a failed open's credit before that file's own close runs).
+ * It is protected by tty_lock.
*/
/* RX and TX queues can buffer QUEUE_SIZE packets before they hit the
@@ -128,6 +146,7 @@ struct gs_port {
wait_queue_head_t close_wait;
bool suspended; /* port suspended */
bool start_delayed; /* delay start when suspended */
+ unsigned int open_close_failures; /* protected by tty_lock */
struct async_icount icount;
/* REVISIT this state ... */
@@ -135,8 +154,9 @@ struct gs_port {
};
static struct portmaster {
- struct mutex lock; /* protect open/close */
+ struct mutex lock; /* protect open/close and port slot */
struct gs_port *port;
+ bool reserved;
} ports[MAX_U_SERIAL_PORTS];
#define GS_CLOSE_TIMEOUT 15 /* seconds */
@@ -603,22 +623,63 @@ static int gserial_wakeup_host(struct gserial *gser)
/* TTY Driver */
+static int gs_install(struct tty_driver *driver, struct tty_struct *tty)
+{
+ struct gs_port *port;
+ struct tty_port *tport;
+ int ret;
+
+ mutex_lock(&ports[tty->index].lock);
+ port = ports[tty->index].port;
+ if (!port) {
+ mutex_unlock(&ports[tty->index].lock);
+ return -ENODEV;
+ }
+
+ tport = tty_port_get(&port->port);
+ if (!tport) {
+ mutex_unlock(&ports[tty->index].lock);
+ return -ENODEV;
+ }
+
+ ret = tty_port_install(tport, driver, tty);
+ if (ret) {
+ mutex_unlock(&ports[tty->index].lock);
+ tty_port_put(tport);
+ return ret;
+ }
+
+ tty->driver_data = port;
+ mutex_unlock(&ports[tty->index].lock);
+
+ return 0;
+}
+
+static void gs_cleanup(struct tty_struct *tty)
+{
+ tty_port_put(tty->port);
+}
+
/*
- * gs_open sets up the link between a gs_port and its associated TTY.
- * That link is broken *only* by TTY close(), and all driver methods
- * know that.
+ * gs_open associates an open TTY with its gs_port.
+ *
+ * There are two TTY-to-port relationships: port->port.tty exists from the
+ * first successful open until final close, while tty->driver_data is assigned
+ * during gs_install() and remains valid through gs_cleanup().
*/
static int gs_open(struct tty_struct *tty, struct file *file)
{
int port_num = tty->index;
- struct gs_port *port;
+ struct gs_port *port = tty->driver_data;
int status = 0;
+ if (!port)
+ return -ENODEV;
+
mutex_lock(&ports[port_num].lock);
- port = ports[port_num].port;
- if (!port) {
+ if (ports[port_num].port != port) {
status = -ENODEV;
- goto out;
+ goto fail_unlock;
}
spin_lock_irq(&port->port_lock);
@@ -638,7 +699,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
if (status) {
pr_debug("gs_open: ttyGS%d (%p,%p) no buffer\n",
port_num, tty, file);
- goto out;
+ goto fail_unlock;
}
spin_lock_irq(&port->port_lock);
@@ -648,7 +709,6 @@ static int gs_open(struct tty_struct *tty, struct file *file)
if (port->port.count++)
goto exit_unlock_port;
- tty->driver_data = port;
port->port.tty = tty;
/* if connected, start the I/O stream */
@@ -672,7 +732,11 @@ static int gs_open(struct tty_struct *tty, struct file *file)
exit_unlock_port:
spin_unlock_irq(&port->port_lock);
-out:
+ mutex_unlock(&ports[port_num].lock);
+ return status;
+
+fail_unlock:
+ port->open_close_failures++;
mutex_unlock(&ports[port_num].lock);
return status;
}
@@ -695,6 +759,14 @@ static void gs_close(struct tty_struct *tty, struct file *file)
struct gs_port *port = tty->driver_data;
struct gserial *gser;
+ if (!port)
+ return;
+
+ if (port->open_close_failures > 0) {
+ port->open_close_failures--;
+ return;
+ }
+
spin_lock_irq(&port->port_lock);
if (port->port.count != 1) {
@@ -909,8 +981,10 @@ static int gs_get_icount(struct tty_struct *tty,
}
static const struct tty_operations gs_tty_ops = {
+ .install = gs_install,
.open = gs_open,
.close = gs_close,
+ .cleanup = gs_cleanup,
.write = gs_write,
.put_char = gs_put_char,
.flush_chars = gs_flush_chars,
@@ -1203,14 +1277,41 @@ static void gs_console_exit(struct gs_port *port)
#endif
-static int
+static void gs_port_destruct(struct tty_port *tport)
+{
+ struct gs_port *port = container_of(tport, struct gs_port, port);
+ unsigned int port_num = port->port_num;
+
+ mutex_lock(&ports[port_num].lock);
+ if (WARN_ON(ports[port_num].port))
+ ports[port_num].port = NULL;
+ WARN_ON(!ports[port_num].reserved);
+ if (gs_tty_driver)
+ gs_tty_driver->ports[port_num] = NULL;
+ ports[port_num].reserved = false;
+ mutex_unlock(&ports[port_num].lock);
+
+ kfifo_free(&port->port_write_buf);
+ kfree(port);
+}
+
+static const struct tty_port_operations gs_port_ops = {
+ .destruct = gs_port_destruct,
+};
+
+static struct gs_port *
gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding)
{
struct gs_port *port;
int ret = 0;
mutex_lock(&ports[port_num].lock);
- if (ports[port_num].port) {
+ if (WARN_ON_ONCE(ports[port_num].port && !ports[port_num].reserved)) {
+ ret = -EBUSY;
+ goto out;
+ }
+
+ if (ports[port_num].reserved) {
ret = -EBUSY;
goto out;
}
@@ -1222,6 +1323,7 @@ gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding)
}
tty_port_init(&port->port);
+ port->port.ops = &gs_port_ops;
spin_lock_init(&port->port_lock);
init_waitqueue_head(&port->drain_wait);
init_waitqueue_head(&port->close_wait);
@@ -1235,10 +1337,13 @@ gs_port_alloc(unsigned port_num, struct usb_cdc_line_coding *coding)
port->port_num = port_num;
port->port_line_coding = *coding;
- ports[port_num].port = port;
+ ports[port_num].reserved = true;
+ mutex_unlock(&ports[port_num].lock);
+ return port;
+
out:
mutex_unlock(&ports[port_num].lock);
- return ret;
+ return ERR_PTR(ret);
}
static int gs_closed(struct gs_port *port)
@@ -1258,8 +1363,7 @@ static void gserial_free_port(struct gs_port *port)
/* wait for old opens to finish */
wait_event(port->close_wait, gs_closed(port));
WARN_ON(port->port_usb != NULL);
- tty_port_destroy(&port->port);
- kfree(port);
+ tty_port_put(&port->port);
}
void gserial_free_line(unsigned char port_num)
@@ -1276,15 +1380,15 @@ void gserial_free_line(unsigned char port_num)
ports[port_num].port = NULL;
mutex_unlock(&ports[port_num].lock);
- gserial_free_port(port);
tty_unregister_device(gs_tty_driver, port_num);
+ gserial_free_port(port);
}
EXPORT_SYMBOL_GPL(gserial_free_line);
int gserial_alloc_line_no_console(unsigned char *line_num)
{
struct usb_cdc_line_coding coding;
- struct gs_port *port;
+ struct gs_port *port = ERR_PTR(-EBUSY);
struct device *tty_dev;
int ret;
int port_num;
@@ -1295,19 +1399,20 @@ int gserial_alloc_line_no_console(unsigned char *line_num)
coding.bDataBits = USB_CDC_1_STOP_BITS;
for (port_num = 0; port_num < MAX_U_SERIAL_PORTS; port_num++) {
- ret = gs_port_alloc(port_num, &coding);
- if (ret == -EBUSY)
- continue;
- if (ret)
+ port = gs_port_alloc(port_num, &coding);
+ if (IS_ERR(port)) {
+ ret = PTR_ERR(port);
+ if (ret == -EBUSY)
+ continue;
return ret;
+ }
break;
}
- if (ret)
- return ret;
+ if (IS_ERR(port))
+ return PTR_ERR(port);
/* ... and sysfs class devices, so mdev/udev make /dev/ttyGS* */
- port = ports[port_num].port;
tty_dev = tty_port_register_device(&port->port,
gs_tty_driver, port_num, NULL);
if (IS_ERR(tty_dev)) {
@@ -1315,15 +1420,16 @@ int gserial_alloc_line_no_console(unsigned char *line_num)
__func__, port_num, PTR_ERR(tty_dev));
ret = PTR_ERR(tty_dev);
- mutex_lock(&ports[port_num].lock);
- ports[port_num].port = NULL;
- mutex_unlock(&ports[port_num].lock);
- gserial_free_port(port);
- goto err;
+ tty_port_put(&port->port);
+ return ret;
}
+
+ mutex_lock(&ports[port_num].lock);
+ ports[port_num].port = port;
+ mutex_unlock(&ports[port_num].lock);
+
*line_num = port_num;
-err:
- return ret;
+ return 0;
}
EXPORT_SYMBOL_GPL(gserial_alloc_line_no_console);
|
| 23/3 | 2026/10/02 19:12 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 5679 output: 43 thoughts: 1188 Thoughts: **KMSAN Needs Assessment: USB Gadget Serial Driver Patch** Alright, let's break this down. The core question is whether this patch, touching the USB gadget serial driver, necessitates a dedicated KMSAN fuzzing session. My job is to assess if the changes introduce uninitialized memory access risks that *only* KMSAN would catch, because let's be real, running a KMSAN session is a resource hog. If KASAN, LOCKDEP, or some other standard tool would find the bug, we don't need KMSAN. So, what does KMSAN actually look for? It's all about reading uninitialized memory, be it on the stack, heap, or within page allocations, and also kernel-to-user memory leaks. KASAN is the workhorse for out-of-bounds access, use-after-free, double-free, and bad frees. LOCKDEP handles locking issues, including deadlocks. I need to keep this in mind as I dive into the code. Now for the patch itself. The documentation update is nice, but irrelevant to our KMSAN assessment. Let's look at the structure changes, adding `open_close_failures` to `gs_port` and `reserved` to `portmaster`. The `open_close_failures` counter seems to be related to managing failed open/close attempts, and `reserved` sounds like a state flag for the portmaster. Not seeing any immediately glaring KMSAN risks here. The added functions, `gs_install` and `gs_cleanup`, are interesting. `gs_install` installs a `tty_driver` and `tty_port`, and the `gs_cleanup` call seems to be removing those, or decrementing the reference count. Again, not jumping out as an KMSAN issue. `gs_open` and `gs_close` modifications update the `open_close_failures` counter, and now `gs_open` pulls the port info using the driver data instead of referencing an external array, this is good for consistency. No KMSAN flags. Now the important one, `gs_port_destruct` and `gs_port_alloc`. `gs_port_alloc` sets `ports[port_num].reserved = true;`, so instead of putting the port on the array right away it keeps it separate to be reserved. This smells like some change in memory ownership / lifecycle management. `gs_port_destruct` is a destruction function, responsible for freeing the `gs_port` structure and related resources. It releases the port from the external array `ports[]`. The use of `kfifo_free` indicates that it's handling a FIFO buffer. No red flags here. This is looking very careful, not as if we'd be missing a KMSAN case. `gserial_free_port` and `gserial_free_line` now use `tty_port_put` instead of direct `kfree` and it might be that this refactoring is a good sign: no need to allocate a KMSAN, at first glance. `gserial_alloc_line_no_console` registers the tty_dev before publishing `ports[port_num].port = port;`, which improves the order of these operations. No KMSAN cases here. Alright, after a close examination, I don't see anything screaming "uninitialized memory access" that *only* KMSAN would detect. The patch seems to be about improving resource management, port lifecycle, and potentially fixing some race conditions or improving the error handling around port open/close failures. It is safe to say that **this patch does not justify a dedicated KMSAN fuzzing session.** The changes seem to be in the realm of memory management, ref counting, and data structure synchronization, but not in the area of exposing uninitialized memory that would be invisible to KASAN or other standard bug detectors. We can stick with our standard fuzzing setup for now. |
| 24/3 | 2026/10/02 19:13 | tool | read-file |
0mArgs:{
"File": "drivers/usb/gadget/function/u_serial.c",
"FirstLine": 1310,
"LineCount": 40
}Results: {
"Contents": "1310:\t\t\tret = -EBUSY;\n1311:\t\t\tgoto out;\n1312:\t\t}\n1313:\t\n1314:\t\tif (ports[port_num].reserved) {\n1315:\t\t\tret = -EBUSY;\n1316:\t\t\tgoto out;\n1317:\t\t}\n1318:\t\n1319:\t\tport = kzalloc_obj(struct gs_port);\n1320:\t\tif (port == NULL) {\n1321:\t\t\tret = -ENOMEM;\n1322:\t\t\tgoto out;\n1323:\t\t}\n1324:\t\n1325:\t\ttty_port_init(\u0026port-\u003eport);\n1326:\t\tport-\u003eport.ops = \u0026gs_port_ops;\n1327:\t\tspin_lock_init(\u0026port-\u003eport_lock);\n1328:\t\tinit_waitqueue_head(\u0026port-\u003edrain_wait);\n1329:\t\tinit_waitqueue_head(\u0026port-\u003eclose_wait);\n1330:\t\n1331:\t\tINIT_DELAYED_WORK(\u0026port-\u003epush, gs_rx_push);\n1332:\t\n1333:\t\tINIT_LIST_HEAD(\u0026port-\u003eread_pool);\n1334:\t\tINIT_LIST_HEAD(\u0026port-\u003eread_queue);\n1335:\t\tINIT_LIST_HEAD(\u0026port-\u003ewrite_pool);\n1336:\t\n1337:\t\tport-\u003eport_num = port_num;\n1338:\t\tport-\u003eport_line_coding = *coding;\n1339:\t\n1340:\t\tports[port_num].reserved = true;\n1341:\t\tmutex_unlock(\u0026ports[port_num].lock);\n1342:\t\treturn port;\n1343:\t\n1344:\tout:\n1345:\t\tmutex_unlock(\u0026ports[port_num].lock);\n1346:\t\treturn ERR_PTR(ret);\n1347:\t}\n1348:\t\n1349:\tstatic int gs_closed(struct gs_port *port)\n"
} |
| 25/3 | 2026/10/02 19:13 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 8294 output: 43 thoughts: 148 Thoughts: Here's my analysis of the code, presented as my internal thought process: **Analyzing Port Allocation and Initialization** Okay, let's break down how these `gs_port` structs are handled. First, I see that the `port` variable is allocated using `kzalloc_obj(struct gs_port)`. Right, that means the kernel is using `kzalloc`, which is crucial. It zero-initializes the allocated memory. This is really important because it means the `open_close_failures` member within the `gs_port` struct is going to start at zero. Good. We don't have to worry about uninitialized memory leading to unexpected behavior. Now, let's consider `ports`. It's declared as `static struct portmaster ports[MAX_U_SERIAL_PORTS]`. Ah, a static array! This puts it in the BSS (Block Started by Symbol) section of the program. Because it's static and an array of structs, it will *also* be zero-initialized by the kernel at program start. This is the same as the kzalloc'ed `port`. Next, I'll shift my attention to `line_num`. I'm going to look at how it's being used within the `gserial_alloc_line_no_console` function. It looks like when the function returns 0 (success), it assigns `port_num` to `*line_num`. I wonder what the ramifications of that are... This suggests `line_num` is being passed by pointer. Fine. Furthermore, I see `coding` is on the stack, so I will have to keep an eye on how it's used. Let me go straight to the source now, lines 1385-1405 in `drivers/usb/gadget/function/u_serial.c`. This section should tell me everything I need to know. |
| 26/3 | 2026/10/02 19:13 | tool | read-file |
0mArgs:{
"File": "drivers/usb/gadget/function/u_serial.c",
"FirstLine": 1385,
"LineCount": 30
}Results: {
"Contents": "1385:\t}\n1386:\tEXPORT_SYMBOL_GPL(gserial_free_line);\n1387:\t\n1388:\tint gserial_alloc_line_no_console(unsigned char *line_num)\n1389:\t{\n1390:\t\tstruct usb_cdc_line_coding\tcoding;\n1391:\t\tstruct gs_port\t\t\t*port = ERR_PTR(-EBUSY);\n1392:\t\tstruct device\t\t\t*tty_dev;\n1393:\t\tint\t\t\t\tret;\n1394:\t\tint\t\t\t\tport_num;\n1395:\t\n1396:\t\tcoding.dwDTERate = cpu_to_le32(9600);\n1397:\t\tcoding.bCharFormat = 8;\n1398:\t\tcoding.bParityType = USB_CDC_NO_PARITY;\n1399:\t\tcoding.bDataBits = USB_CDC_1_STOP_BITS;\n1400:\t\n1401:\t\tfor (port_num = 0; port_num \u003c MAX_U_SERIAL_PORTS; port_num++) {\n1402:\t\t\tport = gs_port_alloc(port_num, \u0026coding);\n1403:\t\t\tif (IS_ERR(port)) {\n1404:\t\t\t\tret = PTR_ERR(port);\n1405:\t\t\t\tif (ret == -EBUSY)\n1406:\t\t\t\t\tcontinue;\n1407:\t\t\t\treturn ret;\n1408:\t\t\t}\n1409:\t\t\tbreak;\n1410:\t\t}\n1411:\t\tif (IS_ERR(port))\n1412:\t\t\treturn PTR_ERR(port);\n1413:\t\n1414:\t\t/* ... and sysfs class devices, so mdev/udev make /dev/ttyGS* */\n"
} |
| 27/3 | 2026/10/02 19:13 | llm | kmsan-evaluator |
0mModel:gemini-3.8-flash Args: null Results: null Tokens: input: 9373 output: 250 thoughts: 794 Thoughts: **Patch Analysis: Addressing Serial Driver Vulnerabilities** Okay, so this `coding` situation—it was already like that, even before the patch. This patch really digs into refactoring how the lifetime, reference counting, and port lifecycle are handled in `u_serial.c`. The focus here is on fixing some nasty use-after-free scenarios and race conditions that happen between the TTY open/close/hangup/unregister steps. Specifically, it looks like `ports[port_num].port` could be accessed or freed at the wrong time, even while the TTY was open or in the process of closing, causing a UAF. This patch tackles that head-on. Now, `tty_port_get` is used at the crucial moments in `gs_install()` , `tty->driver_data = port;`, and `gs_port_destruct` runs when the last reference drops. Failed `gs_open()` attempts are now tracked using `open_close_failures` and there's a minor reservation held until `gs_port_destruct`. My immediate concern is: has this patch introduced or exposed any uninitialized memory risks? Let's check: 1. **Kernel structures to user space**: Any chance of uninitialized fields leaking to userspace? No, there are no copy-to-user or info leak paths touched here. Good. 2. **Conditional logic**: Are there any branches that rely on potentially uninitialized variables? Nope. All added fields, like `struct gs_port.open_close_failures`, are zeroed. The `ports` array is static. 3. **Complex structures**: Any new complex data structures where uninitialized fields could be a problem? The `port` is allocated with `kzalloc`, and `tty_port_init` initializes the `tty_port`. 4. **Buffer bounds**: Does the patch change bounds/lengths in a way that could allow access to uninitialized bytes? No. So, it doesn't look like this patch introduces any uninitialized memory risks. It fixes lifetime management, reference counting, and race conditions between the TTY core and the USB gadget serial driver. Use-after-free, double-free, and race conditions are detectable by KASAN, LOCKDEP, and kernel assertions. Let's do a final quick review of the diff, step-by-step: - `gs_install`: Grabs a mutex, checks port, gets a reference with `tty_port_get`, installs the TTY port, sets the driver data. - `gs_cleanup`: Puts the reference. - `gs_open`: Reads the port from driver data, handles error credit. - `gs_close`: Checks the open failure counter. - `gs_port_destruct`: Frees the buffer and port. - `gs_port_alloc`: kzallocs, reserves. - `gserial_alloc_line_no_console`: Checks the error, registers the device, publishes the port. Everything is properly initialized. No uninitialized memory reads or leaks to userspace. This patch is focused on fixing reference counting bugs, UAF, locking/deadlock, and race conditions. So, KMSAN is not needed here; standard kernel debugging facilities are sufficient. |
| 28/3 | 2026/10/02 19:13 | tool | set-results |
0mArgs:{
"KMSANReasoning": "The patch modifies the USB gadget serial driver (`u_serial.c`) to fix lifecycle and reference-counting issues between the TTY core and the gadget driver. It introduces `gs_install()`, `gs_cleanup()`, `gs_port_destruct()`, and tracks open failure counts (`open_close_failures`) and port slot reservations (`reserved`).\n\nAll modified and newly added struct fields belong either to `struct gs_port` (which is allocated with `kzalloc_obj`, ensuring zero-initialization) or to `struct portmaster` (which is stored in the zero-initialized static array `ports[]`). No uninitialized stack or heap variables are read, no buffer lengths or bounds are altered, and no kernel data is exposed or copied to user space. \n\nPotential defects in this patch involve object lifetimes, reference counting, use-after-free, or concurrency issues, which are covered by KASAN, LOCKDEP, and standard kernel runtime assertions. There is no risk of uninitialized memory usage, so a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
}Results: {
"KMSANReasoning": "The patch modifies the USB gadget serial driver (`u_serial.c`) to fix lifecycle and reference-counting issues between the TTY core and the gadget driver. It introduces `gs_install()`, `gs_cleanup()`, `gs_port_destruct()`, and tracks open failure counts (`open_close_failures`) and port slot reservations (`reserved`).\n\nAll modified and newly added struct fields belong either to `struct gs_port` (which is allocated with `kzalloc_obj`, ensuring zero-initialization) or to `struct portmaster` (which is stored in the zero-initialized static array `ports[]`). No uninitialized stack or heap variables are read, no buffer lengths or bounds are altered, and no kernel data is exposed or copied to user space. \n\nPotential defects in this patch involve object lifetimes, reference counting, use-after-free, or concurrency issues, which are covered by KASAN, LOCKDEP, and standard kernel runtime assertions. There is no risk of uninitialized memory usage, so a dedicated KMSAN fuzzing session is not warranted.",
"NeedsKMSAN": false
} |
| Total Calls | Total Tokens | Avg Tokens | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|
| Total Calls | Total Duration (Seconds) | Avg Duration (Seconds) |
|---|