Skip to content

bpf, sockmap: Fix infinite recursion in sock_map_close

Jakub Sitnicki bpf netdev 2 versions – Applied

Status from this message: This series was applied to bpf/bpf.git (master)

Get series with b4
b4 am [email protected] change-id 20230113-sockmap-fix-83d0359301b7

Versions newest first · linked by author and title

  1. v2 Latest4 patches 4 repliesApplied 4/4
  2. v13 patches 6 repliesSuperseded

Changes in v2 from the cover letter

v1: https://lore.kernel.org/r/[email protected]
[v1 didn't hit bpf@ ML by mistake]

* pull in Eric's patch to protect against recursion loop bugs (Eric)
* add a macro helper to check if pointer is inside a memory range (Eric)

Patches in v2 All 4 applied

#Subject and filesSizeRepliesApplied
1/4bpf, sockmap: Don't let sock_map_{close,destroy,unhash} call itselfnet/core/sock_map.c+34 -271 replyApplied
2/4bpf, sockmap: Check for any of tcp_bpf_prots when cloning a listenerinclude/linux/util_macros.h net/ipv4/tcp_bpf.c+14 -21 replyApplied
3/4selftests/bpf: Pass BPF skeleton to sockmap_listen ops teststools/testing/selftests/bpf/prog_tests/sockmap_listen.c+37 -181 replyApplied
4/4selftests/bpf: Cover listener cloning with progs attached to sockmaptools/testing/selftests/bpf/prog_tests/sockmap_listen.c+28 -21 replyApplied

Reviews trailers per patch

All 4 patches have a Reviewed-by or Acked-by.

PatchJohn Fastabend
1/4A-b
2/4A-b
3/4A-b
4/4A-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.

Read the v2 thread

Cover letter [PATCH bpf v2 0/4] bpf, sockmap: Fix infinite recursion in sock_map_close

This patch set addresses the syzbot report in [1].

Patch #1 has been suggested by Eric [2]. I extended it to cover the rest of sock_map proto callbacks. Otherwise we would still overflow the stack.

Patch #2 contains the actual fix and bug analysis. Patches #3 & #4 add coverage to selftests to trigger the bug.

[1] https://lore.kernel.org/all/[email protected]/
[2] https://lore.kernel.org/all/CANn89iK2UN1FmdUcH12fv_xiZkv2G+Nskvmq7fG6aA_6VKRf6g@mail.gmail.com/

---
v1 -> v2:
v1: https://lore.kernel.org/r/[email protected]
[v1 didn't hit bpf@ ML by mistake]

* pull in Eric's patch to protect against recursion loop bugs (Eric)
* add a macro helper to check if pointer is inside a memory range (Eric)

---
Jakub Sitnicki (4):
bpf, sockmap: Don't let sock_map_{close,destroy,unhash} call itself bpf, sockmap: Check for any of tcp_bpf_prots when cloning a listener selftests/bpf: Pass BPF skeleton to sockmap_listen ops tests selftests/bpf: Cover listener cloning with progs attached to sockmap

 include/linux/util_macros.h                        | 12 ++++
 net/core/sock_map.c                                | 61 ++++++++--------
 net/ipv4/tcp_bpf.c                                 |  4 +-
 .../selftests/bpf/prog_tests/sockmap_listen.c      | 81 +++++++++++++++++-----
 4 files changed, 111 insertions(+), 47 deletions(-)