[SRU][F][PATCH 1/1] bpf: Allow delete from sockmap/sockhash only if update is allowed
Massimiliano Pellizzer
massimiliano.pellizzer at canonical.com
Thu Nov 14 21:38:06 UTC 2024
From: Jakub Sitnicki <jakub at cloudflare.com>
We have seen an influx of syzkaller reports where a BPF program attached to
a tracepoint triggers a locking rule violation by performing a map_delete
on a sockmap/sockhash.
We don't intend to support this artificial use scenario. Extend the
existing verifier allowed-program-type check for updating sockmap/sockhash
to also cover deleting from a map.
>From now on only BPF programs which were previously allowed to update
sockmap/sockhash can delete from these map types.
Fixes: ff9105993240 ("bpf, sockmap: Prevent lock inversion deadlock in map delete elem")
Reported-by: Tetsuo Handa <penguin-kernel at i-love.sakura.ne.jp>
Reported-by: syzbot+ec941d6e24f633a59172 at syzkaller.appspotmail.com
Signed-off-by: Jakub Sitnicki <jakub at cloudflare.com>
Signed-off-by: Daniel Borkmann <daniel at iogearbox.net>
Tested-by: syzbot+ec941d6e24f633a59172 at syzkaller.appspotmail.com
Acked-by: John Fastabend <john.fastabend at gmail.com>
Closes: https://syzkaller.appspot.com/bug?extid=ec941d6e24f633a59172
Link: https://lore.kernel.org/bpf/20240527-sockmap-verify-deletes-v1-1-944b372f2101@cloudflare.com
(backported from commit 98e948fb60d41447fd8d2d0c3b8637fc6b6dc26d)
[mpellizzer: backported modifying only the function
check_map_func_compatibility() since may_update_sockmap() was introduced
by 0126240f448d which landed upstream in v5.10-rc1 and has never been
backported]
CVE-2024-38662
Signed-off-by: Massimiliano Pellizzer <massimiliano.pellizzer at canonical.com>
---
kernel/bpf/verifier.c | 2 --
1 file changed, 2 deletions(-)
diff --git a/kernel/bpf/verifier.c b/kernel/bpf/verifier.c
index 7776b1a6a24c..9baefb4239c9 100644
--- a/kernel/bpf/verifier.c
+++ b/kernel/bpf/verifier.c
@@ -3593,14 +3593,12 @@ static int check_map_func_compatibility(struct bpf_verifier_env *env,
case BPF_MAP_TYPE_SOCKMAP:
if (func_id != BPF_FUNC_sk_redirect_map &&
func_id != BPF_FUNC_sock_map_update &&
- func_id != BPF_FUNC_map_delete_elem &&
func_id != BPF_FUNC_msg_redirect_map)
goto error;
break;
case BPF_MAP_TYPE_SOCKHASH:
if (func_id != BPF_FUNC_sk_redirect_hash &&
func_id != BPF_FUNC_sock_hash_update &&
- func_id != BPF_FUNC_map_delete_elem &&
func_id != BPF_FUNC_msg_redirect_hash)
goto error;
break;
--
2.43.0
More information about the kernel-team
mailing list