From: "Mickaël Salaün" <mic@digikod.net>
To: Tahera Fahimi <fahimitahera@gmail.com>
Cc: Jann Horn <jannh@google.com>,
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,
netdev@vger.kernel.org
Subject: Re: [PATCH v8 1/4] Landlock: Add abstract unix socket connect restriction
Date: Fri, 9 Aug 2024 10:49:17 +0200 [thread overview]
Message-ID: <20240809.gooHaid7mo1b@digikod.net> (raw)
In-Reply-To: <ZrVR9ni4qpFdF0iA@tahera-OptiPlex-5000>
On Thu, Aug 08, 2024 at 05:17:10PM -0600, Tahera Fahimi wrote:
> On Wed, Aug 07, 2024 at 04:44:36PM +0200, Mickaël Salaün wrote:
> > On Wed, Aug 07, 2024 at 03:45:18PM +0200, Jann Horn wrote:
> > > On Wed, Aug 7, 2024 at 9:21 AM Mickaël Salaün <mic@digikod.net> wrote:
> > > > On Tue, Aug 06, 2024 at 10:46:43PM +0200, Jann Horn wrote:
> > > > > I think adding something like this change on top of your code would
> > > > > make it more concise (though this is entirely untested):
> > > > >
> > > > > --- /tmp/a 2024-08-06 22:37:33.800158308 +0200
> > > > > +++ /tmp/b 2024-08-06 22:44:49.539314039 +0200
> > > > > @@ -15,25 +15,12 @@
> > > > > * client_layer must be a signed integer with greater capacity than
> > > > > * client->num_layers to ensure the following loop stops.
> > > > > */
> > > > > BUILD_BUG_ON(sizeof(client_layer) > sizeof(client->num_layers));
> > > > >
> > > > > - if (!server) {
> > > > > - /*
> > > > > - * Walks client's parent domains and checks that none of these
> > > > > - * domains are scoped.
> > > > > - */
> > > > > - for (; client_layer >= 0; client_layer--) {
> > > > > - if (landlock_get_scope_mask(client, client_layer) &
> > > > > - scope)
> > > > > - return true;
> > > > > - }
> > > > > - return false;
> > > > > - }
> > > >
> > > > This loop is redundant with the following one, but it makes sure there
> > > > is no issue nor inconsistencies with the server or server_walker
> > > > pointers. That's the only approach I found to make sure we don't go
> > > > through a path that could use an incorrect pointer, and makes the code
> > > > easy to review.
> > >
> > > My view is that this is a duplication of logic for one particular
> > > special case - after all, you can also end up walking up to the same
> > > state (client_layer==-1, server_layer==-1, client_walker==NULL,
> > > server_walker==NULL) with the loop at the bottom.
> >
> > Indeed
> >
> > >
> > > But I guess my preference for more concise code is kinda subjective -
> > > if you prefer the more verbose version, I'm fine with that too.
> > >
> > > > > -
> > > > > - server_layer = server->num_layers - 1;
> > > > > - server_walker = server->hierarchy;
> > > > > + server_layer = server ? (server->num_layers - 1) : -1;
> > > > > + server_walker = server ? server->hierarchy : NULL;
> > > >
> > > > We would need to change the last loop to avoid a null pointer deref.
> > >
> > > Why? The first loop would either exit or walk the client_walker up
> > > until client_layer is -1 and client_walker is NULL; the second loop
> > > wouldn't do anything because the walkers are at the same layer; the
> > > third loop's body wouldn't be executed because client_layer is -1.
> >
> > Correct, I missed that client_layer would always be greater than
> > server_layer (-1).
> >
> > Tahera, could you please take Jann's proposal?
> Done.
> We will have duplicate logic, but it would be easier to read and review.
With Jann's proposal we don't have duplicate logic.
> >
> > >
> > > The case where the server is not in any Landlock domain is just one
> > > subcase of the more general case "client and server do not have a
> > > common ancestor domain".
> > >
> > > > >
> > > > > /*
> > > > > * Walks client's parent domains down to the same hierarchy level as
> > > > > * the server's domain, and checks that none of these client's parent
> > > > > * domains are scoped.
> > > > >
> > >
>
next prev parent reply other threads:[~2024-08-09 8:49 UTC|newest]
Thread overview: 23+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-08-02 4:02 [PATCH v8 0/4] Landlock: Add abstract unix socket connect Tahera Fahimi
2024-08-02 4:02 ` [PATCH v8 1/4] Landlock: Add abstract unix socket connect restriction Tahera Fahimi
2024-08-02 16:47 ` Mickaël Salaün
2024-08-03 11:29 ` Mickaël Salaün
2024-08-06 19:35 ` Mickaël Salaün
2024-08-06 20:46 ` Jann Horn
2024-08-07 7:21 ` Mickaël Salaün
2024-08-07 13:45 ` Jann Horn
2024-08-07 14:44 ` Mickaël Salaün
2024-08-08 23:17 ` Tahera Fahimi
2024-08-09 8:49 ` Mickaël Salaün [this message]
2024-08-09 17:54 ` Tahera Fahimi
2024-08-07 15:37 ` Tahera Fahimi
2024-08-09 14:13 ` Mickaël Salaün
2024-08-06 19:36 ` Jann Horn
2024-08-02 4:02 ` [PATCH v8 2/4] selftests/landlock: Abstract unix socket restriction tests Tahera Fahimi
2024-08-07 15:08 ` Mickaël Salaün
2024-08-02 4:02 ` [PATCH v8 3/4] sample/Landlock: Support abstract unix socket restriction Tahera Fahimi
2024-08-09 14:11 ` Mickaël Salaün
2024-08-09 18:16 ` Tahera Fahimi
2024-08-12 17:06 ` Mickaël Salaün
2024-08-02 4:02 ` [PATCH v8 4/4] Landlock: Document LANDLOCK_SCOPED_ABSTRACT_UNIX_SOCKET and ABI versioning Tahera Fahimi
2024-08-07 15:14 ` 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=20240809.gooHaid7mo1b@digikod.net \
--to=mic@digikod.net \
--cc=bjorn3_gh@protonmail.com \
--cc=fahimitahera@gmail.com \
--cc=gnoack@google.com \
--cc=jannh@google.com \
--cc=jmorris@namei.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).