The Linux Kernel Mailing List
 help / color / mirror / Atom feed
* [BUG] KASAN: slab-use-after-free Write in gb_operation_put_active
@ 2026-12-01 20:12 Farhad Alemi
  2026-12-02  7:39 ` Greg KH
  0 siblings, 1 reply; 2+ messages in thread
From: Farhad Alemi @ 2026-12-01 20:12 UTC (permalink / raw)
  To: Johan Hovold, Alex Elder; +Cc: greybus-dev, linux-staging, linux-kernel

[-- Attachment #1: Type: text/plain, Size: 11078 bytes --]

Hello,

We are reporting the following crash (reproducer attached):
Linux version 7.4.0-rc5-00048-g693c2e04e3f1
Build Config: UpstreamAppArmorKASAN (KASAN + UBSAN, panic_on_warn=1)

[   31.065785][  T991] BUG: KASAN: slab-use-after-free in
_raw_spin_lock_irqsave+0x8f/0x100
[   31.065812][  T991] Write of size 4 at addr ffff88801cd46068 by
task kworker/0:3/991
[   31.065818][  T991]
[   31.065831][  T991] CPU: 0 UID: 0 PID: 991 Comm: kworker/0:3 Not
tainted 7.4.0-rc5-00048-g693c2e04e3f1 #1 PREEMPT(full)
[   31.065839][  T991] Hardware name: QEMU Standard PC (Q35 + ICH9,
2009), BIOS 1.17.0-debian-1.17.0-1ubuntu1 04/01/2014
[   31.065844][  T991] Workqueue: greybus_completion gb_operation_work
[   31.065861][  T991] Call Trace:
[   31.065865][  T991]  <TASK>
[   31.065868][  T991]  dump_stack_lvl+0x94/0xd0
[   31.065876][  T991]  print_address_description+0x55/0x1e0
[   31.065887][  T991]  ? _raw_spin_lock_irqsave+0x8f/0x100
[   31.065896][  T991]  print_report+0x58/0x70
[   31.065905][  T991]  kasan_report+0x130/0x170
[   31.065919][  T991]  ? _raw_spin_lock_irqsave+0x8f/0x100
[   31.065928][  T991]  kasan_check_range+0x264/0x2c0
[   31.065934][  T991]  _raw_spin_lock_irqsave+0x8f/0x100
[   31.065943][  T991]  ? __pfx__raw_spin_lock_irqsave+0x10/0x10
[   31.065951][  T991]  ? preempt_schedule_thunk+0x16/0x40
[   31.065960][  T991]  ? preempt_schedule_common+0x7f/0xd0
[   31.065970][  T991]  gb_operation_put_active+0x44/0x360
[   31.065981][  T991]  gb_operation_work+0x7d5/0x9d0
[   31.065988][  T991]  process_scheduled_works+0x8d9/0x11d0
[   31.065998][  T991]  worker_thread+0x988/0xde0
[   31.066006][  T991]  ? _raw_spin_lock_irqsave+0x9c/0x100
[   31.066015][  T991]  ? __kthread_parkme+0x148/0x1a0
[   31.066023][  T991]  kthread+0x335/0x420
[   31.066032][  T991]  ? __pfx_worker_thread+0x10/0x10
[   31.066040][  T991]  ? __pfx_kthread+0x10/0x10
[   31.066057][  T991]  ret_from_fork+0x351/0x940
[   31.066063][  T991]  ? __pfx_ret_from_fork+0x10/0x10
[   31.066069][  T991]  ? __switch_to+0xbe8/0x11f0
[   31.066079][  T991]  ? __pfx_kthread+0x10/0x10
[   31.066088][  T991]  ret_from_fork_asm+0x1a/0x30
[   31.066096][  T991]  </TASK>
[   31.066098][  T991]
[   31.066104][  T991] Allocated by task 13 on cpu 0 at 29.949374s:
[   31.066110][  T991]  kasan_save_track+0x3f/0xb0
[   31.066119][  T991]  __kasan_kmalloc+0x93/0xb0
[   31.066128][  T991]  __kmalloc_cache_noprof+0x244/0x500
[   31.066138][  T991]  _gb_connection_create+0x1b0/0x9f0
[   31.066144][  T991]  gb_connection_create+0x7d/0x90
[   31.066150][  T991]  gb_usb_probe+0xfd/0x290
[   31.066160][  T991]  gbphy_dev_probe+0x20f/0x480
[   31.066169][  T991]  really_probe+0x267/0xaf0
[   31.066179][  T991]  __driver_probe_device+0x1e2/0x350
[   31.066187][  T991]  driver_probe_device+0x4f/0x240
[   31.066196][  T991]  __device_attach_driver+0x270/0x410
[   31.066205][  T991]  bus_for_each_drv+0x257/0x2f0
[   31.066211][  T991]  __device_attach+0x2bd/0x420
[   31.066219][  T991]  device_initial_probe+0x9c/0x100
[   31.066228][  T991]  __bus_probe_device+0x126/0x220
[   31.066233][  T991]  device_add+0x7ea/0xb80
[   31.066241][  T991]  gb_gbphy_probe+0x368/0x580
[   31.066249][  T991]  greybus_probe+0x5ec/0x840
[   31.066257][  T991]  really_probe+0x267/0xaf0
[   31.066266][  T991]  __driver_probe_device+0x1e2/0x350
[   31.066274][  T991]  driver_probe_device+0x4f/0x240
[   31.066283][  T991]  __device_attach_driver+0x270/0x410
[   31.066292][  T991]  bus_for_each_drv+0x257/0x2f0
[   31.066298][  T991]  __device_attach+0x2bd/0x420
[   31.066305][  T991]  device_initial_probe+0x9c/0x100
[   31.066314][  T991]  __bus_probe_device+0x126/0x220
[   31.066320][  T991]  device_add+0x7ea/0xb80
[   31.066326][  T991]  gb_bundle_add+0x1e/0x180
[   31.066331][  T991]  gb_interface_enable+0x58f/0x900
[   31.066340][  T991]  gb_module_add+0x1b3/0x3d0
[   31.066348][  T991]  gb_svc_process_deferred_request+0x8c6/0x1150
[   31.066357][  T991]  process_scheduled_works+0x8d9/0x11d0
[   31.066364][  T991]  worker_thread+0x988/0xde0
[   31.066371][  T991]  kthread+0x335/0x420
[   31.066379][  T991]  ret_from_fork+0x351/0x940
[   31.066384][  T991]  ret_from_fork_asm+0x1a/0x30
[   31.066391][  T991]
[   31.066392][  T991] Freed by task 13 on cpu 0 at 31.024497s:
[   31.066398][  T991]  kasan_save_track+0x3f/0xb0
[   31.066406][  T991]  kasan_save_free_info+0x46/0x50
[   31.066413][  T991]  __kasan_slab_free+0x70/0x90
[   31.066422][  T991]  kfree+0x18c/0x4e0
[   31.066429][  T991]  gb_usb_probe+0x1eb/0x290
[   31.066438][  T991]  gbphy_dev_probe+0x20f/0x480
[   31.066446][  T991]  really_probe+0x267/0xaf0
[   31.066455][  T991]  __driver_probe_device+0x1e2/0x350
[   31.066463][  T991]  driver_probe_device+0x4f/0x240
[   31.066472][  T991]  __device_attach_driver+0x270/0x410
[   31.066481][  T991]  bus_for_each_drv+0x257/0x2f0
[   31.066487][  T991]  __device_attach+0x2bd/0x420
[   31.066495][  T991]  device_initial_probe+0x9c/0x100
[   31.066503][  T991]  __bus_probe_device+0x126/0x220
[   31.066509][  T991]  device_add+0x7ea/0xb80
[   31.066516][  T991]  gb_gbphy_probe+0x368/0x580
[   31.066524][  T991]  greybus_probe+0x5ec/0x840
[   31.066531][  T991]  really_probe+0x267/0xaf0
[   31.066540][  T991]  __driver_probe_device+0x1e2/0x350
[   31.066548][  T991]  driver_probe_device+0x4f/0x240
[   31.066557][  T991]  __device_attach_driver+0x270/0x410
[   31.066566][  T991]  bus_for_each_drv+0x257/0x2f0
[   31.066571][  T991]  __device_attach+0x2bd/0x420
[   31.066579][  T991]  device_initial_probe+0x9c/0x100
[   31.066588][  T991]  __bus_probe_device+0x126/0x220
[   31.066594][  T991]  device_add+0x7ea/0xb80
[   31.066600][  T991]  gb_bundle_add+0x1e/0x180
[   31.066605][  T991]  gb_interface_enable+0x58f/0x900
[   31.066614][  T991]  gb_module_add+0x1b3/0x3d0
[   31.066622][  T991]  gb_svc_process_deferred_request+0x8c6/0x1150
[   31.066631][  T991]  process_scheduled_works+0x8d9/0x11d0
[   31.066637][  T991]  worker_thread+0x988/0xde0
[   31.066644][  T991]  kthread+0x335/0x420
[   31.066652][  T991]  ret_from_fork+0x351/0x940
[   31.066657][  T991]  ret_from_fork_asm+0x1a/0x30
[   31.066664][  T991]
[   31.066665][  T991] The buggy address belongs to the object at
ffff88801cd46000
[   31.066665][  T991]  which belongs to the cache kmalloc-192 of size 192
[   31.066671][  T991] The buggy address is located 104 bytes inside of
[   31.066671][  T991]  freed 192-byte region [ffff88801cd46000,
ffff88801cd460c0)
[   31.066678][  T991]
[   31.066679][  T991] The buggy address belongs to the physical page:
[   31.066687][  T991] page: refcount:0 mapcount:0
mapping:0000000000000000 index:0x0 pfn:0x1cd46
[   31.066697][  T991] flags: 0xfff00000000000(node=0|zone=1|lastcpupid=0x7ff)
[   31.066706][  T991] page_type: f5(slab)
[   31.066715][  T991] raw: 00fff00000000000 ffff8880134413c0
dead000000000100 dead000000000122
[   31.066721][  T991] raw: 0000000000000000 0000000000100010
00000000f5000000 0000000000000000
[   31.066724][  T991] page dumped because: kasan: bad access detected
[   31.066729][  T991] page_owner tracks the page as allocated
[   31.066732][  T991] 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 2636390459
[   31.066743][  T991]  post_alloc_hook+0x1f9/0x250
[   31.066753][  T991]  prep_new_page+0x22/0xc0
[   31.066762][  T991]  get_page_from_freelist+0x274a/0x2830
[   31.066771][  T991]  __alloc_frozen_pages_noprof+0x226/0x560
[   31.066781][  T991]  allocate_slab+0x7d/0x5e0
[   31.066788][  T991]  refill_objects+0x304/0x380
[   31.066794][  T991]  __pcs_replace_empty_main+0x208/0x530
[   31.066800][  T991]  __kmalloc_noprof+0x3b3/0x630
[   31.066809][  T991]  usb_alloc_urb+0x46/0x150
[   31.066815][  T991]  usb_control_msg+0x118/0x3e0
[   31.066821][  T991]  usb_get_string+0xa1/0x3c0
[   31.066829][  T991]  usb_string_sub+0x76/0x420
[   31.066836][  T991]  usb_string+0x38f/0x7d0
[   31.066842][  T991]  usb_cache_string+0x7d/0xf0
[   31.066849][  T991]  usb_new_device+0x2a5/0x1720
[   31.066856][  T991]  register_root_hub+0x265/0x5e0
[   31.066861][  T991] page_owner free stack trace missing
[   31.066863][  T991]
[   31.066865][  T991] Memory state around the buggy address:
[   31.066869][  T991]  ffff88801cd45f00: 00 00 00 00 00 00 00 00 00
00 00 00 fc fc fc fc
[   31.066873][  T991]  ffff88801cd45f80: fc fc fc fc fc fc fc fc fc
fc fc fc fc fc fc fc
[   31.066877][  T991] >ffff88801cd46000: fa fb fb fb fb fb fb fb fb
fb fb fb fb fb fb fb
[   31.066881][  T991]
          ^
[   31.066884][  T991]  ffff88801cd46080: fb fb fb fb fb fb fb fb fc
fc fc fc fc fc fc fc
[   31.066889][  T991]  ffff88801cd46100: fa fb fb fb fb fb fb fb fb
fb fb fb fb fb fb fb
[   31.066892][  T991]
==================================================================
[   31.066899][  T991] Kernel panic - not syncing: KASAN: panic_on_warn set ...
[   31.145657][  T991] CPU: 0 UID: 0 PID: 991 Comm: kworker/0:3 Not
tainted 7.4.0-rc5-00048-g693c2e04e3f1 #1 PREEMPT(full)
[   31.146672][  T991] Hardware name: QEMU Standard PC (Q35 + ICH9,
2009), BIOS 1.17.0-debian-1.17.0-1ubuntu1 04/01/2014
[   31.147692][  T991] Workqueue: greybus_completion gb_operation_work
[   31.148317][  T991] Call Trace:
[   31.148703][  T991]  <TASK>
[   31.148994][  T991]  vpanic+0x241/0x6e0
[   31.149391][  T991]  panic+0xc5/0xd0
[   31.149763][  T991]  ? __pfx_panic+0x10/0x10
[   31.150179][  T991]  ? __pfx__printk+0x10/0x10
[   31.150613][  T991]  ? _raw_spin_lock_irqsave+0x8f/0x100
[   31.151123][  T991]  check_panic_on_warn+0x89/0xb0
[   31.151587][  T991]  ? _raw_spin_lock_irqsave+0x8f/0x100
[   31.152094][  T991]  end_report+0x45/0xe0
[   31.152485][  T991]  ? _raw_spin_lock_irqsave+0x8f/0x100
[   31.152988][  T991]  kasan_report+0x141/0x170
[   31.153419][  T991]  ? _raw_spin_lock_irqsave+0x8f/0x100
[   31.153922][  T991]  kasan_check_range+0x264/0x2c0
[   31.154382][  T991]  _raw_spin_lock_irqsave+0x8f/0x100
[   31.154897][  T991]  ? __pfx__raw_spin_lock_irqsave+0x10/0x10
[   31.155473][  T991]  ? preempt_schedule_thunk+0x16/0x40
[   31.155996][  T991]  ? preempt_schedule_common+0x7f/0xd0
[   31.156531][  T991]  gb_operation_put_active+0x44/0x360
[   31.157032][  T991]  gb_operation_work+0x7d5/0x9d0
[   31.157493][  T991]  process_scheduled_works+0x8d9/0x11d0
[   31.158006][  T991]  worker_thread+0x988/0xde0
[   31.158536][  T991]  ? _raw_spin_lock_irqsave+0x9c/0x100
[   31.159068][  T991]  ? __kthread_parkme+0x148/0x1a0
[   31.159560][  T991]  kthread+0x335/0x420
[   31.159958][  T991]  ? __pfx_worker_thread+0x10/0x10
[   31.160435][  T991]  ? __pfx_kthread+0x10/0x10
[   31.160904][  T991]  ret_from_fork+0x351/0x940
[   31.161358][  T991]  ? __pfx_ret_from_fork+0x10/0x10
[   31.161857][  T991]  ? __switch_to+0xbe8/0x11f0
[   31.162298][  T991]  ? __pfx_kthread+0x10/0x10
[   31.162729][  T991]  ret_from_fork_asm+0x1a/0x30
[   31.163178][  T991]  </TASK>
[   31.163502][  T991] Kernel Offset: disabled
[   31.163903][  T991] Rebooting in 86400 seconds..


Regards,

[-- Attachment #2: reproducer.c --]
[-- Type: application/octet-stream, Size: 8571 bytes --]

#define _GNU_SOURCE
#include <dirent.h>
#include <fcntl.h>
#include <pthread.h>
#include <sched.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <sys/ioctl.h>
#include <sys/wait.h>
#include <linux/usb/ch9.h>
#include <linux/usb/raw_gadget.h>

#define MAX_TRANSFER				1024

#define ES2_REQUEST_ARPC_RUN			0x12

#define GB_TYPE_RESPONSE			0x80
#define GB_REQUEST_TYPE_CPORT_SHUTDOWN		0x00
#define GB_SVC_CPORT				0
#define GB_SVC_TYPE_PROTOCOL_VERSION		0x01
#define GB_SVC_TYPE_SVC_HELLO			0x02
#define GB_SVC_TYPE_DME_PEER_GET		0x09
#define GB_SVC_TYPE_DME_PEER_SET		0x0a
#define GB_SVC_TYPE_MODULE_INSERTED		0x1f
#define GB_SVC_TYPE_INTF_VSYS_ENABLE		0x21
#define GB_SVC_TYPE_INTF_REFCLK_ENABLE		0x23
#define GB_SVC_TYPE_INTF_UNIPRO_ENABLE		0x25
#define GB_SVC_TYPE_INTF_ACTIVATE		0x27
#define GB_SVC_INTF_TYPE_GREYBUS		0x03
#define GB_CONTROL_TYPE_VERSION			0x01
#define GB_CONTROL_TYPE_GET_MANIFEST_SIZE	0x03
#define GB_CONTROL_TYPE_GET_MANIFEST		0x04
#define GB_CONTROL_TYPE_BUNDLE_ACTIVATE		0x12

struct greybus_message_header {
	uint16_t size;
	uint16_t operation_id;
	uint8_t type;
	uint8_t result;
	uint8_t host_cport;
	uint8_t pad;
} __attribute__((packed));

static int raw_gadget_fd;
static int arpc_in_endpoint, cport_out_endpoint;
static volatile int cport_in_endpoint = -1;

static const struct usb_device_descriptor es2_device_descriptor = {
	.bLength = USB_DT_DEVICE_SIZE,
	.bDescriptorType = USB_DT_DEVICE,
	.bcdUSB = 0x0200,
	.bMaxPacketSize0 = 64,
	.idVendor = 0x18d1,
	.idProduct = 0x1eaf,
	.bNumConfigurations = 1,
};

static const struct usb_endpoint_descriptor es2_endpoints[3] = {
	{ USB_DT_ENDPOINT_SIZE, USB_DT_ENDPOINT, 0x81, USB_ENDPOINT_XFER_BULK, 512 },
	{ USB_DT_ENDPOINT_SIZE, USB_DT_ENDPOINT, 0x82, USB_ENDPOINT_XFER_BULK, 512 },
	{ USB_DT_ENDPOINT_SIZE, USB_DT_ENDPOINT, 0x01, USB_ENDPOINT_XFER_BULK, 512 },
};

static const unsigned char module_manifest[28] = {
	28, 0, 0, 1,
	8, 0, 1, 0,	0, 0, 0, 0,
	8, 0, 3, 0,	1, 0x0a, 0, 0,
	8, 0, 4, 0,	1, 0, 1, 0x06,
};

static int raw_gadget_io(unsigned long request, int endpoint, void *data, int length)
{
	struct {
		struct usb_raw_ep_io io;
		unsigned char data[MAX_TRANSFER];
	} buffer;
	int is_read = request == USB_RAW_IOCTL_EP_READ || request == USB_RAW_IOCTL_EP0_READ;
	int transferred;

	buffer.io.ep = endpoint;
	buffer.io.flags = 0;
	buffer.io.length = length;
	if (!is_read)
		memcpy(buffer.data, data, length);
	transferred = ioctl(raw_gadget_fd, request, &buffer);
	if (is_read && transferred > 0)
		memcpy(data, buffer.data, transferred);
	return transferred;
}

static void handle_control_request(struct usb_ctrlrequest *ctrl)
{
	unsigned char data[MAX_TRANSFER];
	int reply_length = -1, i;

	if (ctrl->bRequestType & USB_TYPE_VENDOR) {
		if (ctrl->bRequestType & USB_DIR_IN) {
			data[0] = 3;
			data[1] = 0;
			raw_gadget_io(USB_RAW_IOCTL_EP0_WRITE, 0, data, 2);
			return;
		}
		raw_gadget_io(USB_RAW_IOCTL_EP0_READ, 0, data, ctrl->wLength);
		if (ctrl->bRequest == ES2_REQUEST_ARPC_RUN) {
			data[2] = 0;
			raw_gadget_io(USB_RAW_IOCTL_EP_WRITE, arpc_in_endpoint, data, 3);
		}
		return;
	}
	if (ctrl->bRequest == USB_REQ_GET_DESCRIPTOR && (ctrl->wValue >> 8) == USB_DT_DEVICE) {
		reply_length = sizeof(es2_device_descriptor);
		memcpy(data, &es2_device_descriptor, reply_length);
	} else if (ctrl->bRequest == USB_REQ_GET_DESCRIPTOR && (ctrl->wValue >> 8) == USB_DT_CONFIG) {
		static const unsigned char config_and_interface[18] = {
			9, USB_DT_CONFIG, 9 + 9 + 3 * USB_DT_ENDPOINT_SIZE, 0, 1, 1, 0, 0x80, 0xfa,
			9, USB_DT_INTERFACE, 0, 0, 3, 0xff, 0, 0, 0,
		};
		memcpy(data, config_and_interface, 18);
		for (i = 0; i < 3; i++)
			memcpy(data + 18 + i * USB_DT_ENDPOINT_SIZE, &es2_endpoints[i], USB_DT_ENDPOINT_SIZE);
		reply_length = 18 + 3 * USB_DT_ENDPOINT_SIZE;
	} else if (ctrl->bRequest == USB_REQ_SET_CONFIGURATION) {
		arpc_in_endpoint = ioctl(raw_gadget_fd, USB_RAW_IOCTL_EP_ENABLE, &es2_endpoints[1]);
		cport_out_endpoint = ioctl(raw_gadget_fd, USB_RAW_IOCTL_EP_ENABLE, &es2_endpoints[2]);
		cport_in_endpoint = ioctl(raw_gadget_fd, USB_RAW_IOCTL_EP_ENABLE, &es2_endpoints[0]);
		ioctl(raw_gadget_fd, USB_RAW_IOCTL_CONFIGURE, 0);
		raw_gadget_io(USB_RAW_IOCTL_EP0_READ, 0, data, 0);
		return;
	}
	if (reply_length < 0)
		ioctl(raw_gadget_fd, USB_RAW_IOCTL_EP0_STALL, 0);
	else
		raw_gadget_io(USB_RAW_IOCTL_EP0_WRITE, 0, data,
			      reply_length < ctrl->wLength ? reply_length : ctrl->wLength);
}

static void *ep0_event_pump(void *unused)
{
	struct {
		struct usb_raw_event event;
		unsigned char data[MAX_TRANSFER];
	} buffer;

	for (;;) {
		buffer.event.type = 0;
		buffer.event.length = MAX_TRANSFER;
		if (ioctl(raw_gadget_fd, USB_RAW_IOCTL_EVENT_FETCH, &buffer) < 0)
			return NULL;
		if (buffer.event.type == USB_RAW_EVENT_CONTROL)
			handle_control_request((struct usb_ctrlrequest *)buffer.event.data);
	}
}

static void send_to_host(uint16_t operation_id, uint8_t type, uint8_t host_cport,
			 const void *payload, int payload_length)
{
	unsigned char message[MAX_TRANSFER];
	struct greybus_message_header *header = (void *)message;

	memset(header, 0, sizeof(*header));
	header->size = sizeof(*header) + payload_length;
	header->operation_id = operation_id;
	header->type = type;
	header->host_cport = host_cport;
	memcpy(message + sizeof(*header), payload, payload_length);
	raw_gadget_io(USB_RAW_IOCTL_EP_WRITE, cport_in_endpoint, message, header->size);
}

static int response_payload(const struct greybus_message_header *request, unsigned char *payload)
{
	memset(payload, 0, MAX_TRANSFER);
	if (request->host_cport == GB_SVC_CPORT) {
		switch (request->type) {
		case GB_SVC_TYPE_DME_PEER_GET:
			payload[2] = 0x26;
			payload[3] = 0x01;
			return 6;
		case GB_SVC_TYPE_DME_PEER_SET:
			return 2;
		case GB_SVC_TYPE_INTF_VSYS_ENABLE:
		case GB_SVC_TYPE_INTF_REFCLK_ENABLE:
		case GB_SVC_TYPE_INTF_UNIPRO_ENABLE:
			return 1;
		case GB_SVC_TYPE_INTF_ACTIVATE:
			payload[1] = GB_SVC_INTF_TYPE_GREYBUS;
			return 2;
		}
		return 0;
	}
	switch (request->type) {
	case GB_CONTROL_TYPE_VERSION:
		return 2;
	case GB_CONTROL_TYPE_GET_MANIFEST_SIZE:
		payload[0] = sizeof(module_manifest);
		return 2;
	case GB_CONTROL_TYPE_GET_MANIFEST:
		memcpy(payload, module_manifest, sizeof(module_manifest));
		return sizeof(module_manifest);
	case GB_CONTROL_TYPE_BUNDLE_ACTIVATE:
		return 1;
	}
	return 0;
}

static void make_cpu0_kworkers_sched_idle(void)
{
	struct sched_param param = { 0 };
	DIR *proc = opendir("/proc");
	struct dirent *entry;
	char path[300], comm[64];
	int fd;

	while ((entry = readdir(proc))) {
		snprintf(path, sizeof(path), "/proc/%s/comm", entry->d_name);
		fd = open(path, O_RDONLY);
		if (fd < 0)
			continue;
		if (read(fd, comm, sizeof(comm)) > 10 && !strncmp(comm, "kworker/0:", 10))
			sched_setscheduler(atoi(entry->d_name), SCHED_IDLE, &param);
		close(fd);
	}
	closedir(proc);
}

static void emulate_es2_svc_and_module(void)
{
	static const unsigned char protocol_version[2] = { 0, 1 };
	static const unsigned char hello[3] = { 0, 0, 1 };
	static const unsigned char module_inserted[4] = { 2, 1, 0, 0 };
	unsigned char message[MAX_TRANSFER], payload[MAX_TRANSFER];
	struct greybus_message_header *header = (void *)message;
	struct usb_raw_init init;
	pthread_t ep0_thread;

	raw_gadget_fd = open("/dev/raw-gadget", O_RDWR);
	memset(&init, 0, sizeof(init));
	strcpy((char *)init.driver_name, "dummy_udc");
	strcpy((char *)init.device_name, "dummy_udc.0");
	init.speed = USB_SPEED_HIGH;
	ioctl(raw_gadget_fd, USB_RAW_IOCTL_INIT, &init);
	ioctl(raw_gadget_fd, USB_RAW_IOCTL_RUN, 0);
	pthread_create(&ep0_thread, NULL, ep0_event_pump, NULL);
	while (cport_in_endpoint < 0)
		usleep(10000);

	send_to_host(1, GB_SVC_TYPE_PROTOCOL_VERSION, GB_SVC_CPORT, protocol_version, 2);
	send_to_host(2, GB_SVC_TYPE_SVC_HELLO, GB_SVC_CPORT, hello, 3);
	send_to_host(3, GB_SVC_TYPE_MODULE_INSERTED, GB_SVC_CPORT, module_inserted, 4);

	for (;;) {
		raw_gadget_io(USB_RAW_IOCTL_EP_READ, cport_out_endpoint, message, MAX_TRANSFER);
		if (header->type & GB_TYPE_RESPONSE)
			continue;
		if (header->type == GB_REQUEST_TYPE_CPORT_SHUTDOWN)
			return;
		usleep(2000);
		send_to_host(header->operation_id, header->type | GB_TYPE_RESPONSE, header->host_cport,
			     payload, response_payload(header, payload));
	}
}

int main(void)
{
	int fd;

	fd = open("/sys/devices/system/cpu/cpu1/online", O_WRONLY);
	write(fd, "0", 1);
	close(fd);

	if (fork() == 0) {
		emulate_es2_svc_and_module();
		make_cpu0_kworkers_sched_idle();
		_exit(0);
	}
	wait(NULL);
	sleep(3);
	return 0;
}

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: [BUG] KASAN: slab-use-after-free Write in gb_operation_put_active
  2026-12-01 20:12 [BUG] KASAN: slab-use-after-free Write in gb_operation_put_active Farhad Alemi
@ 2026-12-02  7:39 ` Greg KH
  0 siblings, 0 replies; 2+ messages in thread
From: Greg KH @ 2026-12-02  7:39 UTC (permalink / raw)
  To: Farhad Alemi
  Cc: Johan Hovold, Alex Elder, greybus-dev, linux-staging,
	linux-kernel

On Tue, Dec 01, 2026 at 01:12:34PM -0700, Farhad Alemi wrote:
> Hello,
> 
> We are reporting the following crash (reproducer attached):
> Linux version 7.4.0-rc5-00048-g693c2e04e3f1
> Build Config: UpstreamAppArmorKASAN (KASAN + UBSAN, panic_on_warn=1)

Great, send a patch if you wish to resolve this.

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2026-12-02  7:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-12-01 20:12 [BUG] KASAN: slab-use-after-free Write in gb_operation_put_active Farhad Alemi
2026-12-02  7:39 ` Greg KH

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox