[bug]: Known TLV records in lnwire decode with the wrong length and shift the stream
I maintainer di solito rispondono entro 1 giorno
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Idoneità per principianti
- 74/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Attiva
- Stack tecnologico
- go
- Ambito
- networking
Direzione di ricerca
Start at tlv/stream.go:238-250, where the stream hands a record to its decoder without bounding the reader to length or checking bytes consumed, then read the three offending decoders: lnwire/msat.go decodeMilliSatoshis, lnwire/node_announcement_2.go rgbDecoder, and lnwire/channel_update_2.go booleanDecoder. Decide whether to enforce the invariant centrally in the stream decoder or per-decoder (the fixed-size decoders already self-check), and check tlv/primitive.go DBigSize and tlv/record.go MakeBigSizeRecord. Done means all four hex inputs in the issue make lnwire.ReadMessage fail with a parse error while existing lnwire and tlv tests still pass — verify with the Go repro program in the issue body.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Description
The lnwire TLV stream decoder calls each known record's decoder with the
declared length but does not check that the decoder consumed exactly
length bytes. Three record decoders consume a different number of bytes than
the record declares:
MilliSatoshi(lnwire/msat.go:76-92,decodeMilliSatoshis) calls
tlv.DBigSize, which reads one BigSize value and ignoresl.
tlv/record.go:276-293(MakeBigSizeRecord) behaves the same for
BigSizeTrecords. This affectschannel_update_2types 12 and 14,
dyn_committypes 2 and 4, anddyn_proposetypes 2 and 4.Color(lnwire/node_announcement_2.go:346-352,rgbDecoder) always reads
3 bytes regardless ofl.TrueBoolean(lnwire/channel_update_2.go:457-466,booleanDecoder)
returns success forl == 0 || l == 1and never reads the reader.
tlv/stream.go:238-250 continues at the reader's actual position after the
decoder returns, so any byte the decoder did not consume is reparsed as the
next record's type. A message that BOLT 1 requires the receiver to fail to
parse instead decodes as a different message.
The fixed-size primitive decoders check the declared length themselves.
Existing length-validation tests cover those decoders and cannot reach the
three decoders above. The MilliSatoshi and BigSizeT decoders read
variable-length values from lnwire/msat.go and the tlv primitive and
ignore the record length, and the Color and TrueBoolean decoders live in
the two gossip-v2 message files, so length validation remains incomplete for
all four messages listed below.
Steps to reproduce
Each input below is a complete message in hex.
010d0102010203 node_announcement_2, Color length 2
010d01040102030421abababababababababababababababababababababababababababababababab
node_announcement_2, Color length 4, then NodeID record
010f0c03010d00 channel_update_2, MilliSatoshi length 3
010f08010a020001 channel_update_2, TrueBoolean length 1, then CLTV record
package main
import (
"bytes"
"encoding/hex"
"fmt"
"github.com/lightningnetwork/lnd/lnwire"
)
func main() {
inputs := []string{
"010d0102010203",
"010f0c03010d00",
"010f08010a020001",
}
for _, in := range inputs {
b, _ := hex.DecodeString(in)
msg, err := lnwire.ReadMessage(bytes.NewReader(b), 0)
fmt.Printf("%s err=%v msg=%T\n", in, err, msg)
}
}
Observed:
010d0102010203 err=<nil> msg=*lnwire.NodeAnnouncement2
010f0c03010d00 err=<nil> msg=*lnwire.ChannelUpdate2
010f08010a020001 err=<nil> msg=*lnwire.ChannelUpdate2
All three malformed messages decode without error. In the first input the
Color record declares length 2, the decoder consumes 3 bytes, and the stream
still ends clean. In the second and third inputs the decoder consumes fewer
bytes than declared, and the leftover bytes are parsed as further TLV records
(type 4 NodeID with length 0x21, type 10 CLTV with length 2).
Expected behavior
BOLT 1 (01-messaging.md, Type-Length-Value Format, receiving node rules):
if
typeis known:
- MUST decode the next
lengthbytes using the known encoding fortype.- if
lengthis not exactly equal to that required for the known encoding
fortype:
- MUST fail to parse the
tlv_stream.
A conforming reader fails the parse for all four inputs. The current reader
accepts them and changes the parsed message.
Root cause
tlv/stream.go:238-250 hands the record to its decoder but neither bounds the
reader to length nor verifies that the decoder consumed exactly that many
bytes. Three decoders do not consume length bytes:
lnwire/msat.go:76-92(decodeMilliSatoshis) relies on
tlv.DBigSize(tlv/primitive.go:356-376), which reads one varint and
ignoresl;tlv/record.go:276-293(MakeBigSizeRecord) is the same for
BigSizeT.lnwire/node_announcement_2.go:346-352(rgbDecoder) reads R, G, B with
ReadElementsand ignoresl.lnwire/channel_update_2.go:457-466(booleanDecoder) returns success for
l == 0 || l == 1and never reads the reader.
The fixed-size decoders check l themselves, so the invariant depends on each
decoder implementation rather than on the stream decoder.
- Lingua principale
- Go
- Stelle
- 8.2k
- Fork
- 2.3k
- Merge medio
- 1g 11h
- PR unite (30g)
- 103
Preparare l'ambiente
- Include un Dockerfile o un file Docker Compose
- Ha un modello di pull request
- Nessuna guida per i contributori
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di lightningnetwork/lnd
-
funding: failure logs print `<nil>` error and zero channel IDForse già presa @litbot-9000 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 90/100
lightningnetwork/lnd#11676 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 Mezza giornata Idoneità per principianti 85/100
lightningnetwork/lnd#11674 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
lightningnetwork/lnd#11672 ·
I maintainer di solito rispondono entro 1 giorno
-
test flake
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
lightningnetwork/lnd#11663 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
-
[flake]: lnwallet/test/bitcoind.TestLightningWalletBitcoindRPCPolling/spend_unconfirmed_outputsApertatest flake
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
lightningnetwork/lnd#11642 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno
Tutte le issue di lightningnetwork/lnd
Issue simili
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
I maintainer di solito rispondono entro 1 giorno
-
ConcatAgenticMessages loses the approval request ID of a streamed MCP tool callForse già presa @ningsiyuan1024 l’ha presa oggi. Aperta
Difficoltà 2/5 1-3 ore Idoneità per principianti 86/100
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 74/100
containers/gvisor-tap-vsock#796 ·
I maintainer di solito rispondono entro 2 giorni
-
external needs:triage
Difficoltà 2/5 1-3 ore Idoneità per principianti 68/100
celestiaorg/celestia-node#5448 ·
I maintainer di solito rispondono entro 1 giorno