A gossiped block can end the node process: no recover on the block ingestion goroutine
Report
Area: State chain and multisig governance / P2P
Suggested tier: Medium (2,500 XE). Policy row: "Validation, accounting & load edge cases: validation gap". Read the overlap note below before assigning.
Version tested: 978785929bc17a2f4ab30c383e5fc9cf4d634512 (HEAD)
CWE: CWE-248 (Uncaught Exception), CWE-400
Overlap note, read this first
The concrete panic I used to reach the crash, pk[:12] in core/multisig.go:99,
is already covered by the open PR #7, which replaces it with shortHash(pk).
shortHash at core/ledger.go:2711 checks the length before slicing, so once PR
#7 merges the slice panic is gone and the executable path I describe below with
it.
So the panic itself is not novel, and I am not claiming it as such. What PR #7
does not change is the reason that panic killed the process instead of one
message: the goroutine that ingests gossip blocks has no recover, and the
gossip block validator never checks that signatures[].public_key is a
well-formed 64 character hex string. Either of those alone turns the next panic
on that path into a process exit.
If you treat the slice panic as the whole finding, this is a duplicate of PR #7
and I would rather you close it than pay for it. If you treat the missing
recover and the validator gap as separate defects, they are unfixed by every
open PR and this is a validation gap worth fixing before the next crash lands
there.
Summary
Any libp2p peer can kill the entire node process with one gossiped block, and needs no account, balance, XUSD or valid key material to do it.
Three defects cover for each other:
core/multisig.go:99slicessignatures[].public_keyto twelve characters with no length check. A five character string panics.net/gossip_validate.go:63does not validatepublic_keylength, so the malformed block passes gossip validation and is accepted asValidationAccept.node/node.go:570runshandleIncomingin a goroutine with norecover, so a panic there ends the process, while the same panic over HTTP only ends one request.
The third point is what separates this from the ordinary HTTP panic. Through
POST /blocks/multisig_open, net/http recovers per connection and the node
survives. Through gossip, nothing catches it.
Evidence
The victim was built from the audited source with the testnet-0005 genesis and
no other peers. The attacker is a separate process importing the net and
core packages from the same repo, so handshake and framing match a real node.
victim pid=1291925
BEFORE health=200
victim multiaddr: /ip4/127.0.0.1/tcp/29711/p2p/12D3KooWGgkhY5EXnz9xCVEee4UNAMFPMVe8SzqpQNgwwdn4ChMs
attacker peer id: 12D3KooWJdW3QwvrjNjA9RwcsiXxQShmvKrDpWR9ajt6FZ6FKiYT
connected to victim: 12D3KooWGgkhY5EXnz9xCVEee4UNAMFPMVe8SzqpQNgwwdn4ChMs
netcheck: handshake answered
peers on topic: 1
block: hash=72b72e2815... pk="abcde" (len 5)
PoW nonce=3770910114026266168 (difficulty 0xfffff80000000000)
publish attempt 1 (peers=1) ... PUBLISHED
DIAGNOSTIC: gossipsub delivered the message — topic path is live
AFTER health=000
PROC=DEAD
panic count: 1
handleIncoming in stack: 1
Stack trace showing the gossip path rather than the HTTP path:
panic: runtime error: slice bounds out of range [:12] with length 5
goroutine 228 [running]:
github.com/xeprotocol/xe/core.VerifyMultisig({0x33d531297440, 0x40}, {0x33d52babdbe0, 0x1, 0x7f6da10a24e8?}, 0x33d52babdbc0)
/root/xe-src/core/multisig.go:99 +0x70e
github.com/xeprotocol/xe/core.(*Ledger).verifyBlockCredential(0x33d52ba96000, 0x33d52bcf0820)
/root/xe-src/core/ledger.go:1436 +0x219
github.com/xeprotocol/xe/core.(*Ledger).addBlock(0x33d52ba96000, 0x33d52bcf0680, 0x0)
/root/xe-src/core/ledger.go:801 +0x9df
github.com/xeprotocol/xe/core.(*Ledger).AddBlock(...)
/root/xe-src/core/ledger.go:732
github.com/xeprotocol/xe/node.(*Node).handleIncoming(0x33d52b908788, 0x33d52ba03dc0)
/root/xe-src/node/node.go:711 +0xd2
github.com/xeprotocol/xe/node.New.func25()
/root/xe-src/node/node.go:570 +0x72
created by github.com/xeprotocol/xe/node.New in goroutine 1
node.New.func25 at node/node.go:570 is
go func() { defer n.wg.Done(); n.handleIncoming(...) }(). There is no recover
in that goroutine or inside handleIncoming.
How the block gets past the gossip filter
net/gossip.go:150 drops blocks where len(b.Signature) != 128:
b := bm.Block
if len(b.Hash) != 64 || len(b.Signature) != 128 || len(b.Account) != 64 {
continue
}
A multisig block does not use the single Signature field, so it arrives empty
and the filter drops it. That does not stop an attacker, because Signature is
not part of the hash. MarshalBlockCanonical and MarshalBlockAux never write
b.Signature, so filling that field with 128 junk characters leaves the hash and
the proof of work valid and the block passes.
Confirmed both ways: with an empty Signature the node survives because the
filter drops the block, and with 128 junk characters the node dies.
What I did not prove
- Execution against a live testnet node. That would take a public node down and
spread through the mesh. All evidence comes from nodes built from the audited
commit with the same
testnet-0005genesis. - That the live binaries are byte-identical here. Live reports
xe/92d83d1, a commit that is not in the public repo. Howevercore/multisig.goandnet/gossip.gohave not changed sincea47b973(testnet-0003), andcore/multisig.gowas last touched bye5e65ba(testnet-0005), so the logic at all three points is the same live. - Any path to stealing funds. This is availability only.
Controls
- A block with a correctly sized
public_key(64 hex) does not panic; it is rejected withsigner ... not in keyset. - The malicious block with an empty
Signatureleaves the node alive because the gossip filter drops it. That shows the filter works and that the panic comes from the block contents rather than from publishing. - An attacker without a
/xe/netcheck/1implementation gets its connection closed and the node survives. That shows the handshake has to be passed, and that netcheck does not reject a peer for having no credentials.
Fix
- Add
recoverto the goroutine atnode/node.go:570and tospawnGate.spawn, so a panic while replaying a block fails one round instead of ending the process. - In
blockValidator, reject any block whoseSignaturescontain apublic_keythat is not 64 hex characters, so malformed blocks die at gossip validation and never reach the ledger. - Validate
signatures[].public_keyinVerifyMultisigandVerifyMultisigAnybefore use. - Replace the remaining
pk[:12]uses with a length safe helper such asshortHash. PR #7 already does this one.
Prior art
I read the body of every open issue and the actual patch of every open PR.
PR #7 replaces the three pk[:12] uses in core/multisig.go with shortHash,
which is the slice panic. Its net/gossip_validate.go change only swaps the
certificate validator, not blockValidator. Its node/node.go change only adds
isHostedChatRecipient for chat. It does not add a recover to the gossip
goroutine.
PR #9 changes net/gossip.go only by lowercasing the vote dedup key in
enqueueVote. The len(b.Signature) != 128 filter at line 150 is untouched.
PR #5 and PR #11 do not touch the gossip path at all.
Searching every issue body for recover returns one hit, "unrecoverable keyset"
in issue #6, which is about lost keys rather than a recover() for a panic. No
issue reports a goroutine without recover.
Thread
Nothing public yet.