Skip to content

Backport four Bitcoin Core 30.4/30.5 advisory fixes: TCP urgent data, 64-bit file positions, paused send timeout, duplicate INVs - #296

Merged
cdonnachie merged 6 commits into
mainfrom
fix/core-advisory-backports
Nov 28, 2026
Merged

cdonnachie merged 6 commits into
mainfrom
fix/core-advisory-backports

Conversation

@cdonnachie

Copy link
Copy Markdown
Member

Four network and storage fixes from Bitcoin Core 30.4 and 30.5, each published there with a security advisory, and the follow-up to the first. Avian 5.x is based on 30.2 and had none of them. One commit per upstream change, with Github-Pull and Rebased-From lines.

Independent of #295: the two touch different files, and the release notes are added in different places.

What is taken, and what it means for Avian

Bitcoin Core Advisory Change On Avian
#36665 (30.4) and #36716 (master) CVE-2026-117350 The select() backend put every socket in the exception set. TCP urgent data on a peer whose receive side was paused showed as an error event, the handler read on, and what it read was kept without bound. Applies to Windows and macOS nodes, which use select(). Linux uses poll() and was not affected. This is the one that matters.
#36669 (30.4) CVE-2026-117346 Positions in block and undo files were 32 bits wide. An undo file has no size cap; past 4 GiB the position wrapped, and on Windows fseek() failed from 2 GiB. Applies. It takes a miner building blocks with very large undo data. Nothing on disk changes: positions are stored as varints.
#36667 (30.4) CVE-2026-117349 A peer that has kept the send buffer full for 20 minutes is disconnected. The published route needs a peer too old to answer pings. Avian refuses peers below protocol version 70033, so that route is closed here. Taken as an explicit bound.
#35878 (30.5) CVE-2026-117348 An inv message is handled once per transaction it names, however often it names it. The published stall needs a wtxid announcement of an orphan. Avian does not negotiate wtxid relay and ignores such announcements, so it is not reachable today. It would be once wtxid relay is turned on.

Differences from upstream

  • #36716 is not in the 30.x branch yet (it is marked for backport there). It is ported by hand to the 30.x event names (RECV, SEND, ERR). Without it, the first fix leaves a busy loop: a socket waited on for reading with urgent data pending wakes the handler every time with nothing to read. The Stratum v2 listener, which disconnects a client on ERR, now finds a broken connection through recv() on Windows and macOS, as the P2P handler does.
  • #36669 needed one line of Avian's own: BlockManager::ReadRawBlock() computed the header position with a brace-initialized int64_t, which does not take a uint64_t.
  • #35878: the functional test of the upstream change is left out. Its main cases need wtxid relay, and the functional suite is not localized.

How it was checked

Built and run in WSL (clang 18). Nothing was run on Windows or macOS.

  • Unit tests: 167 of 168 suites pass; script_assets_tests is skipped locally for want of its data directory. The new sock_tests/wait_ignores_urgent_data goes through select() in the macOS CI job.
  • Urgent data, on the select() path: sock.cpp built for select() on Linux, with one more check added for the test run: a wait for sending only, as for a paused peer, must not report an error.
Code Wait for sending only Wait for reading
5.0.6 reports the urgent byte reports the urgent byte
with #36665 clean reports the urgent byte
with #36665 and #36716 clean clean
  • Duplicate announcements: the txid cases of the upstream test, run against a regtest node with the framework's P2P layer set to Avian's magic and protocol version. One "got inv" per transaction with this change, also for 50,000 copies of one txid; two on the 5.0.6 build.
  • File positions: the files that handle them, compiled with -Wshorten-64-to-32 before and after: no place where a position is cut back to 32 bits, and three such places gone.
  • Windows-only lines (_fseeki64, _ftelli64, _chsize_s, the select() branch): -fsyntax-only with mingw-w64 passes for fs_helpers.cpp, streams.cpp, flatfile.cpp and sock.cpp. CI has no Windows job, so the Guix build is the first full compile of them.

Not tested: the send buffer timeout, and the attack of the first advisory against a running node.

The select() backend, which Windows and macOS use, put every socket into
the exception set, whatever was asked of it. A peer whose receive side is
paused is waited on for sending only, and TCP urgent data then showed as an
error event; the socket handler reads on an error event, so the pause did
not hold and what was read was kept without bound. poll(), which Linux
uses, has no such case.

