From 3ffd3cdfe397a0274bdb8ce97517a29c3ad9344e Mon Sep 17 00:00:00 2001 From: Suren Baghdasaryan Date: Wed, 31 Aug 2022 11:10:40 -0700 Subject: [PATCH] ANDROID: Revert "psi: allow unprivileged users with CAP_SYS_RESOURCE to write psi files" This reverts commit 6db12ee0456d0e369c7b59788d46e15a56ad0294. In Android, system_server registers psi trigger to detect memory pressure. This commit requires processes registering new triggers to have CAP_SYS_RESOURCE capability, which system_server does not have. Reverting this change until a solution can be found to fix the breakage of functionality in Android T using 5.15 kernels. Bug: 243781242 Bug: 244148051 Reported-by: liuhailong Signed-off-by: Suren Baghdasaryan Change-Id: If6c8580af8734f3b765d48c782a536aad357e6f0 (cherry picked from commit e1b8ef44fd2930d2cc840b2c179b691c83e1f20b) --- kernel/sched/psi.c | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/kernel/sched/psi.c b/kernel/sched/psi.c index 966d79d22ab5..5b42e7c425d0 100644 --- a/kernel/sched/psi.c +++ b/kernel/sched/psi.c @@ -1302,27 +1302,19 @@ static int psi_cpu_show(struct seq_file *m, void *v) 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) { - return psi_open(file, psi_io_show); + return single_open(file, psi_io_show, NULL); } static int psi_memory_open(struct inode *inode, struct file *file) { - return psi_open(file, psi_memory_show); + return single_open(file, psi_memory_show, NULL); } static int psi_cpu_open(struct inode *inode, struct file *file) { - return psi_open(file, psi_cpu_show); + return single_open(file, psi_cpu_show, NULL); } static ssize_t psi_write(struct file *file, const char __user *user_buf, @@ -1432,9 +1424,9 @@ static int __init psi_proc_init(void) { if (psi_enable) { proc_mkdir("pressure", NULL); - proc_create("pressure/io", 0666, NULL, &psi_io_proc_ops); - proc_create("pressure/memory", 0666, NULL, &psi_memory_proc_ops); - proc_create("pressure/cpu", 0666, NULL, &psi_cpu_proc_ops); + proc_create("pressure/io", 0, NULL, &psi_io_proc_ops); + proc_create("pressure/memory", 0, NULL, &psi_memory_proc_ops); + proc_create("pressure/cpu", 0, NULL, &psi_cpu_proc_ops); } return 0; }