From 15bded54c94013e1911394ab8886437296a16fd5 Mon Sep 17 00:00:00 2001 From: wanghao-free Date: Thu, 9 Sep 2021 02:30:38 -0700 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=9B=9E=E9=80=80=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E5=90=88=E5=85=A5=E7=9A=84=E8=A7=A3=E5=86=B3getgroups=E7=9A=84?= =?UTF-8?q?list=E6=AF=94=E8=AE=BE=E7=BD=AE=E7=9A=84list=E5=A4=9A=E4=B8=80?= =?UTF-8?q?=E4=B8=AAgid=E9=97=AE=E9=A2=98=E7=9A=84=E4=BF=AE=E6=94=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 主干不存在该问题. 回退原因是要求维护这边合入的人没有跟问题修改人赵天宇确认,实际上这个问题单解决不在内核这边, 内核这边的提交需要回退 Close #I48FMK Signed-off-by: wanghao-free --- syscall/process_syscall.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/syscall/process_syscall.c b/syscall/process_syscall.c index 467bd1a4..b54f8bb8 100644 --- a/syscall/process_syscall.c +++ b/syscall/process_syscall.c @@ -683,12 +683,12 @@ int SysGetGroupID(void) } #ifdef LOSCFG_SECURITY_CAPABILITY -static int SetGroups(int size, const int *safeList) +static int SetGroups(int listSize, const int *safeList, int size) { User *oldUser = NULL; unsigned int intSave; - User *newUser = LOS_MemAlloc(m_aucSysMem1, sizeof(User) + size * sizeof(int)); + User *newUser = LOS_MemAlloc(m_aucSysMem1, sizeof(User) + listSize * sizeof(int)); if (newUser == NULL) { return -ENOMEM; } @@ -696,11 +696,14 @@ static int SetGroups(int size, const int *safeList) SCHEDULER_LOCK(intSave); oldUser = OsCurrUserGet(); (VOID)memcpy_s(newUser, sizeof(User), oldUser, sizeof(User)); - if (size != 0) { + if (safeList != NULL) { (VOID)memcpy_s(newUser->groups, size * sizeof(int), safeList, size * sizeof(int)); } - - newUser->groupNumber = size; + if (listSize == size) { + newUser->groups[listSize] = oldUser->gid; + } + + newUser->groupNumber = listSize + 1; OsCurrProcessGet()->user = newUser; SCHEDULER_UNLOCK(intSave); @@ -721,7 +724,7 @@ static int GetGroups(int size, int list[]) SCHEDULER_UNLOCK(intSave); listSize = groupCount * sizeof(int); - if ((size == 0) || (groupCount == 0)) { + if (size == 0) { return groupCount; } else if (list == NULL) { return -EFAULT; @@ -779,6 +782,7 @@ int SysSetGroups(int size, const int list[]) #ifdef LOSCFG_SECURITY_CAPABILITY int ret; int gid; + int listSize = size; unsigned int count; int *safeList = NULL; #endif @@ -809,14 +813,16 @@ int SysSetGroups(int size, const int list[]) } gid = OsCurrUserGet()->gid; for (count = 0; count < size; count++) { - if (safeList[count] < 0) { + if (safeList[count] == gid) { + listSize = size - 1; + } else if (safeList[count] < 0) { ret = -EINVAL; goto EXIT; } } } - ret = SetGroups(size, safeList); + ret = SetGroups(listSize, safeList, size); EXIT: if (safeList != NULL) { (void)LOS_MemFree(m_aucSysMem1, safeList); -- GitLab