From: "Mickaël Salaün" <mic@digikod.net>
To: Tahera Fahimi <fahimitahera@gmail.com>, linux-api@vger.kernel.org
Cc: outreachy@lists.linux.dev, gnoack@google.com,
paul@paul-moore.com, jmorris@namei.org, serge@hallyn.com,
linux-security-module@vger.kernel.org,
linux-kernel@vger.kernel.org, bjorn3_gh@protonmail.com,
jannh@google.com, netdev@vger.kernel.org,
Alejandro Colomar <alx@kernel.org>
Subject: Re: [PATCH v11 1/8] Landlock: Add abstract UNIX socket restriction
Date: Fri, 13 Sep 2024 12:46:34 +0200 [thread overview]
Message-ID: <20240913.nuu9Eevo2Pha@digikod.net> (raw)
In-Reply-To: <5f7ad85243b78427242275b93481cfc7c127764b.1725494372.git.fahimitahera@gmail.com>
On Wed, Sep 04, 2024 at 06:13:55PM -0600, Tahera Fahimi wrote:
> This patch introduces a new "scoped" attribute to the
> landlock_ruleset_attr that can specify
> "LANDLOCK_SCOPED_ABSTRACT_UNIX_SOCKET" to scope abstract UNIX sockets
> from connecting to a process outside of the same Landlock domain. It
> implements two hooks, unix_stream_connect and unix_may_send to enforce
> this restriction.
>
> Closes: https://github.com/landlock-lsm/linux/issues/7
> Signed-off-by: Tahera Fahimi <fahimitahera@gmail.com>
> diff --git a/security/landlock/task.c b/security/landlock/task.c
> index 849f5123610b..b9390445d242 100644
> --- a/security/landlock/task.c
> +++ b/security/landlock/task.c
> +static int hook_unix_stream_connect(struct sock *const sock,
> + struct sock *const other,
> + struct sock *const newsk)
> +{
> + const struct landlock_ruleset *const dom =
> + landlock_get_current_domain();
> +
> + /* quick return for non-sandboxed processes */
> + if (!dom)
> + return 0;
> +
> + if (is_abstract_socket(other) && sock_is_scoped(other, dom))
> + return -EPERM;
I was wondering if it would make more sense to return -EACCES here.
EACCES is usually related to file permission, but send(2)/sendto(2)
don't return EPERM according to man pages. Well, according to the
kernel code they can return EPERM so I think we are good with EPERM.
It looks like other LSMs always use EACCES though...
> +
> + return 0;
> +}
> +
> +static int hook_unix_may_send(struct socket *const sock,
> + struct socket *const other)
> +{
> + const struct landlock_ruleset *const dom =
> + landlock_get_current_domain();
> +
> + if (!dom)
> + return 0;
> +
> + if (is_abstract_socket(other->sk)) {
> + /*
> + * Checks if this datagram socket was already allowed to
> + * be connected to other.
> + */
> + if (unix_peer(sock->sk) == other->sk)
> + return 0;
> +
> + if (sock_is_scoped(other->sk, dom))
> + return -EPERM;
ditto
next prev parent reply other threads:[~2024-09-13 10:46 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-05 0:13 [PATCH v11 0/8] Landlock: Add abstract UNIX socket restriction Tahera Fahimi
2024-09-05 0:13 ` [PATCH v11 1/8] " Tahera Fahimi
2024-09-13 10:46 ` Mickaël Salaün [this message]
2024-09-13 13:32 ` Mickaël Salaün
2024-09-16 12:32 ` Tahera Fahimi
2024-09-05 0:13 ` [PATCH v11 2/8] selftests/landlock: Add test for handling unknown scope Tahera Fahimi
2024-09-05 0:13 ` [PATCH v11 3/8] selftests/landlock: Add abstract UNIX socket restriction tests Tahera Fahimi
2024-09-05 0:13 ` [PATCH v11 4/8] selftests/landlock: Add tests for UNIX sockets with any address formats Tahera Fahimi
2024-09-05 0:13 ` [PATCH v11 5/8] selftests/landlock: Test connected vs non-connected datagram UNIX socket Tahera Fahimi
2024-09-05 0:14 ` [PATCH v11 6/8] selftests/landlock: Restrict inherited datagram UNIX socket to connect Tahera Fahimi
2024-09-05 0:14 ` [PATCH v11 7/8] sample/landlock: Add support abstract UNIX socket restriction Tahera Fahimi
2024-09-05 0:14 ` [PATCH v11 8/8] Landlock: Document LANDLOCK_SCOPED_ABSTRACT_UNIX_SOCKET and ABI version Tahera Fahimi
2024-09-13 16:33 ` [PATCH v11 0/8] Landlock: Add abstract UNIX socket restriction Mickaël Salaün
2024-09-13 17:39 ` Mickaël Salaün
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=20240913.nuu9Eevo2Pha@digikod.net \
--to=mic@digikod.net \
--cc=alx@kernel.org \
--cc=bjorn3_gh@protonmail.com \
--cc=fahimitahera@gmail.com \
--cc=gnoack@google.com \
--cc=jannh@google.com \
--cc=jmorris@namei.org \
--cc=linux-api@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-security-module@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=outreachy@lists.linux.dev \
--cc=paul@paul-moore.com \
--cc=serge@hallyn.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;
as well as URLs for NNTP newsgroup(s).