为什么必须使用copy_to_user()/copy_from_user()从内核访问用户空间? [英] Why do you have to use copy_to_user()/copy_from_user() to access user space from the kernel?
本文介绍了为什么必须使用copy_to_user()/copy_from_user()从内核访问用户空间?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我很好奇,因为在尝试直接访问内存(然后我发现了这些功能)后出现了内核恐慌.
I'm curious, because I got a kernel panic after trying to access memory directly (then I found these functions).
推荐答案
这些函数可以执行以下操作:
These functions do a few things:
- 他们检查提供的用户空间块是否完全在地址空间(
access_ok()
)的用户部分内-这可以防止用户空间应用程序要求内核读取/写入内核地址; - 如果无法访问任何地址,它们将返回错误,从而允许将错误返回给用户空间(
EFAULT
)而不是使内核崩溃(这是通过与页面错误处理程序的特殊协作来实现的,特别是可以检测其中一个用户存储器访问功能何时发生故障); - 它们允许使用特定于体系结构的魔术,例如,以确保具有虚拟标记的缓存的体系结构的一致性,禁用诸如SMAP的保护或切换具有单独的用户/内核地址空间(如S/390)的体系结构上的地址空间.
- They check if the supplied userspace block is entirely within the user portion of the address space (
access_ok()
) - this prevents userspace applications from asking the kernel to read/write kernel addresses; - They return an error if any of the addresses are inaccessible, allowing the error to be returned to userspace (
EFAULT
) instead of crashing the kernel (this is implemented by special co-operation with the page fault handler, which specifically can detect when a fault occurs in one of the user memory access functions); - They allow architecture-specific magic, for example to ensure consistency on architectures with virtually-tagged caches, to disable protections like SMAP or to switch address spaces on architectures with separate user/kernel address spaces like S/390.
这篇关于为什么必须使用copy_to_user()/copy_from_user()从内核访问用户空间?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文