Ignore syscalls which are not registered in cached rbpf executable. (#14898)
This commit is contained in:
		
				
					committed by
					
						
						GitHub
					
				
			
			
				
	
			
			
			
						parent
						
							996a27d475
						
					
				
				
					commit
					d026da4a1b
				
			@@ -2142,7 +2142,6 @@ fn test_program_upgradeable_locks() {
 | 
				
			|||||||
    }
 | 
					    }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
#[ignore]
 | 
					 | 
				
			||||||
#[cfg(feature = "bpf_rust")]
 | 
					#[cfg(feature = "bpf_rust")]
 | 
				
			||||||
#[test]
 | 
					#[test]
 | 
				
			||||||
fn test_program_bpf_syscall_feature_activation() {
 | 
					fn test_program_bpf_syscall_feature_activation() {
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -147,6 +147,19 @@ pub fn register_syscalls(
 | 
				
			|||||||
    Ok(syscall_registry)
 | 
					    Ok(syscall_registry)
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					macro_rules! bind_feature_gated_syscall_context_object {
 | 
				
			||||||
 | 
					    ($vm:expr, $invoke_context:expr, $feature_id:expr, $syscall_context_object:expr $(,)?) => {
 | 
				
			||||||
 | 
					        if $invoke_context.is_feature_active($feature_id) {
 | 
				
			||||||
 | 
					            match $vm.bind_syscall_context_object($syscall_context_object, None) {
 | 
				
			||||||
 | 
					                Err(EbpfError::SyscallNotRegistered(_)) | Ok(()) => {}
 | 
				
			||||||
 | 
					                Err(err) => {
 | 
				
			||||||
 | 
					                    return Err(err);
 | 
				
			||||||
 | 
					                }
 | 
				
			||||||
 | 
					            }
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					    };
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
pub fn bind_syscall_context_objects<'a>(
 | 
					pub fn bind_syscall_context_objects<'a>(
 | 
				
			||||||
    loader_id: &'a Pubkey,
 | 
					    loader_id: &'a Pubkey,
 | 
				
			||||||
    vm: &mut EbpfVm<'a, BPFError, crate::ThisInstructionMeter>,
 | 
					    vm: &mut EbpfVm<'a, BPFError, crate::ThisInstructionMeter>,
 | 
				
			||||||
@@ -178,50 +191,51 @@ pub fn bind_syscall_context_objects<'a>(
 | 
				
			|||||||
        None,
 | 
					        None,
 | 
				
			||||||
    )?;
 | 
					    )?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if invoke_context.is_feature_active(&sol_log_compute_units_syscall::id()) {
 | 
					    bind_feature_gated_syscall_context_object!(
 | 
				
			||||||
        vm.bind_syscall_context_object(
 | 
					        vm,
 | 
				
			||||||
            Box::new(SyscallLogBpfComputeUnits {
 | 
					        invoke_context,
 | 
				
			||||||
                cost: 0,
 | 
					        &sol_log_compute_units_syscall::id(),
 | 
				
			||||||
                compute_meter: invoke_context.get_compute_meter(),
 | 
					        Box::new(SyscallLogBpfComputeUnits {
 | 
				
			||||||
                logger: invoke_context.get_logger(),
 | 
					            cost: 0,
 | 
				
			||||||
            }),
 | 
					            compute_meter: invoke_context.get_compute_meter(),
 | 
				
			||||||
            None,
 | 
					            logger: invoke_context.get_logger(),
 | 
				
			||||||
        )?;
 | 
					        }),
 | 
				
			||||||
    }
 | 
					    );
 | 
				
			||||||
    if invoke_context.is_feature_active(&pubkey_log_syscall_enabled::id()) {
 | 
					 | 
				
			||||||
        vm.bind_syscall_context_object(
 | 
					 | 
				
			||||||
            Box::new(SyscallLogPubkey {
 | 
					 | 
				
			||||||
                cost: bpf_compute_budget.log_pubkey_units,
 | 
					 | 
				
			||||||
                compute_meter: invoke_context.get_compute_meter(),
 | 
					 | 
				
			||||||
                logger: invoke_context.get_logger(),
 | 
					 | 
				
			||||||
                loader_id,
 | 
					 | 
				
			||||||
            }),
 | 
					 | 
				
			||||||
            None,
 | 
					 | 
				
			||||||
        )?;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if invoke_context.is_feature_active(&sha256_syscall_enabled::id()) {
 | 
					    bind_feature_gated_syscall_context_object!(
 | 
				
			||||||
        vm.bind_syscall_context_object(
 | 
					        vm,
 | 
				
			||||||
            Box::new(SyscallSha256 {
 | 
					        invoke_context,
 | 
				
			||||||
                sha256_base_cost: bpf_compute_budget.sha256_base_cost,
 | 
					        &pubkey_log_syscall_enabled::id(),
 | 
				
			||||||
                sha256_byte_cost: bpf_compute_budget.sha256_byte_cost,
 | 
					        Box::new(SyscallLogPubkey {
 | 
				
			||||||
                compute_meter: invoke_context.get_compute_meter(),
 | 
					            cost: bpf_compute_budget.log_pubkey_units,
 | 
				
			||||||
                loader_id,
 | 
					            compute_meter: invoke_context.get_compute_meter(),
 | 
				
			||||||
            }),
 | 
					            logger: invoke_context.get_logger(),
 | 
				
			||||||
            None,
 | 
					            loader_id,
 | 
				
			||||||
        )?;
 | 
					        }),
 | 
				
			||||||
    }
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if invoke_context.is_feature_active(&ristretto_mul_syscall_enabled::id()) {
 | 
					    bind_feature_gated_syscall_context_object!(
 | 
				
			||||||
        vm.bind_syscall_context_object(
 | 
					        vm,
 | 
				
			||||||
            Box::new(SyscallRistrettoMul {
 | 
					        invoke_context,
 | 
				
			||||||
                cost: 0,
 | 
					        &sha256_syscall_enabled::id(),
 | 
				
			||||||
                compute_meter: invoke_context.get_compute_meter(),
 | 
					        Box::new(SyscallSha256 {
 | 
				
			||||||
                loader_id,
 | 
					            sha256_base_cost: bpf_compute_budget.sha256_base_cost,
 | 
				
			||||||
            }),
 | 
					            sha256_byte_cost: bpf_compute_budget.sha256_byte_cost,
 | 
				
			||||||
            None,
 | 
					            compute_meter: invoke_context.get_compute_meter(),
 | 
				
			||||||
        )?;
 | 
					            loader_id,
 | 
				
			||||||
    }
 | 
					        }),
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					    bind_feature_gated_syscall_context_object!(
 | 
				
			||||||
 | 
					        vm,
 | 
				
			||||||
 | 
					        invoke_context,
 | 
				
			||||||
 | 
					        &ristretto_mul_syscall_enabled::id(),
 | 
				
			||||||
 | 
					        Box::new(SyscallRistrettoMul {
 | 
				
			||||||
 | 
					            cost: 0,
 | 
				
			||||||
 | 
					            compute_meter: invoke_context.get_compute_meter(),
 | 
				
			||||||
 | 
					            loader_id,
 | 
				
			||||||
 | 
					        }),
 | 
				
			||||||
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    vm.bind_syscall_context_object(
 | 
					    vm.bind_syscall_context_object(
 | 
				
			||||||
        Box::new(SyscallCreateProgramAddress {
 | 
					        Box::new(SyscallCreateProgramAddress {
 | 
				
			||||||
@@ -232,16 +246,16 @@ pub fn bind_syscall_context_objects<'a>(
 | 
				
			|||||||
        None,
 | 
					        None,
 | 
				
			||||||
    )?;
 | 
					    )?;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    if invoke_context.is_feature_active(&try_find_program_address_syscall_enabled::id()) {
 | 
					    bind_feature_gated_syscall_context_object!(
 | 
				
			||||||
        vm.bind_syscall_context_object(
 | 
					        vm,
 | 
				
			||||||
            Box::new(SyscallTryFindProgramAddress {
 | 
					        invoke_context,
 | 
				
			||||||
                cost: bpf_compute_budget.create_program_address_units,
 | 
					        &try_find_program_address_syscall_enabled::id(),
 | 
				
			||||||
                compute_meter: invoke_context.get_compute_meter(),
 | 
					        Box::new(SyscallTryFindProgramAddress {
 | 
				
			||||||
                loader_id,
 | 
					            cost: bpf_compute_budget.create_program_address_units,
 | 
				
			||||||
            }),
 | 
					            compute_meter: invoke_context.get_compute_meter(),
 | 
				
			||||||
            None,
 | 
					            loader_id,
 | 
				
			||||||
        )?;
 | 
					        }),
 | 
				
			||||||
    }
 | 
					    );
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    // Cross-program invocation syscalls
 | 
					    // Cross-program invocation syscalls
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user