Message ID | cover.1727335530.git.vmalik@redhat.com (mailing list archive) |
---|---|
Headers | show |
Series | bpf: Add kfuncs for read-only string operations | expand |
On Thu, 2024-09-26 at 09:29 +0200, Viktor Malik wrote: > Kernel contains highly optimised implementation of traditional string > operations. Expose them as kfuncs to allow BPF programs leverage the > kernel implementation instead of needing to reimplement the operations. > > These will be very helpful to bpftrace as it now needs to implement all > the string operations in LLVM IR. Note that existing string related helpers take a pointer to a string and it's maximal length, namely: - bpf_strtol - bpf_strtoul - bpf_snprintf_btf - bpf_strncmp The unbounded variants that are being exposed in this patch-set (like strcmp) are only safe to use if string is guaranteed to be null terminated. Verifier does not check this property at the moment (idk how easy/hard such analysis might be). I'd suggest not to expose unbounded variants of string functions. [...]
On 9/27/24 03:37, Eduard Zingerman wrote: > On Thu, 2024-09-26 at 09:29 +0200, Viktor Malik wrote: >> Kernel contains highly optimised implementation of traditional string >> operations. Expose them as kfuncs to allow BPF programs leverage the >> kernel implementation instead of needing to reimplement the operations. >> >> These will be very helpful to bpftrace as it now needs to implement all >> the string operations in LLVM IR. > > Note that existing string related helpers take a pointer to a string > and it's maximal length, namely: > - bpf_strtol > - bpf_strtoul > - bpf_snprintf_btf > - bpf_strncmp > > The unbounded variants that are being exposed in this patch-set > (like strcmp) are only safe to use if string is guaranteed to be null terminated. > Verifier does not check this property at the moment (idk how easy/hard > such analysis might be). > > I'd suggest not to expose unbounded variants of string functions. That's a great point, thanks. Let me remove the unbounded variants for now, until we add the null-byte check to the verifier. The bounded variants will still be useful to bpftrace so I'd love to have them added. Viktor > > [...] >