On Tue, Aug 20, 2024 at 3:18 AM Jordan Rome <linux@xxxxxxxxxxxxxx> wrote: > > This adds a kfunc wrapper around strncpy_from_user, > which can be called from sleepable BPF programs. > > This matches the non-sleepable 'bpf_probe_read_user_str' > helper except it includes an additional 'flags' > param, which allows consumers to clear the entire > destination buffer on success or failure. > > Signed-off-by: Jordan Rome <linux@xxxxxxxxxxxxxx> > --- > include/uapi/linux/bpf.h | 9 ++++++++ > kernel/bpf/helpers.c | 42 ++++++++++++++++++++++++++++++++++ > tools/include/uapi/linux/bpf.h | 9 ++++++++ > 3 files changed, 60 insertions(+) > > diff --git a/include/uapi/linux/bpf.h b/include/uapi/linux/bpf.h > index e05b39e39c3f..d3b69cb055c0 100644 > --- a/include/uapi/linux/bpf.h > +++ b/include/uapi/linux/bpf.h > @@ -7513,4 +7513,13 @@ struct bpf_iter_num { > __u64 __opaque[1]; > } __attribute__((aligned(8))); > > +/* > + * Flags to control bpf_copy_from_user_str() behaviour. > + * - BPF_F_PAD_ZEROS: Pad destination buffer with zeros. (See the respective > + * helper documentation for details.) > + */ > +enum { > + BPF_F_PAD_ZEROS = (1ULL << 0) Pls add , so this line doesn't have to be touched in the future. > +++ b/tools/include/uapi/linux/bpf.h > +enum { > + BPF_F_PAD_ZEROS = (1ULL << 0) and here, of course, as well. > +__bpf_kfunc int bpf_copy_from_user_str(void *dst, u32 dst__szk, const void __user *unsafe_ptr__ign, u64 flags) 'k' in __szk is probably too restrictive. It should work with __sz. The difference is 'k' requires absolute constant while __sz is ok with bounded value. Probably worth adding a test as well.