rendered paste body#include <linux/module.h>#include <linux/cgroup.h>#include <linux/fs.h>#include <linux/slab.h>MODULE_LICENSE("GPL");MODULE_AUTHOR("bblom");u64 test1 = 0;struct test1_cgroup { struct cgroup_subsys_state css;};static struct cgroup_subsys_state *test1_create(struct cgroup_subsys *ss, struct cgroup *cgroup){ struct test1_cgroup *foo = kzalloc(sizeof(*foo), GFP_KERNEL); if (!foo) return ERR_PTR(-ENOMEM); return &foo->css;}static int test1_can_attach(struct cgroup_subsys *ss, struct cgroup *new_cgroup, struct task_struct *task, bool threadgroup){ if (test1 == 42) return 0; return -EPERM;}static int test1_write(struct cgroup *cgrp, struct cftype *cft, u64 val){ test1 = val; return 0;}static u64 test1_read(struct cgroup *cgrp, struct cftype *cft){ return test1;}static struct cftype test1_file = { .name = "hax", .write_u64 = test1_write, .read_u64 = test1_read,};static int test1_populate(struct cgroup_subsys *ss, struct cgroup *cgroup){ return cgroup_add_file(cgroup, ss, &test1_file);}struct cgroup_subsys test1_subsys = { .name = "test1", .can_attach = test1_can_attach, .create = test1_create, .populate = test1_populate, .module = THIS_MODULE,};static int test1_load(void){ return cgroup_load_subsys(&test1_subsys);}module_init(test1_load);