linux-um archives
 help / color / mirror / Atom feed
From: BlaisorBlade <blaisorblade_spam@yahoo.it>
To: user-mode-linux-devel@lists.sourceforge.net
Subject: Re: [uml-devel] [tracked down] Kernel mode fault with /dev/kmem
Date: Thu, 8 Jan 2004 18:34:43 +0100	[thread overview]
Message-ID: <200401081834.44045.blaisorblade_spam@yahoo.it> (raw)
In-Reply-To: <Pine.LNX.4.44.0401071254540.1058-100000@gradall.private.brainfood.com>

Alle 20:18, mercoledì 7 gennaio 2004, Adam Heath ha scritto:
> On Thu, 8 Jan 2004, Jeff Chua wrote:
> > open("/dev/kmem", O_RDONLY)             = 3
> > _llseek(0x3, 0, 0xa8965000, 0xbffff934, 0) = 0
> > read(3, Kernel panic: Kernel mode fault at addr 0x48965000, ip 0x400df1a4
>
> 0xa8965000 != 0x48965000
>
> Note how only the first octet is different.

Ok, excellent note; or better, that behaviour (a different address) *is* 
right, but the difference is *wrong*.

Reading the code of read_kmem as patched, we get this pseudo-code:

p=*ppos; //position pointer
...
p = __va(p); /*translate physical address to virtual, like: */
//p += uml_physmem;

However, starting from 0xa8965000, and increasing it by 2,5Gb, we get an 
overflow, i.e. p becomes <old p> + 2,5Gb - 4Gb = <old p> - 1,5 Gb=0x48965000.

So we've got to the bug. But anyway, doing p=__va(p) is a wrong fix because an 
offset inside /dev/kmem is already virtual (comments in the file are clear), 
and in read_mem we see:
  copy_to_user(buf, __va(p), count).

So, the patch just turns /dev/kmem into /dev/mem, on reading, while it doesn't 
do the overflow check done inside read_mem. On writing, instead, it changes 
nothing, so we would have probably other panics.

What I've read about the patch was that the kmem driver "incorrectly assumes 
the address space starts from the 0 address", IIRC. If this is correct, then 
the correct fix would be to check whether the address is mapped and to 
provide a suitable error code, either -EFAULT, or 0, as here:

static ssize_t read_mem(struct file * file, char * buf,
                        size_t count, loff_t *ppos) {
        unsigned long p = *ppos;
        unsigned long end_mem;
        ssize_t read;

        end_mem = __pa(high_memory);
        if (p >= end_mem)
                return 0;
	/*...*/
}

However, I'm not up to see how to exactly do the check (even if this check is 
already done when using the copy_from_user macros).

Bye
-- 
cat <<EOSIGN
Paolo Giarrusso, aka Blaisorblade
Linux Kernel 2.4.23/2.6.0 on an i686; Linux registered user n. 292729
EOSIGN


-------------------------------------------------------
This SF.net email is sponsored by: Perforce Software.
Perforce is the Fast Software Configuration Management System offering
advanced branching capabilities and atomic changes on 50+ platforms.
Free Eval! http://www.perforce.com/perforce/loadprog.html
_______________________________________________
User-mode-linux-devel mailing list
User-mode-linux-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

  reply	other threads:[~2004-01-08 17:38 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-12-29 16:32 [uml-devel] Kernel mode fault at addr 0x48965000, ip 0x400e51a4 Jeff Chua
     [not found] ` <200401061718.i 06HILtd002620@ccure.user-mode-linux.org>
     [not found] ` <200401061718.i  06HILtd002620@ccure.user-mode-linux.org>
     [not found] ` <200401060258.i 062wuFI023117@ccure.user-mode-linux.org>
2003-12-30 18:06 ` BlaisorBlade
2004-01-01  6:14   ` Jeff Chua
2004-01-06  2:58 ` Jeff Dike
2004-01-06 15:57   ` Johannes Formann
2004-01-06 17:18     ` Jeff Dike
2004-01-06 18:11       ` Johannes Formann
2004-01-06 18:18         ` BlaisorBlade
2004-01-06 18:49           ` Johannes Formann
2004-01-06 16:33             ` [uml-devel] Kernel mode fault at addr 0x48965000, ip0x400e51a4 stian
2004-01-06 19:06               ` Johannes Formann
2004-01-06 19:40                 ` Johannes Formann
2004-01-06 19:34                   ` Jeff Chua
2004-01-06 21:00                     ` Johannes Formann
2004-01-06 20:47                       ` Jeff Chua
2004-01-06 21:47                         ` Johannes Formann
2004-01-06 21:32                           ` Jeff Chua
2004-01-06 21:55                             ` Johannes Formann
2004-01-06 21:39                               ` Jeff Chua
2004-01-07  5:53                                 ` Johannes Formann
2004-01-07 17:10                                   ` Jeff Chua
2004-01-07 19:18                                     ` Johannes Formann
2004-01-07 19:25                     ` BlaisorBlade
2004-01-10 20:33                       ` Johannes Formann
2004-01-11 12:34                         ` BlaisorBlade
2004-01-11 15:25                           ` Johannes Formann
2004-01-11 15:46                             ` BlaisorBlade
2004-01-11 18:04                               ` Johannes Formann
2004-02-21 11:23                                 ` Johannes Formann
2004-02-21 15:34                                   ` BlaisorBlade
2004-01-11 23:04                               ` Jeff Chua
2004-01-13 18:14                                 ` BlaisorBlade
2004-01-06 20:55                   ` Jeff Dike
2004-03-04  2:16                   ` Jeff Dike
2004-03-04 22:46                     ` [uml-devel] compile issue when removing CONFIG_MODE_TT roland
2004-01-06 19:07             ` [uml-devel] Kernel mode fault at addr 0x48965000, ip 0x400e51a4 BlaisorBlade
2004-01-06 18:00     ` Jeff Chua
2004-01-06 16:15       ` stian
2004-01-07 17:08         ` Jeff Chua
2004-01-07 19:18           ` Adam Heath
2004-01-08 17:34             ` BlaisorBlade [this message]
2004-03-04  2:16 ` Jeff Dike
2004-03-04  2:19   ` Jeff Chua
2004-03-07 10:54     ` 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=200401081834.44045.blaisorblade_spam@yahoo.it \
    --to=blaisorblade_spam@yahoo.it \
    --cc=user-mode-linux-devel@lists.sourceforge.net \
    /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