Skip to content

Commit 385aac1

Browse files
odinugehtejun
authored andcommitted
cgroup: fix psi monitor for root cgroup
Fix NULL pointer dereference when adding new psi monitor to the root cgroup. PSI files for root cgroup was introduced in df5ba5b by using system wide psi struct when reading, but file write/monitor was not properly fixed. Since the PSI config for the root cgroup isn't initialized, the current implementation tries to lock a NULL ptr, resulting in a crash. Can be triggered by running this as root: $ tee /sys/fs/cgroup/cpu.pressure <<< "some 10000 1000000" Signed-off-by: Odin Ugedal <[email protected]> Reviewed-by: Suren Baghdasaryan <[email protected]> Acked-by: Dan Schatzberg <[email protected]> Fixes: df5ba5b ("kernel/sched/psi.c: expose pressure metrics on root cgroup") Acked-by: Johannes Weiner <[email protected]> Cc: [email protected] # 5.2+ Signed-off-by: Tejun Heo <[email protected]>
1 parent b5e5657 commit 385aac1

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

kernel/cgroup/cgroup.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3564,6 +3564,7 @@ static ssize_t cgroup_pressure_write(struct kernfs_open_file *of, char *buf,
35643564
{
35653565
struct psi_trigger *new;
35663566
struct cgroup *cgrp;
3567+
struct psi_group *psi;
35673568

35683569
cgrp = cgroup_kn_lock_live(of->kn, false);
35693570
if (!cgrp)
@@ -3572,7 +3573,8 @@ static ssize_t cgroup_pressure_write(struct kernfs_open_file *of, char *buf,
35723573
cgroup_get(cgrp);
35733574
cgroup_kn_unlock(of->kn);
35743575

3575-
new = psi_trigger_create(&cgrp->psi, buf, nbytes, res);
3576+
psi = cgroup_ino(cgrp) == 1 ? &psi_system : &cgrp->psi;
3577+
new = psi_trigger_create(psi, buf, nbytes, res);
35763578
if (IS_ERR(new)) {
35773579
cgroup_put(cgrp);
35783580
return PTR_ERR(new);

0 commit comments

Comments
 (0)