net: fix SO_RESERVE_MEM socket type restriction and value bounds
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v2 Latest2 patches 5 repliesIn review 1 of 2 applied
- v12 patches 4 repliesSuperseded
Changes in v2 from the cover letter
- Patch 1: use page-aligned SZ_1G instead of INT_MAX >> 1 so values returned by getsockopt(SO_RESERVE_MEM) always round-trip through setsockopt(SO_RESERVE_MEM) (Sashiko).
- Patch 2: enable CONFIG_CGROUPS=y and CONFIG_MEMCG=y in tools/testing/selftests/net/config, skip when memcg socket accounting
is unavailable, restore cgroup.subtree_control on teardown, accept ENOPROTOOPT when MPTCP is disabled via sysctl, move the test process
out of cg_child before lowering memory.max, wait for SK_MEMINFO_WMEM_QUEUED to drain before checking cfd forward alloc,
and drop the arch-specific SO_RESERVE_MEM fallback define (Sashiko).
- Link to v1: https://lore.kernel.org/netdev/[email protected]/
Patches in v2 1 of 2 applied
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | net: restrict SO_RESERVE_MEM to TCP sockets and cap max valuenet/ | +2 | 1 reply | Applied |
| 2/2 | selftests/net: add SO_RESERVE_MEM testtools/ tools/ tools/ +1 more | +408 | 4 replies |
Reviews trailers per patch
All 2 patches have a Reviewed-by or Acked-by.
| Patch | Wei Wang |
|---|---|
| 1/2 | R-b R-b |
| 2/2 | R-b |
Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes.
Cover letter [PATCH v2 net 0/2] net: fix SO_RESERVE_MEM socket type restriction and value bounds
This series fixes two issues with SO_RESERVE_MEM and adds a kselftest suite:
- Patch 1 restricts sock_reserve_memory() to TCP sockets (sk_is_tcp(sk)) instead of sk_has_account(sk), and caps the requested reservation to SZ_1G in sk_setsockopt(SO_RESERVE_MEM).
Currently, sk_has_account(sk) allows SO_RESERVE_MEM on UDP sockets, where sk->sk_forward_alloc is protected by sk->sk_receive_queue.lock rather than the socket lock, and udp_rmem_release() does not account for sk_unused_reserved_mem(sk). Concurrent UDP packet processing and setsockopt(SO_RESERVE_MEM) corrupt sk_forward_alloc and memcg accounting. In addition, values near INT_MAX overflow 32-bit signed int in sk_mem_pages(delta) and (pages << PAGE_SHIFT).
- Patch 2 adds a kselftest (tools/testing/selftests/net/so_reserve_mem.c) covering non-TCP rejection (UDP, AF_UNIX, SOCK_RAW, MPTCP), bounds validation, reserve grow/shrink/rounding and SK_MEMINFO_FWD_ALLOC reporting, cgroup v2 memory.max enforcement, accept() child zero-reserve inheritance, and reserve retention across TCP traffic.
v2:
- Patch 1: use page-aligned SZ_1G instead of INT_MAX >> 1 so values returned by getsockopt(SO_RESERVE_MEM) always round-trip through setsockopt(SO_RESERVE_MEM) (Sashiko).
- Patch 2: enable CONFIG_CGROUPS=y and CONFIG_MEMCG=y in tools/testing/selftests/net/config, skip when memcg socket accounting
is unavailable, restore cgroup.subtree_control on teardown, accept ENOPROTOOPT when MPTCP is disabled via sysctl, move the test process
out of cg_child before lowering memory.max, wait for SK_MEMINFO_WMEM_QUEUED to drain before checking cfd forward alloc,
and drop the arch-specific SO_RESERVE_MEM fallback define (Sashiko).
- Link to v1: https://lore.kernel.org/netdev/[email protected]/
Eric Dumazet (2):
net: restrict SO_RESERVE_MEM to TCP sockets and cap max value selftests/net: add SO_RESERVE_MEM test
net/core/sock.c | 4 +- tools/testing/selftests/net/.gitignore | 1 + tools/testing/selftests/net/Makefile | 1 + tools/testing/selftests/net/config | 2 + tools/testing/selftests/net/so_reserve_mem.c | 404 +++++++++++++++++++ 5 files changed, 410 insertions(+), 2 deletions(-) create mode 100644 tools/testing/selftests/net/so_reserve_mem.c
Signature · 1 line
2.56.0.rc1.315.gc6ed9934b7-goog