KASAN: slab-use-after-free Read in cdev_put

Status: upstream: reported C repro on 2026/11/15 16:46
Subsystems: fs driver-core
Labels: prio:normal
[Documentation on labels]
Reported-by: syzbot+667788430769ef9ddf25@syzkaller.appspotmail.com
First crash: 4d05h, last: 1d16h
✨ AI-generated root cause summary:

In posix_clock_register() (kernel/time/posix-clock.c), clk->dev and clk->cdev.owner are assigned only after cdev_device_add(&clk->cdev, dev) returns. As soon as cdev_add() executes inside cdev_device_add(), the character device is live and can be opened by userspace. If posix_clock_open() runs in this window while clk->dev is still NULL, get_device(clk->dev) is a no-op and fails to acquire a reference on the device. When the file is later closed, posix_clock_release() calls put_device(clk->dev) on the now-initialized pointer, causing an unbalanced reference drop that prematurely frees the struct ptp_clock; subsequent invocation of cdev_put(inode->i_cdev) in __fput() then accesses the freed memory, causing a slab use-after-free.

▶ ▼ ✨ Full AI root cause analysis
Based on kernel commit 067c5c24cef2:

Root Cause Analysis

1. Involved Components

  • Source File: kernel/time/posix-clock.c
  • Related Files: fs/char_dev.c, fs/file_table.c, drivers/ptp/ptp_clock.c
  • Structs and Fields:
    • struct ptp_clock: embeds struct posix_clock clock (at offset 0) and struct device dev (at offset 0x158).
    • struct posix_clock: embeds struct cdev cdev (at offset 80 / +0x50) and holds pointer struct device *dev (at offset 184 / +0xb8).
    • struct cdev: field struct module *owner (at offset 64 / +0x40 inside struct cdev, making its offset within struct ptp_clock equal to 144 / 0x90).

2. Mechanism of the Defect

In kernel/time/posix-clock.c, posix_clock_register() initializes and registers a character device for POSIX clock devices (such as PTP clocks):

int posix_clock_register(struct posix_clock *clk, struct device *dev)
{
	int err;

	init_rwsem(&clk->rwsem);

	cdev_init(&clk->cdev, &posix_clock_file_operations);
	err = cdev_device_add(&clk->cdev, dev);
	if (err) {
		pr_err("%s unable to add device %d:%d\n",
			dev_name(dev), MAJOR(dev->devt), MINOR(dev->devt));
		return err;
	}
	clk->cdev.owner = clk->ops.owner;
	clk->dev = dev;

	return 0;
}

Notice the order of operations:

  1. cdev_device_add(&clk->cdev, dev) internally calls cdev_set_parent(cdev, &dev->kobj), cdev_add(cdev, dev->devt, 1), and device_add(dev).
  2. As soon as cdev_add() finishes, the character device is registered in cdev_map and immediately exposed to userspace.
  3. Crucially, clk->dev = dev; and clk->cdev.owner = clk->ops.owner; are only assigned after cdev_device_add() successfully completes.

Because struct ptp_clock was allocated with kzalloc_obj() in ptp_clock_register(), clk->dev is initialized to NULL.

3. Invariant Violation and Failure Flow

  1. Window of Race: During driver probe or PCI rescan (e.g. e1000_probe -> e1000e_ptp_init -> ptp_clock_register), while task 1 is executing cdev_device_add() inside posix_clock_register(), userspace task 2 opens /dev/ptp0.

  2. Failed Reference Increment in posix_clock_open(): When task 2 opens the device node, posix_clock_open() runs:

    fp->private_data = pccontext;
    get_device(clk->dev);
    

    Because clk->dev is still NULL, get_device(NULL) is executed, which is a no-op that returns NULL without incrementing the reference count on &ptp->dev.

  3. Subsequent Initialization: Task 1 completes cdev_device_add() and assigns clk->dev = dev;.

  4. Unbalanced Reference Drop in posix_clock_release(): When task 2 closes /dev/ptp0 (during process exit via close_files() -> filp_close_sync() -> __fput()), __fput() executes:

    if (file->f_op->release)
        file->f_op->release(inode, file);
    if (unlikely(S_ISCHR(inode->i_mode) && inode->i_cdev != NULL &&
             !(mode & FMODE_PATH))) {
        cdev_put(inode->i_cdev);
    }
    

    First, file->f_op->release() calls posix_clock_release(), which runs:

    put_device(clk->dev);
    

    Now clk->dev is non-NULL (&ptp->dev). Because get_device() was never invoked during open, this put_device() drops a reference that was never acquired, leading to an extra/unbalanced decrement.

  5. Premature Deallocation & Use-After-Free: The unbalanced put_device(&ptp->dev) decrements ptp->dev.kobj's reference count to zero. This triggers device_release() -> ptp_clock_release():

    static void ptp_clock_release(struct device *dev)
    {
        ...
        kfree(ptp);
    }
    

    The entire memory block holding struct ptp_clock (including ptp->clock.cdev) is freed. Immediately after file->f_op->release() returns in __fput(), line 515 executes:

    cdev_put(inode->i_cdev);
    

    In cdev_put(struct cdev *p) (fs/char_dev.c):

    void cdev_put(struct cdev *p)
    {
        if (p) {
            struct module *owner = p->owner;
            kobject_put(&p->kobj);
            module_put(owner);
        }
    }
    

    Here p is &ptp->clock.cdev. Dereferencing p->owner reads offset 144 (0x90) inside the freed 4096-byte kmalloc-4k slab object, directly triggering the reported slab-use-after-free read.

▶ ▼ ✨ AI Jobs (2)
ID Workflow Result Correct Bug Created Started Finished Revision
db76940b repro-c Reproduced: ✅ ❓ KASAN: slab-use-after-free Read in cdev_put 2026/11/14 00:20 2026/11/14 00:20 2026/11/14 05:09 819ebe34
7fcadaca assessment-security DenialOfService: ✅ Exploitable: ✅ FilesystemTrigger: ❌ FuzzingArtifact: ❌ MemoryCorruption: ✅ NetworkNeedsSetup: ❌ NetworkTrigger: ❌ PeripheralTrigger: ❌ RemoteTrigger: ❌ Unprivileged: ❌ UserNamespace: ❌ VMGuestTrigger: ❌ VMHostTrigger: ❌ ❓ KASAN: slab-use-after-free Read in cdev_put 2026/11/11 15:56 2026/11/11 15:56 2026/11/11 16:36 8d68b303
▶ ▼ Discussions (1)
Title Replies (including bot) Last reply
[syzbot] [fs?] [driver-core?] KASAN: slab-use-after-free Read in cdev_put 0 (1) 2026/11/15 16:46
▶ ▼ Last patch testing requests (1)
Created Duration User Patch Repo Result
2026/11/14 05:10 16m retest repro git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2800868f63227c8237d70c41e70d441c919620d6 report job log log

Sample crash report:
=========================
==================================================================
BUG: KASAN: slab-use-after-free in cdev_put fs/char_dev.c:363 [inline]
BUG: KASAN: slab-use-after-free in cdev_put+0x58/0x60 fs/char_dev.c:360
Read of size 8 at addr ffff888043a4a090 by task syz-executor804/6199

CPU: 2 UID: 0 PID: 6199 Comm: syz-executor804 Not tainted syzkaller #0 PREEMPT(full) 
Hardware name: QEMU Standard PC (Q35 + ICH9, 2009), BIOS 1.16.3-debian-1.16.3-2 04/01/2014
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
 cdev_put fs/char_dev.c:363 [inline]
 cdev_put+0x58/0x60 fs/char_dev.c:360
 __fput+0x904/0xb50 fs/file_table.c:515
 fput_close_sync+0x118/0x250 fs/file_table.c:618
 filp_close_sync+0x75/0xa0 fs/open.c:1574
 close_files fs/file.c:572 [inline]
 put_files_struct fs/file.c:584 [inline]
 put_files_struct+0x1f7/0x390 fs/file.c:581
 switch_files_struct fs/file.c:598 [inline]
 exit_files+0x85/0xb0 fs/file.c:604
 do_exit+0x896/0x2a00 kernel/exit.c:977
 do_group_exit+0xd5/0x2a0 kernel/exit.c:1123
 __do_sys_exit_group kernel/exit.c:1134 [inline]
 __se_sys_exit_group kernel/exit.c:1132 [inline]
 __ia32_sys_exit_group+0x3e/0x50 kernel/exit.c:1132
 ia32_sys_call+0x1a39/0x1a40 arch/x86/include/generated/asm/syscalls_32.h:253
 do_syscall_32_irqs_on arch/x86/entry/syscall_32.c:79 [inline]
 __do_fast_syscall_32+0x14d/0x8e0 arch/x86/entry/syscall_32.c:286
 do_fast_syscall_32+0x32/0x70 arch/x86/entry/syscall_32.c:311
 entry_SYSENTER_compat_after_hwframe+0x84/0x8e
RIP: 0023:0xf7e91fbc
Code: Unable to access opcode bytes at 0xf7e91f92.
RSP: 002b:00000000f5e85688 EFLAGS: 00000292 ORIG_RAX: 00000000000000fc
RAX: ffffffffffffffda RBX: 0000000000000000 RCX: 00000000ffffffe8
RDX: 00000000000000fc RSI: 00000000f5e856d0 RDI: 00000000f5e856d0
RBP: 00000000f5e856d0 R08: 0000000000000000 R09: 0000000000000000
R10: 0000000000000000 R11: 0000000000000246 R12: 0000000000000000
R13: 0000000000000000 R14: 0000000000000000 R15: 0000000000000000
 </TASK>

Allocated by task 6126:
 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+0xaa/0xb0 mm/kasan/common.c:426
 kasan_kmalloc include/linux/kasan.h:263 [inline]
 __kmalloc_cache_noprof+0x2f8/0x6d0 mm/slub.c:5680
 _kmalloc_noprof include/linux/slab.h:991 [inline]
 _kzalloc_noprof include/linux/slab.h:1312 [inline]
 ptp_clock_register+0x187/0x1780 drivers/ptp/ptp_clock.c:343
 ptp_vclock_register+0x51f/0xa10 drivers/ptp/ptp_vclock.c:256
 n_vclocks_store+0x1b1/0x600 drivers/ptp/ptp_sysfs.c:230
 dev_attr_store+0x58/0x80 drivers/base/core.c:2509
 sysfs_kf_write+0xf2/0x150 fs/sysfs/file.c:145
 kernfs_fop_write_iter+0x3e0/0x5f0 fs/kernfs/file.c:345
 new_sync_write fs/read_write.c:575 [inline]
 vfs_write+0x6af/0x1040 fs/read_write.c:667
 ksys_pwrite64+0x113/0x230 fs/read_write.c:774
 do_syscall_32_irqs_on arch/x86/entry/syscall_32.c:79 [inline]
 do_int80_emulation+0x16a/0x670 arch/x86/entry/syscall_32.c:170
 asm_int80_emulation+0x1a/0x20 arch/x86/include/asm/idtentry.h:598

Freed by task 6199:
 kasan_save_stack+0x30/0x50 mm/kasan/common.c:57
 kasan_save_track+0x14/0x30 mm/kasan/common.c:78
 kasan_save_free_info+0x3b/0x70 mm/kasan/generic.c:584
 poison_slab_object mm/kasan/common.c:264 [inline]
 __kasan_slab_free+0x5f/0x80 mm/kasan/common.c:296
 kasan_slab_free include/linux/kasan.h:235 [inline]
 slab_free_hook mm/slub.c:2780 [inline]
 slab_free mm/slub.c:6630 [inline]
 kfree+0x22b/0x6d0 mm/slub.c:6923
 device_release+0xd2/0x270 drivers/base/core.c:2640
 kobject_cleanup lib/kobject.c:689 [inline]
 kobject_release lib/kobject.c:720 [inline]
 kref_put include/linux/kref.h:65 [inline]
 kobject_put+0x1f7/0x640 lib/kobject.c:737
 put_device+0x1f/0x30 drivers/base/core.c:3886
 posix_clock_release+0xd5/0x150 kernel/time/posix-clock.c:142
 __fput+0x3fb/0xb50 fs/file_table.c:512
 fput_close_sync+0x118/0x250 fs/file_table.c:618
 filp_close_sync+0x75/0xa0 fs/open.c:1574
 close_files fs/file.c:572 [inline]
 put_files_struct fs/file.c:584 [inline]
 put_files_struct+0x1f7/0x390 fs/file.c:581
 switch_files_struct fs/file.c:598 [inline]
 exit_files+0x85/0xb0 fs/file.c:604
 do_exit+0x896/0x2a00 kernel/exit.c:977
 do_group_exit+0xd5/0x2a0 kernel/exit.c:1123
 __do_sys_exit_group kernel/exit.c:1134 [inline]
 __se_sys_exit_group kernel/exit.c:1132 [inline]
 __ia32_sys_exit_group+0x3e/0x50 kernel/exit.c:1132
 ia32_sys_call+0x1a39/0x1a40 arch/x86/include/generated/asm/syscalls_32.h:253
 do_syscall_32_irqs_on arch/x86/entry/syscall_32.c:79 [inline]
 __do_fast_syscall_32+0x14d/0x8e0 arch/x86/entry/syscall_32.c:286
 do_fast_syscall_32+0x32/0x70 arch/x86/entry/syscall_32.c:311
 entry_SYSENTER_compat_after_hwframe+0x84/0x8e

The buggy address belongs to the object at ffff888043a4a000
 which belongs to the cache kmalloc-4k of size 4096
The buggy address is located 144 bytes inside of
 freed 4096-byte region [ffff888043a4a000, ffff888043a4b000)

The buggy address belongs to the physical page:
page: refcount:0 mapcount:0 mapping:0000000000000000 index:0x0 pfn:0x43a48
head: order:3 mapcount:0 entire_mapcount:0 nr_pages_mapped:0 pincount:0
flags: 0x4fff00000000040(head|node=1|zone=1|lastcpupid=0x7ff)
page_type: f5(slab)
raw: 04fff00000000040 ffff88801d443040 dead000000000122 0000000000000000
raw: 0000000000000000 0000000000040004 00000000f5000000 0000000000000000
head: 04fff00000000040 ffff88801d443040 dead000000000122 0000000000000000
head: 0000000000000000 0000000000040004 00000000f5000000 0000000000000000
head: 04fff00000000003 fffffffffffffe01 00000000ffffffff 00000000ffffffff
head: ffffffffffffffff 0000000000000000 00000000ffffffff 0000000000000008
page dumped because: kasan: bad access detected
page_owner tracks the page as allocated
page last allocated via order 3, migratetype Unmovable, gfp_mask 0xd2040(__GFP_IO|__GFP_NOWARN|__GFP_NORETRY|__GFP_COMP|__GFP_NOMEMALLOC), pid 6143, tgid 6143 (udevd), ts 68631299502
 set_page_owner include/linux/page_owner.h:33 [inline]
 post_alloc_hook+0xfd/0x120 mm/page_alloc.c:1860
 prep_new_page mm/page_alloc.c:1868 [inline]
 get_page_from_freelist+0xdae/0x2c80 mm/page_alloc.c:3950
 __alloc_frozen_pages_noprof+0x2ad/0x31e0 mm/page_alloc.c:5492
 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_noprof+0x677/0x840 mm/slub.c:5556
 _kmalloc_noprof include/linux/slab.h:995 [inline]
 tomoyo_realpath_from_path+0xb6/0x690 security/tomoyo/realpath.c:251
 tomoyo_get_realpath security/tomoyo/file.c:151 [inline]
 tomoyo_path_perm+0x276/0x460 security/tomoyo/file.c:827
 tomoyo_path_unlink+0x91/0xe0 security/tomoyo/tomoyo.c:162
 security_path_unlink+0x145/0x2b0 security/security.c:1498
 filename_unlinkat+0x316/0x770 fs/namei.c:5734
 __do_sys_unlink fs/namei.c:5772 [inline]
 __se_sys_unlink fs/namei.c:5769 [inline]
 __x64_sys_unlink+0x46/0x70 fs/namei.c:5769
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x123/0x780 arch/x86/entry/syscall_64.c:89
 entry_SYSCALL_64_after_hwframe+0x77/0x7f
