* [PATCH] setpriv: support setting unnamed capabilities
@ 2017-07-17 21:14 Patrick Steinhardt
2017-07-18 11:55 ` Karel Zak
2017-07-19 6:18 ` Bernhard Voelker
0 siblings, 2 replies; 5+ messages in thread
From: Patrick Steinhardt @ 2017-07-17 21:14 UTC (permalink / raw)
To: util-linux; +Cc: kzak, Patrick Steinhardt
When setting capabilities, we accept human readable names like for
example `sys_rawio` or `net_admin`. To do so the translation between the
capability name and its in-kernel index, we rely on the function
`capng_name_to_capability`. When the function does not know the named
capability, it will return an error value and we abort setting the
capability.
This relies upon the ability of libcap to know all capabilities inside
of the kernel. But actually, it is possible that new capabilities are
introduced inside of the Linux kernel which are not recognized yet by
the library. When dumping these unknown capabilities, libcap will simply
return a string like "cap_38", that is it will append the capability's
in-kernel index to the prefix "cap_". This may lead a user to also think
that "cap_38" may be passed to the switches "--inh-caps" or
"--ambient-caps", which is unfortunately not the case.
We can do better here by instead accepting strings in the form of
"cap_N". To do so, we can simply rely on the fact that capability
indices are steadily increasing and that the highest index known to the
kernel is stored inside of the kernel's procfs, made readily available
by our function `real_cap_last_cap()`. So in case libcap does not know a
capability name, we can simply parse the string and, if it is in the
correct format, check whether the detected index is between 0 and the
highest capability index. If so, we can treat it as a valid capability
string and apply it.
Signed-off-by: Patrick Steinhardt <ps@pks.im>
---
sys-utils/setpriv.c | 3 +++
1 file changed, 3 insertions(+)
diff --git a/sys-utils/setpriv.c b/sys-utils/setpriv.c
index 19753aab8..2402e624f 100644
--- a/sys-utils/setpriv.c
+++ b/sys-utils/setpriv.c
@@ -529,6 +529,9 @@ static void do_caps(enum cap_type type, const char *caps)
int cap = capng_name_to_capability(c + 1);
if (0 <= cap)
cap_update(action, type, cap);
+ else if (sscanf(c + 1, "cap_%d", &cap) == 1
+ && 0 <= cap && cap <= real_cap_last_cap())
+ cap_update(action, type, cap);
else
errx(EXIT_FAILURE,
_("unknown capability \"%s\""), c + 1);
--
2.13.3
^ permalink raw reply related [flat|nested] 5+ messages in thread* Re: [PATCH] setpriv: support setting unnamed capabilities
2017-07-17 21:14 [PATCH] setpriv: support setting unnamed capabilities Patrick Steinhardt
@ 2017-07-18 11:55 ` Karel Zak
2017-07-19 6:18 ` Bernhard Voelker
1 sibling, 0 replies; 5+ messages in thread
From: Karel Zak @ 2017-07-18 11:55 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: util-linux
On Mon, Jul 17, 2017 at 11:14:09PM +0200, Patrick Steinhardt wrote:
> sys-utils/setpriv.c | 3 +++
> 1 file changed, 3 insertions(+)
Applied, thanks.
--
Karel Zak <kzak@redhat.com>
http://karelzak.blogspot.com
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] setpriv: support setting unnamed capabilities
2017-07-17 21:14 [PATCH] setpriv: support setting unnamed capabilities Patrick Steinhardt
2017-07-18 11:55 ` Karel Zak
@ 2017-07-19 6:18 ` Bernhard Voelker
2017-07-19 7:42 ` Patrick Steinhardt
1 sibling, 1 reply; 5+ messages in thread
From: Bernhard Voelker @ 2017-07-19 6:18 UTC (permalink / raw)
To: Patrick Steinhardt, util-linux; +Cc: kzak
On 07/17/2017 11:14 PM, Patrick Steinhardt wrote:
> When setting capabilities, we accept human readable names like for
> example `sys_rawio` or `net_admin`. To do so the translation between the
> capability name and its in-kernel index, we rely on the function
> `capng_name_to_capability`. When the function does not know the named
> capability, it will return an error value and we abort setting the
> capability.
>
> This relies upon the ability of libcap to know all capabilities inside
> of the kernel. But actually, it is possible that new capabilities are
> introduced inside of the Linux kernel which are not recognized yet by
> the library. When dumping these unknown capabilities, libcap will simply
> return a string like "cap_38", that is it will append the capability's
> in-kernel index to the prefix "cap_". This may lead a user to also think
> that "cap_38" may be passed to the switches "--inh-caps" or
> "--ambient-caps", which is unfortunately not the case.
>
> We can do better here by instead accepting strings in the form of
> "cap_N". To do so, we can simply rely on the fact that capability
> indices are steadily increasing and that the highest index known to the
> kernel is stored inside of the kernel's procfs, made readily available
> by our function `real_cap_last_cap()`. So in case libcap does not know a
> capability name, we can simply parse the string and, if it is in the
> correct format, check whether the detected index is between 0 and the
> highest capability index. If so, we can treat it as a valid capability
> string and apply it.
Thanks - would you mind to also add a sentence to the man page?
Thanks & have a nice day,
Berny
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] setpriv: support setting unnamed capabilities
2017-07-19 6:18 ` Bernhard Voelker
@ 2017-07-19 7:42 ` Patrick Steinhardt
2017-07-19 21:34 ` Bernhard Voelker
0 siblings, 1 reply; 5+ messages in thread
From: Patrick Steinhardt @ 2017-07-19 7:42 UTC (permalink / raw)
To: Bernhard Voelker; +Cc: util-linux, kzak
[-- Attachment #1: Type: text/plain, Size: 1946 bytes --]
On Wed, Jul 19, 2017 at 08:18:55AM +0200, Bernhard Voelker wrote:
> On 07/17/2017 11:14 PM, Patrick Steinhardt wrote:
> > When setting capabilities, we accept human readable names like for
> > example `sys_rawio` or `net_admin`. To do so the translation between the
> > capability name and its in-kernel index, we rely on the function
> > `capng_name_to_capability`. When the function does not know the named
> > capability, it will return an error value and we abort setting the
> > capability.
> >
> > This relies upon the ability of libcap to know all capabilities inside
> > of the kernel. But actually, it is possible that new capabilities are
> > introduced inside of the Linux kernel which are not recognized yet by
> > the library. When dumping these unknown capabilities, libcap will simply
> > return a string like "cap_38", that is it will append the capability's
> > in-kernel index to the prefix "cap_". This may lead a user to also think
> > that "cap_38" may be passed to the switches "--inh-caps" or
> > "--ambient-caps", which is unfortunately not the case.
> >
> > We can do better here by instead accepting strings in the form of
> > "cap_N". To do so, we can simply rely on the fact that capability
> > indices are steadily increasing and that the highest index known to the
> > kernel is stored inside of the kernel's procfs, made readily available
> > by our function `real_cap_last_cap()`. So in case libcap does not know a
> > capability name, we can simply parse the string and, if it is in the
> > correct format, check whether the detected index is between 0 and the
> > highest capability index. If so, we can treat it as a valid capability
> > string and apply it.
>
> Thanks - would you mind to also add a sentence to the man page?
>
> Thanks & have a nice day,
> Berny
Sure, can do this. I'll send a follow-up patch tomorrow as the
patch has already been applied.
Patrick
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: [PATCH] setpriv: support setting unnamed capabilities
2017-07-19 7:42 ` Patrick Steinhardt
@ 2017-07-19 21:34 ` Bernhard Voelker
0 siblings, 0 replies; 5+ messages in thread
From: Bernhard Voelker @ 2017-07-19 21:34 UTC (permalink / raw)
To: Patrick Steinhardt; +Cc: util-linux, kzak
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
On 07/19/2017 09:42 AM, Patrick Steinhardt wrote:
> On Wed, Jul 19, 2017 at 08:18:55AM +0200, Bernhard Voelker wrote:
>>
>> Thanks - would you mind to also add a sentence to the man page?
>>
>> Thanks & have a nice day, Berny
>
> Sure, can do this. I'll send a follow-up patch tomorrow as the patch has already been applied.
Thanks!
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2
iQEcBAEBAgAGBQJZb9B+AAoJEEZQLveWkXGV2k4H/25iCFMl+d+XZoi9MXwzvK7l
3bw9k+zZSmyK1KXnDC/u+mY8xYd662SUZoF24b4ZqK7RwNBE9qUkJ/DBVCYOLChk
xSRZIrW3i9eEBknYXB48A6MTOg9nclkj/Y1wABPYd8wHumcuAp2sZ3rEuFi/ftii
uWnCxRU/uqp5KMIr6xmMNCbhhEnfmaqVNHsgB5cfhRDT+6Da+1d5Rh7ASqk5Lfht
5d2bNaPqeyvzaoGcw/Ien4M2gveC/47sLxH8VsbK3Wm+yFdI12pld+NROef7zIuM
B/oB+40MH5suWHgPBq5MPPH7PiKk5AfkjahfOWGsQnJke/KuZl7gJEVQrEJSt8c=
=73Hp
-----END PGP SIGNATURE-----
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2017-07-19 21:35 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-07-17 21:14 [PATCH] setpriv: support setting unnamed capabilities Patrick Steinhardt
2017-07-18 11:55 ` Karel Zak
2017-07-19 6:18 ` Bernhard Voelker
2017-07-19 7:42 ` Patrick Steinhardt
2017-07-19 21:34 ` Bernhard Voelker
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox