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
2 changes: 1 addition & 1 deletion feature-set/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -965,7 +965,7 @@ pub mod enable_sbpf_v3_deployment_and_execution {
}

pub mod remove_accounts_executable_flag_checks {
solana_pubkey::declare_id!("FfgtauHUWKeXTzjXkua9Px4tNGBFHKZ9WaigM5VbbzFx");
solana_pubkey::declare_id!("FXs1zh47QbNnhXcnB6YiAQoJ4sGB91tKF3UFHLcKT7PM");
}

pub mod lift_cpi_caller_restriction {
Expand Down
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)
{
*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 @@ -8470,6 +8470,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 @@ -13634,15 +13674,15 @@ fn test_loader_v3_to_v4_migration() {
finalized_migration_transaction.clone(),
Err(TransactionError::InstructionError(
0,
InstructionError::InvalidInstructionData,
InstructionError::UnsupportedProgramId,
)),
),
(
uninitialized_programdata_account,
finalized_migration_transaction.clone(),
Err(TransactionError::InstructionError(
0,
InstructionError::InvalidInstructionData,
InstructionError::UnsupportedProgramId,
)),
),
(
Expand Down