Page MenuHomeFreeBSD

tcp: cleanup resource handling when adding SYN-cache entries
ClosedPublic

Authored by tuexen on May 31 2026, 4:06 PM.
Tags
None
Referenced Files
F161458746: D57374.diff
Sat, Jul 4, 12:16 AM
Unknown Object (File)
Wed, Jun 24, 6:00 AM
Unknown Object (File)
Wed, Jun 17, 1:39 PM
Unknown Object (File)
Tue, Jun 16, 1:54 AM
Unknown Object (File)
Mon, Jun 8, 3:38 AM
Unknown Object (File)
Sun, Jun 7, 8:54 PM
Unknown Object (File)
Sat, Jun 6, 11:00 PM
Unknown Object (File)
Sat, Jun 6, 6:32 PM
Subscribers

Details

Summary

Handle cred, ipopts, and maclabel using the same pattern: allocate at the beginning and set to NULL when the object is transferred to a struct syncache. When exiting the function, free the objects if not transferred or when transferred to the on-stack struct syncache. This makes use of a new function syncache_release().

This fixes a use after free problem, which was reported by Yuxiang Yang, Yizhou Zhao, Xuewei Feng, Qi Li, and Ke Xu from Tsinghua University using GLM5.1 from Z.ai.

ipopts should only be freed, if the on-stack struct syncache is used and the pointer in this structure still points to the allocated ipopts. If these ipopts are moved from the struct syncache to the struct inpcb in syncache_socket(), which is called by syncache_tfo_expand(), the pointer in the struct syncache is set to NULL.

In a FreeBSD default setup this problem is mitigated by

  1. TCP fast open support on the server side not being enabled (the sysctl-variable net.inet.tcp.fastopen.server_enable is 0).
  2. Incoming IP packet with source routing options are not being processed by the host stack (the sysctl-variable net.inet.ip.accept_sourceroute is 0).

Only if these two sysctl-variables are changed, a FreeBSD system is affected, if a server actually using TCP fast open is running.
This patch is an alternative to D57104 and would be MFCed to stable/14 and stable/15.

Diff Detail

Repository
rG FreeBSD src repository
Lint
Lint Not Applicable
Unit
Tests Not Applicable

Event Timeline

Reading these changes, i looks good to perform more consistently and properly handling the pointers; the logical flow is reordered as described - while the small formatting nits make this change appear a bit more expansive while not changing the flow dramatically.

This revision is now accepted and ready to land.Wed, Jun 17, 1:14 PM