All of lore.kernel.org
 help / color / mirror / Atom feed
From: "Dr. David Alan Gilbert" <linux@treblig.org>
To: Paul Moore <paul@paul-moore.com>
Cc: serge@hallyn.com, linux-security-module@vger.kernel.org,
	linux-kernel@vger.kernel.org
Subject: Re: [PATCH] capability: Remove unused has_capability
Date: Thu, 19 Dec 2024 14:19:44 +0000	[thread overview]
Message-ID: <Z2QrgI0coNmBMonB@gallifrey> (raw)
In-Reply-To: <CAHC9VhTmqMKkemeyWK3d6tyPGSus9ApMpZzTjtrmgHqbC_au+Q@mail.gmail.com>

* Paul Moore (paul@paul-moore.com) wrote:
> On Wed, Dec 18, 2024 at 5:11 PM Dr. David Alan Gilbert
> <linux@treblig.org> wrote:
> > * Paul Moore (paul@paul-moore.com) wrote:
> > > On Sun, Dec 15, 2024 at 11:54 AM <linux@treblig.org> wrote:
> > > >
> > > > From: "Dr. David Alan Gilbert" <linux@treblig.org>
> > > >
> > > > The vanilla has_capability() function has been unused since 2018's
> > > > commit dcb569cf6ac9 ("Smack: ptrace capability use fixes")
> > > >
> > > > Remove it.
> > > >
> > > > (There is still mention in a comment in security/commoncap.c
> > > > but I suspect rather than removing the entry it might be better
> > > > to expand the comment to talk about the other
> > > > has_[ns_]capability[_noaudit] variants).
> >
> > Hi Paul,
> >   Thanks for the review,
> >
> > > I would suggest that this patch would be an excellent place to change
> > > that comment.  Without historical knowledge, the comment will be hard
> > > to understand after this patch is merged as inspecting
> > > has_capability() will be much more difficult, and including the
> > > comment change with the function removal will bind the two changes
> > > nicely in the git log.
> >
> > Yeh, how would you like it? The existing comment is:
> >
> > '
> >  * NOTE WELL: cap_has_capability() cannot be used like the kernel's capable()
> >  * and has_capability() functions.  That is, it has the reverse semantics:
> >  * cap_has_capability() returns 0 when a task has a capability, but the
> >  * kernel's capable() and has_capability() returns 1 for this case.
> > '
> >
> > For a start I think that's wrong; the function it's above is
> > 'cap_capable()' not 'cap_has_capability()' - and has been for 15 years :-)
> 
> The code in security/commoncap.c is fairly mature and stable, and I
> don't expect that many people spend a lot of time in that file, I know
> I don't.  An unfortunate side effect is that certain things that
> aren't caught by a compiler can easily go out of date, and stay that
> way for some time :/

There are 'many eyes' scared to look!

> > How about:
> > '
> >  * NOTE WELL: cap_capable() has reverse semantics to the other kernel
> >  * functions. That is cap_capable() returns 0 when a task has a capability,
> >  * the kernel's capable(), has_ns_capability(), has_ns_capability_noaudit(),
> >  * and has_capability_noaudit() return 1 for this case.
> > '
> 
> Two things come to mind when reading the suggested comment:
> 
> * I don't like the "... reverse semantics to the other kernel
> functions" text simply because the majority of kernel functions do
> follow the "0 on success, negative errno on failure" pattern that we
> see in cap_capable().  I would suggest something along the lines of
> "... reverse semantics of the capable() call".
> 
> * Most (all?) of the capable() family of functions, excluding
> cap_capable() of course, return a bool value, true/false, instead of
> non-zero/zero.  If we're going to complain about the existing comment,
> we probably should get this correct ;)
> 

OK, maybe:

* NOTE WELL: cap_capable() has reverse semantics to the capable() call
* and friends. That is cap_capable() returns an int 0 when a task has
* a capability, while the kernel's capable(), has_ns_capability(),
* has_ns_capability_noaudit(), and has_capability_noaudit() return a
* bool true (1) for this case.

Dave

> -- 
> paul-moore.com
> 
-- 
 -----Open up your eyes, open up your mind, open up your code -------   
/ Dr. David Alan Gilbert    |       Running GNU/Linux       | Happy  \ 
\        dave @ treblig.org |                               | In Hex /
 \ _________________________|_____ http://www.treblig.org   |_______/

  reply	other threads:[~2024-12-19 14:19 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-12-15 16:53 [PATCH] capability: Remove unused has_capability linux
2024-12-18 21:31 ` Paul Moore
2024-12-18 22:11   ` Dr. David Alan Gilbert
2024-12-19  2:24     ` Paul Moore
2024-12-19 14:19       ` Dr. David Alan Gilbert [this message]
2024-12-19 14:55         ` Paul Moore
2024-12-19 17:29           ` Dr. David Alan Gilbert

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=Z2QrgI0coNmBMonB@gallifrey \
    --to=linux@treblig.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=linux-security-module@vger.kernel.org \
    --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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.