mirror of
				https://github.com/torvalds/linux.git
				synced 2025-11-04 10:40:15 +02:00 
			
		
		
		
	x86, PAT: disable /dev/mem mmap RAM with PAT
disable /dev/mem mmap of RAM with PAT. It makes things safer and eliminates aliasing. A future improvement would be to avoid the range_is_allowed duplication. Signed-off-by: Venkatesh Pallipadi <venkatesh.pallipadi@intel.com> Signed-off-by: Ingo Molnar <mingo@elte.hu>
This commit is contained in:
		
							parent
							
								
									4a27214d7b
								
							
						
					
					
						commit
						0124cecfc8
					
				
					 1 changed files with 31 additions and 0 deletions
				
			
		| 
						 | 
					@ -16,6 +16,7 @@
 | 
				
			||||||
#include <asm/msr.h>
 | 
					#include <asm/msr.h>
 | 
				
			||||||
#include <asm/tlbflush.h>
 | 
					#include <asm/tlbflush.h>
 | 
				
			||||||
#include <asm/processor.h>
 | 
					#include <asm/processor.h>
 | 
				
			||||||
 | 
					#include <asm/page.h>
 | 
				
			||||||
#include <asm/pgtable.h>
 | 
					#include <asm/pgtable.h>
 | 
				
			||||||
#include <asm/pat.h>
 | 
					#include <asm/pat.h>
 | 
				
			||||||
#include <asm/e820.h>
 | 
					#include <asm/e820.h>
 | 
				
			||||||
| 
						 | 
					@ -477,6 +478,33 @@ pgprot_t phys_mem_access_prot(struct file *file, unsigned long pfn,
 | 
				
			||||||
	return vma_prot;
 | 
						return vma_prot;
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					#ifdef CONFIG_NONPROMISC_DEVMEM
 | 
				
			||||||
 | 
					/* This check is done in drivers/char/mem.c in case of NONPROMISC_DEVMEM*/
 | 
				
			||||||
 | 
					static inline int range_is_allowed(unsigned long pfn, unsigned long size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						return 1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#else
 | 
				
			||||||
 | 
					static inline int range_is_allowed(unsigned long pfn, unsigned long size)
 | 
				
			||||||
 | 
					{
 | 
				
			||||||
 | 
						u64 from = ((u64)pfn) << PAGE_SHIFT;
 | 
				
			||||||
 | 
						u64 to = from + size;
 | 
				
			||||||
 | 
						u64 cursor = from;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						while (cursor < to) {
 | 
				
			||||||
 | 
							if (!devmem_is_allowed(pfn)) {
 | 
				
			||||||
 | 
								printk(KERN_INFO
 | 
				
			||||||
 | 
							"Program %s tried to access /dev/mem between %Lx->%Lx.\n",
 | 
				
			||||||
 | 
									current->comm, from, to);
 | 
				
			||||||
 | 
								return 0;
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
 | 
							cursor += PAGE_SIZE;
 | 
				
			||||||
 | 
							pfn++;
 | 
				
			||||||
 | 
						}
 | 
				
			||||||
 | 
						return 1;
 | 
				
			||||||
 | 
					}
 | 
				
			||||||
 | 
					#endif /* CONFIG_NONPROMISC_DEVMEM */
 | 
				
			||||||
 | 
					
 | 
				
			||||||
int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
 | 
					int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
 | 
				
			||||||
				unsigned long size, pgprot_t *vma_prot)
 | 
									unsigned long size, pgprot_t *vma_prot)
 | 
				
			||||||
{
 | 
					{
 | 
				
			||||||
| 
						 | 
					@ -485,6 +513,9 @@ int phys_mem_access_prot_allowed(struct file *file, unsigned long pfn,
 | 
				
			||||||
	unsigned long ret_flags;
 | 
						unsigned long ret_flags;
 | 
				
			||||||
	int retval;
 | 
						int retval;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
						if (!range_is_allowed(pfn, size))
 | 
				
			||||||
 | 
							return 0;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	if (file->f_flags & O_SYNC) {
 | 
						if (file->f_flags & O_SYNC) {
 | 
				
			||||||
		flags = _PAGE_CACHE_UC;
 | 
							flags = _PAGE_CACHE_UC;
 | 
				
			||||||
	}
 | 
						}
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in a new issue