allocate user-space memory from kernel

2019-01-18 07:35发布

I'm trying to call

sys_readlink(const char __user *path, char __user *buf, int bufsiz)

directly, but get EFAULT error code. This error appears because buf points to memory from kernel-space.

So, is there possible way to allocate user-space memory from kernel ?

kmalloc(size, GFP_USER) is similar to kmalloc(size, GFP_KERNEL) and returns pointer to kernel memory.

1条回答
萌系小妹纸
2楼-- · 2019-01-18 08:13

You can temporarily disable memory address validity checking by using set_fs

mm_segment_t old_fs;

old_fs = get_fs();
set_fs(KERNEL_DS);
/* Your syscall here */
set_fs(old_fs);
查看更多
登录 后发表回答