Skip to content

Commit

Permalink
---
Browse files Browse the repository at this point in the history
yaml
---
r: 93408
b: refs/heads/master
c: e2beb3e
h: refs/heads/master
v: v3
  • Loading branch information
Venki Pallipadi authored and Ingo Molnar committed Apr 24, 2008
1 parent a464326 commit 7c403d0
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
2 changes: 1 addition & 1 deletion [refs]
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
---
refs/heads/master: ae531c26c5c2a28ca1b35a75b39b3b256850f2c8
refs/heads/master: e2beb3eae627211b67e456c53f946cede2ac10d7
27 changes: 16 additions & 11 deletions trunk/drivers/char/mem.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,24 +109,26 @@ static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t size)
#endif

#ifdef CONFIG_NONPROMISC_DEVMEM
static inline int range_is_allowed(unsigned long from, unsigned long to)
static inline int range_is_allowed(unsigned long pfn, unsigned long size)
{
unsigned long cursor;
u64 from = ((u64)pfn) << PAGE_SHIFT;
u64 to = from + size;
u64 cursor = from;

cursor = from >> PAGE_SHIFT;
while ((cursor << PAGE_SHIFT) < to) {
if (!devmem_is_allowed(cursor)) {
printk(KERN_INFO "Program %s tried to read /dev/mem "
"between %lx->%lx.\n",
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++;
cursor += PAGE_SIZE;
pfn++;
}
return 1;
}
#else
static inline int range_is_allowed(unsigned long from, unsigned long to)
static inline int range_is_allowed(unsigned long pfn, unsigned long size)
{
return 1;
}
Expand Down Expand Up @@ -181,7 +183,7 @@ static ssize_t read_mem(struct file * file, char __user * buf,
*/
ptr = xlate_dev_mem_ptr(p);

if (!range_is_allowed(p, p+count))
if (!range_is_allowed(p >> PAGE_SHIFT, count))
return -EPERM;
if (copy_to_user(buf, ptr, sz))
return -EFAULT;
Expand Down Expand Up @@ -240,7 +242,7 @@ static ssize_t write_mem(struct file * file, const char __user * buf,
*/
ptr = xlate_dev_mem_ptr(p);

if (!range_is_allowed(p, p+sz))
if (!range_is_allowed(p >> PAGE_SHIFT, sz))
return -EPERM;
copied = copy_from_user(ptr, buf, sz);
if (copied) {
Expand Down Expand Up @@ -309,6 +311,9 @@ static int mmap_mem(struct file * file, struct vm_area_struct * vma)
if (!private_mapping_ok(vma))
return -ENOSYS;

if (!range_is_allowed(vma->vm_pgoff, size))
return -EPERM;

vma->vm_page_prot = phys_mem_access_prot(file, vma->vm_pgoff,
size,
vma->vm_page_prot);
Expand Down

0 comments on commit 7c403d0

Please sign in to comment.