KASAN: slab-out-of-bounds Read in gb_operation_work

Status: upstream: reported C repro on 2026/11/12 05:56
Subsystems: greybus usb
Labels: prio:high
[Documentation on labels]
Reported-by: syzbot+0b456664585fa81a47f6@syzkaller.appspotmail.com
First crash: 4d01h, last: 3d22h
✨ AI-generated root cause summary:

In gb_connection_recv() (drivers/greybus/operation.c), the kernel verifies that the incoming buffer length is at least sizeof(struct gb_operation_msg_hdr), but fails to validate that the message header's claimed size (header.size, parsed as msg_size) is also at least sizeof(struct gb_operation_msg_hdr). When msg_size < sizeof(struct gb_operation_msg_hdr), gb_operation_create_incoming() subtracts the header size from msg_size, causing an unsigned integer underflow when calculating request_size. In gb_operation_message_alloc(), the payload size and header size wrap back around and kzalloc(msg_size) allocates an undersized buffer smaller than the header, leading to out-of-bounds reads when reading request_header->operation_id or a ZERO_SIZE_PTR dereference panic when msg_size is zero.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 6628e7d4c6b2:

Root Cause Analysis

1. Involved Files, Functions, and Structs

  • File: drivers/greybus/operation.c
  • Functions: gb_connection_recv(), gb_operation_create_incoming(), gb_operation_message_alloc(), gb_operation_message_init(), gb_operation_response_alloc()
  • Structs & Fields:
    • struct gb_operation_msg_hdr (size 8 bytes): size (__le16, offset 0), operation_id (__le16, offset 2), type (__u8, offset 4), result (__u8, offset 5), pad[2] (offset 6).
    • struct gb_operation: request (struct gb_message *), response (struct gb_message *).
    • struct gb_message: buffer (void *), header (struct gb_operation_msg_hdr *), payload (void *), payload_size (size_t).

2. Detailed Mechanism and Trigger

  1. Missing Message Size Validation in gb_connection_recv(): When receiving data on a Greybus connection in gb_connection_recv() (drivers/greybus/operation.c:1027):

    if (size < sizeof(header)) {
        dev_err_ratelimited(dev, "%s: short message received\n",
                            connection->name);
        return;
    }
    
    memcpy(&header, data, sizeof(header));
    msg_size = le16_to_cpu(header.size);
    if (size < msg_size) {
        ...
        return;
    }
    

    While size (the received URB or transfer buffer length) is checked against sizeof(header) (8 bytes), msg_size (the length encoded in header.size by the peer) is only checked against size via if (size < msg_size). If the peer sends a message with header.size < sizeof(struct gb_operation_msg_hdr) (e.g., header.size = 3 with size >= 8), the condition size < msg_size is false, and the code proceeds to dispatch the message using msg_size:

    gb_connection_recv_request(connection, &header, data, msg_size);
    
  2. Unsigned Arithmetic Underflow in gb_operation_create_incoming(): gb_connection_recv_request() calls gb_operation_create_incoming(connection, operation_id, type, data, size) with size = msg_size (3 in the report). In gb_operation_create_incoming():

    /* Caller has made sure we at least have a message header. */
    request_size = size - sizeof(struct gb_operation_msg_hdr);
    

    Because size < sizeof(struct gb_operation_msg_hdr), the unsigned subtraction underflows: request_size = (size_t)3 - 8 = 0xfffffffffffffffb.

  3. Undersized Buffer Allocation in gb_operation_message_alloc(): gb_operation_create_incoming() calls gb_operation_create_common(), which calls:

    gb_operation_message_alloc(hd, type, request_size, gfp_flags);
    

    Inside gb_operation_message_alloc():

    size_t message_size = payload_size + sizeof(*header);
    

    Here, payload_size is 0xfffffffffffffffb. Adding sizeof(*header) (8) wraps modulo $2^{64}$ back to 3. The size boundary check message_size > hd->buffer_size_max succeeds because 3 <= hd->buffer_size_max, and kzalloc() is called:

    message->buffer = kzalloc(message_size, gfp_flags); /* kzalloc(3, GFP_ATOMIC) */
    

    A buffer of only 3 bytes is allocated from the kmalloc-8 slab cache.

  4. Corrupted Message Initialization and Manifestation: In gb_operation_message_init():

    header = message->buffer;
    message->header = header;
    message->payload = payload_size ? header + 1 : NULL;
    message->payload_size = payload_size;
    
    • message->header points to the 3-byte allocation.
    • message->payload_size is set to the underflowed ~18.4 exabyte value.
    • message->payload is set to header + 1 (offset 8), which already points past the 3-byte allocation.

    When the operation work item runs on the workqueue (gb_operation_work() -> gb_operation_request_handle() -> gb_operation_response_send() -> gb_operation_response_alloc()):

    request_header = operation->request->header;
    response->header->operation_id = request_header->operation_id;
    

    request_header->operation_id is an __le16 located at offset 2 (bytes 2 and 3). Reading 2 bytes starting at offset 2 of a 3-byte slab object reads byte 3, which is past the end of the allocated 3-byte buffer, triggering the reported KASAN slab-out-of-bounds read: Read of size 2 at addr ffff88813689df82 (offset 2 inside allocated 3-byte region [ffff88813689df80, ffff88813689df83)).

  5. Extreme Case (msg_size == 0): If header.size == 0, kzalloc(0) returns ZERO_SIZE_PTR (0x10). Dereferencing request_header->operation_id at offset 2 dereferences address 0x12, triggering a kernel NULL-pointer dereference page fault.


