Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

cred: conditionally declare groups-related functions

The groups-related functions declared in include/linux/cred.h are
defined in kernel/groups.c, which is compiled only when
CONFIG_MULTIUSER=y. Move all these function declarations under #ifdef
CONFIG_MULTIUSER to help avoid accidental usage in contexts where
CONFIG_MULTIUSER might be disabled.

This patch also adds a fallback for groups_search(). Currently this
function is only called from kernel/groups.c itself and
security/keys/permissions.c, where the call is (by coincidence)
optimized away in case CONFIG_MULTIUSER=n. However, the audit subsystem
(which does not depend on CONFIG_MULTIUSER) calls this function in
-next, so the fallback will be needed to avoid compilation errors or
ugly workarounds.

See also:
https://lkml.org/lkml/2018/6/20/670
https://git.kernel.org/pub/scm/linux/kernel/git/pcmoore/audit.git/commit/?h=next&id=af85d1772e31fed34165a1b3decef340cf4080c0

Reported-by: Randy Dunlap <rdunlap@infradead.org>
Tested-by: Randy Dunlap <rdunlap@infradead.org>
Signed-off-by: Ondrej Mosnacek <omosnace@redhat.com>
Signed-off-by: Paul Moore <paul@paul-moore.com>

authored by

Ondrej Mosnáček and committed by
Paul Moore
4b09791b f7859590

+10 -5
+10 -5
include/linux/cred.h
··· 65 65 66 66 extern int in_group_p(kgid_t); 67 67 extern int in_egroup_p(kgid_t); 68 + extern int groups_search(const struct group_info *, kgid_t); 69 + 70 + extern int set_current_groups(struct group_info *); 71 + extern void set_groups(struct cred *, struct group_info *); 72 + extern bool may_setgroups(void); 73 + extern void groups_sort(struct group_info *); 68 74 #else 69 75 static inline void groups_free(struct group_info *group_info) 70 76 { ··· 84 78 { 85 79 return 1; 86 80 } 81 + static inline int groups_search(const struct group_info *group_info, kgid_t grp) 82 + { 83 + return 1; 84 + } 87 85 #endif 88 - extern int set_current_groups(struct group_info *); 89 - extern void set_groups(struct cred *, struct group_info *); 90 - extern int groups_search(const struct group_info *, kgid_t); 91 - extern bool may_setgroups(void); 92 - extern void groups_sort(struct group_info *); 93 86 94 87 /* 95 88 * The security context of a task