From: John Johansen <john.johansen@canonical.com>
To: Casey Schaufler <casey@schaufler-ca.com>,
paul@paul-moore.com, linux-security-module@vger.kernel.org
Cc: jmorris@namei.org, serge@hallyn.com, keescook@chromium.org,
penguin-kernel@i-love.sakura.ne.jp,
stephen.smalley.work@gmail.com, mic@digikod.net
Subject: Re: [PATCH 6/6] LSM: Infrastructure management of the perf_event security blob
Date: Tue, 9 Jul 2024 16:47:04 -0700 [thread overview]
Message-ID: <76721989-04e1-4b30-ae82-eec4f0bcce4c@canonical.com> (raw)
In-Reply-To: <20240708213957.20519-7-casey@schaufler-ca.com>
On 7/8/24 14:39, Casey Schaufler wrote:
> Move management of the perf_event->security blob out of the individual
> security modules and into the security infrastructure. Instead of
> allocating the blobs from within the modules the modules tell the
> infrastructure how much space is required, and the space is allocated
> there.
>
> Signed-off-by: Casey Schaufler <casey@schaufler-ca.com>
again, issue below, and other than Paul's point about the free hook the
rest looks good
> ---
> include/linux/lsm_hooks.h | 1 +
> security/security.c | 12 ++++++++++++
> security/selinux/hooks.c | 18 ++++--------------
> security/selinux/include/objsec.h | 6 ++++++
> 4 files changed, 23 insertions(+), 14 deletions(-)
>
> diff --git a/include/linux/lsm_hooks.h b/include/linux/lsm_hooks.h
> index b6fc6ac88723..f1ca8082075a 100644
> --- a/include/linux/lsm_hooks.h
> +++ b/include/linux/lsm_hooks.h
> @@ -79,6 +79,7 @@ struct lsm_blob_sizes {
> int lbs_ipc;
> int lbs_key;
> int lbs_msg_msg;
> + int lbs_perf_event;
> int lbs_task;
> int lbs_xattr_count; /* number of xattr slots in new_xattrs array */
> int lbs_tun_dev;
> diff --git a/security/security.c b/security/security.c
> index 731a54fabc79..da2111f8d9df 100644
> --- a/security/security.c
> +++ b/security/security.c
> @@ -28,6 +28,7 @@
> #include <linux/xattr.h>
> #include <linux/msg.h>
> #include <linux/overflow.h>
> +#include <linux/perf_event.h>
> #include <net/flow.h>
> #include <net/sock.h>
>
> @@ -232,6 +233,7 @@ static void __init lsm_set_blob_sizes(struct lsm_blob_sizes *needed)
> lsm_set_blob_size(&needed->lbs_key, &blob_sizes.lbs_key);
> #endif
> lsm_set_blob_size(&needed->lbs_msg_msg, &blob_sizes.lbs_msg_msg);
> + lsm_set_blob_size(&needed->lbs_perf_event, &blob_sizes.lbs_perf_event);
> lsm_set_blob_size(&needed->lbs_sock, &blob_sizes.lbs_sock);
> lsm_set_blob_size(&needed->lbs_superblock, &blob_sizes.lbs_superblock);
> lsm_set_blob_size(&needed->lbs_task, &blob_sizes.lbs_task);
> @@ -414,6 +416,7 @@ static void __init ordered_lsm_init(void)
> init_debug("msg_msg blob size = %d\n", blob_sizes.lbs_msg_msg);
> init_debug("sock blob size = %d\n", blob_sizes.lbs_sock);
> init_debug("superblock blob size = %d\n", blob_sizes.lbs_superblock);
> + init_debug("perf event blob size = %d\n", blob_sizes.lbs_perf_event);
> init_debug("task blob size = %d\n", blob_sizes.lbs_task);
> init_debug("tun device blob size = %d\n", blob_sizes.lbs_tun_dev);
> init_debug("xattr slots = %d\n", blob_sizes.lbs_xattr_count);
> @@ -5653,6 +5656,13 @@ int security_perf_event_open(struct perf_event_attr *attr, int type)
> */
> int security_perf_event_alloc(struct perf_event *event)
> {
> + int rc;
> +
> + rc = lsm_blob_alloc(&event->security, blob_sizes.lbs_perf_event,
> + GFP_KERNEL);
> + if (rc)
> + return rc;
> +
again similar issue. While free_event_rcu() is called that one doesn't
actually take care of the security field
> return call_int_hook(perf_event_alloc, event);
> }
>
> @@ -5665,6 +5675,8 @@ int security_perf_event_alloc(struct perf_event *event)
> void security_perf_event_free(struct perf_event *event)
> {
> call_void_hook(perf_event_free, event);
> + kfree(event->security);
> + event->security = NULL;
> }
>
> /**
> diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
> index 79fe75603881..d1d6adfdfbc7 100644
> --- a/security/selinux/hooks.c
> +++ b/security/selinux/hooks.c
> @@ -6952,6 +6952,9 @@ struct lsm_blob_sizes selinux_blob_sizes __ro_after_init = {
> .lbs_key = sizeof(struct key_security_struct),
> #endif /* CONFIG_KEYS */
> .lbs_msg_msg = sizeof(struct msg_security_struct),
> +#ifdef CONFIG_PERF_EVENTS
> + .lbs_perf_event = sizeof(struct perf_event_security_struct),
> +#endif
> .lbs_sock = sizeof(struct sk_security_struct),
> .lbs_superblock = sizeof(struct superblock_security_struct),
> .lbs_xattr_count = SELINUX_INODE_INIT_XATTRS,
> @@ -6983,24 +6986,12 @@ static int selinux_perf_event_alloc(struct perf_event *event)
> {
> struct perf_event_security_struct *perfsec;
>
> - perfsec = kzalloc(sizeof(*perfsec), GFP_KERNEL);
> - if (!perfsec)
> - return -ENOMEM;
> -
> + perfsec = selinux_perf_event(event->security);
> perfsec->sid = current_sid();
> - event->security = perfsec;
>
> return 0;
> }
>
> -static void selinux_perf_event_free(struct perf_event *event)
> -{
> - struct perf_event_security_struct *perfsec = event->security;
> -
> - event->security = NULL;
> - kfree(perfsec);
> -}
> -
> static int selinux_perf_event_read(struct perf_event *event)
> {
> struct perf_event_security_struct *perfsec = event->security;
> @@ -7312,7 +7303,6 @@ static struct security_hook_list selinux_hooks[] __ro_after_init = {
>
> #ifdef CONFIG_PERF_EVENTS
> LSM_HOOK_INIT(perf_event_open, selinux_perf_event_open),
> - LSM_HOOK_INIT(perf_event_free, selinux_perf_event_free),
> LSM_HOOK_INIT(perf_event_read, selinux_perf_event_read),
> LSM_HOOK_INIT(perf_event_write, selinux_perf_event_write),
> #endif
> diff --git a/security/selinux/include/objsec.h b/security/selinux/include/objsec.h
> index b1878f9395b5..d632a9180b41 100644
> --- a/security/selinux/include/objsec.h
> +++ b/security/selinux/include/objsec.h
> @@ -219,4 +219,10 @@ selinux_ib(void *ib_sec)
> return ib_sec + selinux_blob_sizes.lbs_ib;
> }
>
> +static inline struct perf_event_security_struct *
> +selinux_perf_event(void *perf_event)
> +{
> + return perf_event + selinux_blob_sizes.lbs_perf_event;
> +}
> +
> #endif /* _SELINUX_OBJSEC_H_ */
prev parent reply other threads:[~2024-07-09 23:47 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <20240708213957.20519-1-casey.ref@schaufler-ca.com>
2024-07-08 21:39 ` [PATCH 0/6] LSM: Infrastructure blob allocation Casey Schaufler
2024-07-08 21:39 ` [PATCH 1/6] LSM: Infrastructure management of the sock security Casey Schaufler
2024-07-09 19:15 ` Paul Moore
2024-07-09 23:00 ` Casey Schaufler
2024-07-09 23:05 ` Paul Moore
2024-07-09 23:29 ` Casey Schaufler
2024-07-10 0:00 ` Paul Moore
2024-07-09 22:08 ` Paul Moore
2024-07-09 22:32 ` John Johansen
2024-07-08 21:39 ` [PATCH 2/6] LSM: Infrastructure management of the key security blob Casey Schaufler
2024-07-09 22:08 ` Paul Moore
2024-07-09 22:47 ` John Johansen
2024-07-09 23:01 ` Paul Moore
2024-07-08 21:39 ` [PATCH 3/6] LSM: Add helper for blob allocations Casey Schaufler
2024-07-09 22:08 ` Paul Moore
2024-07-09 23:09 ` Casey Schaufler
2024-07-10 0:01 ` Paul Moore
2024-07-09 22:51 ` John Johansen
2024-07-08 21:39 ` [PATCH 4/6] LSM: Infrastructure management of the dev_tun blob Casey Schaufler
2024-07-09 22:08 ` Paul Moore
2024-07-09 23:01 ` John Johansen
2024-07-09 23:11 ` Casey Schaufler
2024-07-08 21:39 ` [PATCH 5/6] LSM: Infrastructure management of the infiniband blob Casey Schaufler
2024-07-09 22:08 ` Paul Moore
2024-07-09 23:38 ` John Johansen
2024-07-08 21:39 ` [PATCH 6/6] LSM: Infrastructure management of the perf_event security blob Casey Schaufler
2024-07-09 22:08 ` Paul Moore
2024-07-09 23:47 ` John Johansen [this message]
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=76721989-04e1-4b30-ae82-eec4f0bcce4c@canonical.com \
--to=john.johansen@canonical.com \
--cc=casey@schaufler-ca.com \
--cc=jmorris@namei.org \
--cc=keescook@chromium.org \
--cc=linux-security-module@vger.kernel.org \
--cc=mic@digikod.net \
--cc=paul@paul-moore.com \
--cc=penguin-kernel@i-love.sakura.ne.jp \
--cc=serge@hallyn.com \
--cc=stephen.smalley.work@gmail.com \
/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