Unreadable content of 'pathname' parameter in 'mkdir()' system call after inline hooking

蓝咒 提交于 2021-01-29 06:13:57

问题


I'm trying inline hooking system calls. The hook function is like this:

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);
}

Now I mkdir 3 directories named 111, 222 and 333. The syscalls were made successfully. However, the pathname is unreadable:

[ 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

I'm not clear how to interpret the content of pathname param.


回答1:


Do note you're printing from a __user pointer. In order to actually access this data you must first use something like the strncpy_from_user or copy_from_user for known-sized structures/buffers.



来源:https://stackoverflow.com/questions/53131457/unreadable-content-of-pathname-parameter-in-mkdir-system-call-after-inline

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!