lkml.org 
[lkml]   [1999]   [May]   [10]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
Subject[patch] file position update when reading /dev/kmem
Date
From

When read()'ing from /dev/kmem, the file position is incorrectly updated, which
bites you if you perform >1 read on the file before close()'ing it. AFAICS, the
bug has been around since at least 2.1.127.

The tiny patch attached below is against 2.2.7 and should fix the problem.
Notice that the first part of the patch is simply an optimisation to avoid
calling vread() and iterating along every vmalloc'd area in the case that
copy_to_user() has already done its stuff. The line involving the update
of *ppos is the important one.

S.


--- v2.2.7/linux/drivers/char/mem.c Mon May 10 22:29:38 1999
+++ linux/drivers/char/mem.c Mon May 10 22:27:59 1999
@@ -247,11 +247,14 @@
count -= read;
}

- virtr = vread(buf, (char *)p, count);
- if (virtr < 0)
- return virtr;
- *ppos += p + virtr;
- return virtr + read;
+ if(count) {
+ if((virtr = vread(buf, (char *)p, count)) < 0)
+ return virtr;
+ read += virtr;
+ }
+
+ *ppos += read;
+ return read;
}

/*
\
 
 \ /
  Last update: 2005-03-22 13:51    [from the cache]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and my Meterkast|Read the blog