]> Git Repo - linux.git/commitdiff
cgroup: fix psi monitor for root cgroup
authorOdin Ugedal <[email protected]>
Sat, 16 Jan 2021 17:36:33 +0000 (18:36 +0100)
committerTejun Heo <[email protected]>
Tue, 19 Jan 2021 16:37:05 +0000 (11:37 -0500)
Fix NULL pointer dereference when adding new psi monitor to the root
cgroup. PSI files for root cgroup was introduced in df5ba5be742 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: df5ba5be7425 ("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]>
kernel/cgroup/cgroup.c

index 613845769103cd36ab9ef9340b9dd90f5c20f5f9..1ea995f801ecfe36098a6e3f08c2dd3e9c2394c2 100644 (file)
@@ -3564,6 +3564,7 @@ static ssize_t cgroup_pressure_write(struct kernfs_open_file *of, char *buf,
 {
        struct psi_trigger *new;
        struct cgroup *cgrp;
+       struct psi_group *psi;
 
        cgrp = cgroup_kn_lock_live(of->kn, false);
        if (!cgrp)
@@ -3572,7 +3573,8 @@ static ssize_t cgroup_pressure_write(struct kernfs_open_file *of, char *buf,
        cgroup_get(cgrp);
        cgroup_kn_unlock(of->kn);
 
-       new = psi_trigger_create(&cgrp->psi, buf, nbytes, res);
+       psi = cgroup_ino(cgrp) == 1 ? &psi_system : &cgrp->psi;
+       new = psi_trigger_create(psi, buf, nbytes, res);
        if (IS_ERR(new)) {
                cgroup_put(cgrp);
                return PTR_ERR(new);
This page took 0.068178 seconds and 4 git commands to generate.