Re: [PATCH] Fix mmap_kmem (was: [question] What's the difference between /dev/km

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Fri, 12 Aug 2005 at 15:25:18 +0100 (BST), Hugh Dickins wrote:

> On Thu, 11 Aug 2005, Steven Rostedt wrote:
> > 
> > Found the problem.  It is a bug with mmap_kmem.  The order of checks is
> > wrong, so here's the patch.
> 
> Good find, looks right to me, so far as it goes (why does this check

 Even with Steven's patch applied, root cannot read from /dev/kmem with the
following program, which works on 2.6.9.  "Invalid argument" means that the
"fd is attached to an object that is unsuitable for reading."

# ./desc2
GDT is at 0xc13097a0
read /dev/kmem: Invalid argument


#include <stdio.h>
#include <fcntl.h>
#define perr(err) { perror(err), exit(1); }

struct {
        unsigned short limit;
        unsigned int base;
} __attribute__ ((packed)) dtr;

int kmem, i;
int buf[1024];

int main() {
        if ((kmem = open("/dev/kmem", O_RDONLY)) < 0)
                perr("open /dev/kmem");

        asm("sgdtl %0" : "=m"(dtr));
        printf("GDT is at 0x%x\n", dtr.base);
        dtr.limit++;  /* convert to size */

        if (lseek(kmem, dtr.base, SEEK_SET) != dtr.base)
                perr("lseek /dev/kmem");
        if (read(kmem, buf, dtr.limit) != dtr.limit)
                perr("read /dev/kmem");

        for (i = 0; i < dtr.limit / 4; i += 2)
                if (buf[i+1])
                        printf("entry %d(0x%x): 0x%x 0x%x\n",
                                i / 2, i / 2, buf[i], buf[i+1]);

        return 0;
}

__
Chuck
-
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to [email protected]
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Please read the FAQ at  http://www.tux.org/lkml/

[Index of Archives]     [Kernel Newbies]     [Netfilter]     [Bugtraq]     [Photo]     [Gimp]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Video 4 Linux]     [Linux for the blind]
  Powered by Linux