linux-security-module.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
Subject: Re: [RFC PATCH v2 02/12] landlock: Add hook on socket creation
Date: Wed, 5 Jun 2024 19:27:16 +0200	[thread overview]
Message-ID: <ZmCf9JVIXmRZrCWk@google.com> (raw)
In-Reply-To: <3cd4fad8-d72e-87cd-3cf9-2648a770f13c@huawei-partners.com>

Hello!

On Thu, May 30, 2024 at 03:20:21PM +0300, Mikhail Ivanov wrote:
> 5/27/2024 11:48 AM, Günther Noack wrote:
> > On Fri, May 24, 2024 at 05:30:05PM +0800, Mikhail Ivanov wrote:
> > > Add hook to security_socket_post_create(), which checks whether the socket
> > > type and family are allowed by domain. Hook is called after initializing
> > > the socket in the network stack to not wrongfully return EACCES for a
> > > family-type pair, which is considered invalid by the protocol.
> > > 
> > > Signed-off-by: Mikhail Ivanov <ivanov.mikhail1@huawei-partners.com>
> > 
> > ## Some observations that *do not* need to be addressed in this commit, IMHO:
> > 
> > get_raw_handled_socket_accesses, get_current_socket_domain and
> > current_check_access_socket are based on the similarly-named functions from
> > net.c (and fs.c), and it makes sense to stay consistent with these.
> > 
> > There are some possible refactorings that could maybe be applied to that code,
> > but given that the same ones would apply to net.c as well, it's probably best to
> > address these separately.
> > 
> >    * Should get_raw_handled_socket_accesses be inlined
> It's a fairly simple and compact function, so compiler should inline it
> without any problems. Mickaël was against optional inlines [1].
> 
> [1] https://lore.kernel.org/linux-security-module/5c6c99f7-4218-1f79-477e-5d943c9809fd@digikod.net/

Sorry for the confusion -- what I meant was not "should we add the inline
keyword", but I meant "should we remove that function and place its
implementation in the place where we are currently calling it"?


> >    * Does the WARN_ON_ONCE(dom->num_layers < 1) check have the right return code?
> 
> Looks like a rudimental check. `dom` is always NULL when `num_layers`< 1
> (see get_*_domain functions).

What I found irritating about it is that with 0 layers (= no Landlock policy was
ever enabled), you would logically assume that we return a success?  But then I
realized that this code was copied verbatim from other places in fs.c and net.c,
and it is actually checking for an internal inconsistency that is never supposed
to happen.  If we were to actually hit that case at some point, we have probably
stumbled over our own feet and it might be better to not permit anything.


> >    * Can we refactor out commonalities (probably not worth it right now though)?
> 
> I had a few ideas about refactoring commonalities, as currently landlock
> has several repetitive patterns in the code. But solution requires a
> good design and a separate patch. Probably it's worth opening an issue
> on github. WDYT?

Absolutely, please do open one.  In my mind, patches in C which might not get
accepted are an expensive way to iterate on such ideas, and it might make sense
to collect some refactoring approaches on a bug or the mailing list before
jumping into the implementation.

(You might want to keep an eye on https://github.com/landlock-lsm/linux/issues/1
as well, which is about some ideas to refactor Landlock's internal data
structures.)


> > ## The only actionable feedback that I have that is specific to this commit is:
> > 
> > In the past, we have introduced new (non-test) Landlock functionality in a
> > single commit -- that way, we have no "loose ends" in the code between these two
> > commits, and that simplifies it for people who want to patch your feature onto
> > other kernel trees.  (e.g. I think we should maybe merge commit 01/12 and 02/12
> > into a single commit.)  WDYT?
> 
> Yeah, this two should be merged and tests commits as well. I just wanted
> to do this in one of the latest patch versions to simplify code review.

That sounds good, thanks!

—Günther

  reply	other threads:[~2024-06-05 17:27 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-05-24  9:30 [RFC PATCH v2 00/12] Socket type control for Landlock Mikhail Ivanov
2024-05-24  9:30 ` [RFC PATCH v2 01/12] landlock: Support socket access-control Mikhail Ivanov
2024-05-27  9:57   ` Günther Noack
2024-05-30 12:05     ` Mikhail Ivanov
2024-06-05 17:04       ` Günther Noack
2024-06-07 13:34         ` Mikhail Ivanov
2024-05-24  9:30 ` [RFC PATCH v2 02/12] landlock: Add hook on socket creation Mikhail Ivanov
2024-05-27  8:48   ` Günther Noack
2024-05-30 12:20     ` Mikhail Ivanov
2024-06-05 17:27       ` Günther Noack [this message]
2024-06-07 14:45         ` Mikhail Ivanov
2024-09-25 18:31           ` Mickaël Salaün
2024-05-24  9:30 ` [RFC PATCH v2 03/12] selftests/landlock: Add protocol.create to socket tests Mikhail Ivanov
2024-05-27 15:27   ` Günther Noack
2024-05-30 12:50     ` Mikhail Ivanov
2024-05-24  9:30 ` [RFC PATCH v2 04/12] selftests/landlock: Add protocol.socket_access_rights " Mikhail Ivanov
2024-05-27 20:52   ` Günther Noack
2024-05-30 14:35     ` Mikhail Ivanov
2024-05-24  9:30 ` [RFC PATCH v2 05/12] selftests/landlock: Add protocol.rule_with_unknown_access " Mikhail Ivanov
2024-05-27 21:11   ` Günther Noack
2024-05-24  9:30 ` [RFC PATCH v2 06/12] selftests/landlock: Add protocol.rule_with_unhandled_access " Mikhail Ivanov
2024-05-27 21:15   ` Günther Noack
2024-05-24  9:30 ` [RFC PATCH v2 07/12] selftests/landlock: Add protocol.inval " Mikhail Ivanov
2024-05-27 21:27   ` Günther Noack
2024-05-30 15:28     ` Mikhail Ivanov
2024-05-24  9:30 ` [RFC PATCH v2 08/12] selftests/landlock: Add tcp_layers.ruleset_overlap " Mikhail Ivanov
2024-05-27 21:09   ` Günther Noack
2024-05-30 15:08     ` Mikhail Ivanov
2024-05-24  9:30 ` [RFC PATCH v2 09/12] selftests/landlock: Add mini.ruleset_with_unknown_access " Mikhail Ivanov
2024-05-24  9:30 ` [RFC PATCH v2 10/12] selftests/landlock: Add mini.socket_overflow " Mikhail Ivanov
2024-05-24  9:30 ` [RFC PATCH v2 11/12] selftests/landlock: Add mini.socket_invalid_type " Mikhail Ivanov
2024-05-24  9:30 ` [RFC PATCH v2 12/12] samples/landlock: Support socket protocol restrictions Mikhail Ivanov
2024-06-04 20:22 ` [RFC PATCH v2 00/12] Socket type control for Landlock Günther Noack
2024-06-06 11:44   ` Mikhail Ivanov
2024-06-06 13:32     ` Günther Noack
2024-06-06 19:32       ` Günther Noack
2024-06-07 13:58       ` Mikhail Ivanov
2024-06-10  8:03     ` Günther Noack
2024-06-10  8:21       ` [PATCH] landlock: Use bit-fields for storing handled layer access masks Günther Noack
2024-06-13 21:20         ` Mickaël Salaün
2024-06-14 12:06           ` Günther Noack
2024-06-15 15:08             ` Mickaël Salaün
2024-06-11 11:35       ` [RFC PATCH v2 00/12] Socket type control for Landlock 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=ZmCf9JVIXmRZrCWk@google.com \
    --to=gnoack@google.com \
    --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).