3. Suggested Fix

In gb_connection_recv() (drivers/greybus/operation.c), validate that msg_size >= sizeof(header) in addition to size < msg_size:

	msg_size = le16_to_cpu(header.size);
	if (msg_size < sizeof(header)) {
		dev_err_ratelimited(dev, "%s: short message received (%zu < %zu)\n",
				    connection->name, msg_size, sizeof(header));
		return;
	}
	if (size < msg_size) {
		...
	}

Additionally, gb_operation_create_incoming() can verify if (size < sizeof(struct gb_operation_msg_hdr)) return NULL; as defense-in-depth against invalid callers.

▶ ▼ ✨ AI Jobs (1)
ID Workflow Result Correct Bug Created Started Finished Revision
44db6c54 assessment-security DenialOfService: ✅ Exploitable: ✅ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ❌ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ✅ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KASAN: slab-out-of-bounds Read in gb_operation_work 2026/11/08 05:16 2026/11/08 05:17 2026/11/08 05:38 5cecaf1f
▶ ▼ Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [greybus?] [usb?] KASAN: slab-out-of-bounds Read in gb_operation_work 0 (1) 2026/11/12 05:56

Sample crash report:
greybus 1-svc: unexpected request 0x7f received (state 0)
==================================================================
BUG: KASAN: slab-out-of-bounds in gb_operation_response_alloc drivers/greybus/operation.c:490 [inline]
BUG: KASAN: slab-out-of-bounds in gb_operation_response_send drivers/greybus/operation.c:832 [inline]
BUG: KASAN: slab-out-of-bounds in gb_operation_request_handle drivers/greybus/operation.c:252 [inline]
BUG: KASAN: slab-out-of-bounds in gb_operation_work+0x8be/0x990 drivers/greybus/operation.c:280
Read of size 2 at addr ffff888105f0a642 by task kworker/u8:2/38

CPU: 1 UID: 0 PID: 38 Comm: kworker/u8:2 Not tainted syzkaller #0 PREEMPT(lazy) 
Hardware name: Google Google Compute Engine/Google Compute Engine, BIOS Google 10/15/2026
Workqueue: greybus1:0 gb_operation_work
Call Trace:
 <TASK>
 __dump_stack lib/dump_stack.c:94 [inline]
 dump_stack_lvl+0x100/0x190 lib/dump_stack.c:120
 print_address_description mm/kasan/report.c:378 [inline]
 print_report+0x13d/0x4b0 mm/kasan/report.c:482
 kasan_report+0xdf/0x1c0 mm/kasan/report.c:595
 gb_operation_response_alloc drivers/greybus/operation.c:490 [inline]
 gb_operation_response_send drivers/greybus/operation.c:832 [inline]
 gb_operation_request_handle drivers/greybus/operation.c:252 [inline]
 gb_operation_work+0x8be/0x990 drivers/greybus/operation.c:280
 process_one_work+0xac7/0x1b10 kernel/workqueue.c:3495
 process_scheduled_works kernel/workqueue.c:3578 [inline]
 worker_thread+0x5ef/0xe50 kernel/workqueue.c:3659
 kthread+0x373/0x450 kernel/kthread.c:436
 ret_from_fork+0x69f/0xc90 arch/x86/kernel/process.c:158
 ret_from_fork_asm+0x1a/0x30 arch/x86/entry/entry_64.S:245
 </TASK>

