Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 34b88491 authored by Jakub Kicinski's avatar Jakub Kicinski Committed by Greg Kroah-Hartman
Browse files

netdevsim: Avoid allocation warnings triggered from user space



[ Upstream commit d0b80a9edb1a029ff913e81b47540e57ad034329 ]

We need to suppress warnings from sily map sizes. Also switch
from GFP_USER to GFP_KERNEL_ACCOUNT, I'm pretty sure I misunderstood
the flags when writing this code.

Fixes: 395cacb5 ("netdevsim: bpf: support fake map offload")
Reported-by: default avatar <syzbot+ad24705d3fd6463b18c6@syzkaller.appspotmail.com>
Signed-off-by: default avatarJakub Kicinski <kuba@kernel.org>
Signed-off-by: default avatarAndrii Nakryiko <andrii@kernel.org>
Link: https://lore.kernel.org/bpf/20220726213605.154204-1-kuba@kernel.org


Signed-off-by: default avatarSasha Levin <sashal@kernel.org>
parent 9d9e0d55
Loading
Loading
Loading
Loading
+5 −3
Original line number Original line Diff line number Diff line
@@ -347,10 +347,12 @@ nsim_map_alloc_elem(struct bpf_offloaded_map *offmap, unsigned int idx)
{
{
	struct nsim_bpf_bound_map *nmap = offmap->dev_priv;
	struct nsim_bpf_bound_map *nmap = offmap->dev_priv;


	nmap->entry[idx].key = kmalloc(offmap->map.key_size, GFP_USER);
	nmap->entry[idx].key = kmalloc(offmap->map.key_size,
				       GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
	if (!nmap->entry[idx].key)
	if (!nmap->entry[idx].key)
		return -ENOMEM;
		return -ENOMEM;
	nmap->entry[idx].value = kmalloc(offmap->map.value_size, GFP_USER);
	nmap->entry[idx].value = kmalloc(offmap->map.value_size,
					 GFP_KERNEL_ACCOUNT | __GFP_NOWARN);
	if (!nmap->entry[idx].value) {
	if (!nmap->entry[idx].value) {
		kfree(nmap->entry[idx].key);
		kfree(nmap->entry[idx].key);
		nmap->entry[idx].key = NULL;
		nmap->entry[idx].key = NULL;
@@ -492,7 +494,7 @@ nsim_bpf_map_alloc(struct netdevsim *ns, struct bpf_offloaded_map *offmap)
	if (offmap->map.map_flags)
	if (offmap->map.map_flags)
		return -EINVAL;
		return -EINVAL;


	nmap = kzalloc(sizeof(*nmap), GFP_USER);
	nmap = kzalloc(sizeof(*nmap), GFP_KERNEL_ACCOUNT);
	if (!nmap)
	if (!nmap)
		return -ENOMEM;
		return -ENOMEM;