From: Sasha Levin <sashal@kernel.org>
To: linux-kernel@vger.kernel.org, stable@vger.kernel.org
Cc: Rik van Riel <riel@surriel.com>,
Shakeel Butt <shakeel.butt@linux.dev>,
Alexei Starovoitov <ast@kernel.org>,
Sasha Levin <sashal@kernel.org>,
daniel@iogearbox.net, andrii@kernel.org, bpf@vger.kernel.org
Subject: [PATCH AUTOSEL 6.1 08/17] bpf: use kvzmalloc to allocate BPF verifier environment
Date: Wed, 23 Oct 2024 10:31:47 -0400 [thread overview]
Message-ID: <20241023143202.2981992-8-sashal@kernel.org> (raw)
In-Reply-To: <20241023143202.2981992-1-sashal@kernel.org>
From: Rik van Riel <riel@surriel.com>
[ Upstream commit 434247637c66e1be2bc71a9987d4c3f0d8672387 ]
The kzmalloc call in bpf_check can fail when memory is very fragmented,
which in turn can lead to an OOM kill.
Use kvzmalloc to fall back to vmalloc when memory is too fragmented to
allocate an order 3 sized bpf verifier environment.
Admittedly this is not a very common case, and only happens on systems
where memory has already been squeezed close to the limit, but this does
not seem like much of a hot path, and it's a simple enough fix.
Signed-off-by: Rik van Riel <riel@surriel.com>
Reviewed-by: Shakeel Butt <shakeel.butt@linux.dev>
Link: https://lore.kernel.org/r/20241008170735.16766766@imladris.surriel.com
Signed-off-by: Alexei Starovoitov <ast@kernel.org>
Signed-off-by: Sasha Levin <sashal@kernel.org>
---
kernel/bpf/verifier.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index eb4073781a3c7..385322a801be0 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -15494,7 +15494,7 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr)
/* 'struct bpf_verifier_env' can be global, but since it's not small,
* allocate/free it every time bpf_check() is called
*/
- env = kzalloc(sizeof(struct bpf_verifier_env), GFP_KERNEL);
+ env = kvzalloc(sizeof(struct bpf_verifier_env), GFP_KERNEL);
if (!env)
return -ENOMEM;
log = &env->log;
@@ -15715,6 +15715,6 @@ int bpf_check(struct bpf_prog **prog, union bpf_attr *attr, bpfptr_t uattr)
mutex_unlock(&bpf_verifier_lock);
vfree(env->insn_aux_data);
err_free_env:
- kfree(env);
+ kvfree(env);
return ret;
}
--
2.43.0
next prev parent reply other threads:[~2024-10-23 14:32 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-10-23 14:31 [PATCH AUTOSEL 6.1 01/17] 9p: Avoid creating multiple slab caches with the same name Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.1 02/17] irqchip/ocelot: Fix trigger register address Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.1 03/17] nvme: tcp: avoid race between queue_lock lock and destroy Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.1 04/17] block: Fix elevator_get_default() checking for NULL q->tag_set Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.1 05/17] HID: multitouch: Add support for B2402FVA track point Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.1 06/17] HID: multitouch: Add quirk for HONOR MagicBook Art 14 touchpad Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.1 07/17] nvme: disable CC.CRIME (NVME_CC_CRIME) Sasha Levin
2024-10-23 14:31 ` Sasha Levin [this message]
2024-10-23 14:31 ` [PATCH AUTOSEL 6.1 09/17] crypto: api - Fix liveliness check in crypto_alg_tested Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.1 10/17] crypto: marvell/cesa - Disable hash algorithms Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.1 11/17] sound: Make CONFIG_SND depend on INDIRECT_IOMEM instead of UML Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.1 12/17] drm/vmwgfx: Limit display layout ioctl array size to VMWGFX_NUM_DISPLAY_UNITS Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.1 13/17] arm64: set POR_EL0 for kernel threads Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.1 14/17] kasan: Disable Software Tag-Based KASAN with GCC Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.1 15/17] nvme-multipath: defer partition scanning Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.1 16/17] powerpc/powernv: Free name on error in opal_event_init() Sasha Levin
2024-10-23 14:31 ` [PATCH AUTOSEL 6.1 17/17] nvme: make keep-alive synchronous operation Sasha Levin
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20241023143202.2981992-8-sashal@kernel.org \
--to=sashal@kernel.org \
--cc=andrii@kernel.org \
--cc=ast@kernel.org \
--cc=bpf@vger.kernel.org \
--cc=daniel@iogearbox.net \
--cc=linux-kernel@vger.kernel.org \
--cc=riel@surriel.com \
--cc=shakeel.butt@linux.dev \
--cc=stable@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.