linux-kernel.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Steven Hand <Steven.Hand@cl.cam.ac.uk>
To: linux-kernel@vger.rutgers.edu
Cc: Steven.Hand@cl.cam.ac.uk
Subject: [patch] file position update when reading /dev/kmem
Date: Mon, 10 May 1999 23:02:51 +0100	[thread overview]
Message-ID: <E10gy8U-0004m5-00@heaton.cl.cam.ac.uk> (raw)

[-- Attachment #1: Type: text/plain, Size: 542 bytes --]


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.



[-- Attachment #2: kmem_patch --]
[-- Type: text/plain , Size: 427 bytes --]

--- 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;
 }
 
 /*

                 reply	other threads:[~1999-05-10 23:48 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=E10gy8U-0004m5-00@heaton.cl.cam.ac.uk \
    --to=steven.hand@cl.cam.ac.uk \
    --cc=linux-kernel@vger.rutgers.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).