diff options
| author | Thiago Rafael Becker <thiago.becker@gmail.com> | 2017-12-14 18:33:12 -0500 |
|---|---|---|
| committer | Linus Torvalds <torvalds@linux-foundation.org> | 2017-12-14 19:00:49 -0500 |
| commit | bdcf0a423ea1c40bbb40e7ee483b50fc8aa3d758 (patch) | |
| tree | 942b1b8fa9b1e52503d5f9894d43674255813566 /kernel | |
| parent | 1f704fd0d14043e76e80f6b8b2251b9b2cedcca6 (diff) | |
kernel: make groups_sort calling a responsibility group_info allocators
In testing, we found that nfsd threads may call set_groups in parallel
for the same entry cached in auth.unix.gid, racing in the call of
groups_sort, corrupting the groups for that entry and leading to
permission denials for the client.
This patch:
- Make groups_sort globally visible.
- Move the call to groups_sort to the modifiers of group_info
- Remove the call to groups_sort from set_groups
Link: http://lkml.kernel.org/r/20171211151420.18655-1-thiago.becker@gmail.com
Signed-off-by: Thiago Rafael Becker <thiago.becker@gmail.com>
Reviewed-by: Matthew Wilcox <mawilcox@microsoft.com>
Reviewed-by: NeilBrown <neilb@suse.com>
Acked-by: "J. Bruce Fields" <bfields@fieldses.org>
Cc: Al Viro <viro@zeniv.linux.org.uk>
Cc: Martin Schwidefsky <schwidefsky@de.ibm.com>
Cc: <stable@vger.kernel.org>
Signed-off-by: Andrew Morton <akpm@linux-foundation.org>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
Diffstat (limited to 'kernel')
| -rw-r--r-- | kernel/groups.c | 5 | ||||
| -rw-r--r-- | kernel/uid16.c | 1 |
2 files changed, 4 insertions, 2 deletions
diff --git a/kernel/groups.c b/kernel/groups.c index e357bc800111..daae2f2dc6d4 100644 --- a/kernel/groups.c +++ b/kernel/groups.c | |||
| @@ -86,11 +86,12 @@ static int gid_cmp(const void *_a, const void *_b) | |||
| 86 | return gid_gt(a, b) - gid_lt(a, b); | 86 | return gid_gt(a, b) - gid_lt(a, b); |
| 87 | } | 87 | } |
| 88 | 88 | ||
| 89 | static void groups_sort(struct group_info *group_info) | 89 | void groups_sort(struct group_info *group_info) |
| 90 | { | 90 | { |
| 91 | sort(group_info->gid, group_info->ngroups, sizeof(*group_info->gid), | 91 | sort(group_info->gid, group_info->ngroups, sizeof(*group_info->gid), |
| 92 | gid_cmp, NULL); | 92 | gid_cmp, NULL); |
| 93 | } | 93 | } |
| 94 | EXPORT_SYMBOL(groups_sort); | ||
| 94 | 95 | ||
| 95 | /* a simple bsearch */ | 96 | /* a simple bsearch */ |
| 96 | int groups_search(const struct group_info *group_info, kgid_t grp) | 97 | int groups_search(const struct group_info *group_info, kgid_t grp) |
| @@ -122,7 +123,6 @@ int groups_search(const struct group_info *group_info, kgid_t grp) | |||
| 122 | void set_groups(struct cred *new, struct group_info *group_info) | 123 | void set_groups(struct cred *new, struct group_info *group_info) |
| 123 | { | 124 | { |
| 124 | put_group_info(new->group_info); | 125 | put_group_info(new->group_info); |
| 125 | groups_sort(group_info); | ||
| 126 | get_group_info(group_info); | 126 | get_group_info(group_info); |
| 127 | new->group_info = group_info; | 127 | new->group_info = group_info; |
| 128 | } | 128 | } |
| @@ -206,6 +206,7 @@ SYSCALL_DEFINE2(setgroups, int, gidsetsize, gid_t __user *, grouplist) | |||
| 206 | return retval; | 206 | return retval; |
| 207 | } | 207 | } |
| 208 | 208 | ||
| 209 | groups_sort(group_info); | ||
| 209 | retval = set_current_groups(group_info); | 210 | retval = set_current_groups(group_info); |
| 210 | put_group_info(group_info); | 211 | put_group_info(group_info); |
| 211 | 212 | ||
diff --git a/kernel/uid16.c b/kernel/uid16.c index ce74a4901d2b..ef1da2a5f9bd 100644 --- a/kernel/uid16.c +++ b/kernel/uid16.c | |||
| @@ -192,6 +192,7 @@ SYSCALL_DEFINE2(setgroups16, int, gidsetsize, old_gid_t __user *, grouplist) | |||
| 192 | return retval; | 192 | return retval; |
| 193 | } | 193 | } |
| 194 | 194 | ||
| 195 | groups_sort(group_info); | ||
| 195 | retval = set_current_groups(group_info); | 196 | retval = set_current_groups(group_info); |
| 196 | put_group_info(group_info); | 197 | put_group_info(group_info); |
| 197 | 198 | ||
