From: Paul Moore <paul@paul-moore.com>
To: Jordan Rome <linux@jordanrome.com>,
linux-security-module@vger.kernel.org
Cc: linux-trace-kernel@vger.kernel.org,
Andrii Nakryiko <andrii@kernel.org>,
Kernel Team <kernel-team@fb.com>, Serge Hallyn <serge@hallyn.com>,
Yonghong Song <yonghong.song@linux.dev>
Subject: Re: [PATCH v1] security: add trace event for cap_capable
Date: Thu, 24 Oct 2024 15:37:09 -0400 [thread overview]
Message-ID: <0920e116b02c7872e6f1897afbe3f702@paul-moore.com> (raw)
In-Reply-To: <20241024104012.1815022-1-linux@jordanrome.com>
On Oct 24, 2024 Jordan Rome <linux@jordanrome.com> wrote:
>
> In cases where we want a stable way to observe/trace
> cap_capable (e.g. protection from inlining and API updates)
> add a tracepoint that passes:
> - The credentials used
> - The user namespace which needs the capability
> - The user namespace that actually has the capability (if one exists)
> - The capability to check for
> - Bitmask of options defined in include/linux/security.h
> - The return value of the check
>
> Signed-off-by: Jordan Rome <linux@jordanrome.com>
> ---
> MAINTAINERS | 1 +
> include/trace/events/capability.h | 58 +++++++++++++++++++++++++++++++
> security/commoncap.c | 21 +++++++----
> 3 files changed, 74 insertions(+), 6 deletions(-)
> create mode 100644 include/trace/events/capability.h
...
> diff --git a/include/trace/events/capability.h b/include/trace/events/capability.h
> new file mode 100644
> index 000000000000..092b8e77063a
> --- /dev/null
> +++ b/include/trace/events/capability.h
> @@ -0,0 +1,58 @@
> +/* SPDX-License-Identifier: GPL-2.0 */
> +#undef TRACE_SYSTEM
> +#define TRACE_SYSTEM capability
> +
> +#if !defined(_TRACE_CAPABILITY_H) || defined(TRACE_HEADER_MULTI_READ)
> +#define _TRACE_CAPABILITY_H
> +
> +#include <linux/cred.h>
> +#include <linux/tracepoint.h>
> +#include <linux/user_namespace.h>
> +
> +/**
> + * capable - called after it's determined if a task has a particular
> + * effective capability
> + *
> + * @cred: The credentials used
> + * @targ_ns: The user namespace which needs the capability
> + * @capable_ns: The user namespace that actually has the capability
> + * if ret is 0 otherwise this will be NULL
> + * @cap: The capability to check for
> + * @opts: Bitmask of options defined in include/linux/security.h
> + * @ret: The return value of the check: 0 if it does, -ve if it does not
> + *
> + * Allows to trace calls to cap_capable in commoncap.c
> + */
> +TRACE_EVENT(capable,
This should either be named "cap_capable" if you are only interested in
the CAP_XXX capability checks or "capable" if you are interested in all
of the checks that are performed when capable() is called from within
the kernel. Presently safesetid, apparmor, and selinux all enforce
access controls when capable() is called, with the potential for
additional checks in future kernel releases.
> + TP_PROTO(const struct cred *cred, struct user_namespace *targ_ns,
> + struct user_namespace *capable_ns, int cap, unsigned int opts, int ret),
> +
> + TP_ARGS(cred, targ_ns, capable_ns, cap, opts, ret),
> +
> + TP_STRUCT__entry(
> + __field(const struct cred *, cred)
> + __field(struct user_namespace *, targ_ns)
> + __field(struct user_namespace *, capable_ns)
> + __field(int, cap)
> + __field(unsigned int, opts)
> + __field(int, ret)
> + ),
> +
> + TP_fast_assign(
> + __entry->cred = cred;
> + __entry->targ_ns = targ_ns;
> + __entry->capable_ns = capable_ns;
> + __entry->cap = cap;
> + __entry->opts = opts;
> + __entry->ret = ret;
> + ),
> +
> + TP_printk("cap %d, opts %u, ret %d",
> + __entry->cap, __entry->opts, __entry->ret)
> +);
> +
> +#endif /* _TRACE_CAPABILITY_H */
> +
> +/* This part must be outside protection */
> +#include <trace/define_trace.h>
--
paul-moore.com
next prev parent reply other threads:[~2024-10-24 19:37 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-24 10:40 [v1] security: add trace event for cap_capable Jordan Rome
2024-10-24 13:19 ` Steven Rostedt
2024-10-24 13:40 ` Jordan Rome
2024-10-24 17:48 ` Andrii Nakryiko
2024-10-25 0:23 ` Steven Rostedt
2024-10-24 17:50 ` Andrii Nakryiko
2024-10-24 19:37 ` Paul Moore [this message]
2024-10-24 20:28 ` sergeh
2024-10-25 1:15 ` Jordan Rome
2024-10-25 11:18 ` sergeh
2024-10-25 11:22 ` Jordan Rome
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=0920e116b02c7872e6f1897afbe3f702@paul-moore.com \
--to=paul@paul-moore.com \
--cc=andrii@kernel.org \
--cc=kernel-team@fb.com \
--cc=linux-security-module@vger.kernel.org \
--cc=linux-trace-kernel@vger.kernel.org \
--cc=linux@jordanrome.com \
--cc=serge@hallyn.com \
--cc=yonghong.song@linux.dev \
/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).