Linux Kernel : What is /dev/mem or /dev/kmem?

本文转载至:http://priyaranjan-technicalzone.blogspot.com/2014/02/linux-kernel-what-is-devmem-or-devkmem.html

The /dev/mem and /dev/kmem character special files provide access to a pseudo device driver that allows read and write access to system memory or I/O address space. 
Programs accessing these special files must have appropriate privilege. Commercial application programs should avoid using the /dev/mem and/dev/kmem files, since the virtual memory image is quite specific to the operating system level and machine platform. Use of these special files thus seriously affects the portability of the application program to other systems.When incorrect access to virtual memory is made through these files, process termination, a system crash, or loss of system data integrity can result.

/dev/mem is the gateway to the "Physical Address Space" of the processor which might include  control registers of many HW peripherals and not just the RAM. In order to prevent attackers from misusing /dev/mem and altering kernel memory, a flagCONFIG_STRICT_DEVMEM needs to be enabled which will prevent user apps from accessing physical address space beyond 1MB. The option  makes the kernel check addresses in /dev/mem with devmem_is_allowed() in arch/.../init.c 


Config Option in the Kernel
CONFIG_STRICT_DEVMEM:
  │ 
  │ If this option is disabled, you allow userspace (root) access to all
  │ of memory, including kernel and userspace memory. Accidental    
  │ access to this is obviously disastrous, but specific access can   
  │ be used by people debugging the kernel. Note that with PAT support    
  │ enabled, even in this case there are restrictions on /dev/mem     
  │ use due to the cache aliasing requirements.         
  │                                                          
  │ If this option is switched on, the /dev/mem file only allows     
  │ userspace access to PCI space and the BIOS code and data regions.    
  │ This is sufficient for dosemu and X and all common users of          
  │ /dev/mem.                                          
  │                                                    
  │ If in doubt, say Y.                             
  │                                                        
  │ Symbol: STRICT_DEVMEM [=y]    
  │ Type  : boolean                                               
  │ Prompt: Filter access to /dev/mem                        
  │   Defined at arch/x86/Kconfig.debug:8      
  │     -> Kernel hacking


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值