History

sched: psi: fix unprivileged polling against cgroups

519fabc7aaba ("psi: remove 500ms min window size limitation for triggers") breaks unprivileged psi polling on cgroups. Historically, we had a privilege check for polling in the open() of a pressure file in /proc, but were erroneously missing it for the open() of cgroup pressure files. When unprivileged polling was introduced in d82caa273565 ("sched/psi: Allow unprivileged polling of N*2s period"), it needed to filter privileges depending on the exact polling parameters, and as such moved the CAP_SYS_RESOURCE check from the proc open() callback to psi_trigger_create(). Both the proc files as well as cgroup files go through this during write(). This implicitly added the missing check for privileges required for HT polling for cgroups. When 519fabc7aaba ("psi: remove 500ms min window size limitation for triggers") followed right after to remove further restrictions on the RT polling window, it incorrectly assumed the cgroup privilege check was still missing and added it to the cgroup open(), mirroring what we used to do for proc files in the past. As a result, unprivileged poll requests that would be supported now get rejected when opening the cgroup pressure file for writing. Remove the cgroup open() check. psi_trigger_create() handles it.

Johannes Weiner committed 3 years ago

Commit 8b39d201 parent eab03c21 file · +0 −12Browse files

Unified · Split

kernel/cgroup/cgroup.c+0−12
@@ -3885,14 +3885,6 @@ static __poll_t cgroup_pressure_poll(struct kernfs_open_file *of, · 3884 unmodified lines
38853885 return psi_trigger_poll(&ctx->psi.trigger, of->file, pt);
38863886 }
38873887
3888−static int cgroup_pressure_open(struct kernfs_open_file *of)
3889−{
3890− if (of->file->f_mode & FMODE_WRITE && !capable(CAP_SYS_RESOURCE))
3891− return -EPERM;
3892−
3893− return 0;
3894−}
3895−
38963888 static void cgroup_pressure_release(struct kernfs_open_file *of)
38973889 {
38983890 struct cgroup_file_ctx *ctx = of->priv;
@@ -5299,7 +5291,6 @@ static struct cftype cgroup_psi_files[] = { · 1400 unmodified lines
52995291 {
53005292 .name = "io.pressure",
53015293 .file_offset = offsetof(struct cgroup, psi_files[PSI_IO]),
5302− .open = cgroup_pressure_open,
53035294 .seq_show = cgroup_io_pressure_show,
53045295 .write = cgroup_io_pressure_write,
53055296 .poll = cgroup_pressure_poll,
@@ -5308,7 +5299,6 @@ static struct cftype cgroup_psi_files[] = { · 2 unmodified lines
53085299 {
53095300 .name = "memory.pressure",
53105301 .file_offset = offsetof(struct cgroup, psi_files[PSI_MEM]),
5311− .open = cgroup_pressure_open,
53125302 .seq_show = cgroup_memory_pressure_show,
53135303 .write = cgroup_memory_pressure_write,
53145304 .poll = cgroup_pressure_poll,
@@ -5317,7 +5307,6 @@ static struct cftype cgroup_psi_files[] = { · 2 unmodified lines
53175307 {
53185308 .name = "cpu.pressure",
53195309 .file_offset = offsetof(struct cgroup, psi_files[PSI_CPU]),
5320− .open = cgroup_pressure_open,
53215310 .seq_show = cgroup_cpu_pressure_show,
53225311 .write = cgroup_cpu_pressure_write,
53235312 .poll = cgroup_pressure_poll,
@@ -5327,7 +5316,6 @@ static struct cftype cgroup_psi_files[] = { · 3 unmodified lines
53275316 {
53285317 .name = "irq.pressure",
53295318 .file_offset = offsetof(struct cgroup, psi_files[PSI_IRQ]),
5330− .open = cgroup_pressure_open,
53315319 .seq_show = cgroup_irq_pressure_show,
53325320 .write = cgroup_irq_pressure_write,
53335321 .poll = cgroup_pressure_poll,