Earlier quoted context omitted.
Reading more about that… How does the verifier detect infinite loops anyway? Halting problem and all. It must use some rather crude heuristics, no?
You need to slightly modify your code. Rather than: while (condition) { … } Do: #define MAX 1000 for n = 0; n Unroll all loops, don’t allow any backward jumps and limit to (say) 1m instructions.
A Beginner's Guide to eBPF
61–70 of 78 posts
Re: A Beginner's Guide to eBPF
#62Earlier quoted context omitted.
Why would your cloud instance panicking affect other users of the cloud provider? Or do you mean something else?
Cloud goes beyond rented VMs. Fully managed cloud services have thousands or millions of production customers on the same node. They have to be very careful about what they run as root.
Re: A Beginner's Guide to eBPF
#63Earlier quoted context omitted.
Cloud goes beyond rented VMs. Fully managed cloud services have thousands or millions of production customers on the same node. They have to be very careful about what they run as root.
I understand your point, but millions sounds an exaggeration- I have a hard time believing a single node can handle millions of concurrent users
Re: A Beginner's Guide to eBPF
#64Re: A Beginner's Guide to eBPF
#65Looks like a "buy my book" ad to me...
Re: A Beginner's Guide to eBPF
#66Earlier quoted context omitted.
You need to slightly modify your code. Rather than: while (condition) { … } Do: #define MAX 1000 for n = 0; n Unroll all loops, don’t allow any backward jumps and limit to (say) 1m instructions.
Incidentally, iteration limits are a good idea for production code anyway. If you don't imagine any input needing more than 50 k iterations, throw a user-friendly exception after something like 10 M iterations. Prevents much more annoying problems than it causes.
while(condition)[1000 label]{…}
Re: A Beginner's Guide to eBPF
#67As I understand it, eBPF is primarily an observation tool and thus is quite limited in the modifications it can make to kernel memory. Does it have any generic way to make arbitrary modifications to kernel memory? Obviously this would invalidate any verification guarantees, but I would expect this to be very minor modifications in practice. For example, if I wanted to hook a page fault handler to change the behaviour…
What you can do is quite limited. You're restricted to some preset eBPF program types, and each program type has a restricted set of operations it can perform (eBPF helper methods). So arbitrary modifications, absolutely not without adding a helper method and/or program type for this purpose. More program types and helper methods are being added all the time but overall it's pretty limited in use cases and operations…
Re: A Beginner's Guide to eBPF
#68Earlier quoted context omitted.
I understand your point, but millions sounds an exaggeration- I have a hard time believing a single node can handle millions of concurrent users
I didn't mean to imply concurrent. A large fraction of the user base is very sporadic in its usage!
Re: A Beginner's Guide to eBPF
#69This may prove useful: > eBPF (often aliased BPF)[2][5] is a technology that can run sandboxed programs in a privileged context such as the operating system kernel.[6] It is used to safely and efficiently extend the capabilities of the kernel at runtime without requiring to change kernel source code or load kernel modules.[7] Safety is provided through an in-kernel verifier which performs static code analysis and rej…
Haven't sandboxed programs in a privileged context been the root cause of me seeing BSOD so often in the late 90ties?
You can crash a kernel with a BPF program. But it's overwhelmingly likely that the crash will arise from buggy pre-existing kernel code that just hadn't been seriously exercised before eBPF gave people new tools to push that code with. What's much, much less likely to happen is a segfault or NPE in your own BPF code.
Re: A Beginner's Guide to eBPF
#70I’m new to Linux kernel programming & eBPF (just started last week) and I’m having major troubles with eBPF verifier. I honestly feel like it would be easier for me to write a kernel module than eBPF code. I do wonder if this is the case for many people. It seems verifier is a bit unpredictable and makes eBPF programming quite painful.
Can confirm, it is quite painful. The bpftools maintainers tell you to learn the bytecode format when you ask them what the errors mean, because they expect you to understand what the verifier means when it tells you "unknown scalar" on every single goddamn line of code. Something like "ebpf coding rules, what to use and what not" would be very helpful. All ebpf examples that are older than say, 3 months, already don…