Commit 6db12ee0 authored by Josh Hunt's avatar Josh Hunt Committed by Peter Zijlstra

psi: allow unprivileged users with CAP_SYS_RESOURCE to write psi files

Currently only root can write files under /proc/pressure. Relax this to
allow tasks running as unprivileged users with CAP_SYS_RESOURCE to be
able to write to these files.
Signed-off-by: default avatarJosh Hunt <johunt@akamai.com>
Signed-off-by: default avatarPeter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: default avatarJohannes Weiner <hannes@cmpxchg.org>
Link: https://lkml.kernel.org/r/20210402025833.27599-1-johunt@akamai.com
parent 0a2b65c0
...@@ -1061,19 +1061,27 @@ static int psi_cpu_show(struct seq_file *m, void *v) ...@@ -1061,19 +1061,27 @@ static int psi_cpu_show(struct seq_file *m, void *v)
return psi_show(m, &psi_system, PSI_CPU); return psi_show(m, &psi_system, PSI_CPU);
} }
static int psi_open(struct file *file, int (*psi_show)(struct seq_file *, void *))
{
if (file->f_mode & FMODE_WRITE && !capable(CAP_SYS_RESOURCE))
return -EPERM;
return single_open(file, psi_show, NULL);
}
static int psi_io_open(struct inode *inode, struct file *file) static int psi_io_open(struct inode *inode, struct file *file)
{ {
return single_open(file, psi_io_show, NULL); return psi_open(file, psi_io_show);
} }
static int psi_memory_open(struct inode *inode, struct file *file) static int psi_memory_open(struct inode *inode, struct file *file)
{ {
return single_open(file, psi_memory_show, NULL); return psi_open(file, psi_memory_show);
} }
static int psi_cpu_open(struct inode *inode, struct file *file) static int psi_cpu_open(struct inode *inode, struct file *file)
{ {
return single_open(file, psi_cpu_show, NULL); return psi_open(file, psi_cpu_show);
} }
struct psi_trigger *psi_trigger_create(struct psi_group *group, struct psi_trigger *psi_trigger_create(struct psi_group *group,
...@@ -1353,9 +1361,9 @@ static int __init psi_proc_init(void) ...@@ -1353,9 +1361,9 @@ static int __init psi_proc_init(void)
{ {
if (psi_enable) { if (psi_enable) {
proc_mkdir("pressure", NULL); proc_mkdir("pressure", NULL);
proc_create("pressure/io", 0, NULL, &psi_io_proc_ops); proc_create("pressure/io", 0666, NULL, &psi_io_proc_ops);
proc_create("pressure/memory", 0, NULL, &psi_memory_proc_ops); proc_create("pressure/memory", 0666, NULL, &psi_memory_proc_ops);
proc_create("pressure/cpu", 0, NULL, &psi_cpu_proc_ops); proc_create("pressure/cpu", 0666, NULL, &psi_cpu_proc_ops);
} }
return 0; return 0;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment