From: "Günther Noack" <gnoack@google.com>
To: Mikhail Ivanov <ivanov.mikhail1@huawei-partners.com>
Cc: "Günther Noack" <gnoack3000@gmail.com>,
mic@digikod.net, 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, konstantin.meskhidze@huawei.com,
"Tahera Fahimi" <fahimitahera@gmail.com>
Subject: Re: [RFC PATCH v2 00/12] Socket type control for Landlock
Date: Mon, 10 Jun 2024 10:03:24 +0200 [thread overview]
Message-ID: <ZmazTKVNlsH3crwP@google.com> (raw)
In-Reply-To: <ebd680cc-25d6-ee14-4856-310f5e5e28e4@huawei-partners.com>
On Thu, Jun 06, 2024 at 02:44:23PM +0300, Mikhail Ivanov wrote:
> 6/4/2024 11:22 PM, Günther Noack wrote:
> I figured out that I define LANDLOCK_SHIFT_ACCESS_SOCKET macro in
> really strange way (see landlock/limits.h):
>
> #define LANDLOCK_SHIFT_ACCESS_SOCKET LANDLOCK_NUM_ACCESS_SOCKET
>
> With this definition, socket access mask overlaps the fs access
> mask in ruleset->access_masks[layer_level]. That's why
> landlock_get_fs_access_mask() returns non-zero mask in hook_file_open().
>
> So, the macro must be defined in this way:
>
> #define LANDLOCK_SHIFT_ACCESS_SOCKET (LANDLOCK_NUM_ACCESS_NET +
> LANDLOCK_NUM_ACCESS_FS)
>
> With this fix, open() doesn't fail in your example.
>
> I'm really sorry that I somehow made such a stupid typo. I will try my
> best to make sure this doesn't happen again.
I found that we had the exact same bug with a wrongly defined "SHIFT" value in
[1].
Maybe we should define access_masks_t as a bit-field rather than doing the
bit-shifts by hand. Then the compiler would keep track of the bit-offsets
automatically.
Bit-fields have a bad reputation, but in my understanding, this is largely
because they make it hard to control the exact bit-by-bit layout. In our case,
we do not need such an exact control though, and it would be fine.
To quote Linus Torvalds on [2],
Bitfields are fine if you don't actually care about the underlying format,
and want gcc to just randomly assign bits, and want things to be
convenient in that situation.
Let me send you a proposal patch which replaces access_masks_t with a bit-field
and removes the need for the "SHIFT" definition, which we already got wrong in
two patch sets now. It has the additional benefit of making the code a bit
shorter and also removing a few static_assert()s which are now guaranteed by the
compiler.
—Günther
[1] https://lore.kernel.org/all/ZmLEoBfHyUR3nKAV@google.com/
[2] https://yarchive.net/comp/linux/bitfields.html
next prev parent reply other threads:[~2024-06-10 8:03 UTC|newest]
Thread overview: 39+ 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
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 [this message]
2024-06-11 11:35 ` 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=ZmazTKVNlsH3crwP@google.com \
--to=gnoack@google.com \
--cc=artem.kuzin@huawei.com \
--cc=fahimitahera@gmail.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).