Skip to content

Enum support for uprobe resolve #4799

@litios

Description

@litios

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem?

When using uprobes with BTF resolve support, enum is not a recognized type and this makes the resolve function not return the right value:

apiVersion: cilium.io/v1alpha1
kind: TracingPolicy
metadata:
  name: "uprobe-example"
spec:
  uprobes:
  - path: "/home/litios/testbin"
    btfPath: "/home/litios/testbin.btf"
    symbols:
    - "testfunc"
    args:
    - index: 0
      type: "uint64"
      btfType: "test_struct"
      resolve: "testenum"
    selectors:
    - matchActions:
      - action: Post  
#include <stdint.h>

enum test_enum {
    TEST_ENUM_0 = 0,
    TEST_ENUM_1 = 1,
    TEST_ENUM_2 = 2,
};

struct test_struct {
    int fd;
    char* test;
    enum test_enum testenum;
};

int testfunc(struct test_struct s) {
    return s.testenum;
}

void main() {
    struct test_struct ctx;
    ctx.fd = 1;
    ctx.test = "dada";
    ctx.testenum = TEST_ENUM_1;
    testfunc(ctx);
}
[11] ENUM 'test_enum' encoding=UNSIGNED size=4 vlen=3
	'TEST_ENUM_0' val=0
	'TEST_ENUM_1' val=1
	'TEST_ENUM_2' val=2
[12] STRUCT 'test_struct' size=24 vlen=3
	'fd' type_id=7 bits_offset=0
	'test' type_id=9 bits_offset=64
	'testenum' type_id=11 bits_offset=128
    "policy_name": "uprobe-example",
    "args": [
      {
        "size_arg": "17"
      }
    ],
    "action": "KPROBE_ACTION_POST"
pwndbg> x/4gx &ctx
0x7fffffffe070:	0x0000000000000001	0x0000555555556004
0x7fffffffe080:	0x00007fff00000001	0x00007fffffffe1b8
pwndbg> p ctx
$3 = {
  fd = 1,
  test = 0x555555556004 "dada",
  testenum = TEST_ENUM_1
}
pwndbg> p (int)TEST_ENUM_1
$4 = 1

Describe the feature you would like

It looks like enum is not being resolved properly with uprobes resolve (BTF).

(@tdaudi provided a solution that seems to work already! PR pending)

Describe your proposed solution

No response

Code of Conduct

  • I agree to follow this project's Code of Conduct

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions