Skip to content

Test heap injection into executables with file capabilities #562

Open

Description

@r1viollet

Behavior

Keep this as a future Linux integration test case: heap-profiler injection can be suppressed when a non-root user launches an executable with file capabilities.

Observed with an Envoy binary carrying cap_net_bind_service=ep, launched as UID 100. Executing it grants a capability and triggers secure execution (AT_SECURE); glibc ignores ddprof's path-based LD_PRELOAD, preventing allocation-library injection.

The preload was honored when running as root with the capability already permitted.

Future test case

Use a dynamically linked malloc/free fixture in a suitably privileged Linux test setup:

  1. Run it through ddprof --preset cpu_live_heap as a non-root user without file capabilities. Verify injection and allocation samples.
  2. Apply setcap cap_net_bind_service=ep to the fixture and repeat, with that capability available in the bounding set so execution can gain it.
  3. Remove the file capability and repeat as a control.

Cover ddprof's behavior/diagnostic for the secure-execution case, and assert library injection and allocation samples rather than just successful startup or CPU samples. This is a test-coverage reminder, not a request to bypass the loader's security protections.

Activity

  1. r1viollet commented on Oct 20, 2026

    @r1viollet
    CollaboratorAuthor

    Test-only reproducer pushed on r1viollet/simple-malloc-file-capabilities: commit 23fd454c.

    The new simple_malloc-file-capabilities CTest runs the target as nobody through ddprof --switch_user, keeping the profiler privileged. It applies/removes cap_net_bind_service=ep on a private copy of simple_malloc, checks its reported security context, and counts allocation samples in do_lot_of_allocations.

    Observed on x86_64 Linux, Ubuntu 24.04/glibc 2.39, GCC 14 Debug build:

    Case AT_SECURE LD_PRELOAD Allocation samples
    No file capabilities 0 Present 64
    File capability set 1 Removed 0
    Capability removed 0 Present 64
    # From a suitable privileged Linux build directory, as root:
    ctest -R '^simple_malloc-file-capabilities$' -V

    The test passes by asserting the current limitation, not by fixing injection. It passed 20 consecutive runs; the existing simple_malloc and event-reordering tests also passed. Non-root and nosuid environments were verified to return skip code 77 rather than report a successful reproduction. No production profiler code was changed.

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