page last free pid 5200 tgid 5200 ts 68611259383 stack trace:
 reset_page_owner include/linux/page_owner.h:26 [inline]
 __free_pages_prepare mm/page_alloc.c:1402 [inline]
 __free_frozen_pages+0x7b1/0x10f0 mm/page_alloc.c:2958
 qlink_free mm/kasan/quarantine.c:163 [inline]
 qlist_free_all+0x47/0xf0 mm/kasan/quarantine.c:179
 kasan_quarantine_reduce+0x1a0/0x1f0 mm/kasan/quarantine.c:286
 __kasan_slab_alloc+0x69/0x90 mm/kasan/common.c:361
 kasan_slab_alloc include/linux/kasan.h:253 [inline]
 slab_post_alloc_hook mm/slub.c:4720 [inline]
 slab_alloc_node mm/slub.c:5033 [inline]
 kmem_cache_alloc_lru_noprof+0x265/0x6a0 mm/slub.c:5066
 shmem_alloc_inode+0x25/0x50 mm/shmem.c:5374
 alloc_inode+0x68/0x250 fs/inode.c:338
 new_inode+0x22/0x1c0 fs/inode.c:1192
 __shmem_get_inode mm/shmem.c:3285 [inline]
 shmem_get_inode+0x1e3/0xff0 mm/shmem.c:3361
 shmem_mknod+0x217/0x480 mm/shmem.c:4072
 lookup_open+0xd8a/0x19e0 fs/namei.c:4575
 open_last_lookups fs/namei.c:4774 [inline]
 path_openat+0xe75/0x23f0 fs/namei.c:5013
 do_file_open+0x20e/0x430 fs/namei.c:5045
 do_sys_openat2+0x163/0x1d0 fs/open.c:1443
 do_sys_open fs/open.c:1449 [inline]
 __do_sys_openat fs/open.c:1465 [inline]
 __se_sys_openat fs/open.c:1460 [inline]
 __x64_sys_openat+0x12d/0x210 fs/open.c:1460
 do_syscall_x64 arch/x86/entry/syscall_64.c:61 [inline]
 do_syscall_64+0x123/0x780 arch/x86/entry/syscall_64.c:89

Memory state around the buggy address:
 ffff888043a49f80: fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc fc
 ffff888043a4a000: fa fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
>ffff888043a4a080: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
                         ^
 ffff888043a4a100: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
 ffff888043a4a180: fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb fb
==================================================================

Crashes (2):
Time Kernel Commit Syzkaller Config Log Report Syz repro C repro VM info Assets (help?) Manager Title
2026/11/14 05:27 git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git 2800868f6322 e56a968c .config console log report C ci-qemu-upstream-386 KASAN: slab-use-after-free Read in cdev_put
2026/11/11 15:56 upstream 067c5c24cef2 e56a968c .config console log report info [disk image (non-bootable)] [vmlinux] [kernel image] ci-qemu-upstream-386 KASAN: slab-use-after-free Read in cdev_put
* Struck through repros no longer work on HEAD.