<?xml version="1.0" encoding="UTF-8" ?>

<bugzilla version="5.2"
          urlbase="https://bugzilla.altlinux.org/"
          
          maintainer="jenya@basealt.ru"
>

    <bug>
          <bug_id>16694</bug_id>
          
          <creation_ts>2008-08-15 05:20:29 +0400</creation_ts>
          <short_desc>sucap useless on current kernels: how to run smth as a given user with a given set of capabilities?</short_desc>
          <delta_ts>2023-01-23 19:15:30 +0300</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>4</classification_id>
          <classification>Development</classification>
          <product>Sisyphus</product>
          <component>libcap-utils</component>
          <version>unstable</version>
          <rep_platform>all</rep_platform>
          <op_sys>Linux</op_sys>
          <bug_status>NEW</bug_status>
          <resolution></resolution>
          
          
          <bug_file_loc>https://silhouetteamericasetup.com/</bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>enhancement</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Ivan Zakharyaschev">imz</reporter>
          <assigned_to name="Mikhail Efremov">sem</assigned_to>
          <cc>glebfm</cc>
    
    <cc>jackie.rosen</cc>
    
    <cc>ldv</cc>
    
    <cc>luciawiltor45678</cc>
    
    <cc>morgan</cc>
    
    <cc>roanparker158</cc>
    
    <cc>samsmithgeek001</cc>
    
    <cc>sem</cc>
          
          <qa_contact>qa-sisyphus</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>75511</commentid>
    <comment_count>0</comment_count>
    <who name="Ivan Zakharyaschev">imz</who>
    <bug_when>2008-08-15 05:20:29 +0400</bug_when>
    <thetext>$ rpm -qf /sbin/sucap 
libcap-utils-1.10-alt16
$ uname -r
2.6.24-std-def-alt6
$ 

Apparently, the implementation of sucap uses an operation not permitted on current kernels; for example, trying to use it when working as root:
# sucap ivan root /bin/bash
Caps: =ep
Caps: =
[debug] uid:502, real uid:502
sucaps: capsetp: Operation not permitted
sucap: child did not exit cleanly.
# 

This makes sucap useless. A possible use of the libcap utilities could be testing of programs being executed as a given user with given capabilities. (A side note: this uselessness has already been noted by other people: http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=439873 .)

Now, there is no way for the user &quot;root&quot; to run a program as a given non-root user with a given set of capabilities (in order to test how it would work).

The standard way that would lead to running a program as a certain non-root user with a certain set of capabilities would be to configure the file capabilities on the executable (e.g., &quot;setcap cap_net_raw=ep /bin/ping&quot; -- an example from http://www.friedhoff.org/posixfilecaps.html ).

The user &quot;root&quot; can do such a configuration (or, as for ALTLinux: &quot;could do in ALTLinux, if there were the utilities for managing POSIX file capabilities&quot;). What my feature request is about is: How to emulate the same result without manipulating the file system? (Before actually setting the file capabilities, the user &quot;root&quot; might want to test how the program will run with the intended capabilities as a non-root user.)

There seems to be no means available for this scenario.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>75512</commentid>
    <comment_count>1</comment_count>
    <who name="Ivan Zakharyaschev">imz</who>
    <bug_when>2008-08-15 06:08:21 +0400</bug_when>
    <thetext>I&apos;ve searched the available documentation (libcap2, linux, etc.), the mailing lists, but haven&apos;t found a potential solution.

Perhaps, there is an option of &quot;capsh&quot; (and a corresponding option in linux processes) that would enable this scenario (the utility &quot;capsh&quot; accompanies libcap2 -- http://www.kernel.org/pub/linux/libs/security/linux-privs/libcap2/ ), but that&apos;s not clear from the documentation. Simply starting a shell with special capabilities wouldn&apos;t enable the wanted scenario, because the capabilities would be &quot;erased&quot; on exec (if no file capabilities are pre-configured on the executed executable).

This problem has already been noticed by other people, but the discussions I found didn&apos;t suggest that this was possible in the discussed versions of linux; so, they tried to push some patches into linux, and it&apos;s not clear whether this scenario ultimately became possible. The links to 2 such discussions: 1) http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-03/5224.html ; 2) http://lkml.org/lkml/2006/9/7/248 .

1) http://linux.derkeiler.com/Mailing-Lists/Kernel/2005-03/5224.html &quot;Re: Capabilities across execve&quot; writes (following a discussion of a suggested patch): 

-----------------------
On Sat, Mar 12, 2005 at 07:21:17PM -0800, Chris Wright wrote:
&gt; * Alexander Nyberg (alexn@dsv.su.se) wrote:
&gt; &gt; This makes it possible for a root-task to pass capabilities to
&gt; &gt; nonroot-task across execve. The root-task needs to change it&apos;s
&gt; &gt; cap_inheritable mask and set prctl(PR_SET_KEEPCAPS, 1) to pass on
&gt; &gt; capabilities.
&gt;
&gt; This overloads keepcaps, which could surprise to existing users.

Chris,

Since you seem to be knowledgeable about the capability system, I have
a question.

... 

I&apos;d like to run a certain program non-root with certain capabilities only. I looked at the above two programs and stupidly thought they&apos;d actually allow me to do this.
...
------------
My comment:

So, down the line, is it possible?

It&apos;s the first thing to do when testing capabilities.

It&apos;s quite illogical if &quot;capabilities across execve&quot; is possible if we modify the filesystem, but isn&apos;t possible in a &quot;clean&quot; (read-only) way just through system calls.

After all, the &quot;trick&quot; with filesystem would still result in a sequence of operations in the kernel. And the super-user &quot;root&quot; should be able perform those operations directly.


2) http://lkml.org/lkml/2006/9/7/248 &quot;Re: patch to make Linux capabilities into something useful (v 0.3.1)&quot; -- patches that are too powerful and non-compliant to the specifications, but also targeting this problem: 

---------
...

So in other words, it may make sense for the process to be able to say &quot;I want these caps to persist across exec&quot; (*1), but it shouldn&apos;t happen automatically based on the file&apos;s attributes. In any case, perhaps it would be worthwhile making this a part of a capability_plusplus module? That would be less controversial, given that I believe many people use the capability module who really just want classic setuid behavior.

...
---------
My comment:

One might be satisfied with even a weaker thing: &quot;I am root, and I want these caps to persist across exec (which I&apos;ll do after setuid)&quot;.

It&apos;s possible by modifying the filesystem -- setting file-capabilities; so why shouldn&apos;t it be available without modifying the filesystem?..

Actually, this could be implemented in a controllable and clear way; perhaps, there is already a way to do this in linux; but, if not, here are the details of an imagined implementation to prove that this is possible in a clear way (and to demonstrate the wanted scenario more definitely):

1) introduce a new capability in linux, like: CAP_&lt;set keep caps across exec&gt;. Normally, this capability is off, but is on for the conventional root.

2) introduce the corresponding &quot;switch&quot;, controlled by, say, prctl(): PR_SET_&lt;keep caps across exec&gt; (analogous to PR_SET_KEEPCAPS). If it&apos;s on, the capabilities are kept across exec, if it&apos;s off, the standard rules involving intersection with file capabilities apply (as described by &quot;Transformation of Capabilities During exec()&quot; in the manpage &quot;capabilities(7)&quot;).

Now, the wanted behavior (available under root) would be programmed like this:

1) we are running under root, so CAP_&lt;set keep caps across exec&gt; is present;

2) do PR_SET_KEEPCAPS;

3) drop extra capabilities;

4) change UID; (the capabilities, incl. the new one, CAP_&lt;set keep caps across exec&gt;, are kept)

5) do PR_SET_&lt;keep caps across exec&gt; (we have the required capability for this);

6) drop extra capabilities except for the wanted one (if any);

7) exec... (the standard rules do not apply due to PR_SET_&lt;keep caps across exec&gt;: the selected capabilities are kept).

So, in the result, we changed UID and kept some wanted capabilities, and executed the wanted executable.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>75538</commentid>
    <comment_count>2</comment_count>
    <who name="Ivan Zakharyaschev">imz</who>
    <bug_when>2008-08-15 17:54:06 +0400</bug_when>
    <thetext>Perhaps, the &quot;securebits&quot; provide a solution to this feature request. A short summary I found when searching for documentation on securebits says:

-------------
...

 + (3) Secure management flags (securebits).
 + + These are only carried by tasks. These govern the way the above
 + credentials are manipulated and inherited over certain operations such as
 + execve(). They aren&apos;t used directly as objective or subjective
 + credentials.

...
-------------
(from http://kerneltrap.org/mailarchive/linux-kernel/2008/8/6/2838844 &quot;[PATCH 21/24] CRED: Documentation [ver #7]&quot;).
</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>75539</commentid>
    <comment_count>3</comment_count>
    <who name="Ivan Zakharyaschev">imz</who>
    <bug_when>2008-08-15 17:58:12 +0400</bug_when>
    <thetext>A comment I have found makes it evident that (at least on August 27, 2007) there seemed to be no solution to my feature request (&quot;without file capabilities there was no way&quot;) -- http://kerneltrap.org/mailarchive/linux-kernel/2007/8/27/165096 &quot;Re: [2.6 patch] remove securebits&quot;:

----------
...

That&apos;s because without file capabilities there was no way for a process to retain capabilities across exec, so not having a privileged root user was simply not workable.

...
----------

My comment: But that&apos;s not logical if the super-user &quot;root&quot; can&apos;t force this behavior (for example, as I said, for the purposes of testing).

(Perhaps, since then, the situation has changed.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>220513</commentid>
    <comment_count>4</comment_count>
    <who name="Andrew G. Morgan">morgan</who>
    <bug_when>2023-01-23 19:15:30 +0300</bug_when>
    <thetext>This bug is very old. Asynchronously setting the capabilities of a distant process was un-auditable, so when we completed the capability implementation in the kernel, this feature was removed and sucap ceased to work. This was back in 2007/2008.

Since then, Ambient capabilities have been invented. They provide a path for addressing the desire expressed in this bug. There is a full write up on the ways of inheriting capabilities, the good, the bad and the ugly here:

  https://sites.google.com/site/fullycapable/inheriting-privilege

Also, some discussion of corner cases that may surprise folk is here:

  https://sites.google.com/site/fullycapable/why-didnt-that-work</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>