]> git.ipfire.org Git - thirdparty/squid.git/commit - src/snmp/Forwarder.h
Protect SMP kids from unsolicited IPC answers (#771)
authorEduard Bagdasaryan <eduard.bagdasaryan@measurement-factory.com>
Fri, 12 Feb 2021 13:33:16 +0000 (13:33 +0000)
committerSquid Anubis <squid-anubis@squid-cache.org>
Fri, 12 Feb 2021 21:00:12 +0000 (21:00 +0000)
commit4c218615874e3002e1dd4d1d047821115027fac0
treebb1b4227756f7090fce7f07b96740298d6a6dd3d
parentd2f0c10659152f0b99e4a21c1040dfc3d260f92e
Protect SMP kids from unsolicited IPC answers (#771)

When an SMP kid restarts, it recreates its IPC socket to flush any old
messages, but it might still receive IPC messages intended for its
previous OS process because the sender may write the message _after_
kid's IPC socket is flushed. Squid IPC communication is connectionless,
so the sender cannot easily detect the reopening of the recipient socket
to prevent this race condition. Some notifications are desirable across
kid restarts, so properly switching to connection-oriented IPC
communication would only complicate things further.

This change protects kids from, for the lack of a better term, an
"unsolicited" answer: An answer to a question the recipient did not ask.
When allowed to reach regular message-handling code, unsolicited answers
result in misleading diagnostics, may trigger assertions, and might even
result in a bad recipient state. For example, a kid might think it has
been successfully registered with Coordinator while its registration
attempt was actually dropped due to a Coordinator restart.

Our protection targets one specific use case: Responses that were born
(or became) "unsolicited" due to a recipient restart. Other problematic
cases may not require any protection, may require a very different
protection mechanism (e.g. cryptography), may deal with requests rather
than responses, or even cannot be reliably detected. For example:

* messages sent by a malicious attacker
* requests sent by a misconfigured Squid instance
* requests sent by a previous Squid instance
* messages sent by a no-longer-running kid process
* messages sent by buggy Squid code

----

Also marked a few out-of-scope problems/improvements, including a bug:

Improved handling of Coordinator and Strand exceptions exposed and
partially addressed an old problem: When configured to listen on an
inaccessible port, Squid used to kill the Coordinator job, resulting in
subsequent kid registration timeouts. Squid now correctly keeps the
Coordinator job running, logging a detailed report:

    WARNING: Ignoring problematic IPC message
        message type: 5
        problem: check failed: fd >= 0
        exception location: TypedMsgHdr.cc(198) putFd

Still, the affected kids do not report the port opening problem and
continue running, listening on the problem-free ports (if any).
Depending on the exception timing, similar behavior was possible before
these changes. The correct action here is to send the port opening error
to the kid process without throwing the putFd() exception, but we should
decide how Squid should handle such inaccessible configured ports first.
45 files changed:
src/DiskIO/IpcIo/IpcIoFile.cc
src/base/Makefile.am
src/base/TypeTraits.h [new file with mode: 0644]
src/ip/Address.h
src/ipc/Coordinator.cc
src/ipc/Forwarder.cc
src/ipc/Forwarder.h
src/ipc/Inquirer.cc
src/ipc/Inquirer.h
src/ipc/Makefile.am
src/ipc/Port.cc
src/ipc/Port.h
src/ipc/QuestionerId.cc [new file with mode: 0644]
src/ipc/QuestionerId.h [new file with mode: 0644]
src/ipc/Request.h
src/ipc/RequestId.cc [new file with mode: 0644]
src/ipc/RequestId.h [new file with mode: 0644]
src/ipc/Response.h
src/ipc/SharedListen.cc
src/ipc/SharedListen.h
src/ipc/Strand.cc
src/ipc/StrandCoord.cc
src/ipc/StrandCoord.h
src/ipc/StrandSearch.cc
src/ipc/StrandSearch.h
src/ipc/TypedMsgHdr.h
src/ipc/forward.h
src/mgr/Action.cc
src/mgr/Action.h
src/mgr/Filler.cc
src/mgr/Filler.h
src/mgr/Forwarder.cc
src/mgr/FunAction.cc
src/mgr/InfoAction.cc
src/mgr/Request.cc
src/mgr/Request.h
src/mgr/Response.cc
src/mgr/Response.h
src/snmp/Forwarder.cc
src/snmp/Forwarder.h
src/snmp/Request.cc
src/snmp/Request.h
src/snmp/Response.cc
src/snmp/Response.h
src/tests/stub_libmgr.cc