Allocated by task 28:
 kasan_save_stack+0x30/0x50 mm/kasan/common.c:57
 kasan_save_track+0x14/0x30 mm/kasan/common.c:78
 poison_kmalloc_redzone mm/kasan/common.c:409 [inline]
 __kasan_kmalloc+0x8f/0xa0 mm/kasan/common.c:426
 kasan_kmalloc include/linux/kasan.h:263 [inline]
 __do_kmalloc_node mm/slub.c:5531 [inline]
 __kmalloc_noprof+0x315/0x7e0 mm/slub.c:5556
 _kmalloc_noprof include/linux/slab.h:995 [inline]
 _kzalloc_noprof include/linux/slab.h:1312 [inline]
 gb_operation_message_alloc+0x9b/0x2c0 drivers/greybus/operation.c:380
 gb_operation_create_common+0x9f/0x710 drivers/greybus/operation.c:532
 gb_operation_create_incoming drivers/greybus/operation.c:644 [inline]
 gb_connection_recv_request drivers/greybus/operation.c:926 [inline]
 gb_connection_recv+0x1dc/0x1050 drivers/greybus/operation.c:1063
 greybus_data_rcvd+0x244/0x600 drivers/greybus/connection.c:89
 cport_in_callback+0x1fb/0x280 drivers/greybus/es2.c:840
 __usb_hcd_giveback_urb+0x38e/0x610 drivers/usb/core/hcd.c:1657
 usb_hcd_giveback_urb+0x3ca/0x4a0 drivers/usb/core/hcd.c:1741
 dummy_timer+0xdb5/0x3840 drivers/usb/gadget/udc/dummy_hcd.c:2051
 __run_hrtimer kernel/time/hrtimer.c:2079 [inline]
 __hrtimer_run_queues+0x448/0x9a0 kernel/time/hrtimer.c:2136
 hrtimer_run_softirq+0x1ca/0x360 kernel/time/hrtimer.c:2153
 handle_softirqs+0x209/0xa00 kernel/softirq.c:669
 __do_softirq kernel/softirq.c:703 [inline]
 invoke_softirq kernel/softirq.c:542 [inline]
 __irq_exit_rcu+0x17a/0x220 kernel/softirq.c:786
 irq_exit_rcu+0x9/0x30 kernel/softirq.c:809
 instr_sysvec_apic_timer_interrupt arch/x86/kernel/apic/apic.c:1062 [inline]
 sysvec_apic_timer_interrupt+0x8f/0xb0 arch/x86/kernel/apic/apic.c:1062
 asm_sysvec_apic_timer_interrupt+0x1a/0x20 arch/x86/include/asm/idtentry.h:674

The buggy address belongs to the object at ffff888105f0a640
 which belongs to the cache kmalloc-8 of size 8
The buggy address is located 2 bytes inside of
 allocated 3-byte region [ffff888105f0a640, ffff888105f0a643)

