From: Martin KaFai Lau Date: Fri, 6 Oct 2017 04:52:11 +0000 (-0700) Subject: bpf: Change bpf_obj_name_cpy() to better ensure map's name is init by 0 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=75b94130058a166f61ce524127bd3b0de2f4d42d;p=GitHub%2FLineageOS%2Fandroid_kernel_motorola_exynos9610.git bpf: Change bpf_obj_name_cpy() to better ensure map's name is init by 0 During get_info_by_fd, the prog/map name is memcpy-ed. It depends on the prog->aux->name and map->name to be zero initialized. bpf_prog_aux is easy to guarantee that aux->name is zero init. The name in bpf_map may be harder to be guaranteed in the future when new map type is added. Hence, this patch makes bpf_obj_name_cpy() to always zero init the prog/map name. Suggested-by: Daniel Borkmann Change-Id: Ib3bb6efbda0bd682e0cdad8617f587320d7dd397 Signed-off-by: Martin KaFai Lau Acked-by: Daniel Borkmann Signed-off-by: David S. Miller --- diff --git a/kernel/bpf/syscall.c b/kernel/bpf/syscall.c index bfac2c458335..176170b002a3 100644 --- a/kernel/bpf/syscall.c +++ b/kernel/bpf/syscall.c @@ -362,6 +362,8 @@ static int bpf_obj_name_cpy(char *dst, const char *src) { const char *end = src + BPF_OBJ_NAME_LEN; + memset(dst, 0, BPF_OBJ_NAME_LEN); + /* Copy all isalnum() and '_' char */ while (src < end && *src) { if (!isalnum(*src) && *src != '_') @@ -373,9 +375,6 @@ static int bpf_obj_name_cpy(char *dst, const char *src) if (src == end) return -EINVAL; - /* '\0' terminates dst */ - *dst = 0; - return 0; }