lkml.org 
[lkml]   [2011]   [Jun]   [17]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[PATCH 01/10] Return EOF on out-of-bounds read from /dev/mem
Date
The off parameter (type loff_t) may specify an offset that cannot
be represented by a long. Currently, /dev/mem wraps around, which
may to cause applications to read/write incorrect regions of memory
by accident.

Follow the usual file semantics here and return 0 when reading or
-EFBIG when writing beyond the accessible range.

Signed-off-by: Petr Tesarik <ptesarik@suse.cz>
---
drivers/char/mem.c | 6 ++++++
1 files changed, 6 insertions(+), 0 deletions(-)

diff --git a/drivers/char/mem.c b/drivers/char/mem.c
index 8fc04b4..f5cbd4e 100644
--- a/drivers/char/mem.c
+++ b/drivers/char/mem.c
@@ -97,6 +97,9 @@ static ssize_t read_mem(struct file *file, char __user *buf,
ssize_t read, sz;
char *ptr;

+ if (p != *ppos)
+ return 0;
+
if (!valid_phys_addr_range(p, count))
return -EFAULT;
read = 0;
@@ -155,6 +158,9 @@ static ssize_t write_mem(struct file *file, const char __user *buf,
unsigned long copied;
void *ptr;

+ if (p != *ppos)
+ return -EFBIG;
+
if (!valid_phys_addr_range(p, count))
return -EFAULT;

--
1.7.3.4

\
 
 \ /
  Last update: 2011-06-17 10:59    [W:0.143 / U:1.072 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site