Skip to content

Commit 8096f22

Browse files
gregkhborkmann
authored andcommitted
bpf: Explicitly memset the bpf_attr structure
For the bpf syscall, we are relying on the compiler to properly zero out the bpf_attr union that we copy userspace data into. Unfortunately that doesn't always work properly, padding and other oddities might not be correctly zeroed, and in some tests odd things have been found when the stack is pre-initialized to other values. Fix this by explicitly memsetting the structure to 0 before using it. Reported-by: Maciej Żenczykowski <[email protected]> Reported-by: John Stultz <[email protected]> Reported-by: Alexander Potapenko <[email protected]> Reported-by: Alistair Delva <[email protected]> Signed-off-by: Greg Kroah-Hartman <[email protected]> Signed-off-by: Daniel Borkmann <[email protected]> Acked-by: Yonghong Song <[email protected]> Link: https://android-review.googlesource.com/c/kernel/common/+/1235490 Link: https://lore.kernel.org/bpf/[email protected]
1 parent 8e7ae25 commit 8096f22

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

kernel/bpf/syscall.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3362,7 +3362,7 @@ static int bpf_map_do_batch(const union bpf_attr *attr,
33623362

33633363
SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, size)
33643364
{
3365-
union bpf_attr attr = {};
3365+
union bpf_attr attr;
33663366
int err;
33673367

33683368
if (sysctl_unprivileged_bpf_disabled && !capable(CAP_SYS_ADMIN))
@@ -3374,6 +3374,7 @@ SYSCALL_DEFINE3(bpf, int, cmd, union bpf_attr __user *, uattr, unsigned int, siz
33743374
size = min_t(u32, size, sizeof(attr));
33753375

33763376
/* copy attributes from user space, may be less than sizeof(bpf_attr) */
3377+
memset(&attr, 0, sizeof(attr));
33773378
if (copy_from_user(&attr, uattr, size) != 0)
33783379
return -EFAULT;
33793380

0 commit comments

Comments
 (0)