Skip to content

kprobes: support having the same argument twice #3711

Open
@kkourt

Description

@kkourt

If we write a policy with the same argument twice,

apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
  name: "sys-lseek"
spec:
  kprobes:
  - call: "sys_lseek"
    syscall: true
    args:
    - index: 0
      type: "int"
      label: "index 0"
    - index: 0
      type: "int"
      label: "index 0 (again)"

The agent will accept it, and then produce a wrong event. For example, if we execute:

echo "100 100 100" | ./contrib/tester-progs/lseek-pipe

We will get:

[
  {
    "int_arg": 100,
    "label": "index 0"
  },
  {
    "int_arg": 0,
    "label": "index 0 (again)"
  }
]

And a warning in the logs:

time="2025-05-07T13:46:20+02:00" level=warning msg="Int type error" arg.usertype= error=EOF

Note that accessing the same argument twice is useful when used with "resolve:". For example:

apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
  name: "lsm"
spec:
  kprobes:
  - call: "security_bprm_check"
    syscall: false
    args:
      - index: 0
        type: "string"
        resolve: "mm.owner.comm"
        label: "proc"
      - index: 0
        type: "string"
        resolve: "mm.owner.real_parent.comm"
        label: "parent"
      - index: 0
        type: "string"
        resolve: "mm.owner.real_parent.real_parent.comm"
        label: "grand-parent"
    selectors:
      - matchActions:
        - action: Post

I'm marking this as a bug because we provide the wrong data to the user and we should (at minimum) reject the policy. The best solution, however, is to support multiple arguments on the same index (which, arguably, is a new feature).

See also: #3710

Metadata

Metadata

Assignees

Labels

kind/featureThis introduces a new functionality

Type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions