bpf: Sanitize the bpf_struct_ops tcp-cc name
authorMartin KaFai Lau <kafai@fb.com>
Sat, 14 Mar 2020 01:02:09 +0000 (18:02 -0700)
committerDaniel Borkmann <daniel@iogearbox.net>
Tue, 17 Mar 2020 19:40:19 +0000 (20:40 +0100)
commit8e7ae2518f5265f0ef09d561748098fde5a87ccd
tree4ca18ed93fa3e56a4c81ff6715d0a8b9d8b7afb9
parent32ca98feab8c9076c89c0697c5a85e46fece809d
bpf: Sanitize the bpf_struct_ops tcp-cc name

The bpf_struct_ops tcp-cc name should be sanitized in order to
avoid problematic chars (e.g. whitespaces).

This patch reuses the bpf_obj_name_cpy() for accepting the same set
of characters in order to keep a consistent bpf programming experience.
A "size" param is added.  Also, the strlen is returned on success so
that the caller (like the bpf_tcp_ca here) can error out on empty name.
The existing callers of the bpf_obj_name_cpy() only need to change the
testing statement to "if (err < 0)".  For all these existing callers,
the err will be overwritten later, so no extra change is needed
for the new strlen return value.

v3:
  - reverse xmas tree style
v2:
  - Save the orig_src to avoid "end - size" (Andrii)

Fixes: 0baf26b0fcd7 ("bpf: tcp: Support tcp_congestion_ops in bpf")
Signed-off-by: Martin KaFai Lau <kafai@fb.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Andrii Nakryiko <andriin@fb.com>
Link: https://lore.kernel.org/bpf/20200314010209.1131542-1-kafai@fb.com
include/linux/bpf.h
kernel/bpf/syscall.c
net/ipv4/bpf_tcp_ca.c