netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Günther Noack" <gnoack@google.com>
To: Mikhail Ivanov <ivanov.mikhail1@huawei-partners.com>
Cc: mic@digikod.net, willemdebruijn.kernel@gmail.com,
	gnoack3000@gmail.com,  linux-security-module@vger.kernel.org,
	netdev@vger.kernel.org,  netfilter-devel@vger.kernel.org,
	yusongping@huawei.com,  artem.kuzin@huawei.com,
	konstantin.meskhidze@huawei.com, alx@kernel.org
Subject: Re: [RFC PATCH v1 2/9] landlock: Support TCP listen access-control
Date: Thu, 1 Aug 2024 12:36:21 +0200	[thread overview]
Message-ID: <ZqtlJZMHVf-otlOq@google.com> (raw)
In-Reply-To: <0a3b8596-f3f3-f617-c40d-de54e8ff05f0@huawei-partners.com>

On Wed, Jul 31, 2024 at 08:20:41PM +0300, Mikhail Ivanov wrote:
> 7/30/2024 11:24 AM, Günther Noack wrote:
> > On Sun, Jul 28, 2024 at 08:25:55AM +0800, Mikhail Ivanov wrote:
> > > LANDLOCK_ACCESS_NET_BIND_TCP is useful to limit the scope of "bindable"
> > > ports to forbid a malicious sandboxed process to impersonate a legitimate
> > > server process. However, bind(2) might be used by (TCP) clients to set the
> > > source port to a (legitimate) value. Controlling the ports that can be
> > > used for listening would allow (TCP) clients to explicitly bind to ports
> > > that are forbidden for listening.
> > > 
> > > Such control is implemented with a new LANDLOCK_ACCESS_NET_LISTEN_TCP
> > > access right that restricts listening on undesired ports with listen(2).
> > 
> > Nit: I would turn around the first two commit message paragraphs and describe
> > your changes first, before explaining the problems in the bind(2) support.  I
> > was initially a bit confused that the description started talking about
> > LANDLOCK_ACCESS_NET_BIND_TCP.
> > 
> > General recommendations at:
> > https://www.kernel.org/doc/html/v6.10/process/submitting-patches.html#describe-your-changes
> 
> I consider the first paragraph as a problem statement for this patch.
> According to linux recommendations problem should be established before
> the description of changes. Do you think that the changes part should
> stand before the problem anyway?

Up to you. To be fair, I'm sold on the approach in this patchset anyway :)


> > When we have the documentation wording finalized,
> > please send an update to the man pages as well,
> > for this and other documentation updates.
> 
> Should I send it after this patchset would be accepted?

Yes, that would be the normal process which we have been following so far.

