[4/5] bpf: Return directly after a failed bpf_map_kmalloc_node() in bpf_cgroup_storage_alloc()

Message ID 996d5970-3295-493f-b144-99a0ff771576@web.de
State New
Headers
Series [1/5] bpf: Improve exception handling in bpf_struct_ops_link_create() |

Commit Message

Markus Elfring Dec. 30, 2023, 8:12 p.m. UTC
  From: Markus Elfring <elfring@users.sourceforge.net>
Date: Sat, 30 Dec 2023 20:06:02 +0100

The kfree() function was called in one case by
the bpf_cgroup_storage_alloc() function during error handling
even if the passed variable contained a null pointer.
This issue was detected by using the Coccinelle software.

Thus return directly after a call of the function “bpf_map_kmalloc_node”
failed at the beginning.

Signed-off-by: Markus Elfring <elfring@users.sourceforge.net>
---
 kernel/bpf/local_storage.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

--
2.43.0
  

Patch

diff --git a/kernel/bpf/local_storage.c b/kernel/bpf/local_storage.c
index a04f505aefe9..e16a80c93cd7 100644
--- a/kernel/bpf/local_storage.c
+++ b/kernel/bpf/local_storage.c
@@ -514,7 +514,7 @@  struct bpf_cgroup_storage *bpf_cgroup_storage_alloc(struct bpf_prog *prog,
 	storage = bpf_map_kmalloc_node(map, sizeof(struct bpf_cgroup_storage),
 				       gfp, map->numa_node);
 	if (!storage)
-		goto enomem;
+		return ERR_PTR(-ENOMEM);

 	if (stype == BPF_CGROUP_STORAGE_SHARED) {
 		storage->buf = bpf_map_kmalloc_node(map, size, gfp,