From: "Mickaël Salaün" <mic@digikod.net>
To: "Jeff Xu" <jeffxu@chromium.org>, "Günther Noack" <gnoack@google.com>
Cc: "Konstantin Meskhidze (A)" <konstantin.meskhidze@huawei.com>,
"Günther Noack" <gnoack3000@gmail.com>,
willemdebruijn.kernel@gmail.com,
linux-security-module@vger.kernel.org, netdev@vger.kernel.org,
netfilter-devel@vger.kernel.org, yusongping@huawei.com,
artem.kuzin@huawei.com, "Jeff Xu" <jeffxu@google.com>,
"Jorge Lucangeli Obes" <jorgelo@chromium.org>,
"Allen Webb" <allenwebb@google.com>,
"Dmitry Torokhov" <dtor@google.com>
Subject: Re: [PATCH v9 00/12] Network support for Landlock - allowed list of protocols
Date: Wed, 28 Jun 2023 21:29:24 +0200 [thread overview]
Message-ID: <43e8acb2-d696-c001-b54b-d2b7cf244de7@digikod.net> (raw)
In-Reply-To: <CABi2SkX-dzUO6NnbyqfrAg7Bbn+Ne=Xi1qC1XMrzHqVEVucQ0Q@mail.gmail.com>
On 28/06/2023 19:03, Jeff Xu wrote:
> Hello,
>
> Thanks for writing up the example for an incoming TCP connection ! It
> helps with the context.
>
> Since I'm late to this thread, one thing I want to ask: all the APIs
> proposed so far are at the process level, we don't have any API that
> applies restriction to socket fd itself, right ? this is what I
> thought, but I would like to get confirmation.
Restriction are applied to actions, not to already existing/opened FDs.
We could add a way to restrict opened FDs, but I don't think this is the
right approach because sandboxing is a deliberate action from a process,
and it should already take care of its FDs.
>
> On Wed, Jun 28, 2023 at 2:09 AM Günther Noack <gnoack@google.com> wrote:
>>
>> Hello!
>>
>> On Mon, Jun 26, 2023 at 05:29:34PM +0200, Mickaël Salaün wrote:
>>> Here is a design to be able to only allow a set of network protocols and
>>> deny everything else. This would be complementary to Konstantin's patch
>>> series which addresses fine-grained access control.
>>>
>>> First, I want to remind that Landlock follows an allowed list approach with
>>> a set of (growing) supported actions (for compatibility reasons), which is
>>> kind of an allow-list-on-a-deny-list. But with this proposal, we want to be
>>> able to deny everything, which means: supported, not supported, known and
>>> unknown protocols.
>>>
>>> We could add a new "handled_access_socket" field to the landlock_ruleset
>>> struct, which could contain a LANDLOCK_ACCESS_SOCKET_CREATE flag.
>>>
>>> If this field is set, users could add a new type of rules:
>>> struct landlock_socket_attr {
>>> __u64 allowed_access;
>>> int domain; // see socket(2)
>>> int type; // see socket(2)
>>> }
>>>
>>> The allowed_access field would only contain LANDLOCK_ACCESS_SOCKET_CREATE at
>>> first, but it could grow with other actions (which cannot be handled with
>>> seccomp):
>>> - use: walk through all opened FDs and mark them as allowed or denied
>>> - receive: hook on received FDs
>>> - send: hook on sent FDs
>>>
>>> We might also use the same approach for non-socket objects that can be
>>> identified with some meaningful properties.
>>>
>>> What do you think?
>>
>> This sounds like a good plan to me - it would make it possible to restrict new
>> socket creation using protocols that were not intended to be used, and I also
>> think it would fit the Landlock model nicely.
>>
>> Small remark on the side: The security_socket_create() hook does not only get
>> invoked as a result of socket(2), but also as a part of accept(2) - so this
>> approach might already prevent new connections very effectively.
>>
> That is an interesting aspect that might be worth discussing more.
> seccomp is per syscall, landlock doesn't necessarily follow the same,
> another design is to add more logic in Landlock, e.g.
> LANDLOCK_ACCESS_SOCKET_PROTOCOL which will apply to all of the socket
> calls (socket/bind/listen/accept/connect). App dev might feel it is
> easier to use.
seccomp restricts the use of the syscall interface, whereas Landlock
restricts the use of kernel objects (i.e. the semantic).
We need to find a good tradeoff between a lot of access rights and a few
grouping different actions. This should make sense from a developer
point of view according to its knowledge and use of the kernel
interfaces (potential wrapped with high level libraries), but also to
the semantic of the sandbox and the security guarantees we want to provide.
We should also keep in mind that high level Landlock libraries can take
care of potential coarse-grained use of restrictions.
>
>> Spelling out some scenarios, so that we are sure that we are on the same page:
>>
>> A)
>>
>> A program that does not need networking could specify a ruleset where
>> LANDLOCK_ACCESS_SOCKET_CREATE is handled, and simply not permit anything.
>>
>> B)
>>
>> A program that runs a TCP server could specify a ruleset where
>> LANDLOCK_NET_BIND_TCP, LANDLOCK_NET_CONNECT_TCP and
>> LANDLOCK_ACCESS_SOCKET_CREATE are handled, and where the following rules are added:
>>
>> /* From Konstantin's patch set */
>> struct landlock_net_service_attr bind_attr = {
>> .allowed_access = LANDLOCK_NET_BIND_TCP,
>> .port = 8080,
>> };
>>
>> /* From Mickaël's proposal */
>> struct landlock_socket_attr sock_inet_attr = {
>> .allowed_access = LANDLOCK_ACCESS_SOCKET_CREATE,
>> .domain = AF_INET,
>> .type = SOCK_STREAM,
>> }
>>
>> struct landlock_socket_attr sock_inet6_attr = {
>> .allowed_access = LANDLOCK_ACCESS_SOCKET_CREATE,
>> .domain = AF_INET6,
>> .type = SOCK_STREAM,
>> }
>>
>> That should then be enough to bind and listen on ports, whereas outgoing
>> connections with TCP and anything using other network protocols would not be
>> permitted.
>>
> TCP server is an interesting case. From a security perspective, a
> process cares if it is acting as a server or client in TCP, a server
> might only want to accept an incoming TCP connection, never initiate
> an outgoing TCP connection, and a client is the opposite.
>
> Processes can restrict outgoing/incoming TCP connection by seccomp for
> accept(2) or connect(2), though I feel Landlock can do this more
> naturally for app dev, and at per-protocol level. seccomp doesn't
> provide per-protocol granularity.
Right, seccomp cannot filter TCP ports.
>
> For bind(2), iirc, it can be used for a server to assign dst port of
> incoming TCP connection, also by a client to assign a src port of an
> outgoing TCP connection. LANDLOCK_NET_BIND_TCP will apply to both
> cases, right ? this might not be a problem, just something to keep
> note.
Good point. I think it is in line with the rule definition: to allow to
bind on a specific port. However, if clients want to set the source port
to a (legitimate) value, then that would be an issue because we cannot
allow a whole range of ports (e.g., >= 1024). I'm not sure if this
practice would be deemed "legitimate" though. Do you know client
applications using bind?
Konstantin, we should have a test for this case anyway.
>
>> (Alternatively, it could bind() the socket early, *then enable Landlock* and
>> leave out the rule for BIND_TCP, only permitting SOCKET_CREATE for IPv4 and
>> IPv6, so that listen() and accept() work on the already-bound socket.)
>>
> For this approach, LANDLOCK_ACCESS_SOCKET_PROTOCOL is a better name,
> so dev is fully aware it is not just applied to socket create.
I don't get the semantic of LANDLOCK_ACCESS_SOCKET_PROTOCOL. What does
PROTOCOL mean?
>
>> Overall, this sounds like an excellent approach to me. 👍
>>
>> —Günther
>>
>> --
>> Sent using Mutt 🐕 Woof Woof
>
> -Jeff
next prev parent reply other threads:[~2023-06-28 19:30 UTC|newest]
Thread overview: 74+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-16 8:58 [PATCH v9 00/12] Network support for Landlock Konstantin Meskhidze
2023-01-16 8:58 ` [PATCH v9 01/12] landlock: Make ruleset's access masks more generic Konstantin Meskhidze
2023-01-16 8:58 ` [PATCH v9 02/12] landlock: Allow filesystem layout changes for domains without such rule type Konstantin Meskhidze
2023-02-10 17:34 ` Mickaël Salaün
2023-02-14 8:51 ` Konstantin Meskhidze (A)
2023-02-14 12:07 ` Mickaël Salaün
2023-02-14 12:57 ` Konstantin Meskhidze (A)
2023-01-16 8:58 ` [PATCH v9 03/12] landlock: Refactor landlock_find_rule/insert_rule Konstantin Meskhidze
2023-02-10 17:36 ` Mickaël Salaün
2023-02-14 10:15 ` Konstantin Meskhidze (A)
2023-02-14 12:09 ` Mickaël Salaün
2023-02-14 13:28 ` Konstantin Meskhidze (A)
2023-01-16 8:58 ` [PATCH v9 04/12] landlock: Refactor merge/inherit_ruleset functions Konstantin Meskhidze
2023-01-16 8:58 ` [PATCH v9 05/12] landlock: Move and rename umask_layers() and init_layer_masks() Konstantin Meskhidze
2023-02-10 17:37 ` Mickaël Salaün
2023-02-14 10:15 ` Konstantin Meskhidze (A)
2023-01-16 8:58 ` [PATCH v9 06/12] landlock: Refactor _unmask_layers() and _init_layer_masks() Konstantin Meskhidze
2023-02-10 17:38 ` Mickaël Salaün
2023-02-14 10:16 ` Konstantin Meskhidze (A)
2023-02-21 18:07 ` Mickaël Salaün
2023-03-06 7:52 ` Konstantin Meskhidze (A)
2023-01-16 8:58 ` [PATCH v9 07/12] landlock: Refactor landlock_add_rule() syscall Konstantin Meskhidze
2023-02-10 17:38 ` Mickaël Salaün
2023-02-14 10:18 ` Konstantin Meskhidze (A)
2023-01-16 8:58 ` [PATCH v9 08/12] landlock: Add network rules and TCP hooks support Konstantin Meskhidze
2023-02-10 17:39 ` Mickaël Salaün
2023-02-14 10:19 ` Konstantin Meskhidze (A)
2023-03-13 9:33 ` Konstantin Meskhidze (A)
2023-03-14 12:13 ` Mickaël Salaün
2023-03-14 14:38 ` Konstantin Meskhidze (A)
2023-02-21 18:04 ` Mickaël Salaün
2023-03-06 10:18 ` Konstantin Meskhidze (A)
2023-01-16 8:58 ` [PATCH v9 09/12] selftests/landlock: Share enforce_ruleset() Konstantin Meskhidze
2023-01-16 8:58 ` [PATCH v9 10/12] selftests/landlock: Add 10 new test suites dedicated to network Konstantin Meskhidze
2023-02-10 17:40 ` Mickaël Salaün
2023-02-14 10:36 ` Konstantin Meskhidze (A)
2023-02-14 12:13 ` Mickaël Salaün
2023-02-14 13:28 ` Konstantin Meskhidze (A)
2023-02-21 18:05 ` Mickaël Salaün
2023-03-06 12:03 ` Konstantin Meskhidze (A)
2023-03-06 16:00 ` Mickaël Salaün
2023-03-06 18:13 ` Konstantin Meskhidze (A)
2023-01-16 8:58 ` [PATCH v9 11/12] samples/landlock: Add network demo Konstantin Meskhidze
2023-01-16 8:58 ` [PATCH v9 12/12] landlock: Document Landlock's network support Konstantin Meskhidze
2023-01-21 23:07 ` Günther Noack
2023-01-23 9:38 ` Konstantin Meskhidze (A)
2023-01-27 18:22 ` Mickaël Salaün
2023-01-30 10:03 ` Konstantin Meskhidze (A)
2023-02-21 16:16 ` Mickaël Salaün
2023-03-06 13:43 ` Konstantin Meskhidze (A)
2023-03-06 16:09 ` Mickaël Salaün
2023-03-06 17:55 ` Konstantin Meskhidze (A)
2023-01-30 12:26 ` Konstantin Meskhidze (A)
2023-02-23 22:17 ` [PATCH v9 00/12] Network support for Landlock Günther Noack
2023-03-06 7:45 ` Konstantin Meskhidze (A)
2023-03-13 17:16 ` Konstantin Meskhidze (A)
2023-03-14 13:28 ` Mickaël Salaün
2023-06-26 15:29 ` [PATCH v9 00/12] Network support for Landlock - allowed list of protocols Mickaël Salaün
2023-06-28 2:33 ` Jeff Xu
2023-06-28 19:03 ` Mickaël Salaün
2023-06-28 21:56 ` Jeff Xu
2023-06-28 8:44 ` Günther Noack
2023-06-28 17:03 ` Jeff Xu
2023-06-28 19:29 ` Mickaël Salaün [this message]
2023-06-29 3:18 ` Jeff Xu
2023-06-29 11:07 ` Mickaël Salaün
2023-06-30 4:18 ` Jeff Xu
2023-06-30 18:23 ` Mickaël Salaün
2023-07-05 15:00 ` Jeff Xu
2023-07-12 11:30 ` Mickaël Salaün
2023-07-13 13:20 ` Konstantin Meskhidze (A)
2023-07-13 14:52 ` Mickaël Salaün
2023-07-13 11:44 ` Konstantin Meskhidze (A)
2023-06-28 19:07 ` 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=43e8acb2-d696-c001-b54b-d2b7cf244de7@digikod.net \
--to=mic@digikod.net \
--cc=allenwebb@google.com \
--cc=artem.kuzin@huawei.com \
--cc=dtor@google.com \
--cc=gnoack3000@gmail.com \
--cc=gnoack@google.com \
--cc=jeffxu@chromium.org \
--cc=jeffxu@google.com \
--cc=jorgelo@chromium.org \
--cc=konstantin.meskhidze@huawei.com \
--cc=linux-security-module@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=netfilter-devel@vger.kernel.org \
--cc=willemdebruijn.kernel@gmail.com \
--cc=yusongping@huawei.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).