-
Notifications
You must be signed in to change notification settings - Fork 12.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Sanitizer handler calls emitted without regard to -mregparm
#89670
Comments
From llvm::CallBase *
CodeGenFunction::EmitRuntimeCallOrInvoke(llvm::FunctionCallee callee,
ArrayRef<llvm::Value *> args,
const Twine &name) {
llvm::CallBase *call = EmitCallOrInvoke(callee, args, name);
call->setCallingConv(getRuntimeCC());
return call;
} the calling convention doesn't seem to have any knowledge of where // Record mregparm value now so it is visible through rest of codegen.
if (Context.getTargetInfo().getTriple().getArch() == llvm::Triple::x86)
getModule().addModuleFlag(llvm::Module::Error, "NumRegisterParameters",
CodeGenOpts.NumRegisterParameters); |
…89707) When building the Linux kernel for i386, the -mregparm=3 option is enabled. Crashes were observed in the sanitizer handler functions, and the problem was found to be mismatched calling convention. As was fixed in commit c167c0a ("[BuildLibCalls] infer inreg param attrs from NumRegisterParameters"), call arguments need to be marked as "in register" when -mregparm is set. Use the same helper developed there to update the function arguments. Since CreateRuntimeFunction() is actually part of CodeGenModule, storage of the -mregparm value is also moved to the constructor, as doing this in Release() is too late. Fixes: #89670
@llvm/issue-subscribers-clang-codegen Author: Kees Cook (kees)
When sanitizer calls are emitted, the `-mregparm=3` option used by the Linux kernel appears to be ignored. For example, here is a build where the argument are being pushed instead of placed in `%eax` and `%edx` (from `lkdtm_ARRAY_BOUNDS`):
0xc18e3a5a <+202>: push %ebx
0xc18e3a5b <+203>: push $0xc26001a0
0xc18e3a60 <+208>: call 0xc157d430 <__ubsan_handle_out_of_bounds> The kernel's handler isn't expecting them on the stack. For example, this is setting a bit in the sanitizer's passed-in data structure (from 0xc157d491 <+97>: btsl $0x1f,%ds:0x4(%eax)
0xc157d497 <+103>: jae 0xc157d4a1 <__ubsan_handle_out_of_bounds+113>
|
When sanitizer calls are emitted, the
-mregparm=3
option used by the Linux kernel appears to be ignored. For example, here is a build where the argument are being pushed instead of placed in%eax
and%edx
(fromlkdtm_ARRAY_BOUNDS
):The kernel's handler isn't expecting them on the stack. For example, this is setting a bit in the sanitizer's passed-in data structure (from
__ubsan_handle_out_of_bounds
):KSPP/linux#350
The text was updated successfully, but these errors were encountered: