[RFC PATCH] proc: add support detach proccess's autogroup
From: Weiping Zhang
Date: Thu Jul 02 2020 - 03:50:43 EST
Since setid will create a autogroup for that process, there is no
way to detach a process from that autogroup, this patch add a new interface
to detach a process from its autogroup. You can write anything to
/proc/<pid>/autogroup_detach to do that.
Signed-off-by: Weiping Zhang <zhangweiping@xxxxxxxxxxxxxx>
---
fs/proc/base.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 50 insertions(+)
diff --git a/fs/proc/base.c b/fs/proc/base.c
index d86c0afc8a85..a210cab8b52d 100644
--- a/fs/proc/base.c
+++ b/fs/proc/base.c
@@ -1541,6 +1541,55 @@ static const struct file_operations proc_pid_sched_autogroup_operations = {
.release = single_release,
};
+static int sched_autogroup_detach_show(struct seq_file *m, void *v)
+{
+ struct inode *inode = m->private;
+
+ seq_printf(m, "write any data to detach this task from a autogroup\n");
+
+ return 0;
+}
+
+static int sched_autogroup_detach_open(struct inode *inode, struct file *filp)
+{
+ int ret;
+
+ ret = single_open(filp, sched_autogroup_detach_show, NULL);
+ if (!ret) {
+ struct seq_file *m = filp->private_data;
+
+ m->private = inode;
+ }
+ return ret;
+}
+
+static ssize_t
+sched_autogroup_detach_write(struct file *file, const char __user *buf,
+ size_t count, loff_t *offset)
+{
+ struct inode *inode = file_inode(file);
+ struct task_struct *p;
+ int ret;
+
+ p = get_proc_task(inode);
+ if (!p)
+ return -ESRCH;
+
+ sched_autogroup_detach(p);
+
+ put_task_struct(p);
+
+ return count;
+}
+
+static const struct file_operations proc_pid_sched_autogroup_detach_operations = {
+ .open = sched_autogroup_detach_open,
+ .read = seq_read,
+ .write = sched_autogroup_detach_write,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
#endif /* CONFIG_SCHED_AUTOGROUP */
#ifdef CONFIG_TIME_NS
@@ -3161,6 +3210,7 @@ static const struct pid_entry tgid_base_stuff[] = {
#endif
#ifdef CONFIG_SCHED_AUTOGROUP
REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
+ REG("autogroup_detach", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_detach_operations),
#endif
#ifdef CONFIG_TIME_NS
REG("timens_offsets", S_IRUGO|S_IWUSR, proc_timens_offsets_operations),
--
2.14.1