Page MenuHomeFreeBSD

tcp: cleanup of syncache_expand()
ClosedPublic

Authored by tuexen on Oct 6 2025, 10:07 PM.
Tags
None
Referenced Files
Unknown Object (File)
Mon, Nov 24, 6:14 AM
Unknown Object (File)
Tue, Nov 18, 2:04 PM
Unknown Object (File)
Mon, Nov 10, 4:42 AM
Unknown Object (File)
Mon, Nov 10, 4:35 AM
Unknown Object (File)
Oct 27 2025, 7:43 PM
Unknown Object (File)
Oct 27 2025, 6:30 PM
Unknown Object (File)
Oct 25 2025, 5:09 PM
Unknown Object (File)
Oct 24 2025, 5:02 PM

Details

Summary
  • Consistently free the string after unlocking the sch, if possible.
  • Remove the failure handling in case of sc != NULL, since this is not possible anymore.
  • Remove the use of goto and instead return 0 in the three cases.

The only change in behavior is that in three out of the four cases, where 0 is returned, *lsop is not set to NULL anymore. So the behavior is now consistent and also documented in a comment. The current in tree callers only look at *lsop, if and only if syncache_expand() returns 1.

Diff Detail

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

Event Timeline

sys/netinet/tcp_syncache.c
1219

Doesn't this free() belong in the if ((s= block above?

And for consistency with the rest of the function, the SCH_UNLOCK(sch) could be done before the tcp_log_addrs and free.

sys/netinet/tcp_syncache.c
1219

Doesn't this free() belong in the if ((s= block above?

Conceptually yes. But then we would hold the lock when calling free and jtl@ preferres to not do that.

And for consistency with the rest of the function, the SCH_UNLOCK(sch) could be done before the tcp_log_addrs and free.

But when generating the log message, we use sc->sc_tsreflect. So if we do SCH_UNLOCK(sch) before log(), we would potentially use memory already freed.
So for log messages without any reference to sc, I do the free() in the if() and do SCH_UNLOCK(sch) before the if(). But if the log messages have a reference to sc, I unlock first and then call free right after the if().
Please note that s is set in any case and calling free() with s == NULL is OK.

sys/netinet/tcp_syncache.c
1219

Doesn't this free() belong in the if ((s= block above?

Conceptually yes. But then we would hold the lock when calling free and jtl@ preferres to not do that.

Yep, agree we should free w/o lock (which the below would this ordering necessary)

And for consistency with the rest of the function, the SCH_UNLOCK(sch) could be done before the tcp_log_addrs and free.

But when generating the log message, we use sc->sc_tsreflect. So if we do SCH_UNLOCK(sch) before log(), we would potentially use memory already freed.

Yes, of course- somehow I missed the use of sc->sc_tsreflect!

So for log messages without any reference to sc, I do the free() in the if() and do SCH_UNLOCK(sch) before the if(). But if the log messages have a reference to sc, I unlock first and then call free right after the if().
Please note that s is set in any case and calling free() with s == NULL is OK.

This revision is now accepted and ready to land.Oct 17 2025, 3:24 AM
This revision was automatically updated to reflect the committed changes.