]> git.ipfire.org Git - thirdparty/squid.git/log
thirdparty/squid.git
4 years agoImprove Transfer-Encoding handling (#702)
Amos Jeffries [Sun, 16 Aug 2020 02:21:22 +0000 (02:21 +0000)] 
Improve Transfer-Encoding handling (#702)

Reject messages containing Transfer-Encoding header with coding other
than chunked or identity. Squid does not support other codings.

For simplicity and security sake, also reject messages where
Transfer-Encoding contains unnecessary complex values that are
technically equivalent to "chunked" or "identity" (e.g., ",,chunked" or
"identity, chunked").

RFC 7230 formally deprecated and removed identity coding, but it is
still used by some agents.

4 years agoForbid obs-fold and bare CR whitespace in framing header fields (#701)
Amos Jeffries [Fri, 14 Aug 2020 15:05:31 +0000 (15:05 +0000)] 
Forbid obs-fold and bare CR whitespace in framing header fields (#701)

Header folding has been used for various attacks on HTTP proxies and
servers. RFC 7230 prohibits sending obs-fold (in any header field) and
allows the recipient to reject messages with folded headers. To reduce
the attack space, Squid now rejects messages with folded Content-Length
and Transfer-Encoding header field values. TODO: Follow RFC 7230 status
code recommendations when rejecting.

Bare CR is a CR character that is not followed by a LF character.
Similar to folding, bare CRs has been used for various attacks. HTTP
does not allow sending bare CRs in Content-Length and Transfer-Encoding
header field values. Squid now rejects messages with bare CR characters
in those framing-related field values.

When rejecting, Squid informs the admin with a level-1 WARNING such as

    obs-fold seen in framing-sensitive Content-Length: ...

4 years agoIgnore SMP queue responses made stale by worker restarts (#711)
Eduard Bagdasaryan [Wed, 12 Aug 2020 22:47:14 +0000 (22:47 +0000)] 
Ignore SMP queue responses made stale by worker restarts (#711)

When a worker restarts (for any reason), the disker-to-worker queue may
contain disker responses to I/O requests sent by the previous
incarnation of the restarted worker process (the "previous generation"
responses). Since the current response:request mapping mechanism relies
on a 32-bit integer counter, and a worker process always starts counting
from 0, there is a small chance that the restarted worker may see a
previous generation response that accidentally matches the current
generation request ID.

For writing transactions, accepting a previous generation response may
mean unlocking a cache entry too soon, making not yet written slots
available to other workers that might read wrong content. For reading
transactions, accepting a previous generation response may mean
immediately serving wrong response content (that have been already
overwritten on disk with the information that the restarted worker is
now waiting for).

To avoid these problems, each disk I/O request now stores the worker
process ID. Workers ignore responses to requests originated by a
different/mismatching worker ID.

4 years agoDo not send keep-alive in 101 (Switching Protocols) responses (#709)
Alex Rousskov [Mon, 10 Aug 2020 18:46:02 +0000 (18:46 +0000)] 
Do not send keep-alive in 101 (Switching Protocols) responses (#709)

... because it breaks clients using websocket_client[1] library and is
redundant in our HTTP/1.1 control messages anyway.

I suspect that at least some buggy clients are confused by a multi-value
Connection field rather than the redundant keep-alive signal itself, but
let's try to follow RFC 7230 Upgrade example more closely this time and
send no keep-alive at all.

[1] https://pypi.org/project/websocket_client/

4 years agoAdd http_port sslflags=CONDITIONAL_AUTH (#510)
trapexit [Sun, 9 Aug 2020 06:14:51 +0000 (06:14 +0000)] 
Add http_port sslflags=CONDITIONAL_AUTH (#510)

Enabling this flag removes SSL_VERIFY_FAIL_IF_NO_PEER_CERT from the
SSL_CTX_set_verify callback. Meaning a client certificate verify
occurs iff provided.

4 years agoFix: cannot stat tests/STUB.h No such file or directory (#707)
Amos Jeffries [Thu, 6 Aug 2020 22:49:34 +0000 (22:49 +0000)] 
Fix: cannot stat tests/STUB.h No such file or directory (#707)

Since 2b5ebbe (PR #670), we have been seeing "random" build failures.

The tests/Stub.am generated by source-maintenance.sh has not included
the tests/STUB.h file for explicit distribution. The source file was
built and included only when seen as a dependency of the files using it.

When stubs are copied for use by the extra binaries from tools/
directory, there is a secondary side effect from "make -j":

* When the -j concurrency is small, tests/STUB.h gets copied during the
  first cycle, and parallel builds compiling other copied files succeed.

* When the -j concurrency is large, tests/STUB.h may be deferred to a
  later copy cycle, and the first actual compile task needing it fails
  with `cannot stat 'src/tests/STUB.h': No such file or directory`.

Add tests/STUB.h to src/Makefile.am EXTRA_DIST to restore the previous
distribution behavior (when STUB_SOURCE contained it explicitly).

Update the pinger source paths that were omitted in 2b5ebbe.

4 years agoEnforce token characters for field-name (#700)
Amos Jeffries [Tue, 4 Aug 2020 04:34:32 +0000 (04:34 +0000)] 
Enforce token characters for field-name  (#700)

RFC 7230 defines field-name as a token. Request splitting and cache
poisoning attacks have used non-token characters to fool broken HTTP
agents behind or in front of Squid for years. This change should
significantly reduce that abuse.

If we discover exceptional situations that need special treatment, the
relaxed parser can allow them on a case-by-case basis (while being extra
careful about framing-related header fields), just like we already
tolerate some header whitespace (e.g., between the response header
field-name and colon).

4 years agoDo not stall while debugging a scan of an empty store_table (#699)
Eduard Bagdasaryan [Wed, 29 Jul 2020 20:51:58 +0000 (20:51 +0000)] 
Do not stall while debugging a scan of an empty store_table (#699)

Non-SMP Squid and each SMP kid allocate a store_table hash. With large
caches, some allocated store_table may have millions of buckets.

Recently we discovered that it is almost impossible to debug SMP Squid
with a large but mostly empty disk cache because the disker registration
times out while store_table is being built -- the disker process is
essentially blocked on a very long debugging loop.

The code suspends the loop every 500 entries (to take care of tasks like
kid registration), but there are no pauses when scanning millions of
empty hash buckets where every bucket prints two debug lines.

Squid now does not report empty store_table buckets explicitly. When
dealing with large caches, the debugged process may still be blocked for
a few hundred milliseconds (instead of many seconds) while scanning the
entire (mostly empty) store_table. Optimizing that should be done as a
part of the complex "store search" API refactoring.

4 years agoFix livelocking in peerDigestHandleReply (#698)
Eduard Bagdasaryan [Mon, 27 Jul 2020 15:28:31 +0000 (15:28 +0000)] 
Fix livelocking in peerDigestHandleReply (#698)

peerDigestHandleReply() was missing a premature EOF check. The existing
peerDigestFetchedEnough() cannot detect EOF because it does not have
access to receivedData.length used to indicate the EOF condition. We did
not adjust peerDigestFetchedEnough() because it is abused to check both
post-I/O state and the state after each digest processing step. The
latter invocations lack access to receivedData.length and should not
really bother with EOF anyway.

4 years agoConvert LRU map into a CLP map (#593)
Amos Jeffries [Sun, 26 Jul 2020 02:21:58 +0000 (02:21 +0000)] 
Convert LRU map into a CLP map (#593)

Revamped LruMap implementation, adding support for value-specific TTLs,
value-specific memory consumption estimates, memory pooling for value
wrappers, and polishing code. Renamed the result to ClpMap.

Fixed memory leak of generated fake SSL certificates in Squids
configured with dynamic_cert_mem_cache_size=0 (the default is 4MB).

Controversially changed sslcrtvalidator_program cache and TTL defaults:

* After we started accounting for key lengths in validator cache
  entries, the old 2048 bytes default size became not just ridiculously
  small but insufficient to cache the vast majority of cache entries
  because an entry key contains a PEM certificate sent to the validator
  (among other validation parameters). A PEM certificate usually
  consumes at least a few kilobytes. Living the old 2KB default would
  essentially mean that we are disabling caching (by default).

* And if we fix one default, it makes sense to fix the other as well.
  The old 60 second TTL default felt too conservative. Most certificate
  invalidations last days, not seconds. We picked one hour because that
  value is still fairly conservative, used as the default by several
  other Squid caches, and should allow for decent cache hit ratio.

Dropped support for the undocumented "sslcrtvalidator_program ttl=-1"
hack that meant unlimited TTL. Large TTL values should be used instead.
TODO: The option parser should be revamped to reject too-large values.

5 years agoReport SMP store queues state (mgr:store_queues) (#690)
Eduard Bagdasaryan [Fri, 10 Jul 2020 16:45:50 +0000 (16:45 +0000)] 
Report SMP store queues state (mgr:store_queues) (#690)

The state of two Store queues is reported: Transients notification queue
(a.k.a. Collapsed Forwarding queue) and SMP I/O request queue (used for
communication with rock diskers). Each worker and disker kid reports its
view of that kid's incoming and outgoing queues state, including a small
sample (up to 7 items) of queued messages. These kid-specific reports
are YAML-compliant.

With the exception of a field labeled "other", each queue report is
self-consistent despite accessing data shared among kids -- the reported
combination of values did exist at the snapshot collection time.

The special "other" field represents a message counter maintained by the
other side of the queue. In most cases, that field will be close to its
correct value, but, due to modifications by the other process of a
non-atomic value, it may be virtually anything. We think it is better to
report (without officially naming) this field because it may be useful
in triage regardless of these caveats. Making the counter atomic just
for these occasional reports is not worth the performance overheads.

Also fixed testStore linking problems (on some platforms) that were
caused by the wrong order of libdiskio and libipc dependencies.

5 years agoHonor on_unsupported_protocol for intercepted https_port (#689)
Alex Rousskov [Mon, 6 Jul 2020 08:04:31 +0000 (08:04 +0000)] 
Honor on_unsupported_protocol for intercepted https_port (#689)

... when Squid discovers a non-TLS client while parsing its handshake.

For https_port traffic, ConnStateData::switchToHttps() relies on start()
to set preservingClientData_ correctly, but shouldPreserveClientData(),
called by start() to set preservingClientData_, was not preserving TLS
bytes in the https_port start() context. Typical debug messages:

    parseTlsHandshake: Got something other than TLS ... Cannot SslBump
    tunnelOnError: may have forgotten client data; send error: 40

5 years agoAdd editorconfig file (#591)
Francesco Chemolli [Sat, 4 Jul 2020 07:43:12 +0000 (07:43 +0000)] 
Add editorconfig file (#591)

5 years agoBug 5054: mark dns_v4_first as obsolete in cf.data.pre (#687)
DrDaveD [Sat, 4 Jul 2020 02:05:27 +0000 (02:05 +0000)] 
Bug 5054: mark dns_v4_first as obsolete in cf.data.pre (#687)

The dns_v4_first directive is ignored since commit fd9c47d.

5 years agoConcurrent hit misses due to Transients entry creation collision (#686)
Alex Rousskov [Fri, 3 Jul 2020 21:06:17 +0000 (21:06 +0000)] 
Concurrent hit misses due to Transients entry creation collision (#686)

Transients::addEntry() fails when two simultaneous cache hit requests
arrive at two different workers:

    Controller.cc find: e:=msV/0x55c2dbdac7f0*0 check failed: slot
    exception location: Transients.cc(236) addEntry

The failure leads to a cache miss for one of the requests. The miss
transaction will overwrite the already cached entry, possibly creating
more misses due to long write locks used by the disk cache. The problem
does not affect collapsed requests. It affects regular cache hits.

The failure happens because two requests are trying to create a
Transients entry at about the same time. Only one can succeed. With the
current ReadWriteLock-based design, some contention is unavoidable, but
the contention window was rather large/long:

* The critical section essentially started when Controller::find() (in
  each request worker) checked Transients and did not find a matching
  entry there. That failed lookup put each request into "create a new
  Transients entry" mode.

* A worker exited that critical section when openForWriting() in
  Transients::addEntry() returned (with a write lock to the
  ready-to-be-filled entry for one of the two requests and with a
  failure for the other).

This change reduces the contention window to the bare minimum necessary
to create and fill a Transients entry inside openOrCreateForReading().
In the micro-tests that exposed this problem, the probability of a
failure is reduced from more than 70% to less than 3%. YMMV.

Also split addEntry() into two directional methods because while they
are structured similarly they actually have almost no common code now.

5 years agoCleanup unit tests (#688)
Amos Jeffries [Mon, 29 Jun 2020 15:50:56 +0000 (15:50 +0000)] 
Cleanup unit tests (#688)

* Prune dependencies for testUrl

* Prune dependencies for testEventLoop

* Remove obsolete stub_SwapDir.cc

* Refactor testEventLoop to remove bitrot and obsolete Dispatcher code

5 years agoGenerated config dumping code does not skip unconfigured options (#684)
Alex Rousskov [Sat, 27 Jun 2020 04:13:43 +0000 (04:13 +0000)] 
Generated config dumping code does not skip unconfigured options (#684)

We must manually skip them. This fix is needed after commit 1c2b446.

5 years agoBug 5048: ResolvedPeers.cc:35: "found != paths_.end()" assertion (#680)
Eduard Bagdasaryan [Fri, 26 Jun 2020 20:06:29 +0000 (20:06 +0000)] 
Bug 5048: ResolvedPeers.cc:35: "found != paths_.end()" assertion (#680)

This bug was caused by a4d576d. ResolvedPeers::retryPath() used
connection object pointers to find the original path location under the
incorrect assumption that the Connection pointers never change. That
assumption was wrong for persistent connections: ResolvedPeers stores a
half-baked Connection object rather than the corresponding open
Connection object that the unfortunate caller got from fwdPconnPool and
passed to ResolvedPeers::retryPath().

While working on a fix, we discovered a second reason why the pointer
comparison was a bad idea (and why a simpler fix of comparing addresses
rather than pointers was also a bad idea): The peer selection code
promises to deliver unique destinations, but we now suspect that, under
presumably rare circumstances, it may deliver duplicates. This broken
promise is now an out-of-scope XXX in PeerSelector::addSelection().

Squid now eliminates the search (and the previously documented concern
about its slow speed) by remembering Connection's position in the
destination array. The position is remembered in a smart Connection
pointer (compatible with Comm::ConnectionPointer) so that the rest of
the code (that does not really care about all this) is preserved largely
unchanged. Most changes are just renaming the pointer type.

Also freshened a FwdState call and comment made stale by 25b0ce4.

Also marked an out-of-scope problem in maybeGivePrimeItsChance() caller.

5 years agoAvoid FwdState::serverConn while establishing a CONNECT tunnel (#681)
Alex Rousskov [Thu, 25 Jun 2020 09:39:45 +0000 (09:39 +0000)] 
Avoid FwdState::serverConn while establishing a CONNECT tunnel (#681)

Master/v6 commit 25b0ce4 missed two cases where serverConnection() was
used prematurely: One case requires --enable-delay-pools, and the other
does not actually dereference the prematurely used serverConnection().
Both cases establish a CONNECT tunnel through a cache_peer.

5 years agoBug 5051: Some collapsed revalidation responses never expire (#652)
DrDaveD [Tue, 23 Jun 2020 18:41:15 +0000 (18:41 +0000)] 
Bug 5051: Some collapsed revalidation responses never expire (#652)

Since negative caching support was repaired in master commit 91870bf, it
has been found to last indefinitely when cache revalidation happens.

New revalidation requests were collapsing on a negatively cached
response forever because handleIMS() logic does not validate response
freshness (still assuming that the reply came in response to the current
request even though that assumption could be false since collapsed
revalidation support was added in master commit 1a210de).

Clearing the ENTRY_REQUIRES_COLLAPSING flag when hitting the negatively
cached collapsed revalidaiton response for the first time works around
this "lack of freshness check" problem. The same solution existed in the
official code for positive responses. However, this solution is partial
and unreliable because there is no guarantee that the clearing code will
be reached (and reached while the cached response is still fresh).

Also added additional partial protections against collapsing on entries
abandoned by their writers, including idle hittingRequiresCollapsing()
StoreEntry objects.

Also fixed a tiny race condition missed in master commit d1d3b4d which
addressed a much bigger (and more frequent) problem. I am not aware of
any real-world cases where this race condition surfaced, but they would
probably manifest in unwarranted failures to collapse.

5 years agoFix "make check" with GCC-10 (#677)
Amos Jeffries [Mon, 22 Jun 2020 18:01:29 +0000 (18:01 +0000)] 
Fix "make check" with GCC-10 (#677)

Latest GCC-10 release on some OS (Debian initially) no
longer locates files in "." by default. Fix Makefile hack
pulling tests/ files into tools/ for stub linking.

Also, Squid #includes under src/ are supposed to always
use path relative to src/. Fix wrong STUB.h references.

5 years agoMaintenance: rename .list auto-generated files to .am (#670)
Amos Jeffries [Mon, 22 Jun 2020 09:54:09 +0000 (09:54 +0000)] 
Maintenance: rename .list auto-generated files to .am (#670)

The contents are automake script. Also this allows
the source format enforcement to correctly detect
that and enforce our automake code guidelines.

5 years agoSource Format Enforcement (#665)
squidadm [Sat, 20 Jun 2020 21:05:22 +0000 (21:05 +0000)] 
Source Format Enforcement (#665)

Does not contain astyle-driven changes.

Makefile changes are what commit 2a06115 mistakenly claimed to contain.

5 years agoPreserve caller context in MemObject::abort callbacks (#671)
Eduard Bagdasaryan [Sat, 20 Jun 2020 16:58:14 +0000 (16:58 +0000)] 
Preserve caller context in MemObject::abort callbacks (#671)

Store abused time-based event API to deliver abort notifications, losing
transaction context in the process. Further refactoring may crystallize
the currently vague/obscured "store writer" concept. Such refactoring is
outside this project scope but will benefit from these changes.

5 years agoMaintenance: fix syntax of profiler/xprof_type.h (#669)
Amos Jeffries [Sat, 20 Jun 2020 14:07:26 +0000 (14:07 +0000)] 
Maintenance: fix syntax of profiler/xprof_type.h (#669)

Generate xprof_type.h compliant with Squid coding
guidelines to prevent syntax collisions when astyle
is not available to enforce correctness.

5 years agoAvoid corruption of source files when astyle cannot start (#668)
Alex Rousskov [Thu, 18 Jun 2020 16:30:28 +0000 (16:30 +0000)] 
Avoid corruption of source files when astyle cannot start (#668)

    $ export ASTYLE=/no/such/file
    $ ./scripts/formater.pl src/tunnel.cc
    open2: exec of /no/such/file ... failed: No such file or directory

    # for debugging; most admins will just fix the ASTYLE value
    $ file src/tunnel.cc
    src/tunnel.cc: cannot open `src/tunnel.cc' (No such file or ...)

    $ export ASTYLE=/usr/bin/astyle
    $ ./scripts/formater.pl src/tunnel.cc
    Can not open input file: src/tunnel.cc.astylebak.2

    $ xxd -C src/tunnel.cc
    00000000: 00

Also avoids creation of new source files, as (poorly) illustrated by the
single-byte src/tunnel.cc file created (after being removed) above.

Also improves diagnostic when dealing with misspelled file names:

    $ ./scripts/formater.pl src/tunnel.ccsrc/FwdState.cc
    Can not open input file: src/tunnel.ccsrc/FwdState.cc.astylebak
    Can't open output file: src/tunnel.ccsrc/FwdState.cc

5 years agoReforward CONNECT after TLS handshake failure with peer (#489)
Eduard Bagdasaryan [Wed, 17 Jun 2020 13:01:37 +0000 (13:01 +0000)] 
Reforward CONNECT after TLS handshake failure with peer (#489)

When Squid received a CONNECT request and attempted to establish a
secure connection to an SSL cache_peer, it did not try the next
available destination after a TLS negotiation failure.

Why retry such TLS negotiation failures? Peer B may not have the same
misconfiguration that led to the negotiation failure when talking to
peer A. Admins may improve fault tolerance by using pools of different
peers or pools of identical peers that are reconfigured one by one. And
FwdState already does this -- flags.connected_okay is not set until TLS
negotiation is successful.

5 years agoSslBump: Support parsing GREASEd (and future) TLS handshakes (#663)
Christos Tsantilas [Fri, 12 Jun 2020 23:32:16 +0000 (23:32 +0000)] 
SslBump: Support parsing GREASEd (and future) TLS handshakes (#663)

A peeking or staring Squid aborted TLS connections containing a GREASE
version in the supported_versions handshake extension (e.g., 0x3a3a).
Here is a sample cache.log error (debug_options ALL,1 83,2):

```
parseTlsHandshake: ... check failed: vMajor == 3
    exception location: Handshake.cc(119) ParseProtocolVersion
```

The same problem would apply to some other "unsupported" (and currently
non-existent) TLS versions (e.g., 0x0400). The growing popularity of
GREASE values exposed the bug (just like RFC 8710 was designed to do).

Squid now ignores all unsupported-by-Squid TLS versions in handshake
extensions. Squid still requires a supported TLS version for
framing-related handshake fields -- no changes there.

It is difficult to define "supported" in this context precisely because
a peeking Squid only observes the TLS handshake. Our handshake parser
may report the following versions: SSL v2.0, SSL v3.0, and TLS v1.x
(with x >= 0). This logic allows us to safely parse the handshake (no
framing errors) and continue to make version-based decisions like
disabling OpenSSL TLS v1.3 support when the agents are negotiating TLS
v1.3+ (master cd29a42). Also, access logs benefit from this "support"
going beyond TLS v1.2 even though Squid cannot bump most TLS v1.3+
handshakes.

Squid was and still is compliant with the "MUST NOT treat GREASE values
differently from any unknown value" requirement of RFC 8710.

Also added source code comments to mark other places where unsupported
(for some definition of "support") TLS values, including GREASE values
may appear.

Folks studying debugging logs (where GREASE values may appear) will
probably either recognize their easy-to-remember 0x?A?A pattern or
not really know/care about RFC 8710 and its special values.

This is a Measurement Factory project.

5 years agorefactor peerConnectTimeout to CachePeer::connectTimeout (#664)
Francesco Chemolli [Thu, 11 Jun 2020 18:17:16 +0000 (18:17 +0000)] 
refactor peerConnectTimeout to CachePeer::connectTimeout (#664)

Resolve a TODO in the code.

5 years agoMaintenance: Consistent whitespace in Perl scripts (#660)
Francesco Chemolli [Thu, 11 Jun 2020 09:01:37 +0000 (09:01 +0000)] 
Maintenance: Consistent whitespace in Perl scripts (#660)

Manually adjusted Perl sources to use 4-space indent
and to remove trailing whitespaces.

5 years agoMaintenance: Remove FIXME and \todo labels (#647)
Amos Jeffries [Wed, 10 Jun 2020 21:19:26 +0000 (21:19 +0000)] 
Maintenance: Remove FIXME and \todo labels (#647)

Update old ad-hoc FIXME labels and experimental use of doxygen \todo
listings to use XXX or TODO labels for consistency sake.

Approximate current definitions (to be formalized elsewhere):
 * XXX - a problem, often a serious one
 * TODO - a problem, often a minor one
 * BUG - a problem that is worth informing admin about

Existing TODO, XXX, and BUG labels may not fit the above definitions.

Some old marks were edited or purged.

5 years agoFix clang (with its own libc++) build after 9865de7 (#661)
Francesco Chemolli [Tue, 9 Jun 2020 02:04:45 +0000 (02:04 +0000)] 
Fix clang (with its own libc++) build after 9865de7 (#661)

Compilers that check allocator/container value_type matching detected a
mismatch because multimap::value_type is _not_ std::pair<key,T> but
std::pair<const key,T>!

Symptoms (when compiling files that include src/PingData.h):

     Allocator::value_type must be same type as value_type

5 years agoRemove leakfinder (--enable-leakfinder) (#655)
Francesco Chemolli [Mon, 8 Jun 2020 21:40:57 +0000 (21:40 +0000)] 
Remove leakfinder (--enable-leakfinder) (#655)

There are better leak finding tools for most use cases now. The removed
code can be manually added back for experiments in other use cases. The
original leakfinder design required code modifications anyway.

5 years agomake the way version.h is included standard (#654)
Francesco Chemolli [Sat, 6 Jun 2020 07:19:01 +0000 (07:19 +0000)] 
make the way version.h is included standard (#654)

include guards for version.h are in squid.h
Change this to use the standard approach

5 years agoRelease notes prep for 5.0.3 and 4.12 (#651)
Amos Jeffries [Fri, 5 Jun 2020 18:02:20 +0000 (18:02 +0000)] 
Release notes prep for 5.0.3 and 4.12 (#651)

5 years agoPreserve caller context across ping timeout events (#635)
Eduard Bagdasaryan [Thu, 4 Jun 2020 11:23:31 +0000 (11:23 +0000)] 
Preserve caller context across ping timeout events (#635)

PeerSelector was losing its transaction context while handling an
event-driven timeout. Also, the old code generating HandlePingTimeout
event was problematic for two reasons:

* it used raw 'this' for cbdata-protected child class. Sooner or later,
  code like this leads to "real" bugs similar to those fixed in ce9bb79,
  38a9f55 / 9e64d84, and 4299f87.

* It (mis)used event API for the transaction-specific purpose.

We created a new "ping timeout service" that keeps at most one
transaction-agnostic event.h timeout at any given time while maintaining
an internal list of transactions awaiting a ping response. Similar
architecture was used for HappyConnOpener helper services.

We rejected the alternative idea of enhancing event API to support
asynchronous calls because event.cc internals were never meant to handle
thousands of concurrently pending transaction-related timeouts on busy
proxies. While it would be possible to enhance those internals as well,
timeout services offer an even better performance, are much easier to
enhance to support timeout reconfigurations, and offer better "Squid
state" debugging.

5 years agoSourceLayout: Avoid including cppunit outside unit tests (#649)
Francesco Chemolli [Wed, 3 Jun 2020 08:29:24 +0000 (08:29 +0000)] 
SourceLayout: Avoid including cppunit outside unit tests (#649)

compat/cppunit.h is needed on some soon-to-be-deprecated
OSes (centos-6). But it's not necessary to include it
everywhere.
Change so that it is only included in unit tests

5 years agoSummarize Squid Project security policy (#630)
Amos Jeffries [Tue, 2 Jun 2020 04:05:02 +0000 (04:05 +0000)] 
Summarize Squid Project security policy (#630)

As an added bonus, GitHub recognizes this file as one of the "Community
health" files and refers folks filing security issues to it.

5 years agoMaintenance: Support custom astyle versions (#644)
Francesco Chemolli [Mon, 1 Jun 2020 23:23:09 +0000 (23:23 +0000)] 
Maintenance: Support custom astyle versions (#644)

... to override the astyle version used for official sources:

    $ ./scripts/source-maintenance.sh
    Astyle version problem. You have 3.1 instead of 2.04

    $ ./scripts/source-maintenance.sh --enable-astyle 3.1
    Found astyle 3.1. Formatting...

5 years agoMake testUriScheme independent of translation unit order (#645)
Francesco Chemolli [Mon, 1 Jun 2020 19:45:25 +0000 (19:45 +0000)] 
Make testUriScheme independent of translation unit order (#645)

Changing the translation unit linkage order will break testUriScheme.
Use explicit subsystems initialization, like testURL already does.

5 years agoMaintenance: Sort source file lists in Makefiles (#643)
Francesco Chemolli [Mon, 1 Jun 2020 16:28:33 +0000 (16:28 +0000)] 
Maintenance: Sort source file lists in Makefiles (#643)

Automate keeping files in Makefile.am SOURCES
directives in the appropriate order and apply to
current Makefile.am throughout the source

5 years agoAllow upgrading from HTTP/1.1 to other protocols (#481)
Christos Tsantilas [Fri, 29 May 2020 21:26:08 +0000 (21:26 +0000)] 
Allow upgrading from HTTP/1.1 to other protocols (#481)

Support admin-authorized HTTP Upgrade-driven (RFC 7230 Section 6.7)
protocol switching. The new http_upgrade_request_protocols configuration
directive allows admin to control what client Upgrade offer(s) are
forwarded to the server. Squid does not automatically check whether the
server selection matches one of the client offers, but the admin can
deny unacceptable server responses using http_reply_access.

By default, Squid still does not forward any Upgrade headers,
effectively blocking an upgrade attempt.

Squid itself does not understand the protocols being upgraded to and
participates in the upgraded communication only as a dumb TCP proxy.

This is a Measurement Factory project.

5 years agoRemove obsolete membanger test (#642)
Amos Jeffries [Mon, 25 May 2020 03:15:41 +0000 (03:15 +0000)] 
Remove obsolete membanger test (#642)

The binary code has major bitrot and has not built in a long time.
If any of its logic is needed in future we can look at the repo history.

5 years agoDetail TLS and CONNECT cache_peer negotiation failures (#518)
Christos Tsantilas [Thu, 21 May 2020 22:22:22 +0000 (22:22 +0000)] 
Detail TLS and CONNECT cache_peer negotiation failures (#518)

Before PeerConnector and Tunneler were introduced, FwdState and
TunnelStateData naturally owned their to-server connection. When CONNECT
and TLS negotiation were outsourced, we kept that ownership to minimize
changes and simplify negotiation code. That was wrong because FwdState
and TunnelStateData, as connection owners, had to monitor for connection
closures but could not distinguish basic TCP peer closures from complex
CONNECT/TLS negotiation failures that required further detailing. The
user got generic error messages instead of details known to negotiators.

Now, Ssl::PeerConnector and Http::Tunneler jobs own the connection they
work with and, hence, are responsible for monitoring it and, upon
successful negotiation, returning it to the initiators. In case of
problems, these jobs send detailed errors to the initiators instead.

Passing connection ownership to and from a helper job is difficult
because the connection may be either closed or begin to close (e.g. by
shutdown) while the callback is pending without working close handlers.
Many changes focus on keeping Connection::fd in sync with Comm.

Also improved tunnel.cc mimicking of (better) FwdState code: Partially
open connections after Comm::ConnOpener failures are now closed, and
Http::Tunneler failures are now retried.

This is a Measurement Factory project.

5 years agoAdd flexible RFC 3986 URI encoder (#617)
Amos Jeffries [Thu, 21 May 2020 14:42:02 +0000 (14:42 +0000)] 
Add flexible RFC 3986 URI encoder (#617)

Use AnyP::Uri namespace to self-document encoder scope and
coding type.

Use SBuf and CharacterSet for more flexible input and actions
than previous RFC 1738 encoder. Allowing callers to trivially
determine which characters are encoded.

5 years agoFix keyblock use for Heimdal in kerberos_ldap_group helper (#627)
huaraz [Wed, 20 May 2020 13:00:00 +0000 (13:00 +0000)] 
Fix keyblock use for Heimdal in kerberos_ldap_group helper (#627)

Heimdal uses a different keyblock structure. Symptoms:

    error: 'krb5_creds' ... has no member named 'keyblock'

5 years agoReduced startup time with large rock cache_dirs (#634)
Eduard Bagdasaryan [Tue, 19 May 2020 17:01:40 +0000 (17:01 +0000)] 
Reduced startup time with large rock cache_dirs (#634)

... addressing an old TODO.

Before scanning the disks to find the actual entries, the old rock
cache_dir initialization code had to populate its index as if all disk
slots were available and then remove all the added entries. Those two
wasteful operations took ~1.5 seconds for a 200GB disk before the
PageStack ABA bug was fixed in a586085. With the tree-based fix, that
time increased to ~15 seconds. The delay is completely gone now,
reducing the total index initialization time (for a 200GB disk) down to
a second.

5 years agotest-builds.sh: in case of error dump full log (#622)
Francesco Chemolli [Tue, 19 May 2020 01:06:41 +0000 (01:06 +0000)] 
test-builds.sh: in case of error dump full log (#622)

Change behaviour of the test-builds script to
dump the full output of the current layer's log in
case of error. This will help better diagnose errors
as the root cause of an error may have exited the 20-lines
buffer we currently use

5 years agoFix PoolingAllocator build errors with older GCCs (#632)
Alex Rousskov [Mon, 18 May 2020 21:42:05 +0000 (21:42 +0000)] 
Fix PoolingAllocator build errors with older GCCs (#632)

    error: no class template named rebind in class PoolingAllocator

GCC v4.8.4 (at least) does not fully implement C++11 Allocator-related
APIs, forcing the developer to manually provide Allocator traits that
are supposed to come automatically via std::allocator_traits.

The problem may only manifest itself when using a custom allocator with
types such as std::map<T> and std::list<T> that allocate wrapper
objects instead of Ts. For example, std::vector is unaffected.

5 years agoFix sending of unknown validation errors to cert. validator (#633)
Christos Tsantilas [Fri, 15 May 2020 04:54:54 +0000 (04:54 +0000)] 
Fix sending of unknown validation errors to cert. validator (#633)

Squid may be compiled with an OpenSSL release introducing X509
validation errors that Squid does not have the names for. Send their
integer codes.

Also sync Squid certificate verification errors with OpenSSL v1.1.1g.

This is a Measurement Factory project.

5 years agoValidate Content-Length value prefix (#629)
Alex Rousskov [Wed, 13 May 2020 14:05:00 +0000 (14:05 +0000)] 
Validate Content-Length value prefix (#629)

The new code detects all invalid Content-Length prefixes but the old
code was already rejecting most invalid prefixes using strtoll(). The
newly covered (and now rejected) invalid characters are

* explicit "+" sign;
* explicit "-" sign in "-0" values;
* isspace(3) characters that are not (relaxed) OWS characters.

In most deployment environments, the last set is probably empty because
the relaxed OWS set has all the POSIX/C isspace(3) characters but the
new line, and the new line is unlikely to sneak in past other checks.

Thank you, Amit Klein <amit.klein@safebreach.com>, for elevating the
importance of this 2016 TODO (added in commit a1b9ec2).

5 years agoFix the ABA problem with Ipc::Mem::PageStack::pop() in c3408a3 (#587)
Alex Rousskov [Wed, 13 May 2020 06:37:31 +0000 (06:37 +0000)] 
Fix the ABA problem with Ipc::Mem::PageStack::pop() in c3408a3 (#587)

Suspected symptoms:

    assertion failed: mem/PageStack.cc:35: "old == expected"
    assertion failed: mem/PageStack.cc:27: "nxt != TakenPage"
    assertion failed: mem/PageStack.cc:33: "nxt != TakenPage"
    assertion failed: StoreMap.cc:337: "validSlice(sliceId)"

Replaced a list-based PageStack implementation with a tree-based one.
The new code uses a deterministic binary tree. Inner nodes count the
number of available IDs in their child subtrees. Leaf nodes store IDs
using bitmasks. The root node tells the pop() method whether it is going
to find a free page. The method then adjusts counters in 1-23 nodes
(depending on the tree hight) on the path to the leaf containing a page.
The push() method adds a bit to the leaf node and adjusts the counters
of all the inner nodes (1-23) on the way up to the root one. All the
adjustments are lockless. Push may also be wait-free. No ABA problems.

An alternative fix that preserved list-based implementation was
implemented but ultimately rejected: Avoiding ABA problems required
complex code, and that complexity prevented meaningful validation using
Rust's Loom. Also, dirty performance tests of outside-of-Squid code
showed unexplained significant response time growth of the list-based
implementation when concurrency levels were being increased beyond a few
threads. While these validation and performance concerns could be red
herrings, their existence decreased our confidence in the list-based
algorithm that already had a history of fooling developers.

The tree-based PageStack implementation needs 8-16x less RAM. Roughly:
* list-based: sizeof(uint32_t) * capacity          or  4*capacity
* tree-based: sizeof(uint64_t) * 2 * rcapacity/64  or  rcapacity/4
  where rounded capacity is somewhere between capacity and 2*capacity

The absolute RAM savings are minor for most environments, but the
footprint reduction might be enough to fit a significant part of some
hot index in a modern L1 CPU cache: (e.g., a 32GB rock cache_dir may
have 16GB/16KB = 1M slot IDs = 512KB tree size).

The tree-based structure may make future support for caches with more
than 2^25 entries easier because it does not heavily rely on combining a
cache entry ID and an ABA version/nonce in a single 64-bit atomic.

TODO: While absolute tree- and list-based operation costs are all small
(under 1 microsecond), tree-based implementation cost are higher. Since
rock code pops all disk slots at startup (a known performance bug), rock
startup costs increased significantly. For example, a 200 GB disk cache
test shows ~18 seconds startup time for the tree-based implementation
versus ~4 seconds for list-based. This will be addressed by fixing that
known performance bug. The fix will not alter the tree algorithm.

TODO: The PageStack class should be renamed. Ideally, that renaming
should coincide with refactoring the PagePool/PageStack split, which is
an old XXX also currently exposes a lot of internal PageStack code.

See also: https://en.wikipedia.org/wiki/ABA_problem

5 years agogcc-8+ build error: undefined reference to __atomic_is_lock_free (#625)
Eduard Bagdasaryan [Tue, 12 May 2020 14:50:10 +0000 (14:50 +0000)] 
gcc-8+ build error: undefined reference to __atomic_is_lock_free (#625)

Compilers warned about AC_SEARCH_LIBS(__atomic_load_8)-generated code.
Newer, stricter compilers (e.g., gcc-8), exit with an error, resulting
in AC_SEARCH_LIBS failure when determining whether libatomic is needed.

More at https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=907277#30

It is unclear whether autoconf will ever handle this case better. Let's
use a custom-made test for now. The current test refuses to build Squid
on platforms where a program using std::atomic<T>::is_lock_free() cannot
be successfully linked (either with or without libatomic) for a the
largest atomic T used by Squid (i.e. a 64 bit integer).

Linking with libatomic may be required for many reasons that we do not
fully understand, but we know that std::atomic<T>::is_lock_free() does
require linking with libatomic in some environments, even where T is an
inlineable atomic. That is why we use that as a test case.

5 years agoFix whitespace shell bugs in configure library detection (#628)
Amos Jeffries [Sun, 10 May 2020 10:29:24 +0000 (10:29 +0000)] 
Fix whitespace shell bugs in configure library detection (#628)

Whitespace around shell variable assign and append operators
results in those operations not being performed.
This caused the with_*, *_PATH and *_LIBS variables to not
be set to the correct path when a custom path is used.

Also, lack of condition on the *_CFLAGS assign can pollute
the compiler parameters with non-existent directories.
It should also have been an append like PATH and LIBS to
add the auto-detected value after any user-provided value
instead of overwriting.

Broken since master commit 2453140.

5 years agoFixed TLS selected_version parsing and debugging (#621)
Alex Rousskov [Wed, 6 May 2020 01:54:07 +0000 (01:54 +0000)] 
Fixed TLS selected_version parsing and debugging (#621)

The description of the expected input was given to the wrong parsing
function. This typo may have affected parsing because it told the TLS
version tokenizer that more data may be expected for the already fully
extracted extension. I believe that the lie could affect error
diagnostic when parsing malformed input, but had no effect on handling
well-formed TLS handshakes (other than less-specific debugging).

Detected by Coverity. CID 1462621: Incorrect expression (NO_EFFECT)

Broken by master commit cd29a42.

5 years agoBug 5045: ext_edirectory_userip_acl is missing include files (#624)
Alex Rousskov [Tue, 5 May 2020 22:24:51 +0000 (22:24 +0000)] 
Bug 5045: ext_edirectory_userip_acl is missing include files (#624)

Discovered on FreeBSD v12.1 running on amd64 with clang v8.0.1.

    error: use of undeclared identifier 'AF_INET6'
    error: member access into incomplete type 'struct sockaddr_in6'
    ...

Co-Authored-By: Pavel Timofeev <timp87@gmail.com>
5 years agoBug 5046: FreeBSD lacks open(2) O_DSYNC flag (#623)
Amos Jeffries [Tue, 5 May 2020 13:57:24 +0000 (13:57 +0000)] 
Bug 5046: FreeBSD lacks open(2) O_DSYNC flag (#623)

ext_session_acl built with TrivialDB uses O_DSYNC to ensure
thread-safe manipulation of data within the TDB files in Squid
multi-process environment.

FreeBSD lacks this flag entirely. Use the O_SYNC flag as a
backup, which apparently provides file-level synchronization.
It is not clear whether this flag will prevent duplicate keys or
record overwrites in the case of process write race collisions.

NP: this appears to be FreeBSD specific. Other BSD either define
O_DSYNC or lack support for these POSIX flags entirely.

5 years agoFix IPFilter IPv6 detection, especially on NetBSD (#596)
sborrill [Fri, 1 May 2020 02:26:44 +0000 (02:26 +0000)] 
Fix IPFilter IPv6 detection, especially on NetBSD (#596)

Has been broken since 4eaf432.

1. acinclude/os-deps.m4 was missing sys/param.h header

2. acinclude/os-deps.m4 was incorrectly assuming that netinet/ip_nat.h
   header is always present

3. acinclude/os-deps.m4 was missing netinet/ip_nat.h header where it was
   used instead of ip_nat.h

4. src/ip/Intercept.cc assumed that AC_CHECK_MEMBERS(`struct X`)
   outputs `HAVE_X`, but it actually outputs `HAVE_STRUCT_X`.

5. acinclude/os-deps.m4: AC_CHECK_MEMBERS(`X  `) converted trailing
   whitespace into surprising trailing underscores: `HAVE_X__`

5 years agoAdd --progress option to test-builds.sh (#618)
Francesco Chemolli [Thu, 30 Apr 2020 11:31:11 +0000 (11:31 +0000)] 
Add --progress option to test-builds.sh (#618)

Add an option to test-builds.sh to emit dots
to enable tracking progress in the test without
being fully verbose

In the context of the build farm, this will save storage
and bandwidth on the build nodes, while still showing
issues if anything were to occur, and showing whether
progress is being made or a build is stuck.

5 years agoPreserve caller context in commHandleWriteHelper() (#607)
Eduard Bagdasaryan [Thu, 30 Apr 2020 06:26:05 +0000 (06:26 +0000)] 
Preserve caller context in commHandleWriteHelper() (#607)

This event handler resumes write operations for descriptors,
queued due to delay pool restraints. Before this fix, the enqueuing
code did not save and the dequeuing code did not restore transaction
contexts.

5 years agoAdd missing libsystemd build logic (#616)
Amos Jeffries [Thu, 30 Apr 2020 00:18:42 +0000 (00:18 +0000)] 
Add missing libsystemd build logic (#616)

* "Minimum build" test should run --without-systemd

* Add -lsystemd to linker flags

Completes the changes added in GitHub PR 539 (commit
6fa8c66435d55a2e713db0222cdca3a9dccf5bbe).

5 years agoCleanup: remove urlHostname hacks (#615)
Amos Jeffries [Sat, 25 Apr 2020 06:08:35 +0000 (06:08 +0000)] 
Cleanup: remove urlHostname hacks (#615)

The urlHostname() function and class it uses employ a very dirty
hack to parse a guess at the hostname portion of a URL.

AnyP::Uri objects can be used instead for better parsing of URLs
with far more accurate hostname extraction in a wider set of URI.

5 years agoSslBump: Disable OpenSSL TLSv1.3 support for older TLS traffic (#588)
Christos Tsantilas [Fri, 24 Apr 2020 22:08:23 +0000 (22:08 +0000)] 
SslBump: Disable OpenSSL TLSv1.3 support for older TLS traffic (#588)

This change fixes stalled peeked-at during step2 connections from IE11
and FireFox v56 running on Windows 10 (at least), producing "Handshake
with SSL server failed" cache.log errors with this OpenSSL detail:

`SSL routines:ssl_choose_client_version:inappropriate fallback`

Disabling TLS v1.3 support for older TLS connections is required
because, in the affected environments, OpenSSL detects and, for some
unknown reason, blocks a "downgrade" when a server claims support for
TLS v1.3 but then accepts a TLS v1.2 connection from an older client.

This is a Measurement Factory project

5 years agoStreamline ./configure handling of optional libraries (#606)
Amos Jeffries [Fri, 24 Apr 2020 03:19:02 +0000 (03:19 +0000)] 
Streamline ./configure handling of optional libraries (#606)

Squid macros to simplify most AC_ARG_WITH behaviour.

These macros perform the necessary checks for on/off and
custom library path validation for Squid coding policy.

Usage:
* When the parameter is for a build value rather than a
  library to link. Use AC_ARG_WITH.

* When a library is experimental and should default disable.
   Use SQUID_OPTIONAL_LIB to detect the --with parameter.

* When a library is expected to be available and default enable.
  Use SQUID_AUTO_LIB to detect --without parameter.

Sets pkg-config variables to enable more consistent configure.ac
logic for libraries even if pkg-config is not used or supported
for any specific library.

Fixes several trivial bugs where unnecessary or duplicate
library entries were injected into CXXFLAGS, LDFLAGS and similar.
Followup logic for some libraries is adjusted to inject the
pkg-config variables to retain build behaviour for now.

5 years agoHappy Eyeballs: Do not discard viable reforwarding destinations (#567)
Eduard Bagdasaryan [Thu, 23 Apr 2020 05:12:27 +0000 (05:12 +0000)] 
Happy Eyeballs: Do not discard viable reforwarding destinations (#567)

When HappyConnOpener starts opening two connections, both destinations
are removed from the shared destinations list. As soon as one connection
(X) succeeded, the other destination (Y) was essentially forgotten. If
FwdState, after using X, decided to reforward the request, then the
request was never reforwarded to Y. We now return Y to the list.

Also abort the still-active ConnOpener job upon the termination of its
"parent" HappyConnOpener job. Without an explicit termination, those
abandoned child jobs wasted OS and Squid resources while the OS was
trying to open the requested connection. They would terminate on a
timeout or when the connection was finally opened (and discarded).

Waiting for the child ConnOpener job to end is a useful optimization,
but it remains a TODO. It requires complex accumulation avoidance logic.

Also fixed retrying via FwdState::fail() which could reorder addresses.
It incorrectly assumed that only the prime connections were retried.

5 years agoRemove cache_diff extra binary (#612)
Francesco Chemolli [Tue, 21 Apr 2020 11:49:53 +0000 (11:49 +0000)] 
Remove cache_diff extra binary (#612)

cache_diff is built but not distributed.
squid-users and squid-dev polls have not revealed any users.

5 years agoReduce Pointer refcounting in forwarding (#592)
Amos Jeffries [Mon, 20 Apr 2020 01:06:54 +0000 (01:06 +0000)] 
Reduce Pointer refcounting in forwarding (#592)

Remove temporary Pointer copy which confused Coverity scan
into thinking there is a double-free. Should resolve Issue #1461170
and maybe others.

5 years agoMaintenance: Move sort-includes.pl to scripts/maintenance/ (#599)
Amos Jeffries [Sun, 19 Apr 2020 02:06:34 +0000 (02:06 +0000)] 
Maintenance: Move sort-includes.pl to scripts/maintenance/ (#599)

We will no longer get `changed #include order` notices but will get
`changed: by maintenance/sort-includes.pl` notices, including for
whitespace-only changes.

5 years agoPreserve half-closed transaction context (#605)
Eduard Bagdasaryan [Sat, 18 Apr 2020 10:09:00 +0000 (10:09 +0000)] 
Preserve half-closed transaction context (#605)

The code monitoring half-closed connections (with half_closed_clients
"on") did not save and did not restore transaction contexts.

5 years agoRelease prep for 5.0.2 and 4.11 (#604)
Amos Jeffries [Fri, 17 Apr 2020 01:02:56 +0000 (01:02 +0000)] 
Release prep for 5.0.2 and 4.11 (#604)

5 years agoSupport plugin-style scripts for source format enforcement (#531)
Amos Jeffries [Sat, 11 Apr 2020 18:21:40 +0000 (18:21 +0000)] 
Support plugin-style scripts for source format enforcement (#531)

Allow the source-maintenance script to run arbitrary code or sub-scripts
to perform enforcement of Squid code style and content.

Code placed in the scripts/maintenance/ sub-folder MUST meet the
following criteria:

 * be self-executable,
 * receive filename of the code file to be touched as one and only
   command-line parameter,
 * always dump the file contents to stdout (with or without edits),
 * not depend on any other code in this sub-folder being run first.

5 years agoDocs: fix version typo in wccp_address, wccp2_address directives (#595)
tomofumi-yoshida [Sat, 11 Apr 2020 01:00:00 +0000 (01:00 +0000)] 
Docs: fix version typo in wccp_address, wccp2_address directives (#595)

The descriptions of wccp_address and wccp2_address directives were
reversed.

5 years agoSource Format Enforcement (#579)
squidadm [Fri, 10 Apr 2020 19:10:37 +0000 (19:10 +0000)] 
Source Format Enforcement (#579)

.

5 years agoBug 5036: capital 'L's in logs when daemon queue overflows (#576)
DrDaveD [Thu, 2 Apr 2020 17:58:10 +0000 (17:58 +0000)] 
Bug 5036: capital 'L's in logs when daemon queue overflows (#576)

Varying number of capital 'L's have been observed in access logs
written by the daemon module.  The 'L's corresponded with the
cache log message:

  "queue is too large; some log messages have been lost."

This was caused by the fact that the 'L' command byte was
buffered even when the queue was too large to accept messages.

Deferring buffering the command byte until just before the
message itself is buffered.

5 years agoRestore PURGE miss replies to be "404 Not Found", not "0 Init" (#586)
Christos Tsantilas [Thu, 2 Apr 2020 15:21:28 +0000 (15:21 +0000)] 
Restore PURGE miss replies to be "404 Not Found", not "0 Init" (#586)

Since commit 6956579, PURGE requests resulted in invalid HTTP responses
with zero status code when Store lacked both GET and HEAD entries with
the requested URI.

Also adjusted Http::StatusLine packing code to avoid generating similar
invalid responses in the future (and to attract developer attention to
their presence in the code logic with a BUG message).

This is a Measurement Factory project.

5 years agoFix auth digest refcount integer overflow (#585)
desbma-s1n [Thu, 2 Apr 2020 11:16:45 +0000 (11:16 +0000)] 
Fix auth digest refcount integer overflow (#585)

This fixes a possible overflow of the nonce reference counter in the
digest authentication scheme, found by security researchers
@synacktiv.

It changes `references` to be an 64 bits unsigned integer. This makes
overflowing the counter impossible in practice.

5 years agoTests: Support passing a custom config.cache to test builds (#570)
Francesco Chemolli [Wed, 1 Apr 2020 21:53:47 +0000 (21:53 +0000)] 
Tests: Support passing a custom config.cache to test builds (#570)

usage:

    $ cache_file=/tmp/custom-config.cache ./test-builds.sh \
        --aggressively-use-config-cache \
        --config-cache-file=somefile.ccache
    Already bootstrapped, skipping step
    TESTING: layer-00-default

5 years agoFix clang-10 build [-Wimplicit-int-float-conversion] (#582)
Francesco Chemolli [Mon, 30 Mar 2020 21:22:45 +0000 (21:22 +0000)] 
Fix clang-10 build [-Wimplicit-int-float-conversion] (#582)

Converting std::chrono::nanoseconds::rep to double may lead to rounding
errors [-Wimplicit-int-float-conversion]. Use explicit cast to signal
that we want to ignore those errors in the max-value checking context.

Also polished CheckTimeValue()-related code.

5 years agoBug 5021: Spelling errors fixed by running scripts/spell-check.sh (#578)
mrumph [Sat, 28 Mar 2020 23:44:59 +0000 (23:44 +0000)] 
Bug 5021: Spelling errors fixed by running scripts/spell-check.sh (#578)

5 years agoFix clang-6.0 build on FreeBSD 12 [-Wformat] (#577)
Francesco Chemolli [Sat, 28 Mar 2020 14:09:19 +0000 (14:09 +0000)] 
Fix clang-6.0 build on FreeBSD 12 [-Wformat] (#577)

Cast and print std::chrono:nanoseconds::count() as intmax_t because its
actual type might be larger than the 64 bytes expected by %PRId64.

The problem was not, technically, specific to clang or FreeBSD.

The error message says "long" because %PRId64 is %ld on platforms where
"long" is 64 bits:

    format specifies type 'long' but the argument has type [...]
    'long long' [-Wformat]

5 years agoCreate and preserve code context in peerCountMcastPeers* events (#575)
Eduard Bagdasaryan [Wed, 25 Mar 2020 01:14:35 +0000 (01:14 +0000)] 
Create and preserve code context in peerCountMcastPeers* events (#575)

These event handlers initiate multicast cache peer pinging and collect
multicast statistics for the peer in CachePeer::mcast. Before the fix,
both handlers ran without any context, ignoring the existing
ICP transaction context.

5 years agoBug 5021: Add a script to fix spelling error with codespell (#565)
mrumph [Tue, 24 Mar 2020 14:13:26 +0000 (14:13 +0000)] 
Bug 5021: Add a script to fix spelling error with codespell (#565)

Running scripts/spell-check.sh from the Squid source tree root directory
should fix many spelling errors in a subset of git-controlled files.

This commit excludes the spelling fixes themselves.

5 years agoFtpGateway.cc: fix build on gcc-10 [-Werror=class-memaccess] (#573)
Francesco Chemolli [Sat, 21 Mar 2020 22:18:43 +0000 (22:18 +0000)] 
FtpGateway.cc: fix build on gcc-10 [-Werror=class-memaccess] (#573)

Since a1c06c7, tokens initialization is done by FtpLineToken
constructor, and g++-10 complains about memsetting a nontrivial object:

    clearing an object of non-trivial type [-Werror=class-memaccess]

5 years agoSource Format Enforcement (#571)
squidadm [Thu, 19 Mar 2020 12:13:07 +0000 (12:13 +0000)] 
Source Format Enforcement (#571)

5 years agoBug 5030: Negative responses are never cached (#566)
DrDaveD [Wed, 18 Mar 2020 17:34:45 +0000 (17:34 +0000)] 
Bug 5030: Negative responses are never cached (#566)

Negative caching was blocked by checkCachable().

Since 3e98df2, Squid cached ENTRY_NEGCACHED entries in memory cache
only. Back then, storeCheckSwapable() prevented what later became
ENTRY_NEGCACHED entries from going to disk. The design was obscured by
8350fe9 that renamed storeCheckSwapable() to storeCheckCachable().

Commit 97754f5 violated that (obscured) design by adding a
checkCachable() call to StoreEntry::memoryCachable(), effectively
blocking ENTRY_NEGCACHED entries from the memory cache as well. That
call should have been added, but checkCachable() should not have denied
caching rights to ENTRY_NEGCACHED -- the corresponding check should have
been moved into StoreEntry::mayStartSwapOut().

By removing ENTRY_NEGCACHED from checkCachable(), we now allow
ENTRY_NEGCACHED entries into both memory and disk caches, subject to all
the other checks. We allow ENTRY_NEGCACHED to be cached on disk because
negative responses are fundamentally no different than positive ones:
HTTP allows caching of 4xx and 5xx responses expiring in the future.
Hopefully, the increased disk cache traffic will not be a problem.

5 years agoESI: convert parse exceptions into 500 status response (#411)
Amos Jeffries [Mon, 16 Mar 2020 05:25:42 +0000 (05:25 +0000)] 
ESI: convert parse exceptions into 500 status response  (#411)

Produce a valid HTTP 500 status reply and continue operations when
ESI parser throws an exception. This will prevent incomplete ESI
responses reaching clients on server errors. Such responses might
have been cacheable and thus corrupted, albeit corrupted consistently
and at source by the reverse-proxy delivering them.

5 years agoRemove layer-00-bootstrap from snapshot script (#569)
Amos Jeffries [Sun, 15 Mar 2020 09:16:15 +0000 (09:16 +0000)] 
Remove layer-00-bootstrap from snapshot script (#569)

Bootstrap has been integrated and the layer removed since 395d284.

5 years agoparanoid_hit_validation directive (#559)
Eduard Bagdasaryan [Mon, 9 Mar 2020 19:29:04 +0000 (19:29 +0000)] 
paranoid_hit_validation directive (#559)

This directive controls whether Squid should perform paranoid validation
of cache entry metadata integrity every time a cache entry is hit. The
client transaction experiences a cache miss instead.

This feature does not protect from the corruption that happens while the
hit is being delivered because the validation runs once per client
request when that client request discovers a cache hit. Future versions
may add more checkpoints.

The paranoid hit validation statistics are available by means of several
new cache manager counters, available by mgr:counters, mgr:5min and
mgr:60min requests. The statistics are reported only when
paranoid_hit_validation is enabled.

5 years agoPreserve caller context across tunnelDelayed*Read (#560)
Eduard Bagdasaryan [Mon, 9 Mar 2020 18:11:12 +0000 (18:11 +0000)] 
Preserve caller context across tunnelDelayed*Read (#560)

tunnel.cc code approximates delay pools functionality using event.h API
that is not meant for transaction-specific events. We (temporary) add a
transaction context data member to TunnelStateData until the class
switches to using transaction-specific deferred reads API.

5 years agoCleanup: cf_gen code updates (#558)
Amos Jeffries [Fri, 6 Mar 2020 18:40:43 +0000 (18:40 +0000)] 
Cleanup: cf_gen code updates (#558)

* cf_gen: fix obsolete yoda stye comparison

* cf.data.pre: replace NOCOMMENT_START/END with
  clearer CONFIG_START/END tags

* cf_gen: fix special class constructor/destructors
     * Comply with the 'Big Three / Big Five' rule.
     * Use C++11 initialization for class Entry member
     * Remove unnecessary entries in constructor lists

* cf_gen: use C++11 ranged-for loops

5 years agoSupply ALE to request_header_add/reply_header_add (#564)
Christos Tsantilas [Wed, 4 Mar 2020 16:26:01 +0000 (16:26 +0000)] 
Supply ALE to request_header_add/reply_header_add (#564)

Supply ALE to request_header_add and reply_header_add ACLs that need it
(e.g., external, annotate_client, and annotate_transaction ACLs). Fixes
"ACL is used in context without an ALE state" errors when external ACLs
are used in the same context (other ACLs do not yet properly disclose
that they need ALE).

Also provides HTTP reply to reply_header_add ACLs.

This is a Measurement Factory project.

5 years agoChange time_units test to also work on 32bit systems (#563)
Francesco Chemolli [Mon, 2 Mar 2020 16:00:49 +0000 (16:00 +0000)] 
Change time_units test to also work on 32bit systems (#563)

With a 64-bit maximum value, "make check" failed on 32-bit platforms
(e.g., arm7l) with:

    configuration error: directive supports time values up to 2147483647
    but is given 9223372036 seconds

5 years agoBan reserved annotations in "note", "adaptation_meta" directives (#561)
Christos Tsantilas [Sat, 29 Feb 2020 11:37:02 +0000 (11:37 +0000)] 
Ban reserved annotations in "note", "adaptation_meta" directives (#561)

Squid defines a list of names used internally for exchanging name=value
pairs with various helpers. When Squid receives a name=value pair with a
reserved name, Squid stores it as if it was any other annotation; the
information can be checked with a "note" ACL and logged with %note. An
admin who configures a custom annotation with the same reserved name may
see strange/unexpected results such as seemingly corrupted access.log
record fields and mismatching ACLs.

Squid already prohibits reserved annotation names in
annotate_transaction and annotate_client ACLs. This change adds the
missing protection to the "note" and adaptation_meta directives.

This is a Measurement Factory project

5 years agoBug 4796: comm.cc !isOpen(conn->fd) assertion when rotating logs (#474)
Eduard Bagdasaryan [Sat, 29 Feb 2020 05:59:35 +0000 (05:59 +0000)] 
Bug 4796: comm.cc !isOpen(conn->fd) assertion when rotating logs (#474)

This long-term solution overrides the short-term fix at 2cd72a2. Now,
debug.cc correctly maintains meta information associated with its file
descriptors.

IMO, the correct place for calling _db_init() is just after locking the
PID file because we want to log ASAP, but cache.log is a common resource
that requires protection. Thus, the two old _db_init() calls were both
excessive and misplaced:

* The first call happens too early, allowing another Squid instance to
  pollute cache.log with messages unrelated to the cache.log-owning
  instance (e.g., a "FATAL: Squid is already running" message when
  attempting to start another instance).

* The second call happens too late, missing earlier debugs() that ought
  to be written into cache.log (e.g., debugs() in comm_init()).

Fixing _db_init() calls led to adjustments like moving mainSetCwd() to
be called prior to the relocated _db_init(). However, these changes
should not affect chroot-sensitive code such as UseConfigRunners().

Some early debugs() messages are no longer written into cache.log:

* Exception messages like "Squid is already running" emitted by another
  Squid instance. This is an improvement: Messages about other instances
  do not belong to the cache.log locked by the running instance.

* Messages (mostly errors and warning) from "finalizeConfig" callers
  (e.g., "WARNING: mem-cache size is too small..."). This loss is
  regrettable. Long-term, these messages should be reported after
  configuration is finalized (TODO). Delayed reporting will also help
  when Squid starts rejecting invalid reconfigurations.

* Messages from a few early enter_suid()/leave_suid() calls, such as
  "enter_suid: PID" and "leave_suid: PID". This is an improvement: These
  debugging messages pollute cache.log.

* A few early SquidMain() messages emitted between parseConfigFile() and
  StartUsingConfig() (e.g., "Doing post-config initialization"). This is
  an improvement: These debugging messages pollute cache.log.

Also removed outdated 'TEST_ACCESS' hack for simplicity sake.

Also marked an old XXX: Chrooted SMP master process does not db_init().

5 years agoBug 5022: Reconfigure kills Coordinator in SMP+ufs configurations (#556)
DrDaveD [Fri, 21 Feb 2020 05:12:04 +0000 (05:12 +0000)] 
Bug 5022: Reconfigure kills Coordinator in SMP+ufs configurations (#556)

In these unsupported SMP+ufs configurations, depending on the deployment
specifics, the Coordinator process could exit due to swap state file
opening errors:

    kid11| FATAL: UFSSwapDir::openLog: Failed to open swap log.

5 years agoHigh precision time units (#443)
Eduard Bagdasaryan [Thu, 20 Feb 2020 21:13:27 +0000 (21:13 +0000)] 
High precision time units (#443)

This patch introduces new time units of microsecond and
nanosecond precision forming a new 'time-units-small' category.

Also found and fixed several problems, related to time parameters
parsing:

* Obscure "integer overflow" fatal messages. For example, passing
  "0.0001 second" caused this message. After fixing, Squid reports
  that the value "is too small to be used in this context".

* Ignoring possible zero-rounded values after parsing. For example, if
  a second-precision parameter was configured with 0.1 second, it
  became zero after rounding, which is unexpected. It is treated
  as a fatal error now.

* Inconsistent parameter overflow type. For example, parameters
  with millisecond and second precision reported that 'time_msec_t'
  overflowed. Now we introduce an absolute time maximum allowed,
  equal to the maximum of chrono::nanoseconds type which is about
  293 years. This absolute maximum allows to keep the time parsing
  code simple and at the same time should satisfy any reasonable
  configuration need. Note that this solution treats existing
  configurations with unreasonably huge time values > 293 years
  as fatal errors, such configurations should be fixed accordingly.

* Time overflows for icap_service_failure_limit parameter were not
  checked at all. This is probably a result of code duplication.
  By fixing the latter problem, the former one was resolved
  automatically.

* Unclear fatal message if a time parameter lacked time unit. Now
  Squid reports about "missing time unit".

* Improved error reporting when an inapplicable time unit was used, for
  example a 'millisecond' instead of a 'second'. For the majority of
  time parameters, it reported only a common "FATAL: Bungled..."
  message. For url_rewrite_timeout parameter, it reported an irrelevant
  "unsupported option ..." message (since it began to treat the faulty
  time unit as the next option). Now in both cases it reports about the
  underlying time unit problem.

While fixing these bugs I had to refactor and improve time parsing
functions, using safer std::chrono types instead of raw integer types.

5 years agoSupport worker-dedicated listening queues (SO_REUSEPORT) (#369)
Eduard Bagdasaryan [Tue, 18 Feb 2020 20:45:00 +0000 (20:45 +0000)] 
Support worker-dedicated listening queues (SO_REUSEPORT) (#369)

This performance optimization has a few cons, including security
concerns, but it improves CPU core utilization/balance in many SMP
environments and is supported by many high-performance servers. Enabled
by the new `*_port worker-queues` configuration option.

Worker-dedicated listening queues reduce client-worker affinity for
requests submitted over different TCP connections. The effect of that
reduction on Squid performance depends on the environment, but many busy
SMP proxies handling modern traffic should benefit.

TODO: Linux tests show load balancing effects of SO_REUSEPORT, but
untested FreeBSD probably needs SO_REUSEPORT_LB to get those effects.

Recommended reading:
* https://blog.cloudflare.com/the-sad-state-of-linux-socket-balancing/
* https://lwn.net/Articles/542629/
* https://stackoverflow.com/a/14388707

5 years agoRemove 8K limit for single access.log line (#332)
Daris A Nevil [Tue, 18 Feb 2020 14:26:06 +0000 (14:26 +0000)] 
Remove 8K limit for single access.log line (#332)

The function logfilePrintf() currently limits a single line
to no more than 8K characters.  It allocates an 8K buffer
on the stack, which is not safe. This PR eliminates
the 8K limit, and moves the buffer to the heap.

5 years agoTest suite: move bootstrap to the main test script (#555)
Francesco Chemolli [Tue, 18 Feb 2020 07:05:50 +0000 (07:05 +0000)] 
Test suite: move bootstrap to the main test script (#555)

* Refactor test suite: move bootstrap from being a fake test layer to explicit command

* Refactor test suite: move bootstrap from being a fake test layer to explicit command

5 years agoRemove pointer from the input of Digest nonce hashes (#549)
squidcontrib [Wed, 29 Jan 2020 06:10:04 +0000 (06:10 +0000)] 
Remove pointer from the input of Digest nonce hashes (#549)

This is a follow-up to #491 (b20ce97), which hashed what was previously
revealed as plaintext. Removing the pointer from the input to the hash
removes the possibility that someone could recover a pointer by
reversing a hash. Having the pointer as input was not adding anything:
Squid remembers all outstanding nonces, so it really only requires
uniqueness, which is already guaranteed by the
authenticateDigestNonceFindNonce loop.