linux-api.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Song Liu <song@kernel.org>
To: "Maxime Bélair" <maxime.belair@canonical.com>
Cc: linux-security-module@vger.kernel.org,
	john.johansen@canonical.com,  paul@paul-moore.com,
	jmorris@namei.org, serge@hallyn.com, mic@digikod.net,
	 kees@kernel.org, stephen.smalley.work@gmail.com,
	casey@schaufler-ca.com,  takedakn@nttdata.co.jp,
	penguin-kernel@i-love.sakura.ne.jp,  linux-api@vger.kernel.org,
	apparmor@lists.ubuntu.com,  linux-kernel@vger.kernel.org
Subject: Re: [PATCH 1/3] Wire up the lsm_manage_policy syscall
Date: Wed, 7 May 2025 23:06:55 -0700	[thread overview]
Message-ID: <CAPhsuW4FVMS7v8p_C-QzE8nBxCb6xDRhEecm_KHZ3KbKUjOXrQ@mail.gmail.com> (raw)
In-Reply-To: <aa3c41f9-6b25-4871-a4be-e08430e59730@canonical.com>

On Wed, May 7, 2025 at 8:37 AM Maxime Bélair
<maxime.belair@canonical.com> wrote:
[...]
> >
> > These two do not feel like real benefits:
> > - One syscall cannot fit all use cases well...
>
> This syscall is not intended to cover every case, nor to replace existing kernel
> interfaces.
>
> Each LSM can decide which operations it wants to support (if any). For example, when
> loading policies, an LSM may choose to allow only policies that further restrict
> privileges.
>
> > - Not working in containers is often not an issue, but a feature.
>
> Indeed, using this syscall requires appropriate capabilities and will not permit
> unprivileged containers to manage policies arbitrarily.
>
> With this syscall, capability checks remain the responsibility of each LSM.
>
> For instance, in the AppArmor patch, a profile can be loaded only if
> aa_policy_admin_capable() succeeds (which requires CAP_MAC_ADMIN). Moreover, by design,
> policies can be loaded only in the current namespace.
>
> I see this syscall as a middle point between exposing the entire sysfs, creating a large
> attack surface, and blocking everything.
>
> Landlock’s existing syscalls already improve security by allowing processes to further
> restrict their ambient rights while adding only a modest attack surface.
>
> This syscall is a further step in that direction: it lets LSMs add restrictive policies
> without requiring exposing every other interface.

I don't think a syscall makes the API more secure. If necessary, we can add
permission check to each pseudo file. The downside of the syscall, however,
is that all the permission checks are hard-coded in the kernel (except for
BPF LSM); while the sys admin can configure permissions of the pseudo
files in user space.

> Again, each module decides which operations to expose through this syscall. In many cases
> the operation will still require CAP_SYS_ADMIN or a similar capability, so environments
> that choose this interface remain secure while gaining its advantages.
>
> >>   - Avoids overhead of other kernel interfaces for better efficiency
> >
> > .. and it is is probably less efficient, because everything need to
> > fit in the same API.
>
> As shown below, the syscall can significantly improve the performance of policy management.
> A more detailed benchmark is available in [1].
>
> The following table presents the time required to load an AppArmor profile.
>
> For every cell, the first value is the total time taken by aa-load, and the value in
> parentheses is the time spent to load the policy in the kernel only (total - dry‑run).
>
> Results are in microseconds and are averaged over 10 000 runs to reduce variance.
>
>
> | t (µs)    | syscall     | pseudofs    | Speedup       |
> |-----------|-------------|-------------|---------------|
> | 1password | 4257 (1127) | 3333 (192)  | x1.28 (x5.86) |
> | Xorg      | 6099 (2961) | 5167 (2020) | x1.18 (x1.47) |
>

I am not sure the performance of loading security policies is on any
critical path.
The implementation calls the hook for each LSM, which is why I think the
syscall is not efficient.

Overall, I am still not convinced a syscall for all LSMs is needed. To
justify such
a syscall, I think we need to show that it is useful in multiple LSMs.
Also, if we
really want to have single set of APIs for all LSMs, we may also need
get_policy,
remove_policy, etc. This set as-is appears to be an incomplete design. The
implementation, with call_int_hook, is also problematic. It can easily
cause some
controversial behaviors.

Thanks,
Song

  parent reply	other threads:[~2025-05-08  6:07 UTC|newest]

Thread overview: 36+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2025-05-06 14:32 [PATCH 0/3] lsm: introduce lsm_manage_policy() syscall Maxime Bélair
2025-05-06 14:32 ` [PATCH 1/3] Wire up the lsm_manage_policy syscall Maxime Bélair
2025-05-07  6:26   ` Song Liu
2025-05-07 15:37     ` Maxime Bélair
2025-05-07 22:04       ` Tetsuo Handa
2025-05-08  7:52         ` John Johansen
2025-05-09 10:25           ` Mickaël Salaün
2025-05-11 11:09             ` John Johansen
2025-05-08  6:06       ` Song Liu [this message]
2025-05-08  8:18         ` John Johansen
2025-05-09 10:26           ` Mickaël Salaün
2025-05-11 10:47             ` John Johansen
2025-05-12 10:20               ` Mickaël Salaün
2025-05-17  7:59                 ` John Johansen
2025-05-08  7:12     ` John Johansen
2025-05-07 13:58   ` kernel test robot
2025-05-06 14:32 ` [PATCH 2/3] lsm: introduce security_lsm_manage_policy hook Maxime Bélair
2025-05-07  6:19   ` Song Liu
2025-05-07 15:37     ` Maxime Bélair
2025-05-08  8:20       ` John Johansen
2025-05-07 10:40   ` Tetsuo Handa
2025-05-07 15:37     ` Maxime Bélair
2025-05-07 20:25     ` Paul Moore
2025-05-08  8:29       ` John Johansen
2025-05-08 16:54         ` Casey Schaufler
2025-05-09 10:26           ` Mickaël Salaün
2025-05-09 14:21             ` Casey Schaufler
2025-05-11 11:26               ` John Johansen
2025-05-11 11:20             ` John Johansen
2025-05-08  8:25     ` John Johansen
2025-05-08 12:55       ` Tetsuo Handa
2025-05-08 14:44         ` John Johansen
2025-05-08 15:07           ` Tetsuo Handa
2025-05-09  3:25             ` John Johansen
2025-05-07 12:04   ` kernel test robot
2025-05-06 14:32 ` [PATCH 3/3] AppArmor: add support for lsm_manage_policy Maxime Bélair

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=CAPhsuW4FVMS7v8p_C-QzE8nBxCb6xDRhEecm_KHZ3KbKUjOXrQ@mail.gmail.com \
    --to=song@kernel.org \
    --cc=apparmor@lists.ubuntu.com \
    --cc=casey@schaufler-ca.com \
    --cc=jmorris@namei.org \
    --cc=john.johansen@canonical.com \
    --cc=kees@kernel.org \
    --cc=linux-api@vger.kernel.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=maxime.belair@canonical.com \
    --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 \
    --cc=takedakn@nttdata.co.jp \
    /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).