From ef598ee6e582e43051976707ebd6f0c2887fa8cf Mon Sep 17 00:00:00 2001 From: "mergify[bot]" <37929162+mergify[bot]@users.noreply.github.com> Date: Thu, 3 Aug 2023 17:00:01 +0200 Subject: [PATCH] v1.16: Fix - Adds missing "Executable account not owned by the BPF loader" error to `remove_bpf_loader_incorrect_program_id` (backport of #32695) (#32700) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Fix - Adds missing "Executable account not owned by the BPF loader" error to `remove_bpf_loader_incorrect_program_id` (#32695) Adds missing "Executable account not owned by the BPF loader" error. (cherry picked from commit b5a80a72f0792e31468b3c1a67b23fab54c4c3b1) Co-authored-by: Alexander Meißner --- programs/bpf_loader/src/lib.rs | 23 +++++++++++++++++++---- 1 file changed, 19 insertions(+), 4 deletions(-) diff --git a/programs/bpf_loader/src/lib.rs b/programs/bpf_loader/src/lib.rs index 6a85263fb27f54..8a6b9a5f9c1d6d 100644 --- a/programs/bpf_loader/src/lib.rs +++ b/programs/bpf_loader/src/lib.rs @@ -494,11 +494,13 @@ fn process_instruction_inner( transaction_context.get_key_of_account_at_index(index_in_transaction) }); let program_id = instruction_context.get_last_program_key(transaction_context)?; - if first_account_key == program_id - || second_account_key - .map(|key| key == program_id) - .unwrap_or(false) + let program_account_index = if first_account_key == program_id { + first_instruction_account + } else if second_account_key + .map(|key| key == program_id) + .unwrap_or(false) { + first_instruction_account.saturating_add(1) } else { let first_account = try_borrow_account( transaction_context, @@ -509,6 +511,19 @@ fn process_instruction_inner( ic_logger_msg!(log_collector, "BPF loader is executable"); return Err(Box::new(InstructionError::IncorrectProgramId)); } + first_instruction_account + }; + let program = try_borrow_account( + transaction_context, + instruction_context, + program_account_index, + )?; + if program.is_executable() && !check_loader_id(program.get_owner()) { + ic_logger_msg!( + log_collector, + "Executable account not owned by the BPF loader" + ); + return Err(Box::new(InstructionError::IncorrectProgramId)); } }