我正在尝试内联挂钩系统调用。挂钩函数是这样的:
asmlinkage long hooked_mkdir(const char __user *pathname, umode_t mode) {
static char *msg = "hooked sys_mkdir(), mkdir name: ";
printk("%s%s", msg, pathname);
//print hex content to check bug.
int i;
for (i = 0; pathname[i] != '\0'; i++) {
printk("\\x%x", pathname[i]);
}
return old_mkdir(pathname, mode);
}
现在我mkdir
3个目录分别命名为 111 , 222 和 333 。系统调用已成功完成。但是,pathname
不可读:
[ 4856.148778] hooked sys_mkdir(), mkdir name: `\xd0\xf1
\xfe
[ 4856.148779] \x60
[ 4856.148780] \xffffffd0
[ 4856.148780] \xfffffff1
[ 4856.148780] \xc
[ 4856.148781] \xfffffffe
[ 4856.148781] \x7f
[ 4859.028686] hooked sys_mkdir(), mkdir name: \xd0
\xad\xac\xfd
[ 4859.028687] \xffffffd0
[ 4859.028688] \xb
[ 4859.028688] \xffffffad
[ 4859.028688] \xffffffac
[ 4859.028688] \xfffffffd
[ 4859.028689] \x7f
[ 4861.413464] hooked sys_mkdir(), mkdir name: \x90|\xb1\xf3\xff
[ 4861.413465] \xffffff90
[ 4861.413465] \x7c
[ 4861.413465] \xffffffb1
[ 4861.413466] \xfffffff3
[ 4861.413466] \xffffffff
我不清楚如何解释pathname
参数的内容。
答案 0 :(得分:1)
请注意,您是通过__user指针进行打印的。为了实际访问此数据,您必须首先对已知大小的结构/缓冲区使用strncpy_from_user
或copy_from_user
之类的东西。