bugfix for drivers/char/mem.c
Subsystems (2)
PATCH 1/1 bugfix for drivers/char/mem.c
There is a bug in the function read_kmem() in drivers/char/mem.c - the file position is incorrectly updated after a read() from /dev/kmem. This means that successive reads from /dev/kmem without an intervening seek will return incorrect data.
The bug has been around for quite a while, and is present in all the 2.2.x kernels. The following patch (against v.2.3.12) fixes it.
S.
drivers/char/mem.c renamed from linux/drivers/char/mem.c +8 -5
@@ -245,11 +245,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; }/*
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/
Quoted 25 lines
There is a bug in the function
read_kmem()indrivers/char/mem.c- the file position is incorrectly updated after aread()from/dev/kmem. This means that successive reads from/dev/kmemwithout an intervening seek will return incorrect data.The bug has been around for quite a while, and is present in all the 2.2.x kernels. The following patch (against v.2.3.12) fixes it.
S.
drivers/char/mem.c renamed from linux/drivers/char/mem.c +1
-5@@ -245,11 +245,14 @@ count -= read; } - virtr =vread (buf, (char *)p, count); -if (virtr <0 ) -return virtr; - *ppos += p + virtr; -return virtr + read; +if (count) {
drivers/char/mem.c line 258
Quoted 10 lines
drivers/char/mem.c renamed from linux/drivers/char/mem.c +7
-0+if ((virtr =vread (buf, (char *)p, count)) <0 ) +return virtr; + read += virtr; + } + + *ppos += read; +return read; }/*
I see the problem. Can I suggest a simpler fix, based on the fact that vread() returns 0 when count == 0?
- *ppos += p + virtr;
+ *ppos += read + virtr;
Kanoj
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/
Review
Quoted 5 lines
I see the problem. Can I suggest a simpler fix, based on the fact that
vread()returns 0 when count == 0?(quoted diff) +1
-1- *ppos += p + virtr; + *ppos += read + virtr;
Sure if you prefer it.
The main reason I added the if(count) { ... } was just to avoid calling vread() when count is zero (since in this case there's no entry to find on the vmlist, and hence the for loop in vread() will just iterate over all vmalloc()'d areas before returning zero.)
S.
--
To unsubscribe, send a message with 'unsubscribe linux-mm' in the body to [email protected]. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/