(I don't like the process much either, because it decouples feature development
so far from documentation writing, but it's what we have for now.)

An example patch which does that for the network bind(2) and connect(2) features
(and where I would still like a review from Konstantin) is:
https://lore.kernel.org/all/20240723101917.90918-1-gnoack@google.com/


> > Small remarks on what I've done here:
> > 
> > * I am avoiding the word "binding" when referring to the automatic assignment to
> >    an ephemeral port - IMHO, this is potentially confusing, since bind(2) is not
> >    explicitly called.
> > * I am also dropping the "It should be noted" / "Note that" phrase, which is
> >    frowned upon in man pages.
> 
> Didn't know that, thanks

Regarding "note that", see
https://lore.kernel.org/all/0aafcdd6-4ac7-8501-c607-9a24a98597d7@gmail.com/
https://lore.kernel.org/linux-man/20210729223535.qvyomfqvvahzmu5w@localhost.localdomain/
https://lore.kernel.org/linux-man/20230105225235.6cjtz6orjzxzvo6v@illithid/
(The "Kemper notectomy")

This came up in man page reviews, but we'll have an easier time keeping the
kernel and man page documentation in sync if we adhere to man page style
directly.  (The man page style is documented in man-pages(7) and contains some
groff-independent wording advice as well.)


> > If I understand correctly, these are cases where we use TCP on top of protocols
> > that are not IP (or have an additional layer in the middle, like TLS?).  This
> > can not be recognized through the socket family or type?
> 
> ULP can be used in the context of TCP protocols as an additional layer
> (currently supported only by IP and MPTCP), so it cannot be recognized
> with family or type. You can check this test [1] in which TCP IP socket
> is created with ULP control hook.
> 
> [1] https://lore.kernel.org/all/20240728002602.3198398-8-ivanov.mikhail1@huawei-partners.com/

Thanks, this is helpful.

For reference, it seems that ULP were introduced in
https://lore.kernel.org/all/20170614183714.GA80310@davejwatson-mba.dhcp.thefacebook.com/


> > Do we have cases where we can run TCP on top of something else than plain IPv4
> > or IPv6, where the clone method exists?
> 
> Yeah, MPTCP protocol for example (see net/mptcp/subflow.c). ULP control
> hook is supported only by IP and MPTCP, and in both cases
> clone method is checked during listen(2) execution.


> > Aren't the socket type and family checks duplicated with existing logic that we
> > have for the connect(2) and bind(2) support?  Should it be deduplicated, or is
> > that too messy?
> 
> bind(2) and connect(2) hooks also support AF_UNSPEC family, so I think
> such helper is gonna complicate code a little bit. Also it can
> complicate switch in current_check_access_socket().

OK, sounds good. 👍

—Günther

  reply	other threads:[~2024-08-01 10:36 UTC|newest]

Thread overview: 26+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-07-28  0:25 [RFC PATCH v1 0/9] Support TCP listen access-control Mikhail Ivanov
2024-07-28  0:25 ` [RFC PATCH v1 1/9] landlock: Refactor current_check_access_socket() access right check Mikhail Ivanov
2024-07-28  0:25 ` [RFC PATCH v1 2/9] landlock: Support TCP listen access-control Mikhail Ivanov
2024-07-30  8:24   ` Günther Noack
2024-07-31 17:20     ` Mikhail Ivanov
2024-08-01 10:36       ` Günther Noack [this message]
2024-08-01 11:45         ` Mikhail Ivanov
2024-07-31 18:30   ` Mickaël Salaün
2024-08-01  7:52     ` Mikhail Ivanov
2024-08-01 14:45       ` Mickaël Salaün
2024-08-01 15:34         ` Mikhail Ivanov
2024-08-01 16:01           ` Mickaël Salaün
2024-08-01 16:07             ` Mikhail Ivanov
2024-08-01 14:45   ` Mickaël Salaün
2024-08-01 16:04     ` Mikhail Ivanov
2024-07-28  0:25 ` [RFC PATCH v1 3/9] selftests/landlock: Support LANDLOCK_ACCESS_NET_LISTEN_TCP Mikhail Ivanov
2024-07-28  0:25 ` [RFC PATCH v1 4/9] selftests/landlock: Test listening restriction Mikhail Ivanov
2024-07-28  0:25 ` [RFC PATCH v1 5/9] selftests/landlock: Test listen on connected socket Mikhail Ivanov
2024-08-01 14:46   ` Mickaël Salaün
2024-08-01 15:47     ` Mikhail Ivanov
2024-07-28  0:25 ` [RFC PATCH v1 6/9] selftests/landlock: Test listening without explicit bind restriction Mikhail Ivanov
2024-07-28  0:26 ` [RFC PATCH v1 7/9] selftests/landlock: Test listen on ULP socket without clone method Mikhail Ivanov
2024-08-01 15:08   ` Mickaël Salaün
2024-08-01 17:42     ` Mikhail Ivanov
2024-07-28  0:26 ` [RFC PATCH v1 8/9] selftests/landlock: Test changing socket backlog with listen(2) Mikhail Ivanov
2024-07-28  0:26 ` [RFC PATCH v1 9/9] samples/landlock: Support LANDLOCK_ACCESS_NET_LISTEN Mikhail Ivanov

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=ZqtlJZMHVf-otlOq@google.com \
    --to=gnoack@google.com \
    --cc=alx@kernel.org \
    --cc=artem.kuzin@huawei.com \
    --cc=gnoack3000@gmail.com \
    --cc=ivanov.mikhail1@huawei-partners.com \
    --cc=konstantin.meskhidze@huawei.com \
    --cc=linux-security-module@vger.kernel.org \
    --cc=mic@digikod.net \
    --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).