From: Paul Moore <paul@paul-moore.com>
To: Ian Bridges <icb@fastmail.org>,
Stephen Smalley <stephen.smalley.work@gmail.com>,
Ondrej Mosnacek <omosnace@redhat.com>
Cc: selinux@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: Re: [PATCH] selinux: compute the IMA configuration settings string length once at boot
Date: Wed, 15 Jul 2026 21:41:59 -0400 [thread overview]
Message-ID: <2e52b3433b9cac9466eab694752a7603@paul-moore.com> (raw)
In-Reply-To: <alW2ktr8JUVlQNgU@dev>
On Jul 14, 2026 Ian Bridges <icb@fastmail.org> wrote:
>
> selinux_ima_collect_state() builds a string of the current SELinux
> configuration settings. The string lists each setting as a name and
> one digit. The length of the string therefore never changes, but is
> still recomputed on every call.
>
> Add selinux_ima_config_len_init() to compute the length once during
> selinux_init(). Update selinux_ima_collect_state() to use the stored
> length.
>
> Suggested-by: Paul Moore <paul@paul-moore.com>
> Link: https://lore.kernel.org/r/df755e0282dab3b932d19aceab71b7d7@paul-moore.com
> Signed-off-by: Ian Bridges <icb@fastmail.org>
> Reviewed-by: Stephen Smalley <stephen.smalley.work@gmail.com>
> ---
> The produced string is unchanged. selinux_ima_collect_state() now
> depends on selinux_ima_config_len_init() having run. The call sits in
> selinux_init(), as suggested in the review of the seq_buf conversion.
>
> The length computation itself moves verbatim. The strlen() + 1 on
> the string literal could become sizeof(), which counts the
> terminator. That rewrite was left out so the moved block stays
> identical to the applied code.
>
> The patch was tested as follows.
>
> - W=1 build of security/selinux with CONFIG_IMA=y, zero warnings.
> - A userspace differential harness compiled the old and the new
> functions side by side, covering every combination of the settings
> and the policy capabilities. The outputs were byte identical. The
> stored length was an exact fit for the produced string in every
> case, with no overflow and no slack.
>
> security/selinux/hooks.c | 3 +++
> security/selinux/ima.c | 33 ++++++++++++++++++++++++---------
> security/selinux/include/ima.h | 4 ++++
> 3 files changed, 31 insertions(+), 9 deletions(-)
Merged into selinux/dev, thanks for doing this.
--
paul-moore.com
prev parent reply other threads:[~2026-07-16 1:42 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-07-14 4:09 [PATCH] selinux: compute the IMA configuration settings string length once at boot Ian Bridges
2026-07-14 14:49 ` Stephen Smalley
2026-07-16 1:41 ` Paul Moore [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=2e52b3433b9cac9466eab694752a7603@paul-moore.com \
--to=paul@paul-moore.com \
--cc=icb@fastmail.org \
--cc=linux-kernel@vger.kernel.org \
--cc=omosnace@redhat.com \
--cc=selinux@vger.kernel.org \
--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