bpf: fix sock_map_alloc() error path
Subsystems (3)
PATCH 1/1 bpf: fix sock_map_alloc() error path
From: Eric Dumazet <[email protected]>
In case user program provides silly parameters, we want a map_alloc() handler to return an error, not a NULL pointer, otherwise we crash later in find_and_alloc_map()
---
kernel/bpf/sockmap.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
kernel/bpf/sockmap.c +2 -1
@@ -521,8 +521,8 @@ static struct smap_psock *smap_init_psock(struct sock *sock,static struct bpf_map *sock_map_alloc (union bpf_attr *attr) {struct bpf_stab *stab; -int err = -EINVAL ;u64 cost; +int err;if (!capable (CAP_NET_ADMIN ))return ERR_PTR (-EPERM );
@@ -547,6 +547,7 @@ static struct bpf_map *sock_map_alloc(union bpf_attr *attr)/* make sure page count doesn't overflow */ cost = (u64 ) stab->map.max_entries *sizeof (struct sock *); + err = -EINVAL ;if (cost >=U32_MAX -PAGE_SIZE ) goto free_stab;
Quoted 10 lines · Eric Dumazet
From: Eric Dumazet <[email protected]>
In case user program provides silly parameters, we want a
map_alloc()handler to return an error, not a NULL pointer, otherwise we crash later infind_and_alloc_map()Fixes 174a79ff9515 ("bpf: sockmap with sk redirect support")Signed-off-by Eric Dumazet <[email protected]>Reported-by syzbot <[email protected]>---
This would apply to net or bpf trees, not -next ones, sorry for the confusion in the [PATCH bpf-next] prefix.
Bug was added in 4.14
Daniel Borkmann
maintainerHi Eric,
Quoted 7 lines · Eric Dumazet
Quoted 6 lines · Eric Dumazet
From: Eric Dumazet <[email protected]>
In case user program provides silly parameters, we want a
map_alloc()handler to return an error, not a NULL pointer, otherwise we crash later infind_and_alloc_map()
Quoted 7 lines
Quoted 4 lines
Fixes 174a79ff9515 ("bpf: sockmap with sk redirect support")Signed-off-by Eric Dumazet <[email protected]>Reported-by syzbot <[email protected]>---
This would apply to net or bpf trees, not -next ones, sorry for the confusion in the [PATCH bpf-next] prefix.
No problem, thanks for the fix!
Quoted 1 line
Bug was added in 4.14
Fixes tag is actually slightly different, it would be:
I can change it if you want, no need to resend.
Thanks,
Daniel
John Fastabend
Acked-byQuoted 14 lines · Daniel Borkmann
Hi Eric,
Quoted 11 lines · Eric Dumazet
Quoted 10 lines · Eric Dumazet
From: Eric Dumazet <[email protected]>
In case user program provides silly parameters, we want a
map_alloc()handler to return an error, not a NULL pointer, otherwise we crash later infind_and_alloc_map()Fixes 174a79ff9515 ("bpf: sockmap with sk redirect support")Signed-off-by Eric Dumazet <[email protected]>Reported-by syzbot <[email protected]>---
Thanks Eric, also great to see syzkaller working on the sockmap types.
Quoted 4 lines
Quoted 3 lines
This would apply to net or bpf trees, not -next ones, sorry for the confusion in the [PATCH bpf-next] prefix.
Quoted 8 lines
No problem, thanks for the fix!
Quoted 1 line
Bug was added in 4.14
Fixes tag is actually slightly different, it would be:
Fixes 1aa12bdf1bfb ("bpf: sockmap, add sock close() hook to remove socks")
Yep.
Quoted 3 lines
I can change it if you want, no need to resend.> Thanks, Daniel
Alexei Starovoitov
AppliedQuoted 27 lines · John Fastabend
Quoted 14 lines · Daniel Borkmann
Hi Eric,
Quoted 11 lines · Eric Dumazet
Quoted 10 lines · Eric Dumazet
From: Eric Dumazet <[email protected]>
In case user program provides silly parameters, we want a
map_alloc()handler to return an error, not a NULL pointer, otherwise we crash later infind_and_alloc_map()Fixes 174a79ff9515 ("bpf: sockmap with sk redirect support")Signed-off-by Eric Dumazet <[email protected]>Reported-by syzbot <[email protected]>---
Thanks Eric, also great to see syzkaller working on the sockmap types.
Acked-by John Fastabend <[email protected]>Quoted 6 lines
Quoted 3 lines
This would apply to net or bpf trees, not -next ones, sorry for the confusion in the [PATCH bpf-next] prefix.
No problem, thanks for the fix!
Quoted 8 lines
Quoted 6 lines
Quoted 1 line
Bug was added in 4.14
Fixes tag is actually slightly different, it would be:
Fixes 1aa12bdf1bfb ("bpf: sockmap, add sock close() hook to remove socks")Yep.
Applied to bpf tree with corrected Fixes tag, Thanks everyone.