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

Native CPI caller write privileges is incorrect #18629

Closed
jstarry opened this issue Jul 13, 2021 · 5 comments · Fixed by #19750
Closed

Native CPI caller write privileges is incorrect #18629

jstarry opened this issue Jul 13, 2021 · 5 comments · Fixed by #19750
Assignees

Comments

@jstarry
Copy link
Contributor

jstarry commented Jul 13, 2021

Problem

Caller write privileges are not created correctly for native cpi. The caller_write_privileges vector should match up with message.account_keys because they will be indexed into in the same way

Proposed Solution

  • Remove incorrect write privilege value insertion
  • Match up write privileges vector with the accounts vector built from message.account_keys

fix with no tests is in this branch: https://github.com/jstarry/solana/tree/fix-caller-write-privileges

@jstarry
Copy link
Contributor Author

jstarry commented Jul 13, 2021

Since native_invoke is only called for the bpf upgradeable program and that program doesn't modify caller accounts before invoking the native create account instruction, there shouldn't be any change of behavior before and after the fix.

@jackcmay jackcmay self-assigned this Aug 5, 2021
@jstarry
Copy link
Contributor Author

jstarry commented Sep 4, 2021

@jackcmay I'm pretty sure #19645 will be blocked on this issue FYI

@jackcmay
Copy link
Contributor

jackcmay commented Sep 7, 2021

What specifically do you think is blocking?

@jstarry
Copy link
Contributor Author

jstarry commented Sep 7, 2021

caller_write_privileges is constructed in order of keyed_account_indices instead of message.account_keys which contrasts with how accounts and keyed_account_indices_reordered are constructed. This means that if keyed_account_indices is not monotonically increasing, the write privileges can be incorrect. This is problematic because if a native program modifies any accounts before invoking another program, it's possible that the native program could be allowed to write to a read-only account that it owns. Or, it may be prevented from writing to a writable account that it owns.

#19645 introduces a change which modifies a buffer account before the native invoke which means that a malicious user could trick the bpf loader program to successfully deplete the balance of a readonly buffer account.

@github-actions
Copy link
Contributor

This issue has been automatically locked since there has not been any activity in past 7 days after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 31, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants