From b8511832ccf84234e75513839565cd749c8a04c8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Mei=C3=9Fner?= Date: Wed, 14 Sep 2022 20:08:48 +0200 Subject: [PATCH] Adds tests for the two account aliasing restrictions of UpgradeableLoaderInstruction::Upgrade which can be triggered. --- programs/bpf_loader/src/lib.rs | 36 +++++++++++++++++++++++++++++++--- 1 file changed, 33 insertions(+), 3 deletions(-) diff --git a/programs/bpf_loader/src/lib.rs b/programs/bpf_loader/src/lib.rs index 3668aa7773c356..d37e11791ec995 100644 --- a/programs/bpf_loader/src/lib.rs +++ b/programs/bpf_loader/src/lib.rs @@ -3081,6 +3081,36 @@ mod tests { Err(InstructionError::MissingRequiredSignature), ); + // Case: Buffer account and spill account alias + let (transaction_accounts, mut instruction_accounts) = get_accounts( + &buffer_address, + &upgrade_authority_address, + &upgrade_authority_address, + &elf_orig, + &elf_new, + ); + *instruction_accounts.get_mut(3).unwrap() = instruction_accounts.get(2).unwrap().clone(); + process_instruction( + transaction_accounts, + instruction_accounts, + Err(InstructionError::AccountBorrowFailed), + ); + + // Case: Programdata account and spill account alias + let (transaction_accounts, mut instruction_accounts) = get_accounts( + &buffer_address, + &upgrade_authority_address, + &upgrade_authority_address, + &elf_orig, + &elf_new, + ); + *instruction_accounts.get_mut(3).unwrap() = instruction_accounts.get(0).unwrap().clone(); + process_instruction( + transaction_accounts, + instruction_accounts, + Err(InstructionError::AccountBorrowFailed), + ); + // Case: Program account not executable let (mut transaction_accounts, instruction_accounts) = get_accounts( &buffer_address, @@ -3220,7 +3250,7 @@ mod tests { Err(InstructionError::AccountDataTooSmall), ); - // Test small buffer account + // Case: Buffer account too small let (mut transaction_accounts, instruction_accounts) = get_accounts( &buffer_address, &upgrade_authority_address, @@ -3257,7 +3287,7 @@ mod tests { Err(InstructionError::IncorrectAuthority), ); - // Case: None buffer authority + // Case: No buffer authority let (mut transaction_accounts, instruction_accounts) = get_accounts( &buffer_address, &buffer_address, @@ -3279,7 +3309,7 @@ mod tests { Err(InstructionError::IncorrectAuthority), ); - // Case: None buffer and program authority + // Case: No buffer and program authority let (mut transaction_accounts, instruction_accounts) = get_accounts( &buffer_address, &buffer_address,