From: Stanislav Fomichev <hidden> Date: 2021-08-16 16:48:38
Use kvmalloc/kvfree for temporary value when looking up a map.
kmalloc might not be sufficient for percpu maps where the value is big.
Can be reproduced with netcnt test on qemu with "-smp 255".
Signed-off-by: Stanislav Fomichev <redacted>
---
kernel/bpf/syscall.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
From: Daniel Borkmann <daniel@iogearbox.net> Date: 2021-08-16 21:43:25
On 8/16/21 6:48 PM, Stanislav Fomichev wrote:
quoted hunk
Use kvmalloc/kvfree for temporary value when looking up a map.
kmalloc might not be sufficient for percpu maps where the value is big.
Can be reproduced with netcnt test on qemu with "-smp 255".
Signed-off-by: Stanislav Fomichev <redacted>
---
kernel/bpf/syscall.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
On Mon, Aug 16, 2021 at 2:43 PM Daniel Borkmann [off-list ref] wrote:
On 8/16/21 6:48 PM, Stanislav Fomichev wrote:
quoted
Use kvmalloc/kvfree for temporary value when looking up a map.
kmalloc might not be sufficient for percpu maps where the value is big.
Can be reproduced with netcnt test on qemu with "-smp 255".
Signed-off-by: Stanislav Fomichev <redacted>
---
kernel/bpf/syscall.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
On Mon, Aug 16, 2021 at 2:43 PM Daniel Borkmann [off-list ref]
wrote:
quoted
On 8/16/21 6:48 PM, Stanislav Fomichev wrote:
quoted
Use kvmalloc/kvfree for temporary value when looking up a map.
kmalloc might not be sufficient for percpu maps where the value is
big.
quoted
quoted
Can be reproduced with netcnt test on qemu with "-smp 255".
Signed-off-by: Stanislav Fomichev <redacted>
---
kernel/bpf/syscall.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
@@ -1076,7 +1076,7 @@ static int map_lookup_elem(union bpf_attr *attr)value_size=bpf_map_value_size(map);err=-ENOMEM;-value=kmalloc(value_size,GFP_USER|__GFP_NOWARN);+value=kvmalloc(value_size,GFP_USER|__GFP_NOWARN);if(!value)gotofree_key;
What about other cases like map_update_elem(), shouldn't they be adapted
similarly?
And in the same vein (with keys potentially being big as well), should
we switch __bpf_copy_key() to use vmemdup_user() instead of
memdup_user()?
Those are good questions :-)
I'm assuming that whatever is doing kmalloc on top of
bpf_map_value_size() should definitely use kvmalloc since
bpf_map_value_size() can blow up the value size. (will resend)
For __bpf_copy_key I'm less sure, but it might be a good idea as well.
Let me try to look at bit more into it, but feels like there shouldn't
be any downsides?