Skip to content

Correctly handle BADONION onion errors #1703

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

Merged

Conversation

TheBlueMatt
Copy link
Collaborator

Currently we entirely ignore the BADONION bit when deciding how to handle HTLC failures. This opens us up to an attack where a malicious node always fails HTLCs backwards via
update_fail_malformed_htlc with an error code of BADONION|NODE|PERM|X. In this case, we may decide to interpret this as a permanent node failure for the node encrypting the onion, i.e. the counterparty of the node who sent the
update_fail_malformed_htlc message and ultimately failed the HTLC.

Thus, any node we route through could cause us to fully remove its counterparty from our network graph. Luckily we do not do any persistent tracking of removed nodes, and thus will re-add the removed node once it is re-announced or on restart, however we are likely to add such persistent tracking (at least in-memory) in the future.

This probably needs test updates.

@codecov-commenter
Copy link

codecov-commenter commented Sep 7, 2022

Codecov Report

Merging #1703 (befbfe9) into main (301efc8) will increase coverage by 0.75%.
The diff coverage is 96.00%.

❗ Current head befbfe9 differs from pull request most recent head e6a3c23. Consider uploading reports for the commit e6a3c23 to get more accurate results

@@            Coverage Diff             @@
##             main    #1703      +/-   ##
==========================================
+ Coverage   90.92%   91.67%   +0.75%     
==========================================
  Files          86       86              
  Lines       46417    52678    +6261     
  Branches    46417    52678    +6261     
==========================================
+ Hits        42204    48294    +6090     
- Misses       4213     4384     +171     
Impacted Files Coverage Δ
lightning/src/ln/functional_tests.rs 97.79% <95.65%> (+0.67%) ⬆️
lightning/src/ln/onion_utils.rs 94.91% <100.00%> (+0.03%) ⬆️
lightning/src/util/events.rs 36.49% <0.00%> (-3.01%) ⬇️
lightning/src/chain/onchaintx.rs 93.79% <0.00%> (-1.15%) ⬇️
lightning/src/ln/priv_short_conf_tests.rs 96.66% <0.00%> (-0.18%) ⬇️
lightning/src/ln/payment_tests.rs 98.82% <0.00%> (-0.08%) ⬇️
lightning/src/ln/features.rs 99.46% <0.00%> (-0.01%) ⬇️
lightning/src/onion_message/messenger.rs 90.90% <0.00%> (+1.40%) ⬆️
lightning/src/util/wakers.rs 88.28% <0.00%> (+1.57%) ⬆️
... and 9 more

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

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

I don't think the tests will be too tricky after checking this out. I'll begin work on them.

@dunxen
Copy link
Contributor

dunxen commented Sep 12, 2022

I don't think the tests will be too tricky after checking this out. I'll begin work on them.

Should have something up today. Will open against your branch.

@TheBlueMatt TheBlueMatt marked this pull request as ready for review September 12, 2022 18:28
@TheBlueMatt TheBlueMatt force-pushed the 2022-09-badonion-first-check branch from baff002 to 32df0cc Compare September 12, 2022 18:29
@TheBlueMatt
Copy link
Collaborator Author

Thanks @dunxen! Added your test.

@TheBlueMatt TheBlueMatt force-pushed the 2022-09-badonion-first-check branch from 32df0cc to befbfe9 Compare September 12, 2022 19:33
dunxen
dunxen previously approved these changes Sep 12, 2022
Copy link
Contributor

@dunxen dunxen left a comment

Choose a reason for hiding this comment

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

onion_utils change makes sense and LGTM. Obviously just need more eyes on the test :)

Copy link
Contributor

@wpaulino wpaulino left a comment

Choose a reason for hiding this comment

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

LGTM after squash.

Currently we entirely ignore the BADONION bit when deciding how to
handle HTLC failures. This opens us up to an attack where a
malicious node always fails HTLCs backwards via
`update_fail_malformed_htlc` with an error code of
`BADONION|NODE|PERM|X`. In this case, we may decide to interpret
this as a permanent node failure for the node encrypting the onion,
i.e. the counterparty of the node who sent the
`update_fail_malformed_htlc` message and ultimately failed the
HTLC.

Thus, any node we route through could cause us to fully remove its
counterparty from our network graph. Luckily we do not do any
persistent tracking of removed nodes, and thus will re-add the
removed node once it is re-announced or on restart, however we are
likely to add such persistent tracking (at least in-memory) in the
future.
@TheBlueMatt TheBlueMatt force-pushed the 2022-09-badonion-first-check branch from 3b1d0e5 to e6a3c23 Compare September 13, 2022 02:22
@TheBlueMatt
Copy link
Collaborator Author

Squashed without further changes.

@valentinewallace valentinewallace merged commit a82fb62 into lightningdevkit:main Sep 13, 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