linux-man.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: "Günther Noack" <gnoack3000@gmail.com>
To: Alejandro Colomar <alx.manpages@gmail.com>
Cc: "Mickaël Salaün" <mic@digikod.net>, linux-man@vger.kernel.org
Subject: Re: [PATCH v6 1/1] landlock.7: Explain the best-effort fallback mechanism in the example
Date: Sat, 15 Apr 2023 09:16:50 +0200	[thread overview]
Message-ID: <20230415.de079bcd1e29@gnoack.org> (raw)
In-Reply-To: <ba15e85d-db90-88cf-ca60-1d4a11a40c31@gmail.com>

Hello Alejandro!

On Fri, Apr 14, 2023 at 06:35:22PM +0200, Alejandro Colomar wrote:
> On 4/14/23 17:59, Günther Noack wrote:
> > Signed-off-by: Günther Noack <gnoack3000@gmail.com>
> > ---
> >  man7/landlock.7 | 70 ++++++++++++++++++++++++++++++++++++++++++++++---
> >  1 file changed, 66 insertions(+), 4 deletions(-)
> > 
> > diff --git a/man7/landlock.7 b/man7/landlock.7
> > index 24488465e..64bfa0752 100644
> > --- a/man7/landlock.7
> > +++ b/man7/landlock.7
> > [...]
> > +/*
> > + * Table of available file system access rights by ABI version,
> > + * numbers hardcoded to keep the example short.
> > + */
> > +__u64 landlock_fs_access_rights[] = {
> > +    (1ULL << 13) \- 1,  /* ABI v1                 */
> > +    (1ULL << 14) \- 1,  /* ABI v2: add "refer"    */
> > +    (1ULL << 15) \- 1,  /* ABI v3: add "truncate" */
> > +};
> > +
> > +int abi = landlock_create_ruleset(NULL, 0,
> > +                                  LANDLOCK_CREATE_RULESET_VERSION);
> > +if (abi <= 0) {
> > +    perror("Giving up \- No Landlock support");
> 
> Using perror(3) will already print "Operation not supported", since
> errno is ENOTSUP.  Maybe this string is redundant?  How about the
> following?
> 
> 	perror("landlock_create_ruleset");  // EOPNOTSUPP

The fallback code assumes that we don't know the kernel that we run on,
so in practice we also have to handle ENOSYS.

See https://docs.kernel.org/userspace-api/landlock.html#landlock-abi-versions

I'd suggest to just make it more explicit here that it can be two
different error codes:

if (abi <= 0) {
    /* ENOTSUP or ENOSYS */
    perror("Giving up \- No Landlock support");
}

Does that sound reasonable?


> BTW, now I checked that while in Linux ENOTSUP and EOPNOTSUPP are
> equivalent, in POSIX the latter has a connotation that it's about
> sockets.  Should we document ENOTSUP in landlock_create_ruleset(2)
> instead of EOPNOTSUPP?

EOPNOTSUP is also used in Landlock's kernel documentation,
we'd maybe have to update it there as well.
I'll have a look at what is more common.


> > +    exit(EXIT_FAILURE);
> > +}
> > +if (abi > 3)
> > +    abi = 3;
> 
> This makes the example a line shorter (see MIN(3)):
> 
> abi = MIN(abi, 3);

Thanks, good point! I'll add that.

–Günther

  reply	other threads:[~2023-04-15  7:16 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-14 15:59 [PATCH v6 0/1] landlock.7: Explain best-effort fallback in example Günther Noack
2023-04-14 15:59 ` [PATCH v6 1/1] landlock.7: Explain the best-effort fallback mechanism in the example Günther Noack
2023-04-14 16:35   ` Alejandro Colomar
2023-04-15  7:16     ` Günther Noack [this message]
2023-04-17 17:24       ` Alejandro Colomar
2023-04-17 20:54         ` Mickaël Salaün
2023-04-18 14:37           ` Alejandro Colomar
2023-04-18 20:50             ` Mickaël Salaün
2023-04-18 20:54               ` Alejandro Colomar
2023-04-18 20:55                 ` 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=20230415.de079bcd1e29@gnoack.org \
    --to=gnoack3000@gmail.com \
    --cc=alx.manpages@gmail.com \
    --cc=linux-man@vger.kernel.org \
    --cc=mic@digikod.net \
    /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).