Incorrect address displayed by bpf_printk

93 views Asked by At

I have a eBPF function that is attached to the page_fault_user tracepoint.

struct trace_event_raw_x86_exceptions {
    struct trace_entry ent;
    long unsigned int address;
    long unsigned int ip;
    long unsigned int error_code;
    char __data[0];
};

SEC("tp/exceptions/page_fault_user")
int handle_tp(trace_event_raw_x86_exceptions *ctx)
{
    bpf_printk("page-fault-user at %p.\n", ctx->address);
    return 0;
}

struct trace_event_raw_x86_exceptions is defined according to the contents of /sys/kernel/debug/tracing/events/exceptions/page_fault_user/format. However, I cannot get correct faulting address form ctx->address.

I have confirmed that the eBPF function handle_tp is successfully attached to the page_fault_user tracepoint, but bpf_printk prints incorrect faulting address.

1

There are 1 answers

0
WU ZHENWEI On

printk-formats: Pointers printed without a specifier extension (i.e unadorned %p) are hashed to give a unique identifier without leaking kernel addresses to user space.

Use %ps in bff_printk solved my problem.