bpf: check max_entries before allocating memory
authorFlorian Lehner <dev@der-flo.net>
Fri, 28 Oct 2022 18:34:05 +0000 (20:34 +0200)
committerMartin KaFai Lau <martin.lau@kernel.org>
Fri, 28 Oct 2022 22:45:58 +0000 (15:45 -0700)
commite39e739ab57399f46167d453bbdb8ef8d57c6488
tree4c71035f5de99b1d0d4d921ecb00775beda8add4
parentb6d207999c350b19a787e48757f98198d0bf3e5b
bpf: check max_entries before allocating memory

For maps of type BPF_MAP_TYPE_CPUMAP memory is allocated first before
checking the max_entries argument. If then max_entries is greater than
NR_CPUS additional work needs to be done to free allocated memory before
an error is returned.
This changes moves the check on max_entries before the allocation
happens.

Signed-off-by: Florian Lehner <dev@der-flo.net>
Link: https://lore.kernel.org/r/20221028183405.59554-1-dev@der-flo.net
Signed-off-by: Martin KaFai Lau <martin.lau@kernel.org>
kernel/bpf/cpumap.c