<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
		>
<channel>
	<title>Comments on: Examining the Linux VDSO</title>
	<atom:link href="http://anomit.com/2010/04/18/examining-the-linux-vdso/feed/" rel="self" type="application/rss+xml" />
	<link>http://anomit.com/2010/04/18/examining-the-linux-vdso/</link>
	<description></description>
	<lastBuildDate>Sun, 07 Aug 2011 08:30:12 +0000</lastBuildDate>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.2.1</generator>
	<item>
		<title>By: Brandon Potter</title>
		<link>http://anomit.com/2010/04/18/examining-the-linux-vdso/comment-page-1/#comment-8062</link>
		<dc:creator>Brandon Potter</dc:creator>
		<pubDate>Thu, 21 Jul 2011 19:57:40 +0000</pubDate>
		<guid isPermaLink="false">http://anomit.com/?p=200#comment-8062</guid>
		<description>I looked at using the &quot;dd&quot; command for a bit.  I couldn&#039;t figure out how to get it to work with the /proc/pid/mem file.  I don&#039;t know what &quot;dd&quot; is using internally to read from the file, but I ended up getting output similar to Ezra; dropping to root does nothing to resolve the issue.

I know that for /proc/pid/pagemap that you can extract the page frame numbers using lseek and read which is similar to the python script above; I could be that &quot;mem&quot; uses something similar.  It probably only has a few methods defined and &quot;dd&quot; might use something that is not supported.  This is just speculation for /proc/pid/mem as I don&#039;t have any proof.  For /proc/pid/pagemap, see the following LXR link for its operations:
    http://lxr.linux.no/linux+v2.6.39/fs/proc/task_mmu.c#L854

It would be interesting to see if anyone has a method that works directly from a command line and doesn&#039;t require a script or C program.</description>
		<content:encoded><![CDATA[<p>I looked at using the &#8220;dd&#8221; command for a bit.  I couldn&#8217;t figure out how to get it to work with the /proc/pid/mem file.  I don&#8217;t know what &#8220;dd&#8221; is using internally to read from the file, but I ended up getting output similar to Ezra; dropping to root does nothing to resolve the issue.</p>
<p>I know that for /proc/pid/pagemap that you can extract the page frame numbers using lseek and read which is similar to the python script above; I could be that &#8220;mem&#8221; uses something similar.  It probably only has a few methods defined and &#8220;dd&#8221; might use something that is not supported.  This is just speculation for /proc/pid/mem as I don&#8217;t have any proof.  For /proc/pid/pagemap, see the following LXR link for its operations:<br />
    <a href="http://lxr.linux.no/linux+v2.6.39/fs/proc/task_mmu.c#L854" rel="nofollow">http://lxr.linux.no/linux+v2.6.39/fs/proc/task_mmu.c#L854</a></p>
<p>It would be interesting to see if anyone has a method that works directly from a command line and doesn&#8217;t require a script or C program.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Brandon Potter</title>
		<link>http://anomit.com/2010/04/18/examining-the-linux-vdso/comment-page-1/#comment-8056</link>
		<dc:creator>Brandon Potter</dc:creator>
		<pubDate>Thu, 21 Jul 2011 18:29:17 +0000</pubDate>
		<guid isPermaLink="false">http://anomit.com/?p=200#comment-8056</guid>
		<description>You probably have Address Space Layout Randomization (ASLR) turned on.  It randomizes the virtual addresses within the kernel for security reasons.

To check to see if it is enabled, try:
    sudo cat /proc/sys/kernel/randomize_va_space

If it returns 2, the default, then ASLR is turned on.

To turn it off, try:
    sudo su
    sudo echo 0 &gt; /proc/sys/kernel/randomize_va_space

This overcomes the need to write a clever script to extract the virtual address; the address will remain constant on subsequent runs.

I am not sure what you&#039;re doing with the &quot;dd&quot; command because you&#039;re opening up a snapshot of the &quot;dd&quot; process internals.  Previously, you were opening up the &quot;cat&quot; internals.  The two should be completely different.

You might try to write a small C program that contains an infinite loop; you can look at the process ID of that program and then look in /proc/PID/maps for the VDSO page offset.  I think that &quot;dd&quot; uses the decimal offset for the number of pages, the reason why you used &quot;4096&quot;.

The &quot;dd&quot; command becomes:
    dd if=/proc/PID_C_PROGRAM/mem of=linux-gate.dso bs=4096 skip=CALCULATED_OFFSET_IN_PAGES count=1
    objdump -d linux-gate.dso

You might try something like the above.  I don&#039;t really use objdump for anything other than looking at ELF executables.  I don&#039;t really know what /proc/PID/mem contains so I have no idea what the output would look like.  It might work though.</description>
		<content:encoded><![CDATA[<p>You probably have Address Space Layout Randomization (ASLR) turned on.  It randomizes the virtual addresses within the kernel for security reasons.</p>
<p>To check to see if it is enabled, try:<br />
    sudo cat /proc/sys/kernel/randomize_va_space</p>
<p>If it returns 2, the default, then ASLR is turned on.</p>
<p>To turn it off, try:<br />
    sudo su<br />
    sudo echo 0 &gt; /proc/sys/kernel/randomize_va_space</p>
<p>This overcomes the need to write a clever script to extract the virtual address; the address will remain constant on subsequent runs.</p>
<p>I am not sure what you&#8217;re doing with the &#8220;dd&#8221; command because you&#8217;re opening up a snapshot of the &#8220;dd&#8221; process internals.  Previously, you were opening up the &#8220;cat&#8221; internals.  The two should be completely different.</p>
<p>You might try to write a small C program that contains an infinite loop; you can look at the process ID of that program and then look in /proc/PID/maps for the VDSO page offset.  I think that &#8220;dd&#8221; uses the decimal offset for the number of pages, the reason why you used &#8220;4096&#8243;.</p>
<p>The &#8220;dd&#8221; command becomes:<br />
    dd if=/proc/PID_C_PROGRAM/mem of=linux-gate.dso bs=4096 skip=CALCULATED_OFFSET_IN_PAGES count=1<br />
    objdump -d linux-gate.dso</p>
<p>You might try something like the above.  I don&#8217;t really use objdump for anything other than looking at ELF executables.  I don&#8217;t really know what /proc/PID/mem contains so I have no idea what the output would look like.  It might work though.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Igor</title>
		<link>http://anomit.com/2010/04/18/examining-the-linux-vdso/comment-page-1/#comment-5540</link>
		<dc:creator>Igor</dc:creator>
		<pubDate>Thu, 14 Apr 2011 18:18:48 +0000</pubDate>
		<guid isPermaLink="false">http://anomit.com/?p=200#comment-5540</guid>
		<description>For readability /proc//mem see very good explanation here: http://unix.stackexchange.com/questions/6301/how-do-i-read-from-proc-pid-mem-under-linux</description>
		<content:encoded><![CDATA[<p>For readability /proc//mem see very good explanation here: <a href="http://unix.stackexchange.com/questions/6301/how-do-i-read-from-proc-pid-mem-under-linux" rel="nofollow">http://unix.stackexchange.com/questions/6301/how-do-i-read-from-proc-pid-mem-under-linux</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Igor</title>
		<link>http://anomit.com/2010/04/18/examining-the-linux-vdso/comment-page-1/#comment-5539</link>
		<dc:creator>Igor</dc:creator>
		<pubDate>Thu, 14 Apr 2011 18:14:56 +0000</pubDate>
		<guid isPermaLink="false">http://anomit.com/?p=200#comment-5539</guid>
		<description>Suresh&#039;s on-liner doesn&#039;t work, because there are different &#039;selfs&#039; there. 

&#039;cat /proc/self/maps &#124; ...&#039; produces mapping for &#039;cat&#039;, not necessarily identical to that of &#039;dd&#039;.</description>
		<content:encoded><![CDATA[<p>Suresh&#8217;s on-liner doesn&#8217;t work, because there are different &#8216;selfs&#8217; there. </p>
<p>&#8216;cat /proc/self/maps | &#8230;&#8217; produces mapping for &#8216;cat&#8217;, not necessarily identical to that of &#8216;dd&#8217;.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ezra Gilbert</title>
		<link>http://anomit.com/2010/04/18/examining-the-linux-vdso/comment-page-1/#comment-3629</link>
		<dc:creator>Ezra Gilbert</dc:creator>
		<pubDate>Wed, 01 Sep 2010 14:04:18 +0000</pubDate>
		<guid isPermaLink="false">http://anomit.com/?p=200#comment-3629</guid>
		<description>The code in the last comment did not come out very well.  Here is a link to a fork of anomit&#039;s gist above that works with python 2.4.3: http://gist.github.com/560719</description>
		<content:encoded><![CDATA[<p>The code in the last comment did not come out very well.  Here is a link to a fork of anomit&#8217;s gist above that works with python 2.4.3: <a href="http://gist.github.com/560719" rel="nofollow">http://gist.github.com/560719</a></p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ezra Gilbert</title>
		<link>http://anomit.com/2010/04/18/examining-the-linux-vdso/comment-page-1/#comment-3628</link>
		<dc:creator>Ezra Gilbert</dc:creator>
		<pubDate>Wed, 01 Sep 2010 13:57:45 +0000</pubDate>
		<guid isPermaLink="false">http://anomit.com/?p=200#comment-3628</guid>
		<description>Here is a version of the python script that works with python 2.4.3 (maybe 2.4.x).  I basically removed the un-supported &quot;with&quot; statements and replaced os.SEEK_SET with 0 (per http://docs.python.org/library/os.html)

Also, I think the reason Suresh&#039;s 1-line script does not work is because the address read for vdso is for process &#039;cat&#039; and it is not a valid address when process &#039;dd&#039; tries to read from /proc/self/mem.  For it to work, the same process that reads the vdso address from /proc/self/maps needs to read linux-gate.so from /proc/self/mem.

-Ezra

[python]
#!/usr/bin/python

&quot;&quot;&quot;
http://anomit.com/2010/04/18/examining-the-linux-vdso/
http://gist.github.com/369785

This script writes the VDSO to the file linux-gate.dso.1 .
Use `objdump -d linux-gate.dso.1` to examine it.
You might also want to play around more with the other objdump options and
the readelf tool :)

LICENSE: MIT License ( http://www.opensource.org/licenses/mit-license.php )
&quot;&quot;&quot;
#from __future__ import with_statement
import os
import re

## regex pattern for finding out the memory address range from the output line
pattern = re.compile(r&#039;[\w\d]+-[\w\d]+&#039;)
file = open(&#039;/proc/self/maps&#039;, &#039;r&#039;)
for line in file:
    line = line.rstrip()
    if &#039;[vdso]&#039; in line:
        addr_range = pattern.findall(line)[0]
        start_addr, end_addr = [int(addr, 16)
                                for addr in addr_range.split(&#039;-&#039;)]
        break

fd = os.open(&#039;/proc/self/mem&#039;, os.O_RDONLY)
os.lseek(fd, start_addr, 0)
buf = os.read(fd, (end_addr-start_addr))

file = open(&#039;linux-gate.dso.1&#039;, &#039;w&#039;)
file.write(buf)
file.close()
os.close(fd)
[/python]</description>
		<content:encoded><![CDATA[<p>Here is a version of the python script that works with python 2.4.3 (maybe 2.4.x).  I basically removed the un-supported &#8220;with&#8221; statements and replaced os.SEEK_SET with 0 (per <a href="http://docs.python.org/library/os.html" rel="nofollow">http://docs.python.org/library/os.html</a>)</p>
<p>Also, I think the reason Suresh&#8217;s 1-line script does not work is because the address read for vdso is for process &#8216;cat&#8217; and it is not a valid address when process &#8216;dd&#8217; tries to read from /proc/self/mem.  For it to work, the same process that reads the vdso address from /proc/self/maps needs to read linux-gate.so from /proc/self/mem.</p>
<p>-Ezra</p>
<pre class="brush: python; title: ;">
#!/usr/bin/python

&quot;&quot;&quot;
<a href="http://anomit.com/2010/04/18/examining-the-linux-vdso/" rel="nofollow">http://anomit.com/2010/04/18/examining-the-linux-vdso/</a>
<a href="http://gist.github.com/369785" rel="nofollow">http://gist.github.com/369785</a>

This script writes the VDSO to the file linux-gate.dso.1 .
Use `objdump -d linux-gate.dso.1` to examine it.
You might also want to play around more with the other objdump options and
the readelf tool <img src='http://anomit.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> 

LICENSE: MIT License ( <a href="http://www.opensource.org/licenses/mit-license.php" rel="nofollow">http://www.opensource.org/licenses/mit-license.php</a> )
&quot;&quot;&quot;
#from __future__ import with_statement
import os
import re

## regex pattern for finding out the memory address range from the output line
pattern = re.compile(r'[\w\d]+-[\w\d]+')
file = open('/proc/self/maps', 'r')
for line in file:
    line = line.rstrip()
    if '[vdso]' in line:
        addr_range = pattern.findall(line)[0]
        start_addr, end_addr = [int(addr, 16)
                                for addr in addr_range.split('-')]
        break

fd = os.open('/proc/self/mem', os.O_RDONLY)
os.lseek(fd, start_addr, 0)
buf = os.read(fd, (end_addr-start_addr))

file = open('linux-gate.dso.1', 'w')
file.write(buf)
file.close()
os.close(fd)
</pre>
]]></content:encoded>
	</item>
	<item>
		<title>By: anomit</title>
		<link>http://anomit.com/2010/04/18/examining-the-linux-vdso/comment-page-1/#comment-3627</link>
		<dc:creator>anomit</dc:creator>
		<pubDate>Wed, 01 Sep 2010 13:09:01 +0000</pubDate>
		<guid isPermaLink="false">http://anomit.com/?p=200#comment-3627</guid>
		<description>Ezra, you need Python version 2.5 and above to support the context manager concept used by the `with&#039; statement. More here: http://docs.python.org/release/2.5.2/lib/typecontextmanager.html

Sorry for that. You can create just a simple file object using the normal open() and work with it :).</description>
		<content:encoded><![CDATA[<p>Ezra, you need Python version 2.5 and above to support the context manager concept used by the `with&#8217; statement. More here: <a href="http://docs.python.org/release/2.5.2/lib/typecontextmanager.html" rel="nofollow">http://docs.python.org/release/2.5.2/lib/typecontextmanager.html</a></p>
<p>Sorry for that. You can create just a simple file object using the normal open() and work with it <img src='http://anomit.com/wordpress/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> .</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ezra Gilbert</title>
		<link>http://anomit.com/2010/04/18/examining-the-linux-vdso/comment-page-1/#comment-3626</link>
		<dc:creator>Ezra Gilbert</dc:creator>
		<pubDate>Wed, 01 Sep 2010 13:05:20 +0000</pubDate>
		<guid isPermaLink="false">http://anomit.com/?p=200#comment-3626</guid>
		<description>Suresh,

Your dd 1-liner gives me the following error:

dd if=/proc/self/mem of=vdso skip=$((0x`cat /proc/self/maps &#124; grep vdso &#124; cut -d&#039;-&#039; -f1`/0x1000)) count=1 bs=$((0x1000))
dd: reading `/proc/self/mem&#039;: Input/output error
0+0 records in
0+0 records out
0 bytes (0 B) copied, 0.000162585 seconds, 0.0 kB/s

Do I need to do something to make /proc/self/mem readable?  I am on 2.6.18 kernel.

Thanks.</description>
		<content:encoded><![CDATA[<p>Suresh,</p>
<p>Your dd 1-liner gives me the following error:</p>
<p>dd if=/proc/self/mem of=vdso skip=$((0x`cat /proc/self/maps | grep vdso | cut -d&#8217;-&#8217; -f1`/0&#215;1000)) count=1 bs=$((0&#215;1000))<br />
dd: reading `/proc/self/mem&#8217;: Input/output error<br />
0+0 records in<br />
0+0 records out<br />
0 bytes (0 B) copied, 0.000162585 seconds, 0.0 kB/s</p>
<p>Do I need to do something to make /proc/self/mem readable?  I am on 2.6.18 kernel.</p>
<p>Thanks.</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Ezra Gilbert</title>
		<link>http://anomit.com/2010/04/18/examining-the-linux-vdso/comment-page-1/#comment-3625</link>
		<dc:creator>Ezra Gilbert</dc:creator>
		<pubDate>Wed, 01 Sep 2010 13:03:28 +0000</pubDate>
		<guid isPermaLink="false">http://anomit.com/?p=200#comment-3625</guid>
		<description>Thanks for posting this article.  I read the original posting and was stuck on these very same issues.  But when I try to run your script I get error:

[root@asm-99 ~]# ./vdso.py
  File &quot;./vdso.py&quot;, line 20
    with open(&#039;/proc/self/maps&#039;, &#039;r&#039;) as file:
            ^
SyntaxError: invalid syntax

Do I need a particular version of python ?  I am using 2.4.3.

Thanks</description>
		<content:encoded><![CDATA[<p>Thanks for posting this article.  I read the original posting and was stuck on these very same issues.  But when I try to run your script I get error:</p>
<p>[root@asm-99 ~]# ./vdso.py<br />
  File &#8220;./vdso.py&#8221;, line 20<br />
    with open(&#8216;/proc/self/maps&#8217;, &#8216;r&#8217;) as file:<br />
            ^<br />
SyntaxError: invalid syntax</p>
<p>Do I need a particular version of python ?  I am using 2.4.3.</p>
<p>Thanks</p>
]]></content:encoded>
	</item>
	<item>
		<title>By: Suresh Kumar</title>
		<link>http://anomit.com/2010/04/18/examining-the-linux-vdso/comment-page-1/#comment-3465</link>
		<dc:creator>Suresh Kumar</dc:creator>
		<pubDate>Wed, 21 Jul 2010 12:12:10 +0000</pubDate>
		<guid isPermaLink="false">http://anomit.com/?p=200#comment-3465</guid>
		<description>Updated

Seem to have missed objdump

&lt;code&gt;
dd if=/proc/self/mem of=- skip=$((0x`cat /proc/self/maps &#124; grep vdso &#124; cut -d&#039;-&#039; -f1`/0x1000)) count=1 bs=$((0x1000)) &#124; objdump -d --start-address=0xffffe000 - &lt;/code&gt;</description>
		<content:encoded><![CDATA[<p>Updated</p>
<p>Seem to have missed objdump</p>
<p><code><br />
dd if=/proc/self/mem of=- skip=$((0x`cat /proc/self/maps | grep vdso | cut -d'-' -f1`/0x1000)) count=1 bs=$((0x1000)) | objdump -d --start-address=0xffffe000 - </code></p>
]]></content:encoded>
	</item>
</channel>
</rss>

