From 91f67caba2c0bfdd85ec9480574d129e89374bc5 Mon Sep 17 00:00:00 2001 From: ChenJie Date: Mon, 6 Jun 2022 15:15:51 +0800 Subject: [PATCH] add memmgr user and allow it control memcg Signed-off-by: ChenJie --- include/linux/uidgid.h | 4 ++++ kernel/cgroup/cgroup-v1.c | 5 +++++ 2 files changed, 9 insertions(+) diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h index b0542cd11aeb..120ef9f71914 100644 --- a/include/linux/uidgid.h +++ b/include/linux/uidgid.h @@ -55,6 +55,10 @@ static inline gid_t __kgid_val(kgid_t gid) #define GLOBAL_ROOT_UID KUIDT_INIT(0) #define GLOBAL_ROOT_GID KGIDT_INIT(0) +#ifdef CONFIG_HYPERHOLD +#define GLOBAL_MEMMGR_UID KUIDT_INIT(1111) +#endif + #define INVALID_UID KUIDT_INIT(-1) #define INVALID_GID KGIDT_INIT(-1) diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c index 9f5221653f80..d9f8a464b7f4 100644 --- a/kernel/cgroup/cgroup-v1.c +++ b/kernel/cgroup/cgroup-v1.c @@ -511,7 +511,12 @@ static ssize_t __cgroup1_procs_write(struct kernfs_open_file *of, */ cred = of->file->f_cred; tcred = get_task_cred(task); +#ifdef CONFIG_HYPERHOLD + if (!uid_eq(cred->euid, GLOBAL_MEMMGR_UID) && + !uid_eq(cred->euid, GLOBAL_ROOT_UID) && +#else if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) && +#endif !uid_eq(cred->euid, tcred->uid) && !uid_eq(cred->euid, tcred->suid)) ret = -EACCES; -- Gitee