Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

crypto: relax failure message length check #59

Merged

Conversation

joostjager
Copy link
Contributor

The spec does not dictate but only recommends a length of 256 bytes. Future tlv extensions may push the failure message length over this limit. With this change, receivers can ignore the lengthier extensions without handling it as an unreadable failure.

@@ -250,9 +250,9 @@ func (o *OnionErrorDecrypter) DecryptError(encryptedData []byte) (
*DecryptedError, error) {

// Ensure the error message length is as expected.
if len(encryptedData) != onionErrorLength {
if len(encryptedData) < minOnionErrorLength {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To avoid a dos vector of trying to read very very large messages, should there be an upper limit? Or is that handled by the wire message size limits

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think lightning-onion is the place to do it, as this is all independent of the wire message format.

But good question. I'd say there are checks higher up. Found this one (casting to uint16), but not sure if there are more:
https://github.com/lightningnetwork/lnd/blob/59a5f53cfe8b43b9caa70b5244dce4cd6813c042/brontide/noise.go#L869

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this'll be bounded ultimately by what can fit into a single p2p message (65 KB). We can add more constraints on the parsed error itself on the link level.

@halseth
Copy link

halseth commented Oct 12, 2022

With his change we'll only check that the length is above some minimum.

Is that independent to the spec change proposed here: lightning/bolts#1021 ? As that's only about what the sender should do. (so we can't enforce that the read error is exactly 1024 bytes)

@joostjager
Copy link
Contributor Author

It is independent. We should already have allowed variable length failure messages.

Copy link

@halseth halseth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 👍

@joostjager
Copy link
Contributor Author

joostjager commented Oct 12, 2022

Wondering now, should the minimum check be removed too? If we'd receive a shorter failure message today, wouldn't we want to locate the error source and parse the message?

On the other hand, failure messages shorter than 256 bytes may complicate the implementation in lnd: lightningnetwork/lnd#6913 (comment)

@halseth
Copy link

halseth commented Oct 19, 2022

Wondering now, should the minimum check be removed too? If we'd receive a shorter failure message today, wouldn't we want to locate the error source and parse the message?

I would say we should keep it for now. It would be valuable to check what other implementations are doing; if they all send (at least) 256 bytes, we could make this required in the spec.

@joostjager
Copy link
Contributor Author

Updated spec: lightning/bolts#1021 (comment)

Copy link

@carlaKC carlaKC left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

crypto.go Outdated Show resolved Hide resolved
The spec does not dictate but only recommends a length
of 256 bytes. Future tlv extensions may push the failure
message length over this limit. With this change,
receivers can ignore the lengthier extensions without
handling it as an unreadable failure.
@joostjager joostjager force-pushed the relax-failure-len-check branch from 8b364a6 to d83e7f0 Compare December 1, 2022 07:49
Copy link
Member

@Roasbeef Roasbeef left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM 🌳

@@ -250,9 +250,9 @@ func (o *OnionErrorDecrypter) DecryptError(encryptedData []byte) (
*DecryptedError, error) {

// Ensure the error message length is as expected.
if len(encryptedData) != onionErrorLength {
if len(encryptedData) < minOnionErrorLength {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this'll be bounded ultimately by what can fit into a single p2p message (65 KB). We can add more constraints on the parsed error itself on the link level.

@Roasbeef Roasbeef merged commit ca23184 into lightningnetwork:master Dec 2, 2022
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.

5 participants