The exception set is now filled only for a socket that is waited on for
reading, and a socket nothing is asked of is left out of the call.

Backport of Bitcoin Core 30.4 commit d4a065bf0fab, by Antoine Poinsot.

Github-Pull: bitcoin/bitcoin#36665
Rebased-From: 1e0c407377034e9cbb4d52f1f534c06cdf202a36
After the change before this one a socket waited on for reading is still in
the exception set of select(). With urgent data pending on it the wait
returns at once, every time, with nothing for recv() to return: the socket
handler spins for as long as the byte is there.

Windows needs the exception set for one thing, a failed non-blocking
connect(), which it reports nowhere else. So ERR becomes an event that can
be asked for, ConnectToSocket() asks for it, and every other wait leaves the
set empty. With select() a socket waited on without ERR no longer reports
exceptional conditions; a closed or failed connection is seen by the read
that follows, as before. No change with poll().

The Stratum v2 listener disconnects a client on ERR. On Windows and macOS it
now finds a broken connection through recv(), like the P2P handler.

A unit test sends an urgent byte and checks that a wait for reading does
not report an error. Run on Linux with sock.cpp built for select(): it fails
on the code as it was and on the change before this one, and passes here.

Port of Bitcoin Core commit 97e3c9562, by Cory Fields, Vasil Dimov and
Antoine Poinsot, to the event names of 30.x.

Github-Pull: bitcoin/bitcoin#36716
Rebased-From: 97e3c9562291f5bbc2b03fef1c70e4975eb2a8c6
A position in a block or undo file was an unsigned int. Block files are
capped at 128 MiB, undo files are not: the undo data of the blocks of one
block file go into one undo file, and blocks that spend many large outputs
have far more undo data than block data. Past 4 GiB the position wrapped,
and on Windows fseek() takes a 32-bit long and failed from 2 GiB.

The position, the sizes kept per file and the offsets in the block index
are 64 bits wide, and seeking and truncating use the 64-bit calls on
Windows. Positions are written as varints, so nothing on disk changes.

Avian's own part: ReadRawBlock() computed the header position with a
brace-initialized int64_t, which does not take a uint64_t; it casts now.
Compiling the files that handle these positions with -Wshorten-64-to-32
before and after shows no place where a position is cut back to 32 bits.

Backport of Bitcoin Core 30.4 commits adb363c753ee and a9e7b35d06af, by
Antoine Poinsot.

Github-Pull: bitcoin/bitcoin#36669
Rebased-From: 17556cb1f52fcbc807f65245101f72e8ec1573d8
Rebased-From: 48092a9042d8fcfd6bb7ae5911a1d53b8746d546
A peer that does not read leaves the send buffer over its limit, and the
node stops queueing replies for it but goes on queueing announcements. The
time the buffer went over the limit is now kept, and a peer that has not
brought it back under within 20 minutes is disconnected.

In Bitcoin Core the peer that could stay in that state was one too old to
be asked for a pong. Avian refuses peers below protocol version 70033, all
of which answer pings, so the ping timeout already ends such a connection
here. The change is taken to keep the bound explicit and the code in step
with 30.x.

Backport of Bitcoin Core 30.4 commit 96b53721763e, by Antoine Poinsot.

Github-Pull: bitcoin/bitcoin#36667
Rebased-From: cc2534cdf7b14d0f1a18928ebaab7f7fdd7e839e
An inv message may name the same transaction up to 50,000 times, and each
entry was handled as if it were new. Entries are now passed over once their
hash has been seen in the message, txids and wtxids apart.

In Bitcoin Core the costly case is a wtxid announcement of an orphan, which
looks at every missing parent each time. Avian does not negotiate wtxid
relay and ignores wtxid announcements, so that path is not reached today;
it would be once wtxid relay is turned on.

The functional test of the upstream change is left out: it needs wtxid
relay, and the functional suite is not localized. Its txid cases were run
against a regtest node with the P2P layer of the framework set to Avian's
magic and version: one announcement per transaction with this change, two
on 5.0.6.

Backport of Bitcoin Core 30.5 commit 1bb5289d48c1, by Gregory Sanders.

Github-Pull: bitcoin/bitcoin#35878
Rebased-From: 1278a5970d5ada0979052a5bad899e896b8ab40b
@cdonnachie
cdonnachie merged commit 39d5a6c into main Nov 28, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant