* [PATCH] security: fix the key_permission LSM hook function type @ 2020-06-15 18:12 Sami Tolvanen 2020-06-15 18:21 ` Kees Cook ` (2 more replies) 0 siblings, 3 replies; 6+ messages in thread From: Sami Tolvanen @ 2020-06-15 18:12 UTC (permalink / raw) To: David Howells, James Morris, Kees Cook, Eric W. Biederman, KP Singh, Casey Schaufler, Thomas Cedeno, Anders Roxell Cc: linux-kernel, Sami Tolvanen Commit 8c0637e950d6 ("keys: Make the KEY_NEED_* perms an enum rather than a mask") changed the type of the key_permission callback functions, but didn't change the type of the hook, which trips indirect call checking with Control-Flow Integrity (CFI). This change fixes the issue by changing the hook type to match the functions. Fixes: 8c0637e950d6 ("keys: Make the KEY_NEED_* perms an enum rather than a mask") Signed-off-by: Sami Tolvanen <samitolvanen@google.com> --- include/linux/lsm_hook_defs.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h index 6791813cd439..24f6683f1cfc 100644 --- a/include/linux/lsm_hook_defs.h +++ b/include/linux/lsm_hook_defs.h @@ -360,7 +360,7 @@ LSM_HOOK(int, 0, key_alloc, struct key *key, const struct cred *cred, unsigned long flags) LSM_HOOK(void, LSM_RET_VOID, key_free, struct key *key) LSM_HOOK(int, 0, key_permission, key_ref_t key_ref, const struct cred *cred, - unsigned perm) + enum key_need_perm need_perm) LSM_HOOK(int, 0, key_getsecurity, struct key *key, char **_buffer) #endif /* CONFIG_KEYS */ base-commit: b3a9e3b9622ae10064826dccb4f7a52bd88c7407 -- 2.27.0.290.gba653c62da-goog ^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH] security: fix the key_permission LSM hook function type 2020-06-15 18:12 [PATCH] security: fix the key_permission LSM hook function type Sami Tolvanen @ 2020-06-15 18:21 ` Kees Cook 2020-06-15 18:23 ` Nick Desaulniers 2020-06-21 5:54 ` Kees Cook 2020-06-22 17:38 ` James Morris 2 siblings, 1 reply; 6+ messages in thread From: Kees Cook @ 2020-06-15 18:21 UTC (permalink / raw) To: Sami Tolvanen, James Morris Cc: David Howells, Eric W. Biederman, KP Singh, Casey Schaufler, Thomas Cedeno, Anders Roxell, linux-kernel, clang-built-linux On Mon, Jun 15, 2020 at 11:12:32AM -0700, Sami Tolvanen wrote: > Commit 8c0637e950d6 ("keys: Make the KEY_NEED_* perms an enum rather than > a mask") changed the type of the key_permission callback functions, but > didn't change the type of the hook, which trips indirect call checking with > Control-Flow Integrity (CFI). This change fixes the issue by changing the > hook type to match the functions. > > Fixes: 8c0637e950d6 ("keys: Make the KEY_NEED_* perms an enum rather than a mask") > Signed-off-by: Sami Tolvanen <samitolvanen@google.com> Thanks for fixing this! Acked-by: Kees Cook <keescook@chromium.org> I wonder if there is any compiler option we can turn on to catch the implicit enum/int casting that would help for these kinds of things without absolutely exploding the build warnings. I see -Wenum-conversion, but that seems to be between enums, not between int. I see this, but it's external: https://noamlewis.wordpress.com/2017/10/05/type-safe-enums-in-c-using-a-clang-plugin/ -Kees > --- > include/linux/lsm_hook_defs.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h > index 6791813cd439..24f6683f1cfc 100644 > --- a/include/linux/lsm_hook_defs.h > +++ b/include/linux/lsm_hook_defs.h > @@ -360,7 +360,7 @@ LSM_HOOK(int, 0, key_alloc, struct key *key, const struct cred *cred, > unsigned long flags) > LSM_HOOK(void, LSM_RET_VOID, key_free, struct key *key) > LSM_HOOK(int, 0, key_permission, key_ref_t key_ref, const struct cred *cred, > - unsigned perm) > + enum key_need_perm need_perm) > LSM_HOOK(int, 0, key_getsecurity, struct key *key, char **_buffer) > #endif /* CONFIG_KEYS */ > > > base-commit: b3a9e3b9622ae10064826dccb4f7a52bd88c7407 > -- > 2.27.0.290.gba653c62da-goog > -- Kees Cook ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] security: fix the key_permission LSM hook function type 2020-06-15 18:21 ` Kees Cook @ 2020-06-15 18:23 ` Nick Desaulniers 2020-06-15 18:47 ` Kees Cook 0 siblings, 1 reply; 6+ messages in thread From: Nick Desaulniers @ 2020-06-15 18:23 UTC (permalink / raw) To: Kees Cook Cc: Sami Tolvanen, James Morris, David Howells, Eric W. Biederman, KP Singh, Casey Schaufler, Thomas Cedeno, Anders Roxell, LKML, clang-built-linux On Mon, Jun 15, 2020 at 11:21 AM Kees Cook <keescook@chromium.org> wrote: > > On Mon, Jun 15, 2020 at 11:12:32AM -0700, Sami Tolvanen wrote: > > Commit 8c0637e950d6 ("keys: Make the KEY_NEED_* perms an enum rather than > > a mask") changed the type of the key_permission callback functions, but > > didn't change the type of the hook, which trips indirect call checking with > > Control-Flow Integrity (CFI). This change fixes the issue by changing the > > hook type to match the functions. > > > > Fixes: 8c0637e950d6 ("keys: Make the KEY_NEED_* perms an enum rather than a mask") > > Signed-off-by: Sami Tolvanen <samitolvanen@google.com> > > Thanks for fixing this! > > Acked-by: Kees Cook <keescook@chromium.org> > > I wonder if there is any compiler option we can turn on to catch the > implicit enum/int casting that would help for these kinds of things > without absolutely exploding the build warnings. > > I see -Wenum-conversion, but that seems to be between enums, not between > int. > > I see this, but it's external: > https://noamlewis.wordpress.com/2017/10/05/type-safe-enums-in-c-using-a-clang-plugin/ Unfortunately, using a looser integral type is the typical workaround for -Wenum-conversion warnings (which is on by default, GCC recently added that flag, too). For warning on enum to int, the kernel would probably blow up with warnings. I don't know of any such existing warning flag. > > -Kees > > > --- > > include/linux/lsm_hook_defs.h | 2 +- > > 1 file changed, 1 insertion(+), 1 deletion(-) > > > > diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h > > index 6791813cd439..24f6683f1cfc 100644 > > --- a/include/linux/lsm_hook_defs.h > > +++ b/include/linux/lsm_hook_defs.h > > @@ -360,7 +360,7 @@ LSM_HOOK(int, 0, key_alloc, struct key *key, const struct cred *cred, > > unsigned long flags) > > LSM_HOOK(void, LSM_RET_VOID, key_free, struct key *key) > > LSM_HOOK(int, 0, key_permission, key_ref_t key_ref, const struct cred *cred, > > - unsigned perm) > > + enum key_need_perm need_perm) > > LSM_HOOK(int, 0, key_getsecurity, struct key *key, char **_buffer) > > #endif /* CONFIG_KEYS */ > > > > > > base-commit: b3a9e3b9622ae10064826dccb4f7a52bd88c7407 > > -- > > 2.27.0.290.gba653c62da-goog > > > > -- > Kees Cook > > -- > You received this message because you are subscribed to the Google Groups "Clang Built Linux" group. > To unsubscribe from this group and stop receiving emails from it, send an email to clang-built-linux+unsubscribe@googlegroups.com. > To view this discussion on the web visit https://groups.google.com/d/msgid/clang-built-linux/202006151113.7A2F638A7%40keescook. -- Thanks, ~Nick Desaulniers ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] security: fix the key_permission LSM hook function type 2020-06-15 18:23 ` Nick Desaulniers @ 2020-06-15 18:47 ` Kees Cook 0 siblings, 0 replies; 6+ messages in thread From: Kees Cook @ 2020-06-15 18:47 UTC (permalink / raw) To: Nick Desaulniers Cc: Sami Tolvanen, James Morris, David Howells, Eric W. Biederman, KP Singh, Casey Schaufler, Thomas Cedeno, Anders Roxell, LKML, clang-built-linux On Mon, Jun 15, 2020 at 11:23:44AM -0700, Nick Desaulniers wrote: > On Mon, Jun 15, 2020 at 11:21 AM Kees Cook <keescook@chromium.org> wrote: > > > > On Mon, Jun 15, 2020 at 11:12:32AM -0700, Sami Tolvanen wrote: > > > Commit 8c0637e950d6 ("keys: Make the KEY_NEED_* perms an enum rather than > > > a mask") changed the type of the key_permission callback functions, but > > > didn't change the type of the hook, which trips indirect call checking with > > > Control-Flow Integrity (CFI). This change fixes the issue by changing the > > > hook type to match the functions. > > > > > > Fixes: 8c0637e950d6 ("keys: Make the KEY_NEED_* perms an enum rather than a mask") > > > Signed-off-by: Sami Tolvanen <samitolvanen@google.com> > > > > Thanks for fixing this! > > > > Acked-by: Kees Cook <keescook@chromium.org> > > > > I wonder if there is any compiler option we can turn on to catch the > > implicit enum/int casting that would help for these kinds of things > > without absolutely exploding the build warnings. > > > > I see -Wenum-conversion, but that seems to be between enums, not between > > int. > > > > I see this, but it's external: > > https://noamlewis.wordpress.com/2017/10/05/type-safe-enums-in-c-using-a-clang-plugin/ > > Unfortunately, using a looser integral type is the typical workaround > for -Wenum-conversion warnings (which is on by default, GCC recently > added that flag, too). For warning on enum to int, the kernel would > probably blow up with warnings. I don't know of any such existing > warning flag. Yeah, I couldn't find anything either. The closest I could find to avoid one of the common classes of enum -> int conversion is the bitwise operations, which is covered by __attribute__((flag_enum)): https://clang.llvm.org/docs/AttributeReference.html#flag-enum Ah well. We'll let CFI find them. ;) -- Kees Cook ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] security: fix the key_permission LSM hook function type 2020-06-15 18:12 [PATCH] security: fix the key_permission LSM hook function type Sami Tolvanen 2020-06-15 18:21 ` Kees Cook @ 2020-06-21 5:54 ` Kees Cook 2020-06-22 17:38 ` James Morris 2 siblings, 0 replies; 6+ messages in thread From: Kees Cook @ 2020-06-21 5:54 UTC (permalink / raw) To: David Howells, James Morris Cc: Sami Tolvanen, Eric W. Biederman, KP Singh, Casey Schaufler, Thomas Cedeno, Anders Roxell, linux-kernel On Mon, Jun 15, 2020 at 11:12:32AM -0700, Sami Tolvanen wrote: > Commit 8c0637e950d6 ("keys: Make the KEY_NEED_* perms an enum rather than > a mask") changed the type of the key_permission callback functions, but > didn't change the type of the hook, which trips indirect call checking with > Control-Flow Integrity (CFI). This change fixes the issue by changing the > hook type to match the functions. > > Fixes: 8c0637e950d6 ("keys: Make the KEY_NEED_* perms an enum rather than a mask") > Signed-off-by: Sami Tolvanen <samitolvanen@google.com> > --- > include/linux/lsm_hook_defs.h | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/include/linux/lsm_hook_defs.h b/include/linux/lsm_hook_defs.h > index 6791813cd439..24f6683f1cfc 100644 > --- a/include/linux/lsm_hook_defs.h > +++ b/include/linux/lsm_hook_defs.h > @@ -360,7 +360,7 @@ LSM_HOOK(int, 0, key_alloc, struct key *key, const struct cred *cred, > unsigned long flags) > LSM_HOOK(void, LSM_RET_VOID, key_free, struct key *key) > LSM_HOOK(int, 0, key_permission, key_ref_t key_ref, const struct cred *cred, > - unsigned perm) > + enum key_need_perm need_perm) > LSM_HOOK(int, 0, key_getsecurity, struct key *key, char **_buffer) > #endif /* CONFIG_KEYS */ > > > base-commit: b3a9e3b9622ae10064826dccb4f7a52bd88c7407 David, James? Can someone please take this? -- Kees Cook ^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: [PATCH] security: fix the key_permission LSM hook function type 2020-06-15 18:12 [PATCH] security: fix the key_permission LSM hook function type Sami Tolvanen 2020-06-15 18:21 ` Kees Cook 2020-06-21 5:54 ` Kees Cook @ 2020-06-22 17:38 ` James Morris 2 siblings, 0 replies; 6+ messages in thread From: James Morris @ 2020-06-22 17:38 UTC (permalink / raw) To: Sami Tolvanen Cc: David Howells, James Morris, Kees Cook, Eric W. Biederman, KP Singh, Casey Schaufler, Thomas Cedeno, Anders Roxell, linux-kernel, linux-security-module On Mon, 15 Jun 2020, Sami Tolvanen wrote: > Commit 8c0637e950d6 ("keys: Make the KEY_NEED_* perms an enum rather than > a mask") changed the type of the key_permission callback functions, but > didn't change the type of the hook, which trips indirect call checking with > Control-Flow Integrity (CFI). This change fixes the issue by changing the > hook type to match the functions. > > Fixes: 8c0637e950d6 ("keys: Make the KEY_NEED_* perms an enum rather than a mask") > Signed-off-by: Sami Tolvanen <samitolvanen@google.com> Applied to git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security.git fixes-v5.8 NOTE: please cc: the LSM list with patches such as these. -- James Morris <jmorris@namei.org> ^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2020-06-22 17:38 UTC | newest] Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2020-06-15 18:12 [PATCH] security: fix the key_permission LSM hook function type Sami Tolvanen 2020-06-15 18:21 ` Kees Cook 2020-06-15 18:23 ` Nick Desaulniers 2020-06-15 18:47 ` Kees Cook 2020-06-21 5:54 ` Kees Cook 2020-06-22 17:38 ` James Morris
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox; as well as URLs for NNTP newsgroup(s).