From 16c1c75c48e2b9805dc56458112c3cdfb9b02dbd Mon Sep 17 00:00:00 2001 From: ChenJie Date: Tue, 31 May 2022 15:30:34 +0800 Subject: [PATCH 1/3] add memmgr user and allow it control memcg Signed-off-by: ChenJie --- include/linux/uidgid.h | 4 ++++ kernel/cgroup/cgroup-v1.c | 3 +++ 2 files changed, 7 insertions(+) diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h index b0542cd11aeb..3c096646db4f 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_GID KGIDT_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..4b16a6319852 100644 --- a/kernel/cgroup/cgroup-v1.c +++ b/kernel/cgroup/cgroup-v1.c @@ -512,6 +512,9 @@ static ssize_t __cgroup1_procs_write(struct kernfs_open_file *of, cred = of->file->f_cred; tcred = get_task_cred(task); if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) && +#ifdef CONFIG_HYPERHOLD + !uid_eq(cred->euid, GLOBAL_MEMMGR_GID) && +#endif !uid_eq(cred->euid, tcred->uid) && !uid_eq(cred->euid, tcred->suid)) ret = -EACCES; -- Gitee From 31be52e9100b37b9a305ce23f9a45181eaaec43b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=9D=B0?= Date: Mon, 6 Jun 2022 06:24:42 +0000 Subject: [PATCH 2/3] update include/linux/uidgid.h. Signed-off-by: ChenJie --- include/linux/uidgid.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h index 3c096646db4f..120ef9f71914 100644 --- a/include/linux/uidgid.h +++ b/include/linux/uidgid.h @@ -56,7 +56,7 @@ static inline gid_t __kgid_val(kgid_t gid) #define GLOBAL_ROOT_GID KGIDT_INIT(0) #ifdef CONFIG_HYPERHOLD -#define GLOBAL_MEMMGR_GID KGIDT_INIT(1111) +#define GLOBAL_MEMMGR_UID KUIDT_INIT(1111) #endif #define INVALID_UID KUIDT_INIT(-1) -- Gitee From ba0b0f74d19b3acb33760e2edc341d5fe052d9ef Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=99=88=E6=9D=B0?= Date: Mon, 6 Jun 2022 06:27:02 +0000 Subject: [PATCH 3/3] update kernel/cgroup/cgroup-v1.c. Signed-off-by: ChenJie --- kernel/cgroup/cgroup-v1.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/kernel/cgroup/cgroup-v1.c b/kernel/cgroup/cgroup-v1.c index 4b16a6319852..d9f8a464b7f4 100644 --- a/kernel/cgroup/cgroup-v1.c +++ b/kernel/cgroup/cgroup-v1.c @@ -511,9 +511,11 @@ static ssize_t __cgroup1_procs_write(struct kernfs_open_file *of, */ cred = of->file->f_cred; tcred = get_task_cred(task); - if (!uid_eq(cred->euid, GLOBAL_ROOT_UID) && #ifdef CONFIG_HYPERHOLD - !uid_eq(cred->euid, GLOBAL_MEMMGR_GID) && + 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)) -- Gitee