Skip to content

Commit 473d973

Browse files
iamkafaidavem330
authored andcommitted
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 <[email protected]> Signed-off-by: Martin KaFai Lau <[email protected]> Acked-by: Daniel Borkmann <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent f192970 commit 473d973

File tree

1 file changed

+2
-3
lines changed

1 file changed

+2
-3
lines changed

kernel/bpf/syscall.c

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -322,6 +322,8 @@ static int bpf_obj_name_cpy(char *dst, const char *src)
322322
{
323323
const char *end = src + BPF_OBJ_NAME_LEN;
324324

325+
memset(dst, 0, BPF_OBJ_NAME_LEN);
326+
325327
/* Copy all isalnum() and '_' char */
326328
while (src < end && *src) {
327329
if (!isalnum(*src) && *src != '_')
@@ -333,9 +335,6 @@ static int bpf_obj_name_cpy(char *dst, const char *src)
333335
if (src == end)
334336
return -EINVAL;
335337

336-
/* '\0' terminates dst */
337-
*dst = 0;
338-
339338
return 0;
340339
}
341340

0 commit comments

Comments
 (0)