0

I would like to load some text from a file and print it out using eBPF. Is such a thing even possible? I did something similar using bpf_probe_read but I'm wondering if there is a simpler way of doing something like this by just giving it a location? I want to try expanding this by using CSVs for instance as a means of practice.

#!/usr/bin/python3
# BPF PROGRAM
bpfprogram = """

static void helloworld() {
   bpf_trace_printk("Hello World!\\n");
}
int helloworld2(void *ctx)
{
    helloWorld();
    return 0;
}
"""
b = BPF(text=bpfprogram)
b.attach_kprobe(event=b.get_syscall_fnname("clone"), fn_name="helloworld")
b.trace_print()
Qeole
  • 8,284
  • 1
  • 24
  • 52
Zarif Rahman
  • 79
  • 1
  • 8
  • 1
    I don't think there's an easy way to do that. What's the use case? Aren't you better passing some info to user space and printing the content of your file from there? See also [this answer](https://stackoverflow.com/a/66104148/3716552). – Qeole May 27 '21 at 14:00
  • I just read your other answer but am wondering if you have an example of attaching userspace programs to eBPF? Sorry about the nooby question since I do want to see if I can print something out or pass text information through to do certain things. – Zarif Rahman May 27 '21 at 15:56
  • Sorry, I don't understand what you mean by “attaching userspace programs to eBPF”. Do you mean for passing information from eBPF to userspace? We usually do that via the perf buffer or (on more recent kernels) the eBPF ring buffer. There are examples in the kernel repository, or you can probably find a few by searching on the web. – Qeole May 27 '21 at 16:01

0 Answers0