From: BlaisorBlade <blaisorblade_spam@yahoo.it>
To: Marcelo Tosatti <marcelo.tosatti@cyclades.com>
Cc: linux-kernel@vger.kernel.org
Subject: [PATCH/2.4.26] Avoid kernel data corruption through /dev/kmem
Date: Thu, 1 Jul 2004 16:05:29 +0200 [thread overview]
Message-ID: <200407011605.29386.blaisorblade_spam@yahoo.it> (raw)
[-- Attachment #1: Type: text/plain, Size: 224 bytes --]
I'm sending this fix for /dev/kmem; I already sent a cleanup about this, but
since you said "cleanups go in 2.6", then I'm sending only the bugfix.
Bye
--
Paolo Giarrusso, aka Blaisorblade
Linux registered user n. 292729
[-- Attachment #2: fix-mem-return.patch --]
[-- Type: text/x-diff, Size: 1363 bytes --]
We need to check if do_write_mem == -EFAULT.
In fact, without that check, we could execute this:
do_write_mem returns -EFAULT;
wrote = -EFAULT;
buf += wrote; //i.e. buf -= EFAULT (14);
... read other data from buf, and write it to kernel memory
(actually on special circumstances, i.e. p < high_memory &&
p + count > high_memory).
Luckily not at all exploitable (not even in the OpenBSD idea) since
to write on /dev/kmem you must already be root.
---
linux-2.4.26-paolo/drivers/char/mem.c | 8 +++++---
1 files changed, 5 insertions(+), 3 deletions(-)
diff -puN drivers/char/mem.c~fix-mem-return drivers/char/mem.c
--- linux-2.4.26/drivers/char/mem.c~fix-mem-return 2004-07-01 15:14:00.275806312 +0200
+++ linux-2.4.26-paolo/drivers/char/mem.c 2004-07-01 15:28:24.604408392 +0200
@@ -287,11 +287,13 @@ static ssize_t write_kmem(struct file *
char * kbuf; /* k-addr because vwrite() takes vmlist_lock rwlock */
if (p < (unsigned long) high_memory) {
- wrote = count;
+ ssize_t towrite = count;
if (count > (unsigned long) high_memory - p)
- wrote = (unsigned long) high_memory - p;
+ towrite = (unsigned long) high_memory - p;
- wrote = do_write_mem(file, (void*)p, p, buf, wrote, ppos);
+ wrote = do_write_mem(file, (void*)p, p, buf, towrite, ppos);
+ if (wrote != towrite)
+ return wrote;
p += wrote;
buf += wrote;
_
next reply other threads:[~2004-07-01 16:49 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2004-07-01 14:05 BlaisorBlade [this message]
2004-07-02 13:18 ` Marcelo Tosatti
2004-07-03 18:13 ` BlaisorBlade
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=200407011605.29386.blaisorblade_spam@yahoo.it \
--to=blaisorblade_spam@yahoo.it \
--cc=linux-kernel@vger.kernel.org \
--cc=marcelo.tosatti@cyclades.com \
/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
all inboxes | Powered by JetHome®