The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x105f0a
flags: 0x200000000000000(node=0|zone=2)
page_type: f5(slab)
raw: 0200000000000000 ffff888100041500 dead000000000100 dead000000000122
raw: 0000000000000000 0000000000800080 00000000f5000000 0000000000000000
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 0, migratetype Unmovable, gfp_mask 0xd2c00(GFP_NOIO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 1, tgid 1 (swapper/0), ts 6490716744
 set_page_owner include/linux/page_owner.h:33 [inline]
 post_alloc_hook+0xfd/0x120 mm/page_alloc.c:1856
 prep_new_page mm/page_alloc.c:1864 [inline]
 get_page_from_freelist+0xf4b/0x3440 mm/page_alloc.c:3935
 __alloc_frozen_pages_noprof+0x299/0x2d50 mm/page_alloc.c:5444
 alloc_slab_page mm/slub.c:3384 [inline]
 allocate_slab mm/slub.c:3499 [inline]
 new_slab+0xb1/0x6d0 mm/slub.c:3550
 refill_objects+0xe3/0x410 mm/slub.c:7539
 refill_sheaf mm/slub.c:2917 [inline]
 __pcs_replace_empty_main+0x35e/0x650 mm/slub.c:4811
 alloc_from_pcs mm/slub.c:4887 [inline]
 slab_alloc_node mm/slub.c:5021 [inline]
 __do_kmalloc_node mm/slub.c:5530 [inline]
 __kmalloc_node_noprof+0x634/0x820 mm/slub.c:5543
 _kmalloc_array_node_noprof include/linux/slab.h:1297 [inline]
 __blk_mq_realloc_hw_ctxs+0x579/0x820 block/blk-mq.c:4588
 blk_mq_realloc_hw_ctxs block/blk-mq.c:4652 [inline]
 blk_mq_init_allocated_queue+0x36c/0x1500 block/blk-mq.c:4694
 blk_mq_alloc_queue+0x1bd/0x290 block/blk-mq.c:4464
 scsi_alloc_sdev+0x972/0xe90 drivers/scsi/scsi_scan.c:339
 scsi_probe_and_add_lun+0x523/0x720 drivers/scsi/scsi_scan.c:1227
 __scsi_scan_target+0x188/0x420 drivers/scsi/scsi_scan.c:1803
 scsi_scan_channel drivers/scsi/scsi_scan.c:1893 [inline]
 scsi_scan_channel+0x142/0x1e0 drivers/scsi/scsi_scan.c:1868
 scsi_scan_host_selected+0x2b3/0x380 drivers/scsi/scsi_scan.c:1922
 do_scsi_scan_host+0x1f4/0x270 drivers/scsi/scsi_scan.c:2055
page_owner free stack trace missing

Memory state around the buggy address:
 ffff888105f0a500: 06 fc fc fc 00 fc fc fc 00 fc fc fc 00 fc fc fc
 ffff888105f0a580: fa fc fc fc 06 fc fc fc 06 fc fc fc 06 fc fc fc
>ffff888105f0a600: 06 fc fc fc 00 fc fc fc 03 fc fc fc fa fc fc fc
                                           ^
 ffff888105f0a680: fa fc fc fc 00 fc fc fc fa fc fc fc 00 fc fc fc
 ffff888105f0a700: fa fc fc fc 05 fc fc fc 05 fc fc fc 05 fc fc fc
==================================================================

Crashes (5):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/08 08:20 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 6628e7d4c6b2 5cecaf1f .config console log report syz / log C [disk image] [vmlinux] [kernel image] ci2-upstream-usb KASAN: slab-out-of-bounds Read in gb_operation_work
2026/11/08 07:34 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 6628e7d4c6b2 5cecaf1f .config console log report syz / log C [disk image] [vmlinux] [kernel image] ci2-upstream-usb KASAN: slab-out-of-bounds Read in gb_operation_work
2026/11/08 06:49 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 6628e7d4c6b2 5cecaf1f .config console log report syz / log C [disk image] [vmlinux] [kernel image] ci2-upstream-usb KASAN: slab-out-of-bounds Read in gb_operation_work
2026/11/08 06:03 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 6628e7d4c6b2 5cecaf1f .config console log report syz / log C [disk image] [vmlinux] [kernel image] ci2-upstream-usb KASAN: slab-out-of-bounds Read in gb_operation_work
2026/11/08 05:16 https://git.kernel.org/pub/scm/linux/kernel/git/gregkh/usb.git usb-testing 6628e7d4c6b2 5cecaf1f .config console log report info [disk image] [vmlinux] [kernel image] ci2-upstream-usb KASAN: slab-out-of-bounds Read in gb_operation_work
* Struck through repros no longer work on HEAD.