diff options
author | Stanislav Fomichev <sdf@google.com> | 2021-08-18 16:52:16 -0700 |
---|---|---|
committer | Daniel Borkmann <daniel@iogearbox.net> | 2021-08-20 00:09:49 +0200 |
commit | 44779a4b85abd1d1dab9e5b90bd5e6adcfc8143a (patch) | |
tree | 39b2e79db8ddcc12a2329bfe8d28b699ffe57a44 /include/linux/bpfptr.h | |
parent | f0dce1d9b7c81fc3dc9d0cc0bc7ef9b3eae22584 (diff) | |
download | lwn-44779a4b85abd1d1dab9e5b90bd5e6adcfc8143a.tar.gz lwn-44779a4b85abd1d1dab9e5b90bd5e6adcfc8143a.zip |
bpf: Use kvmalloc for map keys in syscalls
Same as previous patch but for the keys. memdup_bpfptr is renamed
to kvmemdup_bpfptr (and converted to kvmalloc).
Signed-off-by: Stanislav Fomichev <sdf@google.com>
Signed-off-by: Daniel Borkmann <daniel@iogearbox.net>
Acked-by: Song Liu <songliubraving@fb.com>
Link: https://lore.kernel.org/bpf/20210818235216.1159202-2-sdf@google.com
Diffstat (limited to 'include/linux/bpfptr.h')
-rw-r--r-- | include/linux/bpfptr.h | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/include/linux/bpfptr.h b/include/linux/bpfptr.h index 5cdeab497cb3..546e27fc6d46 100644 --- a/include/linux/bpfptr.h +++ b/include/linux/bpfptr.h @@ -62,9 +62,17 @@ static inline int copy_to_bpfptr_offset(bpfptr_t dst, size_t offset, return copy_to_sockptr_offset((sockptr_t) dst, offset, src, size); } -static inline void *memdup_bpfptr(bpfptr_t src, size_t len) +static inline void *kvmemdup_bpfptr(bpfptr_t src, size_t len) { - return memdup_sockptr((sockptr_t) src, len); + void *p = kvmalloc(len, GFP_USER | __GFP_NOWARN); + + if (!p) + return ERR_PTR(-ENOMEM); + if (copy_from_bpfptr(p, src, len)) { + kvfree(p); + return ERR_PTR(-EFAULT); + } + return p; } static inline long strncpy_from_bpfptr(char *dst, bpfptr_t src, size_t count) |