Skip to content

Commit 94064f4

Browse files
jsitnickiEvilAnsh
authored andcommitted
UPSTREAM: bpf: Allow delete from sockmap/sockhash only if update is allowed
[ Upstream commit 98e948fb60d41447fd8d2d0c3b8637fc6b6dc26d ] 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@i-love.sakura.ne.jp> Reported-by: syzbot+ec941d6e24f633a59172@syzkaller.appspotmail.com Change-Id: Iba980999fea211fdee11414efbbae4e15b895a7f Signed-off-by: Jakub Sitnicki <jakub@cloudflare.com> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Tested-by: syzbot+ec941d6e24f633a59172@syzkaller.appspotmail.com Acked-by: John Fastabend <john.fastabend@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 Signed-off-by: Sasha Levin <sashal@kernel.org> Signed-off-by: Naveen <133593113+elohim-etz@users.noreply.github.com>
1 parent 6327fc2 commit 94064f4

1 file changed

Lines changed: 7 additions & 3 deletions

File tree

kernel/bpf/verifier.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4890,7 +4890,8 @@ static bool may_update_sockmap(struct bpf_verifier_env *env, int func_id)
48904890
enum bpf_attach_type eatype = env->prog->expected_attach_type;
48914891
enum bpf_prog_type type = resolve_prog_type(env->prog);
48924892

4893-
if (func_id != BPF_FUNC_map_update_elem)
4893+
if (func_id != BPF_FUNC_map_update_elem &&
4894+
func_id != BPF_FUNC_map_delete_elem)
48944895
return false;
48954896

48964897
/* It's not possible to get access to a locked struct sock in these
@@ -4901,6 +4902,11 @@ static bool may_update_sockmap(struct bpf_verifier_env *env, int func_id)
49014902
if (eatype == BPF_TRACE_ITER)
49024903
return true;
49034904
break;
4905+
case BPF_PROG_TYPE_SOCK_OPS:
4906+
/* map_update allowed only via dedicated helpers with event type checks */
4907+
if (func_id == BPF_FUNC_map_delete_elem)
4908+
return true;
4909+
break;
49044910
case BPF_PROG_TYPE_SOCKET_FILTER:
49054911
case BPF_PROG_TYPE_SCHED_CLS:
49064912
case BPF_PROG_TYPE_SCHED_ACT:
@@ -4988,7 +4994,6 @@ static int check_map_func_compatibility(struct bpf_verifier_env *env,
49884994
case BPF_MAP_TYPE_SOCKMAP:
49894995
if (func_id != BPF_FUNC_sk_redirect_map &&
49904996
func_id != BPF_FUNC_sock_map_update &&
4991-
func_id != BPF_FUNC_map_delete_elem &&
49924997
func_id != BPF_FUNC_msg_redirect_map &&
49934998
func_id != BPF_FUNC_sk_select_reuseport &&
49944999
func_id != BPF_FUNC_map_lookup_elem &&
@@ -4998,7 +5003,6 @@ static int check_map_func_compatibility(struct bpf_verifier_env *env,
49985003
case BPF_MAP_TYPE_SOCKHASH:
49995004
if (func_id != BPF_FUNC_sk_redirect_hash &&
50005005
func_id != BPF_FUNC_sock_hash_update &&
5001-
func_id != BPF_FUNC_map_delete_elem &&
50025006
func_id != BPF_FUNC_msg_redirect_hash &&
50035007
func_id != BPF_FUNC_sk_select_reuseport &&
50045008
func_id != BPF_FUNC_map_lookup_elem &&

0 commit comments

Comments
 (0)