Skip to contentSkip to conversation

possible use-after-free in btrfs_get_delayed_node()?

BUG REPORT Giovanni Cabiddu 2 participants 2 messages Dec 2, 2025 Btrfs file system

lore
Share & tools
lore
#0 lore raw

While developing this set [1] I got the following issue which seems unrelated to the set:

    refcount_t: saturated; leaking memory.
    refcount_t: addition on 0; use-after-free.
    ...
    WARNING: CPU: 67 PID: 3156316 at lib/refcount.c:22 refcount_warn_saturate+0x55/0x110
    RIP: 0010:refcount_warn_saturate+0x55/0x110
    CPU: 77 UID: 0 PID: 3002837 Comm: kworker/u1153:6
    Workqueue: btrfs-endio-write btrfs_work_helper
    Call Trace:
     <TASK>
     btrfs_get_delayed_node.isra.0+0xe9/0x1b0
     btrfs_get_or_create_delayed_node.isra.0+0x134/0x1b0
     btrfs_delayed_update_inode+0x28/0x1e0
     btrfs_update_inode+0x59/0xc0
     btrfs_finish_one_ordered+0x5c6/0xa90
     btrfs_work_helper+0xc4/0x190
     process_one_work+0x192/0x350
     worker_thread+0x25a/0x3a0
     kthread+0xfc/0x240
     ret_from_fork+0xf4/0x110
     ret_from_fork_asm+0x1a/0x30
     </TASK>

Could this be a race between btrfs_get_delayed_node() and btrfs_remove_delayed_node() where btrfs_get_delayed_node() reads btrfs_inode->delayed_node and calls refcount_inc() without checking if the node is already being freed?

    btrfs_get_delayed_node()
    ...
        node = READ_ONCE(btrfs_inode->delayed_node);
        if (node) {
            refcount_inc(&node->refs);  // node may already be freed?
            ...
        }

Thanks,

[1] https://lore.kernel.org/all/[email protected]/

Signature · 1 line
Giovanni
#1 lore raw
Quoted 26 lines · Giovanni Cabiddu

While developing this set [1] I got the following issue which seems unrelated to the set:

    refcount_t: saturated; leaking memory.
    refcount_t: addition on 0; use-after-free.
    ...
    WARNING: CPU: 67 PID: 3156316 at lib/refcount.c:22 refcount_warn_saturate+0x55/0x110
    RIP: 0010:refcount_warn_saturate+0x55/0x110
    CPU: 77 UID: 0 PID: 3002837 Comm: kworker/u1153:6
    Workqueue: btrfs-endio-write btrfs_work_helper
    Call Trace:
     <TASK>
     btrfs_get_delayed_node.isra.0+0xe9/0x1b0
     btrfs_get_or_create_delayed_node.isra.0+0x134/0x1b0
     btrfs_delayed_update_inode+0x28/0x1e0
     btrfs_update_inode+0x59/0xc0
     btrfs_finish_one_ordered+0x5c6/0xa90
     btrfs_work_helper+0xc4/0x190
     process_one_work+0x192/0x350
     worker_thread+0x25a/0x3a0
     kthread+0xfc/0x240
     ret_from_fork+0xf4/0x110
     ret_from_fork_asm+0x1a/0x30
     </TASK>
Quoted 4 lines

Could this be a race between btrfs_get_delayed_node() and btrfs_remove_delayed_node() where btrfs_get_delayed_node() reads btrfs_inode->delayed_node and calls refcount_inc() without checking if the node is already being freed?

Already reported before, see:

https://lore.kernel.org/linux-btrfs/[email protected]/

Thanks.

Quoted 16 lines
    btrfs_get_delayed_node()
    ...
        node = READ_ONCE(btrfs_inode->delayed_node);
        if (node) {
            refcount_inc(&node->refs);  // node may already be freed?
            ...
        }

Thanks,

[1] https://lore.kernel.org/all/[email protected]/

--
Giovanni