Skip to content

Fix bpf_tcp_sock and bpf_sk_fullsock issue related to bpf_sk_release

Martin KaFai Lau netdev 4 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v4 Latest5 patches 3 repliesIn review
  2. v32 patches 7 repliesSuperseded
  3. v22 patches 2 repliesSuperseded
Earlier versions · 1
VersionPostedPatchesRepliesStatus
v12 patches3 repliesSuperseded

Changes in v4 from the cover letter

- Tried the one "id" approach. It does not work well and the reason is in the Patch 1 commit message.
- Rename refcount_id to ref_obj_id.
- With ref_obj_id, resetting reg->id to 0 is fine in mark_ptr_or_null_reg() because ref_obj_id is passed to release_reference() instead of reg->id.
- Also reset reg->ref_obj_id in mark_ptr_or_null_reg() when is_null == true
- sk_to_full_sk() is removed from bpf_sk_fullsock() and bpf_tcp_sock().
- bpf_get_listener_sock() is added to do sk_to_full_sk() in Patch 2.
- If tp is from bpf_tcp_sock(sk) and sk is a refcounted ptr, bpf_sk_release(tp) is also allowed.

Patches in v4 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/5bpf: Fix bpf_tcp_sock and bpf_sk_fullsock issue related to bpf_sk_releaseinclude/linux/bpf.h include/linux/bpf_verifier.h kernel/bpf/verifier.c +1 more+115 -630 replies
2/5bpf: Add bpf_get_listener_sock(struct bpf_sock *sk) helperinclude/uapi/linux/bpf.h net/core/filter.c+31 -10 replies
3/5bpf: Sync bpf.h to tools/tools/include/uapi/linux/bpf.h+10 -10 replies
4/5bpf: Test ref release issue in bpf_tcp_sock and bpf_sk_fullsocktools/testing/selftests/bpf/verifier/ref_tracking.c tools/testing/selftests/bpf/verifier/sock.c+170 -20 replies
5/5bpf: Add an example for bpf_get_listener_socktools/testing/selftests/bpf/bpf_helpers.h tools/testing/selftests/bpf/progs/test_sock_fields_kern.c tools/testing/selftests/bpf/test_sock_fields.c+180 -440 replies

Reviews trailers per patch

No Reviewed-by, Acked-by or Tested-by trailers for v4 yet.

Read the v4 thread

Cover letter [PATCH v4 bpf 0/5] Fix bpf_tcp_sock and bpf_sk_fullsock issue related to bpf_sk_release

This set addresses issue about accessing invalid ptr returned from bpf_tcp_sock() and bpf_sk_fullsock() after bpf_sk_release().

v4:
- Tried the one "id" approach. It does not work well and the reason is in the Patch 1 commit message.
- Rename refcount_id to ref_obj_id.
- With ref_obj_id, resetting reg->id to 0 is fine in mark_ptr_or_null_reg() because ref_obj_id is passed to release_reference() instead of reg->id.
- Also reset reg->ref_obj_id in mark_ptr_or_null_reg() when is_null == true
- sk_to_full_sk() is removed from bpf_sk_fullsock() and bpf_tcp_sock().
- bpf_get_listener_sock() is added to do sk_to_full_sk() in Patch 2.
- If tp is from bpf_tcp_sock(sk) and sk is a refcounted ptr, bpf_sk_release(tp) is also allowed.

v3:
- reset reg->refcount_id for the is_null case in mark_ptr_or_null_reg()

v2:
- Remove refcount_id arg from release_reference() because id == refcount_id
- Add a WARN_ON_ONCE to mark_ptr_or_null_regs() to catch an internal verifier bug.

Martin KaFai Lau (5):
bpf: Fix bpf_tcp_sock and bpf_sk_fullsock issue related to
bpf_sk_release
bpf: Add bpf_get_listener_sock(struct bpf_sock *sk) helper
bpf: Sync bpf.h to tools/
bpf: Test ref release issue in bpf_tcp_sock and bpf_sk_fullsock
bpf: Add an example for bpf_get_listener_sock

 include/linux/bpf.h                           |   1 -
 include/linux/bpf_verifier.h                  |  40 +++++
 include/uapi/linux/bpf.h                      |  11 +-
 kernel/bpf/verifier.c                         | 131 ++++++++------
 net/core/filter.c                             |  27 ++-
 tools/include/uapi/linux/bpf.h                |  11 +-
 tools/testing/selftests/bpf/bpf_helpers.h     |   2 +
 .../bpf/progs/test_sock_fields_kern.c         |  88 +++++++--
 .../testing/selftests/bpf/test_sock_fields.c  | 134 +++++++++++---
 .../selftests/bpf/verifier/ref_tracking.c     | 168 ++++++++++++++++++
 tools/testing/selftests/bpf/verifier/sock.c   |   4 +-
 11 files changed, 506 insertions(+), 111 deletions(-)
Signature · 1 line
2.17.1