tcp: clamp return value of tcp_wmem_schedule() to non-negative
Get series with b4
b4 am [email protected]Versions newest first · linked by author and title
- v4 Latest2 patches 4 repliesIn review
- v32 patches 1 replySuperseded
- v22 patches 2 repliesSuperseded
Earlier versions · 1
| Version | Posted | Patches | Replies | Status |
|---|---|---|---|---|
| v1 | 2 patches | 7 replies | Superseded |
Changes in v4 from the cover letter
- Add --define=REQUIRES_MEMCG="1" support in ksft_runner.sh to skip the test when the cgroup2 memory controller is unavailable and clean up pkt_* cgroups and cgroup.subtree_control via an EXIT trap.
- Pin packetdrill to CPU 0, write 0 to memory.high twice to guarantee local per-CPU memcg stock is drained synchronously, and set memory.swap.max=0 in the test cgroup.
- Fix checkpatch warnings (duplicate Signed-off-by trailer and comment line length) and preserve the "net" target prefix on all patches.
Patches in v4 No applies recorded yet
| # | Subject and files | Size | Replies | Applied |
|---|---|---|---|---|
| 1/2 | tcp: clamp return value of tcp_wmem_schedule() to non-negativenet/ | +1 | 4 replies | |
| 2/2 | selftests: net: packetdrill: add test for negative sk_forward_alloc in tcp_wmem_schedule()tools/ tools/ tools/ | +146 | 0 replies |
Reviews trailers per patch
All 2 patches have a Reviewed-by or Acked-by.
| Patch | Kuniyuki Iwashima | Eric Dumazet |
|---|---|---|
| 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 net v4 0/2] tcp: clamp return value of tcp_wmem_schedule() to non-negative
This series fixes a bug discovered in production in tcp_wmem_schedule() where a negative sk->sk_forward_alloc under TCP memory pressure causes tcp_wmem_schedule() to return a negative copy length when sk->sk_wmem_queued already reaches or exceeds sysctl_tcp_wmem[0].
sk->sk_forward_alloc can transiently become negative when tcp_collapse() re-packs partially read or high payload-to-truesize SKBs in the receive queue and charges newly allocated SKBs via sk_mem_charge() before freeing the original SKBs. When a subsequent send hits memory pressure in sk_wmem_schedule() with sk->sk_wmem_queued >= sysctl_tcp_wmem[0], tcp_wmem_schedule() returns min(copy, sk->sk_forward_alloc) < 0. Callers such as tcp_sendmsg_locked() then pass that negative copy length to skb_copy_to_page_nocache() -> copy_from_iter_full() -> check_copy_size(), triggering WARN_ON_ONCE(bytes > INT_MAX) in production and returning -EFAULT instead of waiting for memory or returning -EAGAIN.
Patch 1 clamps the return value of tcp_wmem_schedule() to [0, copy] so a negative sk->sk_forward_alloc is treated as 0 available bytes. Patch 2 adds a packetdrill selftest that reproduces the negative sk->sk_forward_alloc condition via tcp_collapse() under memory pressure and verifies that a non-blocking write fails with EAGAIN rather than EFAULT.
Changes in v4:
- Add --define=REQUIRES_MEMCG="1" support in ksft_runner.sh to skip the test when the cgroup2 memory controller is unavailable and clean up pkt_* cgroups and cgroup.subtree_control via an EXIT trap.
- Pin packetdrill to CPU 0, write 0 to memory.high twice to guarantee local per-CPU memcg stock is drained synchronously, and set memory.swap.max=0 in the test cgroup.
- Fix checkpatch warnings (duplicate Signed-off-by trailer and comment line length) and preserve the "net" target prefix on all patches.
Changes in v3:
- Fix packetdrill test failure in netdev CI (CONFIG_MAX_SKB_FRAGS=17):
adjust segment sizes (35 KB) and buffer limits so the receive SKB truesize is identical across CONFIG_MAX_SKB_FRAGS=17 and 45, and tcp_collapse() deterministically drives sk_forward_alloc below -16 KB without invoking the memcg OOM killer.
Changes in v2:
- Include production warning trace in Patch 1 commit message.
- Skip the packetdrill test when PAGE_SIZE != 4096 via --define=REQUIRES_PAGESIZE="4096" in ksft_runner.sh.
- Collect Reviewed-by tags from Kuniyuki Iwashima and Eric Dumazet.
Octavian Purdila (2):
tcp: clamp return value of tcp_wmem_schedule() to non-negative
selftests: net: packetdrill: add test for negative sk_forward_alloc in
tcp_wmem_schedule()
net/ipv4/tcp.c | 2 +- .../testing/selftests/net/packetdrill/config | 2 + .../selftests/net/packetdrill/ksft_runner.sh | 28 +++++ .../tcp_wmem_schedule_negative_fwd_alloc.pkt | 116 ++++++++++++++++++ 4 files changed, 147 insertions(+), 1 deletion(-) create mode 100644 tools/testing/selftests/net/packetdrill/tcp_wmem_schedule_negative_fwd_alloc.pkt
Signature · 1 line
2.56.0.257.gf7497c7d27-goog