用户空间到内核空间为什么需要拷贝?

2020-02-28 16:05:30来源:博客园 阅读 ()

新老客户大回馈,云服务器低至5折

用户空间到内核空间为什么需要拷贝?

The simple answer to that is, "Kernel Developers do not put blind faith in anything". When any data is passed to the kernel space from userspace, it is the responsibility of the kernel developer to make sure that everything is sanitized. Just as you check for corner conditions in the functions, it is something similar for the kernel developers. Its a hygienic practice to use copy_from_user() to read the userspace data.

We all know that there are all kinds of people in the world, and the same generalization applies to us coders. The kernel developers have to be everything to everyone. So, even if you are a clumsy coder who actually passed a pointer pointing to address in the kernel space by mistake, or if you are a malicious hacker who just wants to fool around and passed malformed data, the kernel should still handle that and not crash. The functions copy_from_user() does all these checks and more before it copies the data from the userspace to kernel space.

Just to make sure that the kernel dev does not have to manually check all these conditions, does not accidentally miss out on any and to abstract it for future use and extendability, the kernel architects have made a simple function that everyone can use. It just adds uniformity to the code and makes things that bit robust, simpler and cleaner.

转载链接:传送门 

保持更新,更多内容请关注cnblogs.com/xuyaowen;

 

原文链接:https://www.cnblogs.com/xuyaowen/p/copy_from_user.html
如有疑问请与原作者联系

标签:

版权申明:本站文章部分自网络,如有侵权,请联系:west999com@outlook.com
特别注意:本站所有转载文章言论不代表本站观点,本站所提供的摄影照片,插画,设计作品,如需使用,请与原作者联系,版权归原作者所有

上一篇:linux中文件系统属性chattr权限

下一篇:精通awk系列(17):awk布尔值、比较和逻辑运算