From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 3CAD3188713; Fri, 15 Nov 2024 06:52:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=10.30.226.201 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731653571; cv=none; b=Fh+KYHOnvQ51alELKwCcemfbqYd89/vlju2Z8fGPWV3F290VgUWT6RcLAQOr+nahA/y/GPz8rb+vqxKpaqY3yTF6EXUg/DwRKlWLClOFFHd7GC76Gs5pPxUkDFNvOrIS/OjcF4lvzPZAwiQH9f61Axxxheji039xmayALH2gMvY= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1731653571; c=relaxed/simple; bh=nRMEzsEDWzbGTF0piGaExc+6rNEj2OnSNFjkJAJSP8Y=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=cisMdV/j8tUzGo6v6S56m7u0dDg0Csi1kx0E8IY4Yu59R3ukdqqtPOhmtN7JgaMwmsvgUUZHKacu1vQhvWjBi4E/IrxYb8Sb/SKTZ669iMPuCSeAUrUTvptOfdkfsy0U8oVicyn6SIPoEvKHQOUl66ESsrF86zSWg/VQTuAYBSI= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b=ZPw0xQy4; arc=none smtp.client-ip=10.30.226.201 Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=linuxfoundation.org header.i=@linuxfoundation.org header.b="ZPw0xQy4" Received: by smtp.kernel.org (Postfix) with ESMTPSA id BB050C4CECF; Fri, 15 Nov 2024 06:52:50 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1731653571; bh=nRMEzsEDWzbGTF0piGaExc+6rNEj2OnSNFjkJAJSP8Y=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZPw0xQy4G2Za8uJ1SEyYI2e2pnj1+QymvDtol6wn1ltb4MyS5XKZoQvm214zMhXcx UQps1scFicHYhjU2k0PdAArNBtMf63QBqeaU5kWmClwAZLN3ynO8+V7db9CF7WYdjo LHYngw5Y1h+cArFvvs/MSs5903f7GhjhzJQeKT0M= From: Greg Kroah-Hartman To: stable@vger.kernel.org Cc: Greg Kroah-Hartman , patches@lists.linux.dev, Rik van Riel , Shakeel Butt , Alexei Starovoitov , Sasha Levin Subject: [PATCH 6.1 13/39] bpf: use kvzmalloc to allocate BPF verifier environment Date: Fri, 15 Nov 2024 07:38:23 +0100 Message-ID: <20241115063723.089182585@linuxfoundation.org> X-Mailer: git-send-email 2.47.0 In-Reply-To: <20241115063722.599985562@linuxfoundation.org> References: <20241115063722.599985562@linuxfoundation.org> User-Agent: quilt/0.67 X-stable: review X-Patchwork-Hint: ignore Precedence: bulk X-Mailing-List: stable@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 6.1-stable review patch. If anyone has any objections, please let me know. ------------------ From: Rik van Riel [ 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 Reviewed-by: Shakeel Butt Link: https://lore.kernel.org/r/20241008170735.16766766@imladris.surriel.com Signed-off-by: Alexei Starovoitov Signed-off-by: Sasha Levin --- 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 bb54f1f4fafba..da90f565317d4 100644 --- a/kernel/bpf/verifier.c +++ b/kernel/bpf/verifier.c @@ -15500,7 +15500,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; @@ -15721,6 +15721,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