From: "Günther Noack" <gnoack3000@gmail.com>
To: Alejandro Colomar <alx.manpages@gmail.com>
Cc: "Mickaël Salaün" <mic@digikod.net>,
"Michael Kerrisk" <mtk.manpages@gmail.com>,
linux-man@vger.kernel.org
Subject: Re: [PATCH v5 3/3] landlock.7: Explain the best-effort fallback mechanism in the example
Date: Sat, 1 Apr 2023 19:19:02 +0200 [thread overview]
Message-ID: <20230401.1316d7f843d7@gnoack.org> (raw)
In-Reply-To: <a5daa228-284e-12d3-cd5b-28611830e21b@gmail.com>
Hello Alejandro!
On Sat, Apr 01, 2023 at 12:29:35AM +0200, Alejandro Colomar wrote:
> Hi Günther,
>
> On 3/24/23 18:24, Günther Noack wrote:
> > Signed-off-by: Günther Noack <gnoack3000@gmail.com>
> > ---
> > man7/landlock.7 | 65 ++++++++++++++++++++++++++++++++++++++++++++++---
> > 1 file changed, 61 insertions(+), 4 deletions(-)
> >
> > diff --git a/man7/landlock.7 b/man7/landlock.7
> > index 9c305edef..d1214ba27 100644
> > --- a/man7/landlock.7
> > +++ b/man7/landlock.7
> > [...]
> > +.EX
> > +/* Table of available file system access rights by ABI version */
> > +__u64 landlock_fs_access_rights[] = {
> > + (1ULL << 13) \- 1, /* ABI v1 */
> > + (1ULL << 14) \- 1, /* ABI v2: add "refer" */
> > + (1ULL << 15) \- 1, /* ABI v3: add "truncate" */
>
> Do these magic numbers have macros? Are users expected to use
> the magic numbers directly?
You are right to point this out - it's the ugly part here :-/
These are bitmasks for the different access rights which are supported
at each ABI version, so they are a bitwise OR of a long list of
LANDLOCK_ACCESS_FS_* constants.
I am aware of three ways to write this out.
Please let me know which of these three you prefer.
(or maybe you have an idea for another alternative?).
(It feels out of scope for this documentation patch, but do you think
these bitmasks should be defined in the uapi/linux/landlock.h header?
You have looked at so many man pages already -- Do you happen to know
other places in the kernel API where such a problem has come up?)
1) Make assumptions about the numbers, for brevity
(as done in the patch I sent).
__u64 landlock_fs_access_rights[] = {
(1ULL << 13) - 1, /* ABI v1 */
(1ULL << 14) - 1, /* ABI v2: add "refer" */
(1ULL << 15) - 1, /* ABI v3: add "truncate" */
}
This is the shortest variant,
but it does not use the Landlock constants from the header.
2) Use the constants from the header and OR them.
This is the "most correct" way, but I feel that it might be too
verbose for a documentation example. What do you think?
__u64 landlock_fs_access_rights[] = {
/* ABI v1 */
LANDLOCK_ACCESS_FS_EXECUTE |
LANDLOCK_ACCESS_FS_WRITE_FILE |
LANDLOCK_ACCESS_FS_READ_FILE |
LANDLOCK_ACCESS_FS_READ_DIR |
LANDLOCK_ACCESS_FS_REMOVE_DIR |
LANDLOCK_ACCESS_FS_REMOVE_FILE |
LANDLOCK_ACCESS_FS_MAKE_CHAR |
LANDLOCK_ACCESS_FS_MAKE_DIR |
LANDLOCK_ACCESS_FS_MAKE_REG |
LANDLOCK_ACCESS_FS_MAKE_SOCK |
LANDLOCK_ACCESS_FS_MAKE_FIFO |
LANDLOCK_ACCESS_FS_MAKE_BLOCK |
LANDLOCK_ACCESS_FS_MAKE_SYM,
/* ABI v2: Add "refer" */
LANDLOCK_ACCESS_FS_EXECUTE |
LANDLOCK_ACCESS_FS_WRITE_FILE |
LANDLOCK_ACCESS_FS_READ_FILE |
LANDLOCK_ACCESS_FS_READ_DIR |
LANDLOCK_ACCESS_FS_REMOVE_DIR |
LANDLOCK_ACCESS_FS_REMOVE_FILE |
LANDLOCK_ACCESS_FS_MAKE_CHAR |
LANDLOCK_ACCESS_FS_MAKE_DIR |
LANDLOCK_ACCESS_FS_MAKE_REG |
LANDLOCK_ACCESS_FS_MAKE_SOCK |
LANDLOCK_ACCESS_FS_MAKE_FIFO |
LANDLOCK_ACCESS_FS_MAKE_BLOCK |
LANDLOCK_ACCESS_FS_MAKE_SYM |
LANDLOCK_ACCESS_FS_REFER,
/* ABI v3: add "truncate" */
LANDLOCK_ACCESS_FS_EXECUTE |
LANDLOCK_ACCESS_FS_WRITE_FILE |
LANDLOCK_ACCESS_FS_READ_FILE |
LANDLOCK_ACCESS_FS_READ_DIR |
LANDLOCK_ACCESS_FS_REMOVE_DIR |
LANDLOCK_ACCESS_FS_REMOVE_FILE |
LANDLOCK_ACCESS_FS_MAKE_CHAR |
LANDLOCK_ACCESS_FS_MAKE_DIR |
LANDLOCK_ACCESS_FS_MAKE_REG |
LANDLOCK_ACCESS_FS_MAKE_SOCK |
LANDLOCK_ACCESS_FS_MAKE_FIFO |
LANDLOCK_ACCESS_FS_MAKE_BLOCK |
LANDLOCK_ACCESS_FS_MAKE_SYM,
LANDLOCK_ACCESS_FS_REFER |
LANDLOCK_ACCESS_FS_TRUNCATE,
}
If I were to write production code, I would probably write it out like
that, to be explicit -- but it feels like a long code example for a
man page? WDYT?
3) Third option is the middle way,
naming the "highest" known access right for each ABI version:
__u64 landlock_fs_access_rights[] = {
(LANDLOCK_ACCESS_FS_MAKE_SYM << 1) - 1, /* ABI v1 */
(LANDLOCK_ACCESS_FS_REFER << 1) - 1, /* ABI v2: add "refer" */
(LANDLOCK_ACCESS_FS_TRUNCATE << 1) - 1, /* ABI v3: add "truncate" */
}
In this case, we still make the assumption that the supported rights
are the "highest" right plus all of the bits in lower order places.
> > +/* Only use the available rights in the ruleset. */
> > +attr.handled_access_fs &= landlock_fs_access_rights[abi \- 1];
> > +.EE
> > +.in
> > +.PP
> > +The available access rights for each ABI version are listed in the
> > +.B VERSIONS
> > +section.
> > +.PP
> > +If our program needed to create hard links or rename files between different directories
>
> Please keep lines below 80 columns. Break lines at phrase
> boundaries as appropriate (e.g., in this line:)
>
> s/ or /\nor /
Thanks, applied. Will be fixed in the next patch version.
> > +.RB ( LANDLOCK_ACCESS_FS_REFER ),
> > +we would require the following change to the backwards compatibility logic:
> > +Directory reparenting is not possible in a process restricted with Landlock ABI version 1.
Fixed it on this line too.
Thank you for the review and for applying the two earlier patches!
–Günther
next prev parent reply other threads:[~2023-04-01 17:19 UTC|newest]
Thread overview: 15+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-03-24 17:24 [PATCH v5 1/3] landlock.7: Document Landlock ABI v2 (file reparenting; Linux 5.19) Günther Noack
2023-03-24 17:24 ` [PATCH v5 2/3] landlock.7: Document Landlock ABI v3 (file truncation; Linux 6.2) Günther Noack
2023-03-31 22:20 ` Alejandro Colomar
2023-03-24 17:24 ` [PATCH v5 3/3] landlock.7: Explain the best-effort fallback mechanism in the example Günther Noack
2023-03-24 18:24 ` Günther Noack
2023-03-31 22:29 ` Alejandro Colomar
2023-04-01 17:19 ` Günther Noack [this message]
2023-04-01 22:01 ` Alejandro Colomar
2023-04-04 7:33 ` Günther Noack
2023-04-05 2:50 ` Alejandro Colomar
2023-04-17 21:13 ` Mickaël Salaün
2023-04-18 14:47 ` Alejandro Colomar
2023-04-02 1:21 ` Alejandro Colomar
2023-04-04 7:17 ` Günther Noack
2023-03-31 22:17 ` [PATCH v5 1/3] landlock.7: Document Landlock ABI v2 (file reparenting; Linux 5.19) Alejandro Colomar
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=20230401.1316d7f843d7@gnoack.org \
--to=gnoack3000@gmail.com \
--cc=alx.manpages@gmail.com \
--cc=linux-man@vger.kernel.org \
--cc=mic@digikod.net \
--cc=mtk.manpages@gmail.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