Skip to content

Fix - Invoke non program account owned by a builtin#5158

Merged
Lichtso merged 2 commits into
anza-xyz:masterfrom
Lichtso:fix/invoke_non_program_account_owned_by_a_builtin
Mar 10, 2025
Merged

Fix - Invoke non program account owned by a builtin#5158
Lichtso merged 2 commits into
anza-xyz:masterfrom
Lichtso:fix/invoke_non_program_account_owned_by_a_builtin

Conversation

@Lichtso
Copy link
Copy Markdown

@Lichtso Lichtso commented Mar 5, 2025

Problem

Currently there is a slight bug once remove_accounts_executable_flag_checks is active:
One can invoke a built-in program by invoking any account owned by it instead. This leads to the built-in running as a different pubkey, thus all ownership checks fail and the built-in has no write access to anything.

This is benign as it only allows invoking built-in programs in a strange nonsensical way. But, it is still a stupid thing to support and would hinder future protocol changes such as these in the account loader.

About rekeying: Well see Discord discussion.

Summary of Changes

Blocks the execution of any non loader owned or non built-in account and adds test_invoke_non_program_account_owned_by_a_builtin() to demonstrate the change in behavior.

Feature Gate Issue: https://github.com/anza-xyz/feature-gate-tracker/issues/69

@Lichtso Lichtso requested review from 2501babe and jstarry March 5, 2025 19:31
@Lichtso Lichtso force-pushed the fix/invoke_non_program_account_owned_by_a_builtin branch from 1738f1c to ad7759a Compare March 5, 2025 19:42
@Lichtso Lichtso force-pushed the fix/invoke_non_program_account_owned_by_a_builtin branch from ad7759a to 64d3113 Compare March 5, 2025 20:58
Comment thread runtime/src/bank/tests.rs
Err(TransactionError::InstructionError(
0,
InstructionError::InvalidInstructionData,
InstructionError::UnsupportedProgramId,
Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

This is where I first noticed this issue.

@Lichtso Lichtso marked this pull request as ready for review March 6, 2025 20:52
@Lichtso Lichtso requested a review from a team as a code owner March 6, 2025 20:52
@Lichtso Lichtso merged commit 9adbffc into anza-xyz:master Mar 10, 2025
1 check passed
@Lichtso Lichtso deleted the fix/invoke_non_program_account_owned_by_a_builtin branch March 10, 2025 12:25
@Lichtso Lichtso added the v2.2 label Mar 10, 2025
@mergify
Copy link
Copy Markdown

mergify Bot commented Mar 10, 2025

Backports to the beta branch are to be avoided unless absolutely necessary for fixing bugs, security issues, and perf regressions. Changes intended for backport should be structured such that a minimum effective diff can be committed separately from any refactoring, plumbing, cleanup, etc that are not strictly necessary to achieve the goal. Any of the latter should go only into master and ride the normal stabilization schedule. Exceptions include CI/metrics changes, CLI improvements and documentation updates on a case by case basis.

mergify Bot pushed a commit that referenced this pull request Mar 10, 2025
* Adds test_invoke_non_program_account_owned_by_a_builtin().

* Throws InstructionError::UnsupportedProgramId when invoking any non loader owned or non built-in account.

(cherry picked from commit 9adbffc)
Comment on lines +532 to +535
if bpf_loader_deprecated::check_id(owner_id)
|| bpf_loader::check_id(owner_id)
|| bpf_loader_upgradeable::check_id(owner_id)
|| loader_v4::check_id(owner_id)
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Shouldn't we apply the same checks to account loading? We could get rid of all of the validated_loaders logic there.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Yes, that is why I added you as reviewer ;)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Haha, great, follow up PR then? And these changes should be amended to the SIMD: solana-foundation/solana-improvement-documents#162

@jstarry
Copy link
Copy Markdown

jstarry commented Mar 10, 2025

I don't think this should have been merged without first rekeying

@Lichtso
Copy link
Copy Markdown
Author

Lichtso commented Mar 10, 2025

Can't rekey in the same PR anymore because SDK was moved out. Have to do it in the sdk repo and then, once the backport lands we can bump the release there. See Discord discussion mentioned above.

@jstarry
Copy link
Copy Markdown

jstarry commented Mar 10, 2025

Actually yeah the rekey should land after the implementation, never mind.

Lichtso added a commit that referenced this pull request Mar 11, 2025
* Adds test_invoke_non_program_account_owned_by_a_builtin().

* Throws InstructionError::UnsupportedProgramId when invoking any non loader owned or non built-in account.

(cherry picked from commit 9adbffc)
Lichtso added a commit that referenced this pull request Mar 25, 2025
* Adds test_invoke_non_program_account_owned_by_a_builtin().

* Throws InstructionError::UnsupportedProgramId when invoking any non loader owned or non built-in account.

(cherry picked from commit 9adbffc)
Lichtso added a commit that referenced this pull request Mar 28, 2025
…#5158) (#5207)

Fix - Invoke non program account owned by a builtin (#5158)

* Adds test_invoke_non_program_account_owned_by_a_builtin().

* Throws InstructionError::UnsupportedProgramId when invoking any non loader owned or non built-in account.

(cherry picked from commit 9adbffc)

Co-authored-by: Alexander Meißner <AlexanderMeissner@gmx.net>
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.

3 participants