Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 16 additions & 1 deletion program-runtime/src/invoke_context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@ use {
program::{BuiltinFunction, SBPFVersion},
vm::{Config, ContextObject, EbpfVm},
},
solana_sdk_ids::{bpf_loader_deprecated, native_loader, sysvar},
solana_sdk_ids::{
bpf_loader, bpf_loader_deprecated, bpf_loader_upgradeable, loader_v4, native_loader, sysvar,
},
solana_stable_layout::stable_instruction::StableInstruction,
solana_timings::{ExecuteDetailsTimings, ExecuteTimings},
solana_transaction_context::{
Expand Down Expand Up @@ -523,6 +525,19 @@ impl<'a> InvokeContext<'a> {
let owner_id = borrowed_root_account.get_owner();
if native_loader::check_id(owner_id) {
*borrowed_root_account.get_key()
} else if self
.get_feature_set()
.is_active(&remove_accounts_executable_flag_checks::id())
{
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)
Comment on lines +532 to +535
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

{
*owner_id
} else {
return Err(InstructionError::UnsupportedProgramId);
}
} else {
*owner_id
}
Expand Down
44 changes: 42 additions & 2 deletions runtime/src/bank/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8392,6 +8392,46 @@ fn test_program_is_native_loader() {
);
}

#[test]
fn test_invoke_non_program_account_owned_by_a_builtin() {
let (genesis_config, mint_keypair) = create_genesis_config(10000000);
let mut bank = Bank::new_for_tests(&genesis_config);
bank.activate_feature(&feature_set::remove_accounts_executable_flag_checks::id());
let (bank, _bank_forks) = bank.wrap_with_bank_forks_for_tests();

let bogus_program = Pubkey::new_unique();
bank.transfer(
genesis_config.rent.minimum_balance(0),
&mint_keypair,
&bogus_program,
)
.unwrap();

let created_account_keypair = Keypair::new();
let mut ix = system_instruction::create_account(
&mint_keypair.pubkey(),
&created_account_keypair.pubkey(),
genesis_config.rent.minimum_balance(0),
0,
&system_program::id(),
);
// Calling an account owned by the system program, instead of calling the system program itself
ix.program_id = bogus_program;
let tx = Transaction::new_signed_with_payer(
&[ix],
Some(&mint_keypair.pubkey()),
&[&mint_keypair, &created_account_keypair],
bank.last_blockhash(),
);
assert_eq!(
bank.process_transaction(&tx),
Err(TransactionError::InstructionError(
0,
InstructionError::UnsupportedProgramId
))
);
}

#[test]
fn test_debug_bank() {
let (genesis_config, _mint_keypair) = create_genesis_config(50000);
Expand Down Expand Up @@ -13556,15 +13596,15 @@ fn test_loader_v3_to_v4_migration() {
finalized_migration_transaction.clone(),
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.

)),
),
(
uninitialized_programdata_account,
finalized_migration_transaction.clone(),
Err(TransactionError::InstructionError(
0,
InstructionError::InvalidInstructionData,
InstructionError::UnsupportedProgramId,
)),
),
(
Expand Down