-
Notifications
You must be signed in to change notification settings - Fork 3.9k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How to use bpf_override_return() on functions NOT in kernel whitelist #2485
Comments
Yes, this is an opt-in feature. You need to add the function to err-injection framework. Note that this is kprobe based. What you have is function parameters. In your case, you should be able to get it from sock and sockaddr, I guess. |
BTW, bcc has a tool |
Thank you @yonghong-song for the response. As I'm new to iovisor-bcc, I need to clarify a couple things.
|
Answer 1: Yes, you need to patch the kernel. |
@gitdhar @yonghong-song As |
I am not sure how you could do that. the The bpf_probe_write_user() writes to user space of the "current" task. If you can find the user address through "current" or "uaddr", you may be able to do that. But |
Sorry I gave wrong function, I think it should be
Thank you for your explanation, and I expect secure fault injection capabilities through bpf without modifying the kernel, as most of our customers don't accept custom kernel or kernel module. I heard sleepable and preemptible BPF programs may appear in the future. Will it support to handle userspace page fault and secure enough to make fault injection? Thank you |
Yes, your example above should work. Regarding to sleepable and preemptible BPF programs, yes, they may appear in the future. Currently, there is an effort to make BPF working better with RT (RealTime) kernel in which case, BPF program may need to be preemptible. No concrete design yet. |
How to know whether if a kernel function is whitelisted or not? |
Try the following command,
The list will contain all error injection-able functions. Most syscalls, but some other functions as well.
The config
|
root@localhost:/bcc# cat /proc/kallsyms | grep _eil_addr I add the vfs_read to the whitelisted,but still have problem in bpf_override_return() root@localhost:/bcc/examples# cat hello_world.py from bcc import BPF BPF(text='int kprobe__vfs_read(void *ctx) { bpf_trace_printk("Hello, World!\n"); bpf_override_return(ctx, 0); return 0; }').trace_print() ./hello_world.py |
Do you have |
@yonghong-song Yes, I have This problem has bothered me for a long time,can you help me? Run on Android platform,Use adeb,other example is ok,only bpf_override_return have some error... Br |
People in kernel community pretty concerned about bpf_override_return() as it might change kernel behavior and crash the kernel. That is why only limited places bpf_override_return() is supported. If you want bpf_override_return() for a particular function, feel free to submit a kernel patch or mention here and somebody might help to craft a patch. |
We need to be able to allow/disallow tcp_v4_connect() under certain conditions (say for a specific dest port/ip). And since this fn. is not "white listed" function, we cannot use the bpf_overriede_return(). Can someone please clarify why this is the case and how we can accomplish this?
The text was updated successfully, but these errors were encountered: