mirror of
https://github.com/cesanta/mongoose.git
synced 2025-01-14 01:38:01 +08:00
Deomid Ryabkov
44b15b76f7
Fix leaking non-active (e.g., bound) LWIP TCP PCBs
tcp_close_tcpip() only closed active TCP PCBs, leaking other types of TCP PCBs (notably bound only, not yet connected/used). With time, this led to DoS situations. Fix by giving up on the hacky way of searching the LWIP innards for the TCP PCB needing closing. The searching was non-comprehensive, hence the problem in principle, and inherently racy: could close a meanwhile freed & reused PCB. Pass the pointer to the struct mg_lwip_conn_state of the struct mg_connection being destroyed to tcp_close_tcpip() instead of the bare PCB pointer, so the PCB pointer stored within can be used. Delay unassigning that pointer from the struct mg_connection until tcp_close_tcpip() finishes, so that a mg_lwip_tcp_error_cb() meanwhile can clear the PCB pointer stored within. That ensures no double-closing of the TCP PCB when a concurrent TCP error makes LWIP close the TCP PCB from the LWIP side. NB! At the moment, PCBs can still leak if tcp_close() fails, which is unlikely but possible as per the API. Retrying tcp_close() should somehow be implemented. For now, at least add logging of tcp_close() failures. Also: remove the extraneous though benign double-calling of tcp_arg(…, NULL). h/t @QRPp
Mongoose - Embedded Web Server / Embedded Networking Library
This branch is only for use by Mongoose OS, for other projects please use the master branch.
Licensing
Mongoose is released under Commercial and GNU GPL v.2 open source licenses.
Commercial Projects: Contact us for commercial license.
Languages
C
90%
C++
4.4%
Makefile
2.8%
JavaScript
1.3%
HTML
0.9%
Other
0.6%