From: Kees Cook <keescook@chromium.org>
To: KP Singh <kpsingh@kernel.org>
Cc: linux-security-module@vger.kernel.org, bpf@vger.kernel.org,
paul@paul-moore.com, casey@schaufler-ca.com, song@kernel.org,
daniel@iogearbox.net, ast@kernel.org, jannh@google.com
Subject: Re: [PATCH v2 5/5] security: Add CONFIG_SECURITY_HOOK_LIKELY
Date: Tue, 20 Jun 2023 13:58:56 -0700 [thread overview]
Message-ID: <202306201356.CF454506@keescook> (raw)
In-Reply-To: <20230616000441.3677441-6-kpsingh@kernel.org>
On Fri, Jun 16, 2023 at 02:04:41AM +0200, KP Singh wrote:
> [...]
> @@ -110,6 +110,9 @@ static __initdata struct lsm_info *exclusive;
> #undef LSM_HOOK
> #undef DEFINE_LSM_STATIC_CALL
>
> +#define security_hook_active(n, h) \
> + static_branch_maybe(CONFIG_SECURITY_HOOK_LIKELY, &SECURITY_HOOK_ACTIVE_KEY(h, n))
> +
> /*
> * Initialise a table of static calls for each LSM hook.
> * DEFINE_STATIC_CALL_NULL invocation above generates a key (STATIC_CALL_KEY)
> @@ -816,7 +819,7 @@ static int lsm_superblock_alloc(struct super_block *sb)
> */
> #define __CALL_STATIC_VOID(NUM, HOOK, ...) \
> do { \
> - if (static_branch_unlikely(&SECURITY_HOOK_ACTIVE_KEY(HOOK, NUM))) { \
> + if (security_hook_active(NUM, HOOK)) { \
> static_call(LSM_STATIC_CALL(HOOK, NUM))(__VA_ARGS__); \
> } \
> } while (0);
> @@ -828,7 +831,7 @@ do { \
>
> #define __CALL_STATIC_INT(NUM, R, HOOK, LABEL, ...) \
> do { \
> - if (static_branch_unlikely(&SECURITY_HOOK_ACTIVE_KEY(HOOK, NUM))) { \
> + if (security_hook_active(NUM, HOOK)) { \
> R = static_call(LSM_STATIC_CALL(HOOK, NUM))(__VA_ARGS__); \
> if (R != 0) \
> goto LABEL; \
I actually think I'd prefer there be no macro wrapping
static_branch_maybe(), just for reading it more easily. i.e. people
reading this code are going to expect the static_branch/static_call code
patterns, and seeing "security_hook_active" only slows them down in
understanding it. I don't think it's _that_ ugly to have it all typed
out. e.g.:
if (static_branch_maybe(CONFIG_SECURITY_HOOK_LIKELY, \
&SECURITY_HOOK_ACTIVE_KEY(HOOK, NUM)) { \
R = static_call(LSM_STATIC_CALL(HOOK, NUM))(__VA_ARGS__); \
if (R != 0) \
goto LABEL; \
--
Kees Cook
next prev parent reply other threads:[~2023-06-20 20:59 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-06-16 0:04 [PATCH v2 0/5] Reduce overhead of LSMs with static calls KP Singh
2023-06-16 0:04 ` [PATCH v2 1/5] kernel: Add helper macros for loop unrolling KP Singh
2023-06-16 0:04 ` [PATCH v2 2/5] security: Count the LSMs enabled at compile time KP Singh
2023-06-16 0:38 ` Casey Schaufler
2023-06-16 22:27 ` Andrii Nakryiko
2023-09-16 0:54 ` KP Singh
2023-06-16 0:04 ` [PATCH v2 3/5] security: Replace indirect LSM hook calls with static calls KP Singh
2023-06-16 1:05 ` Casey Schaufler
2023-06-17 15:09 ` KP Singh
2023-06-16 3:41 ` kernel test robot
2023-06-16 21:09 ` kernel test robot
2023-06-17 15:39 ` KP Singh
2023-06-20 21:53 ` Kees Cook
2023-06-16 0:04 ` [PATCH v2 4/5] bpf: Only enable BPF LSM hooks when an LSM program is attached KP Singh
2023-06-16 0:04 ` [PATCH v2 5/5] security: Add CONFIG_SECURITY_HOOK_LIKELY KP Singh
2023-06-16 1:14 ` Casey Schaufler
2023-06-17 15:11 ` KP Singh
2023-06-20 20:58 ` Kees Cook [this message]
2023-09-18 13:27 ` KP Singh
2023-09-18 13:55 ` Paul Moore
2023-09-18 16:28 ` KP Singh
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=202306201356.CF454506@keescook \
--to=keescook@chromium.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=casey@schaufler-ca.com \
--cc=daniel@iogearbox.net \
--cc=jannh@google.com \
--cc=kpsingh@kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=paul@paul-moore.com \
--cc=song@kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).