Skip to content
This repository was archived by the owner on Jan 22, 2025. It is now read-only.

Re-do rent collection check on rent-exempt account#11349

Merged
ryoqun merged 11 commits intosolana-labs:masterfrom
ryoqun:account-storage-exhaustion
Aug 17, 2020
Merged

Re-do rent collection check on rent-exempt account#11349
ryoqun merged 11 commits intosolana-labs:masterfrom
ryoqun:account-storage-exhaustion

Conversation

@ryoqun
Copy link
Copy Markdown
Contributor

@ryoqun ryoqun commented Aug 3, 2020

Problem

Once passed as a rent-exempt for this epoch, accounts can reside with a penny (= 1 lamport) for the duration of the epoch. This could be exploited to occupy huge amount of storage for accounts, leading to a DOS.

Summary of Changes

rent-collect again only on previously-rent-exempt accounts.

Alternatively, we can use the highest bit of the account.rent_epoch? or introduce a new bit field? This would introduce abi breakage, though... => Well, it turns out the fix is pretty simple.

With this fix in effect, attackers actually must leave enough lamports for 10 * 1024 * 1024-byte MAX_PERMITTED_DATA_LENGTH accounts (= roughly 0.2 SOL (a)) to avoid it from being reclaimed after becoming non-rent-exempt.

So, it costs 10M SOL to do 1-epoch 500TB account storage DOS (b):

[1] pry(main)> 19.055441478439427 * 10 * 1024 * 1024 # <- (a)
=> 199810786.03696102
[5] pry(main)> (500 * 1024 * 1024 * 1024 * 1024) / (10 * 1024 * 1024) * (199810786.03696102 / 1000000000) # <- (b)
=> 10475839.738974622

, meaning we're safe now.

Fixes #11342

Comment thread runtime/src/rent_collector.rs Outdated
Comment thread runtime/src/rent_collector.rs Outdated
Comment thread runtime/src/rent_collector.rs Outdated
@ryoqun
Copy link
Copy Markdown
Contributor Author

ryoqun commented Aug 4, 2020

@t-nelson @mvines Could one of you sanity check this? Once granted, I'll do the remaining work (test fixes, gating).

Also, I guess we should fix this with reasonably quick fashion. :)

@ryoqun ryoqun added automerge Merge this Pull Request automatically once CI passes v1.2 security Pull requests that address a security vulnerability labels Aug 4, 2020
@mergify mergify Bot removed the automerge Merge this Pull Request automatically once CI passes label Aug 4, 2020
@mergify
Copy link
Copy Markdown
Contributor

mergify Bot commented Aug 4, 2020

automerge label removed due to a CI failure

@mvines mvines added the v1.3 label Aug 6, 2020
t-nelson
t-nelson previously approved these changes Aug 7, 2020
Copy link
Copy Markdown
Contributor

@t-nelson t-nelson left a comment

Choose a reason for hiding this comment

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

LGTM! Nice catch!

@ryoqun
Copy link
Copy Markdown
Contributor Author

ryoqun commented Aug 11, 2020

todo

@ryoqun ryoqun force-pushed the account-storage-exhaustion branch from 90b8c1b to 2be9db9 Compare August 11, 2020 16:21
@mergify mergify Bot dismissed t-nelson’s stale review August 11, 2020 16:22

Pull request has been modified.

@ryoqun ryoqun marked this pull request as ready for review August 13, 2020 04:31
@ryoqun ryoqun changed the title wip: re-do rent collection check on rent-exempt account Re-do rent collection check on rent-exempt account Aug 13, 2020
@ryoqun ryoqun requested a review from t-nelson August 13, 2020 04:32
@ryoqun
Copy link
Copy Markdown
Contributor Author

ryoqun commented Aug 13, 2020

@t-nelson Thanks for early-review. I think this pr is now ready for serious review to merge. :)

## Actual processing of collecting rent

Rent is due for one epoch's worth of time, and accounts always have `Account::rent_epoch` of `current_epoch + 1`.
Rent is due for one epoch's worth of time, and accounts have `Account::rent_epoch` of `current_epoch` or `current_epoch + 1` depending on the rent regime.
Copy link
Copy Markdown
Contributor Author

@ryoqun ryoqun Aug 13, 2020

Choose a reason for hiding this comment

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

@rwalker-apple Hi, I'm yet again tweaking the rent protocol a bit, mainly affected by this dos possibility: #11342. Could you review this in your free time?

Comment thread core/src/rpc_pubsub.rs
"data": bs58::encode(expected_data).into_string(),
"executable": false,
"rentEpoch": 1,
"rentEpoch": 0,
Copy link
Copy Markdown
Contributor Author

@ryoqun ryoqun Aug 13, 2020

Choose a reason for hiding this comment

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

@CriesofCarrots @jstarry Strictly speaking, we're breaking some semantics (=~ compatibility) of our rpc api a bit here according to this new rule for rentEpoch: https://github.com/solana-labs/solana/pull/11349/files#r469691300.

It's an incompatible change, but the change is soooo subtle, I think. So, I believe there should be virtually no one relying on rentEpoch being the current epoch or the next for rent-exempt accounts in any-conceivable way for the bizarre usecases.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Or, if you have something to come to mind in terms of various partner integartions, please let me know. :)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

@ryoqun agreed, very unlikely this will cause any issues. I highly doubt anyone is using rentEpoch right now

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I don't know of any integrations using rentEpoch; I'm comfortable with this breaking change.

Comment on lines +101 to +109
account.rent_epoch = self.epoch
+ if !self.enable_old_behavior && exempt {
// Rent isn't collected for the next epoch
// Make sure to check exempt status later in curent epoch again
0
} else {
// Rent is collected for next epoch
1
};
Copy link
Copy Markdown
Contributor Author

@ryoqun ryoqun Aug 13, 2020

Choose a reason for hiding this comment

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

This is the crux of this pr. The rest are just supplemental.

@codecov
Copy link
Copy Markdown

codecov Bot commented Aug 13, 2020

Codecov Report

Merging #11349 into master will increase coverage by 0.0%.
The diff coverage is 97.4%.

@@           Coverage Diff           @@
##           master   #11349   +/-   ##
=======================================
  Coverage    81.8%    81.8%           
=======================================
  Files         327      327           
  Lines       75668    75701   +33     
=======================================
+ Hits        61932    61960   +28     
- Misses      13736    13741    +5     

t-nelson
t-nelson previously approved these changes Aug 13, 2020
Copy link
Copy Markdown
Contributor

@t-nelson t-nelson left a comment

Choose a reason for hiding this comment

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

LGTM! Just one readability nit, should you choose

Comment thread runtime/src/rent_collector.rs Outdated
sol_assert(accounts[ARGUMENT_INDEX].is_signer);
sol_assert(accounts[ARGUMENT_INDEX].is_writable);
sol_assert(accounts[ARGUMENT_INDEX].rent_epoch == 1);
sol_assert(accounts[ARGUMENT_INDEX].rent_epoch == 0);
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@jackcmay Like the RPC land, this pr changes slightly changes the semantics of rent_epoch, which is exposed to programs as well. Are you aware of any programs strictly relying on the current semantics of rent_epoch?

@jackcmay
Copy link
Copy Markdown
Contributor

jackcmay commented Aug 14, 2020 via email

@mergify mergify Bot dismissed t-nelson’s stale review August 14, 2020 01:33

Pull request has been modified.

@t-nelson t-nelson self-requested a review August 14, 2020 07:44
@ryoqun
Copy link
Copy Markdown
Contributor Author

ryoqun commented Aug 14, 2020

@t-nelson Thanks for re-approving! Now waiting for last-minute local testing by me and final say from @rwalker-com / @rwalker-apple (if any).

@rwalker-com
Copy link
Copy Markdown
Contributor

lgtm

@ryoqun ryoqun merged commit 23fa84b into solana-labs:master Aug 17, 2020
mergify Bot pushed a commit that referenced this pull request Aug 17, 2020
* wip: re-do rent collection check on rent-exempt account

* Let's see how the ci goes

* Restore previous code

* Well, almost all new changes are revertable

* Update doc

* Add test and gating

* Fix tests

* Fix tests, especially avoid to change abi...

* Fix more tests...

* Fix snapshot restore

* Align to _new_ with better uninitialized detection

(cherry picked from commit 23fa84b)

# Conflicts:
#	core/src/rpc_subscriptions.rs
#	core/tests/bank_forks.rs
#	runtime/src/bank.rs
mergify Bot pushed a commit that referenced this pull request Aug 17, 2020
* wip: re-do rent collection check on rent-exempt account

* Let's see how the ci goes

* Restore previous code

* Well, almost all new changes are revertable

* Update doc

* Add test and gating

* Fix tests

* Fix tests, especially avoid to change abi...

* Fix more tests...

* Fix snapshot restore

* Align to _new_ with better uninitialized detection

(cherry picked from commit 23fa84b)

# Conflicts:
#	core/src/rpc_subscriptions.rs
@ryoqun
Copy link
Copy Markdown
Contributor Author

ryoqun commented Aug 17, 2020

Now waiting for last-minute local testing by me

This is done finally and merged this!

mergify Bot added a commit that referenced this pull request Aug 17, 2020
* Re-do rent collection check on rent-exempt account (#11349)

* wip: re-do rent collection check on rent-exempt account

* Let's see how the ci goes

* Restore previous code

* Well, almost all new changes are revertable

* Update doc

* Add test and gating

* Fix tests

* Fix tests, especially avoid to change abi...

* Fix more tests...

* Fix snapshot restore

* Align to _new_ with better uninitialized detection

(cherry picked from commit 23fa84b)

# Conflicts:
#	core/src/rpc_subscriptions.rs

* Fix conflicts

Co-authored-by: Ryo Onodera <ryoqun@gmail.com>
mergify Bot added a commit that referenced this pull request Aug 17, 2020
* Re-do rent collection check on rent-exempt account (#11349)

* wip: re-do rent collection check on rent-exempt account

* Let's see how the ci goes

* Restore previous code

* Well, almost all new changes are revertable

* Update doc

* Add test and gating

* Fix tests

* Fix tests, especially avoid to change abi...

* Fix more tests...

* Fix snapshot restore

* Align to _new_ with better uninitialized detection

(cherry picked from commit 23fa84b)

# Conflicts:
#	core/src/rpc_subscriptions.rs
#	core/tests/bank_forks.rs
#	runtime/src/bank.rs

* Fix conflicts

* Add missing comment

Co-authored-by: Ryo Onodera <ryoqun@gmail.com>
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

security Pull requests that address a security vulnerability

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Possible resource exhausition attack for account storage with reasonable funds

7 participants