If sudo_getgrouplist2() returns -1, clamp ngroups based on max_groups.
The ngroups parameter is an out parameter that is filled in with the actual number of groups, which may be less than the static number allocated when max_groups is set in sudo.conf. Fixes a potential out of bounds read found by LLVM libFuzzer.
This commit is contained in:
@@ -263,7 +263,9 @@ sudo_make_gidlist_item(const struct passwd *pw, char * const *unused1,
|
||||
"unable to allocate memory");
|
||||
debug_return_ptr(NULL);
|
||||
}
|
||||
(void)sudo_getgrouplist2(pw->pw_name, pw->pw_gid, &gids, &ngids);
|
||||
/* Clamp to max_groups if insufficient space for all groups. */
|
||||
if (sudo_getgrouplist2(pw->pw_name, pw->pw_gid, &gids, &ngids) == -1)
|
||||
ngids = sudo_user.max_groups;
|
||||
} else {
|
||||
gids = NULL;
|
||||
if (sudo_getgrouplist2(pw->pw_name, pw->pw_gid, &gids, &ngids) == -1) {
|
||||
|
@@ -396,9 +396,11 @@ fill_group_list(const char *user, struct sudo_cred *cred)
|
||||
if (cred->ngroups > 0) {
|
||||
cred->groups = reallocarray(NULL, cred->ngroups, sizeof(GETGROUPS_T));
|
||||
if (cred->groups != NULL) {
|
||||
/* No error on insufficient space if user specified max_groups. */
|
||||
(void)sudo_getgrouplist2(user, cred->gid,
|
||||
&cred->groups, &cred->ngroups);
|
||||
/* Clamp to max_groups if insufficient space for all groups. */
|
||||
if (sudo_getgrouplist2(user, cred->gid, &cred->groups,
|
||||
&cred->ngroups) == -1) {
|
||||
cred->ngroups = sudo_conf_max_groups();
|
||||
}
|
||||
ret = 0;
|
||||
}
|
||||
} else {
|
||||
|
Reference in New Issue
Block a user