* [PATCH] bugfix for drivers/char/mem.c
@ 1999-08-01 10:55 Steven Hand
1999-08-01 18:23 ` Kanoj Sarcar
0 siblings, 1 reply; 3+ messages in thread
From: Steven Hand @ 1999-08-01 10:55 UTC (permalink / raw)
To: Linux-MM; +Cc: Steven.Hand
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.
--- v2.3.12/linux/drivers/char/mem.c Sun Aug 1 11:09:11 1999
+++ linux/drivers/char/mem.c Sun Aug 1 11:25:07 1999
@@ -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 majordomo@kvack.org. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] bugfix for drivers/char/mem.c
1999-08-01 10:55 [PATCH] bugfix for drivers/char/mem.c Steven Hand
@ 1999-08-01 18:23 ` Kanoj Sarcar
1999-08-02 13:27 ` Steven Hand
0 siblings, 1 reply; 3+ messages in thread
From: Kanoj Sarcar @ 1999-08-01 18:23 UTC (permalink / raw)
To: Steven Hand; +Cc: Linux-MM
>
> 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.
>
> --- v2.3.12/linux/drivers/char/mem.c Sun Aug 1 11:09:11 1999
> +++ linux/drivers/char/mem.c Sun Aug 1 11:25:07 1999
> @@ -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;
> }
>
> /*
>
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 majordomo@kvack.org. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/
^ permalink raw reply [flat|nested] 3+ messages in thread* Re: [PATCH] bugfix for drivers/char/mem.c
1999-08-01 18:23 ` Kanoj Sarcar
@ 1999-08-02 13:27 ` Steven Hand
0 siblings, 0 replies; 3+ messages in thread
From: Steven Hand @ 1999-08-02 13:27 UTC (permalink / raw)
To: Kanoj Sarcar; +Cc: Steven Hand, Linux-MM
>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;
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 majordomo@kvack.org. For more info on Linux MM,
see: http://humbolt.geo.uu.nl/Linux-MM/
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~1999-08-02 13:27 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1999-08-01 10:55 [PATCH] bugfix for drivers/char/mem.c Steven Hand
1999-08-01 18:23 ` Kanoj Sarcar
1999-08-02 13:27 ` Steven Hand
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox