title: Read address value from kernel using /dev/kmem
body: <p>Trying to read kernel address value (task_struct)</p>
  
  <p>Wrote this code:</p>
  
  <pre><code>#include &lt;sys/types.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;sys/stat.h&gt;
  #include &lt;sys/mman.h&gt;
  #include &lt;fcntl.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  
  #define addr 0xe6d63a80
  
  extern int errno;
  
  int main()
  {
          int i;
          unsigned char *kmem;
          unsigned char val;
  
          int fd = open("/dev/kmem",O_RDWR|O_SYNC);
          if(fd &lt; 0)
          {
                  printf("Can't open /dev/kmem\n");
                  return 1;
          }
          kmem = (unsigned char *) mmap(0, getpagesize(), PROT_READ|PROT_WRITE, MAP_SHARED, fd, 0xe6d63000);
          if(kmem == NULL)
          {
                  printf("Can't mmap\n");
                  return 1;
          }
          else
                  printf("kmem=%p\n",kmem);
  
  
          return 0;
  }
  </code></pre>
  
  <p>But it produces:</p>
  
  <pre><code>kmem=0xffffffff
  </code></pre>
  
  <p>Which does not look like a valid pointer to values of memory.</p>
  
  <p>How to read content of kernel memory? In this case: 0xe6d63a80. I know task_struct is there, since I verified it with the debugger.</p>
  
  <p>Thanks,</p>