All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Günther Noack" <gnoack@google.com>
To: "Mickaël Salaün" <mic@digikod.net>
Cc: Ada Smith <adasmithgt@gmail.com>,
	Hungyu Lin <dennylin0707@gmail.com>,
	James Morris <jmorris@namei.org>,
	Josef Bacik <josef@toxicpanda.com>,
	Paul Moore <paul@paul-moore.com>, Serge Hallyn <serge@hallyn.com>,
	Serge Hallyn <sergeh@kernel.org>,
	kernel-team@cloudflare.com, linux-kernel@vger.kernel.org,
	linux-security-module@vger.kernel.org
Subject: Re: [PATCH v2 4/6] landlock: Mediate CAP_SYS_ADMIN for the admin memory reserve
Date: Tue, 17 Nov 2026 16:43:43 +0100	[thread overview]
Message-ID: <avx2Lzzv-i9KrKFO@google.com> (raw)
In-Reply-To: <20261117101157.2520463-5-mic@digikod.net>

On Tue, Nov 17, 2026 at 11:11:54AM +0100, Mickaël Salaün wrote:
> With vm.overcommit_memory set to 2, __vm_enough_memory() keeps the
> vm.admin_reserve_kbytes reserve for callers whose LSMs all agree that
> they hold CAP_SYS_ADMIN.  cap_vm_enough_memory() checks it with
> cap_capable(), so a process in a domain that denies CAP_SYS_ADMIN could
> still use this reserve, which is meant to let an administrator recover
> from memory exhaustion.
> 
> Add a Landlock vm_enough_memory hook that withholds the reserve when the
> domain denies CAP_SYS_ADMIN.  Like commoncap and SELinux, do not audit
> this check: it only selects a limit, it runs for every accounted
> mapping, and withholding the reserve can only make an allocation fail
> with -ENOMEM.  As with the previous hooks, LSMs implement their own
> policy in this hook: SELinux already checks CAP_SYS_ADMIN in its own
> vm_enough_memory hook, so making commoncap call security_capable() would
> make SELinux check it twice.
> 
> Cc: Günther Noack <gnoack@google.com>
> Cc: Paul Moore <paul@paul-moore.com>
> Cc: Serge Hallyn <serge@hallyn.com>
> Acked-by: Serge Hallyn (AMD) <sergeh@kernel.org>
> Fixes: 97c8386f1d74 ("landlock: Enforce capability restrictions")
> Signed-off-by: Mickaël Salaün <mic@digikod.net>
> ---
> 
> Changes since v1:
> https://patch.msgid.link/20261110202436.2408244-5-mic@digikod.net
> - Add Serge Hallyn's Acked-by.
> ---
>  security/landlock/cap.c | 22 ++++++++++++++++++++++
>  1 file changed, 22 insertions(+)
> 
> diff --git a/security/landlock/cap.c b/security/landlock/cap.c
> index c89e8d76db8c..c9a900888f3b 100644
> --- a/security/landlock/cap.c
> +++ b/security/landlock/cap.c
> @@ -140,10 +140,32 @@ static int hook_mmap_addr(unsigned long addr)
>  	return check_cap(current_cred(), CAP_SYS_RAWIO, CAP_OPT_NONE);
>  }
>  
> +/**
> + * hook_vm_enough_memory - Restrict the admin memory reserve
> + *
> + * @mm: Address space being charged (unused).
> + * @pages: Number of pages being charged (unused).
> + *
> + * cap_vm_enough_memory() lets CAP_SYS_ADMIN use the vm.admin_reserve_kbytes
> + * reserve, but calls cap_capable() directly, which skips hook_capable().  Check
> + * the same capability against the domain.  commoncap runs first, so this only
> + * sees tasks that commoncap let use the reserve.  Like commoncap, do not log
> + * denials: this only selects a memory limit.
> + *
> + * Return: 0 if the domain does not withhold the reserve, -EPERM if
> + * CAP_SYS_ADMIN use is denied.  An error does not fail the allocation by
> + * itself, but without the reserve, the allocation may fail with -ENOMEM.
> + */
> +static int hook_vm_enough_memory(struct mm_struct *mm, long pages)
> +{
> +	return check_cap(current_cred(), CAP_SYS_ADMIN, CAP_OPT_NOAUDIT);
> +}
> +
>  static struct security_hook_list landlock_hooks[] __ro_after_init = {
>  	LSM_HOOK_INIT(capable, hook_capable),
>  	LSM_HOOK_INIT(capset, hook_capset),
>  	LSM_HOOK_INIT(mmap_addr, hook_mmap_addr),
> +	LSM_HOOK_INIT(vm_enough_memory, hook_vm_enough_memory),
>  };
>  
>  __init void landlock_add_cap_hooks(void)
> -- 
> 2.56.0
> 

Reviewed-by: Günther Noack <gnoack@google.com>

  parent reply	other threads:[~2026-11-17 15:43 UTC|newest]

Thread overview: 19+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-17 10:11 [PATCH v2 0/6] Fix Landlock mediation of commoncap's capability checks Mickaël Salaün
2026-11-17 10:11 ` [PATCH v2 1/6] landlock: Factor out capability denial checks Mickaël Salaün
2026-11-17 10:14   ` sashiko-bot
2026-11-17 13:56   ` Günther Noack
2026-11-17 10:11 ` [PATCH v2 2/6] landlock: Mediate CAP_SYS_RAWIO for mappings below mmap_min_addr Mickaël Salaün
2026-11-17 10:18   ` sashiko-bot
2026-11-17 14:23   ` Günther Noack
2026-11-17 10:11 ` [PATCH v2 3/6] landlock: Mediate CAP_SETPCAP for inheritable capabilities Mickaël Salaün
2026-11-17 10:17   ` sashiko-bot
2026-11-17 15:41   ` Günther Noack
2026-11-17 10:11 ` [PATCH v2 4/6] landlock: Mediate CAP_SYS_ADMIN for the admin memory reserve Mickaël Salaün
2026-11-17 10:16   ` sashiko-bot
2026-11-17 15:43   ` Günther Noack [this message]
2026-11-17 10:11 ` [PATCH v2 5/6] selftests/landlock: Test capability checks outside the capable hook Mickaël Salaün
2026-11-17 10:20   ` sashiko-bot
2026-11-17 16:11   ` Günther Noack
2026-11-17 10:11 ` [PATCH v2 6/6] landlock: Fix capability restriction documentation Mickaël Salaün
2026-11-17 10:17   ` sashiko-bot
2026-11-17 16:25   ` Günther Noack

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=avx2Lzzv-i9KrKFO@google.com \
    --to=gnoack@google.com \
    --cc=adasmithgt@gmail.com \
    --cc=dennylin0707@gmail.com \
    --cc=jmorris@namei.org \
    --cc=josef@toxicpanda.com \
    --cc=kernel-team@cloudflare.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mic@digikod.net \
    --cc=paul@paul-moore.com \
    --cc=serge@hallyn.com \
    --cc=sergeh@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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.