All of lore.kernel.org
 help / color / mirror / Atom feed
From: sashiko-bot@kernel.org
Cc: linux-security-module@vger.kernel.org
Subject: Re: [PATCH v6 7/8] samples/landlock: Add capability and namespace restriction support
Date: Wed, 14 Oct 2026 08:45:32 +0000	[thread overview]
Message-ID: <sashiko-outbox-171036@kernel.org> (raw)
In-Reply-To: <20261014082718.1435842-8-mic@digikod.net>

Thank you for your contribution! Sashiko AI review found 1 potential issue(s) to consider:
- [Medium] landlock: sandbox configuration leak via stale envp
--

commit 89caad8ff02abf64d07b124b6bd1e3374e39181c
Author: Mickaël Salaün <mic@digikod.net>

    samples/landlock: Add capability and namespace restriction support

    Extend the sandboxer sample to demonstrate the new Landlock capability
    and namespace restriction features. LL_CAP takes a colon-delimited list
    of allowed capabilities. Numeric values are always accepted, and when
    libcap development files are available, capability names can also be used.

> diff --git a/samples/landlock/sandboxer.c b/samples/landlock/sandboxer.c
> index 030583273f3f7..1362f08ff14b9 100644
> --- a/samples/landlock/sandboxer.c
> +++ b/samples/landlock/sandboxer.c

[ ... ]

> @@ -597,6 +824,32 @@ int main(const int argc, char *const argv[], char *const *const envp)
>  			~LANDLOCK_ACCESS_NET_CONNECT_SEND_UDP;
>  	}
>  
> +	/* Removes namespace handling if not set by a user. */
> +	if (!getenv(ENV_NS_NAME) && !getenv(ENV_NS_QUIET_NAME))
> +		ruleset_attr.handled_permissions &=
> +			~LANDLOCK_PERMISSION_NAMESPACE_USE;
> +	if (!(ruleset_attr.handled_permissions &
> +	      LANDLOCK_PERMISSION_NAMESPACE_USE)) {
> +		unsetenv(ENV_NS_NAME);
> +		unsetenv(ENV_NS_QUIET_NAME);
> +	}
> +
> +#ifndef USE_LIBCAP
> +	if (getenv(ENV_CAP_NAME) || getenv(ENV_CAP_QUIET_NAME))
> +		fprintf(stderr,
> +			"Warning: Built without libcap; use capability numbers, not names.\n");
> +#endif
> +
> +	/* Removes capability handling if not set by a user. */
> +	if (!getenv(ENV_CAP_NAME) && !getenv(ENV_CAP_QUIET_NAME))
> +		ruleset_attr.handled_permissions &=
> +			~LANDLOCK_PERMISSION_CAPABILITY_USE;
> +	if (!(ruleset_attr.handled_permissions &
> +	      LANDLOCK_PERMISSION_CAPABILITY_USE)) {
> +		unsetenv(ENV_CAP_NAME);
> +		unsetenv(ENV_CAP_QUIET_NAME);
> +	}

[Severity: Medium]
Does this code leak the newly added LL_CAP and LL_NS environment variables
to the sandboxed child if environ is reallocated?

Looking at the end of main() in sandboxer.c, the child is executed with:

	execvpe(cmd_path, cmd_argv, envp);

The environment variables are scrubbed from the environment via unsetenv().
However, if any library (like one loaded via LD_PRELOAD) calls setenv() before
main() begins, libc will reallocate the global environ array onto the heap.

In this scenario, unsetenv() operates on the heap-allocated environ array,
while the local envp pointer passed to execvpe() still points to the original,
unmodified stack array containing the un-scrubbed sandbox configuration.

Could we use execvp(cmd_path, cmd_argv) or execvpe(cmd_path, cmd_argv, environ)
instead to ensure the properly scrubbed environment is propagated?

-- 
Sashiko AI review · https://sashiko.dev/#/patchset/20261014082718.1435842-1-mic@digikod.net?part=7

  reply	other threads:[~2026-10-14  8:45 UTC|newest]

Thread overview: 17+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-10-14  8:27 [PATCH v6 0/8] Landlock: Namespace and capability control Mickaël Salaün
2026-10-14  8:27 ` [PATCH v6 1/8] landlock: Rename quiet_masks to quiet_access Mickaël Salaün
2026-10-14  8:33   ` sashiko-bot
2026-10-14  8:27 ` [PATCH v6 2/8] landlock: Wrap per-layer access masks in struct layer_config Mickaël Salaün
2026-10-14  8:32   ` sashiko-bot
2026-10-14  8:27 ` [PATCH v6 3/8] landlock: Enforce namespace use restrictions Mickaël Salaün
2026-10-14  8:39   ` sashiko-bot
2026-10-14  8:27 ` [PATCH v6 4/8] landlock: Enforce capability restrictions Mickaël Salaün
2026-10-14  8:36   ` sashiko-bot
2026-10-14  8:27 ` [PATCH v6 5/8] selftests/landlock: Add namespace restriction tests Mickaël Salaün
2026-10-14  8:41   ` sashiko-bot
2026-10-14  8:27 ` [PATCH v6 6/8] selftests/landlock: Add capability " Mickaël Salaün
2026-10-14  8:43   ` sashiko-bot
2026-10-14  8:27 ` [PATCH v6 7/8] samples/landlock: Add capability and namespace restriction support Mickaël Salaün
2026-10-14  8:45   ` sashiko-bot [this message]
2026-10-14  8:27 ` [PATCH v6 8/8] landlock: Add documentation for capability and namespace restrictions Mickaël Salaün
2026-10-14  8:43   ` sashiko-bot

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=sashiko-outbox-171036@kernel.org \
    --to=sashiko-bot@kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --cc=sashiko-reviews@lists.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 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.