Skip to content

[BUG]: Clear ambient and inheritable capabilities on container start/exec (breaks dbus-daemon on APatch) #414

Done

Description

@nightshadecf

Kernel Version

4.19.191+ #1 SMP PREEMPT aarch64 (note: this is a kernel-independent capability handling bug in src/security/caps.c)

Kernel Source Link (REQUIRED)

Stock non-GKI 4.19 kernel (no custom kernel modifications; the same issue is purely caused by how APatch populates CapAmb/CapInh and how ds_apply_capability_hardening() only drops CapBnd).

Droidspaces Version

v7.2.0 (confirmed src/security/caps.c is unchanged on main at 77e63323)

Rooting Method

APatch (0f3f42ba:APatch(FolkPatch)) — verified that the exact same Artix rootfs works without issue on an identical TCL 9463A rooted with Magisk.

Device OEM & Model

TCL 9463A1

Android Version & ROM

Android 13 (TP1A.220624.014)

Execution Mode

Both

Networking Mode

NAT

Describe the Bug

On devices rooted with APatch, apd spawns both post-fs-data.sh (which launches droidspacesd) and su shells with all inheritable and ambient capabilities set (CapInh=0000003fffffffff, CapAmb=0000003fffffffff), whereas Android's PID 1 init and Magisk leave both at 0.

In src/security/caps.c, ds_apply_capability_hardening() drops 10 capabilities from the bounding set (prctl(PR_CAPBSET_DROP, ...)), but does not clear CapAmb (PR_CAP_AMBIENT_CLEAR_ALL) or CapInh (via capset()). As a result, PID 1 inside the container (and processes spawned via enter / run) inherit CapInh and CapAmb containing capabilities that are no longer in CapBnd:

CapInh: 0000003fffffffff
CapPrm: 0000003fffffffff
CapEff: 0000003fffffffff
CapBnd: 00000004ffe4fffb
CapAmb: 0000003fffffffff

When dbus-daemon starts inside the container (Artix OpenRC), it attempts to drop capabilities via libcap-ng and immediately fails:

dbus-daemon[1301]: Failed to start message bus: Failed to drop capabilities: Operation not permitted

Because dbus fails to start, NetworkManager cannot connect to D-Bus and stays inactive, so eth0 never obtains its NAT DHCP lease and the container has no network (Network is unreachable).

Additionally, leaving CapAmb=0000003fffffffff on container PID 1 means processes inside the container inherit ambient capabilities unexpectedly.

Steps to Reproduce

  1. Root a device with APatch (confirm su -c 'grep ^Cap /proc/self/status' shows non-zero CapInh and CapAmb).
  2. Install and start an Artix Minimal (OpenRC) container in NAT mode.
  3. Observe rc-status inside the container: dbus is [ failed ], NetworkManager is [ inactive ], and eth0 has no IPv4 address.
  4. Run dbus-daemon --system --nofork --print-address as root inside the container → fails with Failed to drop capabilities: Operation not permitted.
  5. Run setpriv --inh-caps=-all --ambient-caps=-all dbus-daemon --system --nofork --print-address → starts cleanly, and NetworkManager immediately brings up eth0 with DHCP and working DNS.

Logs / Screenshots

Host PID 1 vs droidspacesd and su on APatch:

# Host /proc/1/status
Name:   init
CapInh: 0000000000000000
CapPrm: 0000003fffffffff
CapEff: 0000003fffffffff
CapBnd: 0000003fffffffff
CapAmb: 0000000000000000

# Host droidspacesd (/proc/731/status) & APatch su shell
Name:   droidspaces
CapInh: 0000003fffffffff
CapPrm: 0000003fffffffff
CapEff: 0000003fffffffff
CapBnd: 0000003fffffffff
CapAmb: 0000003fffffffff

Container PID 1 (/proc/1/status inside Artix):

CapInh: 0000003fffffffff
CapPrm: 0000003fffffffff
CapEff: 0000003fffffffff
CapBnd: 00000004ffe4fffb
CapAmb: 0000003fffffffff

After clearing ambient and inheritable caps (setpriv --inh-caps=-all --ambient-caps=-all grep ^Cap /proc/self/status):

CapInh: 0000000000000000
CapPrm: 00000004ffe4fffb
CapEff: 00000004ffe4fffb
CapBnd: 00000004ffe4fffb
CapAmb: 0000000000000000

Suggested Fix

In ds_apply_capability_hardening() (src/security/caps.c, called from src/boot/init.c:509, src/container/exec.c:168, and src/container/exec.c:350):

  1. Clear ambient capabilities with prctl(PR_CAP_AMBIENT, PR_CAP_AMBIENT_CLEAR_ALL, 0, 0, 0) (even before the DS_PRIV_NOCAPS early return, since normal Linux init never starts with ambient caps set).
  2. Clear inheritable via capget()/capset() (with cap_user_header_t version _LINUX_CAPABILITY_VERSION_3), so the subsequent execve() starts the container's init / shell with CapInh=0, CapAmb=0, and CapPrm=CapEff=CapBnd.

Required Acknowledgments

  • I have verified this is not a duplicate issue.
  • I am using a kernel compiled strictly according to Droidspaces' official documentation.
  • I am NOT using a kernel with 69+ random configs, CRC nukes, or a broken ABI.
  • I have confirmed this issue persists in both Daemon and Direct modes.
  • I admit that I am a clown for checking this box, confirming I have NOT read these rules.
  • I admit I did zero research, didn't ask my AI waifu for a fix, and am dropping this here because I'm 100% sure the fault lies with Droidspaces.

Activity

  1. ravindu644 commented on Dec 3, 2026

    @ravindu644
    Owner

    Thanks for the detailed report, you were right, and it was worse than the dbus breakage. On a root exec the kernel sets the new permitted set to bounding | inheritable, so with APatch's full inheritable set every capability we drop from the bounding set came straight back in the container. That's why your PID 1 had CapPrm/CapEff = 3fffffffff next to a hardened CapBnd.

    Fixed in aeeafc4. ds_apply_capability_hardening() now empties the inheritable set before the bounding drops. capset() trims ambient to permitted & inheritable, so that clears ambient as well, no separate PR_CAP_AMBIENT_CLEAR_ALL needed. It covers boot, enter and run, and does nothing on root solutions that already leave inheritable at zero (Magisk, KernelSU).

    I reproduced your cap state on a KernelSU device by raising inheritable + ambient to full before starting the container:

    before: CapInh 1ffffffffff  CapPrm/CapEff 1ffffffffff  CapAmb 1ffffffffff
    after:  CapInh 0            CapPrm/CapEff 1c4ffe4fffb  CapAmb 0   (== CapBnd)
    

    I couldn't test dbus itself on APatch, so please grab the build from this CI run and confirm that dbus and NetworkManager come up on your TCL: https://github.com/ravindu644/Droidspaces-OSS/actions/runs/47076370653 (artifact droidspaces-artifacts). It will be in the next release.

  2. added a commit that references this issue on Dec 3, 2026
    aeeafc4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions