Skip to content

Commit

Permalink
fix incorrect arch register use for kprobe func with more parameters
Browse files Browse the repository at this point in the history
Commit 12107c6 ("use correct arch register for the
4th param of x86_64 syscalls") tries to use proper syscall
specific registers on x86_64 as its 4th param for syscall
is different from non-syscall. Unfortunately, the
implementation also uses syscall arch. register
for non-syscall kernel functions, which is incorrect.

This patch fixed the issue by using syscall arch
registers only for syscalls.

Reported-by: zhenwei pi <pizhenwei@bytedance.com>
Fixes: 12107c6 ("use correct arch register for the 4th param of x86_64 syscalls")
Signed-off-by: Yonghong Song <yhs@fb.com>
  • Loading branch information
yonghong-song committed Feb 19, 2021
1 parent 33393d3 commit b231786
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions src/cc/frontends/clang/b_frontend_action.cc
Original file line number Diff line number Diff line change
Expand Up @@ -766,17 +766,20 @@ void BTypeVisitor::genParamIndirectAssign(FunctionDecl *D, string& preamble,
}

void BTypeVisitor::rewriteFuncParam(FunctionDecl *D) {
const char **calling_conv_regs = get_call_conv(true);

string preamble = "{\n";
if (D->param_size() > 1) {
bool is_syscall = false;
if (strncmp(D->getName().str().c_str(), "syscall__", 9) == 0 ||
strncmp(D->getName().str().c_str(), "kprobe____x64_sys_", 18) == 0)
is_syscall = true;
const char **calling_conv_regs = get_call_conv(is_syscall);

// If function prefix is "syscall__" or "kprobe____x64_sys_",
// the function will attach to a kprobe syscall function.
// Guard parameter assiggnment with CONFIG_ARCH_HAS_SYSCALL_WRAPPER.
// For __x64_sys_* syscalls, this is always true, but we guard
// it in case of "syscall__" for other architectures.
if (strncmp(D->getName().str().c_str(), "syscall__", 9) == 0 ||
strncmp(D->getName().str().c_str(), "kprobe____x64_sys_", 18) == 0) {
if (is_syscall) {
preamble += "#if defined(CONFIG_ARCH_HAS_SYSCALL_WRAPPER) && !defined(__s390x__)\n";
genParamIndirectAssign(D, preamble, calling_conv_regs);
preamble += "\n#else\n";
Expand Down

0 comments on commit b231786

Please sign in to comment.