I’m working on a demo to encrypt cuda kernel binary in CPU side, and decrypt it in GPU side. The purpose is to make cuda kernel confidential in PCIe channel.
Now the CPU side things work well, however in GPU side there are some issues:
- how could I know where a kernel locates in GPU memory? I found an sanitizer API
sanitizerGetFunctionPcAndSize
that may solve the problem, but the API call just failed. - After getting the code location, I hope to read&modify the kernel binary in GPU side through another kernel. Is read&write to kernel code allowed? Can I change the code part to RW permission by setting
CUmemAccess_flags
? - If code part cannot be modified, can I alloc a buffer in GPU side, put code into the buffer, and modify cukernel metadata to point to the new buffer to execute? Is there something similar to NX bit in x86 to prevent a random buffer to be executed? If not, how to change the CUkernel metadata to point to the new code?
My code with sanitizerGetFunctionPcAndSize
:
void SANITIZERAPI
my_callback(void *userdata,
Sanitizer_CallbackDomain domain,
Sanitizer_CallbackId cbid,
const void *cbdata)
{
if (domain == SANITIZER_CB_DOMAIN_LAUNCH) {
Sanitizer_LaunchData *ld = (Sanitizer_LaunchData *)cbdata;
if (cbid == SANITIZER_CBID_LAUNCH_BEGIN) {
std::cout << "launch begin" << std::endl;
std::cout << "mod: " << ld->module << ", name: " << ld->functionName << std::endl;
uint64_t function_pc = 0, function_size = 0;
auto ret = sanitizerGetFunctionPcAndSize(ld->module, ld->functionName, &function_pc,
&function_size);
std::cout << "ret: " << ret << ", function pc: " << function_pc << ", function size: " << function_size << std::endl;
} else if (cbid == SANITIZER_CBID_LAUNCH_AFTER_SYSCALL_SETUP) {
std::cout << "launch after syscall setup" << std::endl;
} else if (cbid == SANITIZER_CBID_LAUNCH_END) {
std::cout << "launch end" << std::endl;
}
}
}
the callback is successfully called, but the get pc call returns error. The output:
launch begin
mod: 0x56276de445e0, name: _Z9vectorAddPKfS0_Pfi
ret: 1, function pc: 0, function size: 0
launch after syscall setup
launch end