Skip to content

Commit

Permalink
ucounts: In set_cred_ucounts assume new->ucounts is non-NULL
Browse files Browse the repository at this point in the history
commit 99c31f9 upstream.

Any cred that is destined for use by commit_creds must have a non-NULL
cred->ucounts field.  Only curing credential construction is a NULL
cred->ucounts valid.  Only abort_creds, put_cred, and put_cred_rcu
needs to deal with a cred with a NULL ucount.  As set_cred_ucounts is
non of those case don't confuse people by handling something that can
not happen.

Link: https://lkml.kernel.org/r/871r4irzds.fsf_-_@disp2133
Tested-by: Yu Zhao <yuzhao@google.com>
Reviewed-by: Alexey Gladkov <legion@kernel.org>
Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
  • Loading branch information
ebiederm authored and gregkh committed Feb 23, 2022
1 parent d464492 commit f418bfa
Showing 1 changed file with 2 additions and 3 deletions.
5 changes: 2 additions & 3 deletions kernel/cred.c
Expand Up @@ -676,15 +676,14 @@ int set_cred_ucounts(struct cred *new)
* This optimization is needed because alloc_ucounts() uses locks
* for table lookups.
*/
if (old_ucounts && old_ucounts->ns == new->user_ns && uid_eq(old_ucounts->uid, new->euid))
if (old_ucounts->ns == new->user_ns && uid_eq(old_ucounts->uid, new->euid))
return 0;

if (!(new_ucounts = alloc_ucounts(new->user_ns, new->euid)))
return -EAGAIN;

new->ucounts = new_ucounts;
if (old_ucounts)
put_ucounts(old_ucounts);
put_ucounts(old_ucounts);

return 0;
}
Expand Down

0 comments on commit f418bfa

Please sign in to comment.