Skip to content

mbset: RemoveID returns early and leaks the followChildren ID (duplicate value, small programs) #5744

Description

@sayboras

What happened? How can we reproduce this?

Suppose a matchBinaries selector with followChildren: true lists the same path twice.
Deleting that policy does not release its mbset ID. Only 64 IDs exist (mbset.MaxIDs),
so after 64 add/delete cycles no policy that uses followChildren can load until the
agent restarts.

Every add and delete in the loop succeeds, so the only sign of the problem is a warning in
the agent log.

Reproduce

  1. Run a standalone agent built from main (no Kubernetes needed):

    sudo ./tetragon --bpf-lib bpf/objs
  2. Save a policy with a repeated followChildren value as dup.yaml:

    apiVersion: cilium.io/v1alpha1
    kind: TracingPolicy
    metadata:
      name: mbset-dup-path
    spec:
      kprobes:
      - call: "fd_install"
        syscall: false
        selectors:
        - matchBinaries:
          - operator: In
            values:
            - "/usr/bin/cat"
            - "/usr/bin/cat"
            followChildren: true

    Save the same policy without the repeated value as valid.yaml:

    apiVersion: cilium.io/v1alpha1
    kind: TracingPolicy
    metadata:
      name: mbset-valid
    spec:
      kprobes:
      - call: "fd_install"
        syscall: false
        selectors:
        - matchBinaries:
          - operator: In
            values:
            - "/usr/bin/cat"
            followChildren: true
  3. Add and delete dup.yaml 64 times. Each command succeeds, and the agent logs
    Destroy hook failed once per delete:

    for i in $(seq 1 64); do
      ./tetra tracingpolicy add dup.yaml
      ./tetra tracingpolicy delete mbset-dup-path
    done
  4. Add the valid policy:

    $ ./tetra tracingpolicy add valid.yaml
    Error: failed to add tracing policy: rpc error: code = Unknown desc = policy handler 'tracing' failed loading policy 'mbset-valid': parseMatchBinaries error: matchBinaries followChildren: failed to allocate ID: cannot allocate new id

Tetragon Version

main branch at 666efe6

Kernel Version

Linux lima-default 7.0.0-34-generic cilium/proxy#34-Ubuntu SMP PREEMPT_DYNAMIC Wed Sep 2 14:34:54 UTC 2026 aarch64 GNU/Linux

Kubernetes Version

N/A

Bugtool

N/A

Activity

  1. transferred this issue fromcilium/proxyon Oct 1, 2026
  2. sayboras commented on Oct 1, 2026

    @sayboras
    MemberAuthor

    Added good first issue label, however, I highly encourage to discuss the approach first to save development times/cycles.

  3. added theissue type on Oct 1, 2026
  4. nicknikolakakis commented on Oct 1, 2026

    @nicknikolakakis

    Hi, I'd like to work on this. Two separate leaks as I read it:

    1. Duplicate value: WriteMatchBinariesPath keeps duplicates, so in RemoveID the first copy deletes the tg_mbset_map key and the second Lookup returns ErrKeyNotExist, returning before delete(s.ids, id). Proposed fix: skip ErrKeyNotExist in the step 1 loop. Test: add a duplicate value to TestMatchBinariesFollowChildrenIDs, which already exhausts all 64 IDs across two add/delete rounds.
    2. Small programs: SetMBSetUpdater is only called with large progs, so RemoveID hits if update == nil { return nil } and never releases the ID, while AllocID still succeeds. Releasing the ID there without clearing execve_map would let a reused ID match processes with the stale bit. Would you prefer rejecting followChildren at load time without large progs, or releasing the ID and accepting/clearing stale bits another way?

    Happy to split these into two PRs if that's easier to review.

  5. abdullahhanif-001 commented on Oct 23, 2026

    @abdullahhanif-001

    Hey everyone, I've opened PR #5907 to fix this issue. It handles path deduplication at write time, skips ErrKeyNotExist inside RemoveID, and correctly un-allocates slots when the execve updater is nil. Validated and unit-tested on Linux.

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

    Type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions