Re: [PATCH v4] sched/psi: fix race between file release and pressure write

From: Edward Adam Davis

Date: Tue Apr 14 2026 - 00:08:52 EST


On Tue, 14 Apr 2026 10:29:20 +0800, Chen Ridong wrote:
> CPU0: write memory.pressure CPU1: write cgroup.pressure=0
> ================================== ==================================
>
> kernfs_fop_write_iter()
> kernfs_get_active_of(of)
> pressure_write()
> cgroup_kn_lock_live(memory.pressure)
> cgroup_tryget(cgrp)
> kernfs_break_active_protection(kn)
> ... blocks on cgroup_mutex
>
> cgroup_pressure_write()
> cgroup_kn_lock_live(cgroup.pressure)
> cgroup_file_show(memory.pressure, false)
> kernfs_show(false)
> kernfs_drain_open_files()
> cgroup_file_release(of)
> kfree(ctx)
> of->priv = NULL
> cgroup_kn_unlock()
>
> ... acquires cgroup_mutex
> ctx = of->priv; // may now be NULL
> if (ctx->psi.trigger) // NULL dereference
>
> IIUC, for rmdir, 'of->priv cannot be NULL' may be true, but for the other patch
> shown above, it might not be.
Marvelous!

Edward
BR