<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	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/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>technomasochism</title>
	<atom:link href="http://twobit.us/blog/feed/" rel="self" type="application/rss+xml" />
	<link>http://twobit.us/blog</link>
	<description>and two-wheeled vehicles</description>
	<lastBuildDate>Mon, 07 May 2012 16:39:23 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Chrome web sandbox on XenClient</title>
		<link>http://twobit.us/blog/2012/04/chrome-web-sandbox-on-xenclient/</link>
		<comments>http://twobit.us/blog/2012/04/chrome-web-sandbox-on-xenclient/#comments</comments>
		<pubDate>Thu, 26 Apr 2012 02:06:11 +0000</pubDate>
		<dc:creator>Philip</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[SysAdmin]]></category>
		<category><![CDATA[XenClient]]></category>

		<guid isPermaLink="false">http://twobit.us/blog/?p=1471</guid>
		<description><![CDATA[There&#8217;s lots of software out there that sets up a &#8220;sandbox&#8221; to protect your system from untrusted code. The examples that come to mind are Chrome and Adobe for the flash sandbox. The strength of these sandboxes are an interesting point of discussion. Strength is always related to the mechanism and if you&#8217;re running on [...]]]></description>
			<content:encoded><![CDATA[<p>There&#8217;s lots of software out there that sets up a &#8220;sandbox&#8221; to protect your system from untrusted code.  The examples that come to mind are Chrome and Adobe for the flash sandbox.  The strength of these sandboxes are an interesting point of discussion.  Strength is always related to the mechanism and if you&#8217;re running on Windows the separation guarantees you get are only as strong as the separation Windows affords to processes.  If this is a strong enough guarantee for you then you probably won&#8217;t find this post very useful.  If you&#8217;re interested in using XenClient and the Xen hypervisor to get yourself the strongest separation that I can think of, then read on!</p>
<h2>Use Case</h2>
<p>XenClient allows you to run any number of operating systems on a single piece of hardware.  In my case this is a laptop.  I&#8217;ve got two VMs: my work desktop (Windows 7) for email and other work stuff and my development system that runs Debian testing (Wheezy as of now).</p>
<p>Long story short, I don&#8217;t trust some of the crap that&#8217;s out on the web to run on either of these systems.  I&#8217;d like to confine my web browsing to a separate VM to protect my company&#8217;s data and my development system.  This article will show you how to build a bare bones Linux VM that runs a web browser (Chromium) and little more.</p>
<h2>Setup</h2>
<p>You&#8217;ll need a linux VM to host your web browser.  I like Debian Wheezy since the PV xen drivers for network and disk work out of the box on XenClient (2.1).  There&#8217;s a small bug that required you use LVM for your rootfs but I typically do that anyways so no worries there.  </p>
<p>Typically I do an install omitting even the &#8220;standard system tools&#8221; to keep things as small as possible.  This results in a root file system that&#8217;s < 1G.  All you need to do then is install the web browser (chromium), rungetty, and the xinint package.  Next is a bit of scripting and some minor configuration changes.</p>
<h3>inittab</h3>
<p>When this VM boots we want the web browser to launch and run full screen.  We don&#8217;t want a window manager or anything.  Just the browser.</p>
<p>When Linux boots, the <code>init</code> process parses the <code>/etc/inittab</code> file.  One of the things specified in <code>inittab</code> are processes that <code>init</code> starts like <code>getty</code>.  Typically <code>inittab</code> starts <code>getty</code>&#8216;s on 6 ttys but we want it to start chrome for us.  We can do this by having init execute <code>rungetty</code> (read the man page!)  which we can then have execute arbitrary commands for us:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;"># /sbin/getty invocations for the runlevels.
#
# The &quot;id&quot; field MUST be the same as the last
# characters of the device (after &quot;tty&quot;).
#
# Format:
#  &lt;id&gt;:&lt;runlevels&gt;:&lt;action&gt;:&lt;process&gt;
#
# Note that on most Debian systems tty7 is used by the X Window System,
# so if you want to add more getty's go ahead but skip tty7 if you run X.
#
1:2345:respawn:/sbin/getty 38400 tty1
2:23:respawn:/sbin/getty 38400 tty2
3:23:respawn:/sbin/getty 38400 tty3
4:23:respawn:/sbin/getty 38400 tty4
5:23:respawn:/sbin/getty 38400 tty5
6:23:respawn:/sbin/rungetty tty6 -u root /usr/sbin/chrome-restore.sh</pre></div></div>

<p>Another configuration change you&#8217;ll have to make is in <code>/etc/X11/Xwrapper.config</code>.  The default configuration in this file prevents users from starting X if their controlling TTY isn&#8217;t a virtual console.  Since we&#8217;re kicking off <code>chromium</code> directly we need to relax this restriction:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">allowed_users=anybody</pre></div></div>

<h3>chromium-restore script</h3>
<p>Notice that we have <code>rungetty</code> execute a script for us and it does so as the root user.  We don&#8217;t want <code>chromium</code> running as root but we need to do some set-up before we kick off <code>chromium</code> as an unprivileged user.  Here&#8217;s the <code>chrome-restore.sh</code> script:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #007800;">USER</span>=chromium
<span style="color: #007800;">HOMEDIR</span>=<span style="color: #000000; font-weight: bold;">/</span>home<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${USER}</span>
<span style="color: #007800;">HOMESAFE</span>=<span style="color: #000000; font-weight: bold;">/</span>usr<span style="color: #000000; font-weight: bold;">/</span>share<span style="color: #000000; font-weight: bold;">/</span><span style="color: #800000;">${USER}</span><span style="color: #660033;">-clean</span>
<span style="color: #007800;">CONFIG</span>=<span style="color: #800000;">${HOMEDIR}</span><span style="color: #000000; font-weight: bold;">/</span>.config<span style="color: #000000; font-weight: bold;">/</span>chromium<span style="color: #000000; font-weight: bold;">/</span>Default<span style="color: #000000; font-weight: bold;">/</span>Preferences
<span style="color: #007800;">LAUNCH</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #c20cb9; font-weight: bold;">which</span> chromium-launch.sh<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-x</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${LAUNCH}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;web-launch.sh not executable: <span style="color: #007800;">${LAUNCH}</span>&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
<span style="color: #007800;">CMD</span>=<span style="color: #ff0000;">&quot;<span style="color: #007800;">${LAUNCH}</span> <span style="color: #007800;">${CONFIG}</span>&quot;</span>
&nbsp;
rsync <span style="color: #660033;">-avh</span> <span style="color: #660033;">--delete</span> <span style="color: #800000;">${HOMESAFE}</span><span style="color: #000000; font-weight: bold;">/</span> <span style="color: #800000;">${HOMEDIR}</span><span style="color: #000000; font-weight: bold;">/</span> <span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;&amp;</span><span style="color: #000000;">1</span>
<span style="color: #c20cb9; font-weight: bold;">chown</span> <span style="color: #660033;">-R</span> <span style="color: #800000;">${USER}</span>:<span style="color: #800000;">${USER}</span> <span style="color: #800000;">${HOMEDIR}</span>
&nbsp;
<span style="color: #000000; font-weight: bold;">/</span>bin<span style="color: #000000; font-weight: bold;">/</span><span style="color: #c20cb9; font-weight: bold;">su</span> - <span style="color: #660033;">--</span> <span style="color: #800000;">${USER}</span> <span style="color: #660033;">-l</span> <span style="color: #660033;">-c</span> <span style="color: #ff0000;">&quot;STARTUP=<span style="color: #000099; font-weight: bold;">\&quot;</span><span style="color: #007800;">${CMD}</span><span style="color: #000099; font-weight: bold;">\&quot;</span> startx&quot;</span> <span style="color: #000000; font-weight: bold;">&lt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null
shutdown <span style="color: #660033;">-Ph</span> now</pre></div></div>

<p>The first part of this script is setting up the home directory for the user (chromium) that will be running chromium.  This is the equivalent of us restoring the users home directory to a &#8220;known good state&#8221;.  This means that the directory located at <code>/usr/share/chromium-clean</code> is a &#8220;known good&#8221; home directory for us to start from.  On my system it&#8217;s basically an empty directory with chrome&#8217;s default config.</p>
<p>The second part of the script, well really the last two lines just runs <code>startx</code> as an unprivileged user.  <code>startx</code> kicks off the X server but first we set a variable <code>STARTUP</code> to be the name of another script: <code>chromium-launch.sh</code>.  When this variable is set, <code>startx</code> runs the command from the variable after the X server is started.  This is a convenient way to kick off an X server that runs just a single graphical application.</p>
<p>The last command shuts down the VM.  The shutdown command will only be run after the X server terminates which will happen once the chromium process terminates.  This means that once the last browser tab is closed the VM will shutdown.</p>
<h3>chromium-launch script</h3>
<p>The <code>chromium-launch.sh</code> script looks like this:</p>

<div class="wp_syntax"><div class="code"><pre class="bash" style="font-family:monospace;"><span style="color: #666666; font-style: italic;">#!/bin/sh</span>
&nbsp;
<span style="color: #007800;">CONFIG</span>=<span style="color: #007800;">$1</span>
<span style="color: #000000; font-weight: bold;">if</span> <span style="color: #7a0874; font-weight: bold;">&#91;</span> <span style="color: #000000; font-weight: bold;">!</span> <span style="color: #660033;">-f</span> <span style="color: #ff0000;">&quot;<span style="color: #007800;">${CONFIG}</span>&quot;</span> <span style="color: #7a0874; font-weight: bold;">&#93;</span>; <span style="color: #000000; font-weight: bold;">then</span>
	<span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #ff0000;">&quot;cannot locate CONFIG: <span style="color: #007800;">${CONFIG}</span>&quot;</span>
	<span style="color: #7a0874; font-weight: bold;">exit</span> <span style="color: #000000;">1</span>
<span style="color: #000000; font-weight: bold;">fi</span>
&nbsp;
<span style="color: #007800;">LINE</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span>xrandr <span style="color: #660033;">-q</span> <span style="color: #000000;">2</span><span style="color: #000000; font-weight: bold;">&gt;</span> <span style="color: #000000; font-weight: bold;">/</span>dev<span style="color: #000000; font-weight: bold;">/</span>null <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">grep</span> Screen<span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">WIDTH</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${LINE}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $8 }'</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
<span style="color: #007800;">HEIGHT</span>=$<span style="color: #7a0874; font-weight: bold;">&#40;</span><span style="color: #7a0874; font-weight: bold;">echo</span> <span style="color: #800000;">${LINE}</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">awk</span> <span style="color: #ff0000;">'{ print $10 }'</span> <span style="color: #000000; font-weight: bold;">|</span> <span style="color: #c20cb9; font-weight: bold;">tr</span> <span style="color: #660033;">-d</span> <span style="color: #ff0000;">','</span><span style="color: #7a0874; font-weight: bold;">&#41;</span>
&nbsp;
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s&amp;\(\s\+<span style="color: #000099; font-weight: bold;">\&quot;</span>bottom<span style="color: #000099; font-weight: bold;">\&quot;</span>:\s\+\)-\?[0-9]\+&amp;\1<span style="color: #007800;">${HEIGHT}</span>&amp;&quot;</span> <span style="color: #800000;">${CONFIG}</span>
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s&amp;\(\s\+<span style="color: #000099; font-weight: bold;">\&quot;</span>left<span style="color: #000099; font-weight: bold;">\&quot;</span>:\s\+\)-\?[0-9]\+&amp;\10&amp;&quot;</span> <span style="color: #800000;">${CONFIG}</span>
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s&amp;\(\s\+<span style="color: #000099; font-weight: bold;">\&quot;</span>right<span style="color: #000099; font-weight: bold;">\&quot;</span>:\s\+\)-\?[0-9]\+&amp;\1<span style="color: #007800;">${WIDTH}</span>&amp;&quot;</span> <span style="color: #800000;">${CONFIG}</span>
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s&amp;\(\s\+<span style="color: #000099; font-weight: bold;">\&quot;</span>top<span style="color: #000099; font-weight: bold;">\&quot;</span>:\s\+\)-\?[0-9]\+&amp;\10&amp;&quot;</span> <span style="color: #800000;">${CONFIG}</span>
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s&amp;\(\s\+<span style="color: #000099; font-weight: bold;">\&quot;</span>work_area_bottom<span style="color: #000099; font-weight: bold;">\&quot;</span>:\s\+\)-\?[0-9]\+&amp;\1<span style="color: #007800;">${HEIGHT}</span>&amp;&quot;</span> <span style="color: #800000;">${CONFIG}</span>
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s&amp;\(\s\+<span style="color: #000099; font-weight: bold;">\&quot;</span>work_area_left<span style="color: #000099; font-weight: bold;">\&quot;</span>:\s\+\)-\?[0-9]\+&amp;\10&amp;&quot;</span> <span style="color: #800000;">${CONFIG}</span>
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s&amp;\(\s\+<span style="color: #000099; font-weight: bold;">\&quot;</span>work_area_right<span style="color: #000099; font-weight: bold;">\&quot;</span>:\s\+\)-\?[0-9]\+&amp;\1<span style="color: #007800;">${WIDTH}</span>&amp;&quot;</span> <span style="color: #800000;">${CONFIG}</span>
<span style="color: #c20cb9; font-weight: bold;">sed</span> <span style="color: #660033;">-i</span> <span style="color: #660033;">-e</span> <span style="color: #ff0000;">&quot;s&amp;\(\s\+<span style="color: #000099; font-weight: bold;">\&quot;</span>work_area_top<span style="color: #000099; font-weight: bold;">\&quot;</span>:\s\+\)-\?[0-9]\+&amp;\10&amp;&quot;</span> <span style="color: #800000;">${CONFIG}</span>
&nbsp;
chromium</pre></div></div>

<p>It&#8217;s a pretty simple script.  It takes one parameter which is the path to the main <code>chromium</code> config file.  It query&#8217;s the X server through <code>xrandr</code> to get the screen dimensions (WIDTH and HEIGHT) which means it must be run <em>after</em> the X server starts.  It then re-writes the relevant values in the config file to the maximum screen width and height so the browser is run &#8220;full screen&#8221;.  Pretty simple stuff &#8230; once you figure out the proper order to do things and the format of the <code>Preferences</code> file which was non-trivial.</p>
<h3>User Homedir</h3>
<p>The other hard part is creating the &#8220;known good&#8221; home directory for your unprivileged user.  What I did was start up <code>chromium</code> once manually.  This causes the standard <code>chromium</code> configuration to be generated with default values.  I then copied this off to /usr/share to be extracted on each boot.</p>
<h3>Conclusion</h3>
<p>So hopefully these instructions are enough to get you a Linux system that boots and runs Chromium as an unprivileged user.  It should restore that users home directory to a known good state on each boot so that any downloaded data will be wiped clean.  When the last browser tab is closed it will power off the system.</p>
<p>I use this on my XenClient XT system for browsing sites that I want to keep separate from my other VMs.  It&#8217;s not perfect though and as always there is more that can be done to secure it.  I&#8217;d start by making the root file system read only and adding SELinux would be fun.  Also the interface is far too minimal.  Finding a way to handle edge cases like making pop-ups manageable and allowing us to do things like control volume levels would also be nice.  This may require configuring a minimal window manager which is a pretty daunting task.  If you have any other interesting ways to make this VM more usable or lock it down better you should leave them in the comments.</p>
]]></content:encoded>
			<wfw:commentRss>http://twobit.us/blog/2012/04/chrome-web-sandbox-on-xenclient/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>openembedded yocto native hello world</title>
		<link>http://twobit.us/blog/2012/04/openembedded-yocto-native-hello-world/</link>
		<comments>http://twobit.us/blog/2012/04/openembedded-yocto-native-hello-world/#comments</comments>
		<pubDate>Fri, 13 Apr 2012 20:12:05 +0000</pubDate>
		<dc:creator>Philip</dc:creator>
				<category><![CDATA[Uncategorized]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[OE]]></category>
		<category><![CDATA[software]]></category>
		<category><![CDATA[Yocto]]></category>

		<guid isPermaLink="false">http://twobit.us/blog/?p=1441</guid>
		<description><![CDATA[I&#8217;ve officially &#8220;drank the Kool-Aid&#8221; and I&#8217;m convinced openembedde and Yocto are pretty awesome. I&#8217;ve had a blast building small Debian systems on PCEngines hardware in the past and while I&#8217;m waiting for my Raspberry Pi to arrive I&#8217;ve been trying to learn the ins and outs of Yocto. The added bonus is that the [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve officially &#8220;drank the Kool-Aid&#8221; and I&#8217;m convinced openembedde and Yocto are pretty awesome.  I&#8217;ve had a blast building small Debian systems on PCEngines hardware in the past and while I&#8217;m waiting for my <a href="http://www.raspberrypi.org/">Raspberry Pi</a> to arrive I&#8217;ve been trying to learn the ins and outs of Yocto.  The added bonus is that the XenClient team at Citrix uses openembedded for our build system so this work can also fall under the heading of &#8220;professional development&#8221;.</p>
<p>Naturally the first task I took on was way too complicated so I made a bunch of great progress (more about that in a future post once I get it stable) but then I hit a wall that I ended up banging my head against for a full day.  I posted a cry for help on the mailing list and didn&#8217;t get any responses so I set out to remove as many moving parts as possible and find the root cause.</p>
<p>First things first read the <a href="http://www.yoctoproject.org/docs/current/dev-manual">Yocto development</a> manual and the <a href="http://www.yoctoproject.org/docs/1.1.1/poky-ref-manual">Yocto reference</a> for whatever release you&#8217;re using.  This is essential because no one will help you till you&#8217;ve read and understand these <img src='http://twobit.us/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p>So the software I&#8217;m trying to build is built using raw Makefiles, none of that fancy autotools stuff.  This can be a bit of a pain because depending on the Makefiles, it&#8217;s not uncommon for assumptions to be made about file system paths.  Openembedded is all about cross compiling so it wants to build and install software under all sorts of strange roots and some Makefiles just can&#8217;t handle this.  I ran into a few of these scenarios but nothing I couldn&#8217;t overcome.</p>
<p>Getting a package for my target architecture wasn&#8217;t bad but I did run into a nasty problem when I tried to get a native package built.  From the searches I did on the interwebs it looks like there have been a number of ways to build native packages.  The current &#8220;right way&#8221; is simply to have your recipe extend the native class.  Thanks to <a href="http://www.xora.org.uk/">XorA</a> for documenting his/her <a href="http://www.xora.org.uk/2010/01/22/openembeddedangstom-new-package-workflow-eggdbus/">new package workflow</a> for that nugget.</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">BBCLASSEXTEND = &quot;native&quot;</pre></div></div>

<p>After having this method blow up for my recipe I was tempted to hack together some crazy work around.  I really want to upstream the stuff I&#8217;m working on though and I figure having crazy shit in my recipe to work around my misunderstanding of the native class was setting the whole thing up for failure.  So instead I went back to basics and made a &#8220;hello world&#8221; program and recipe (included at the end of this post) hoping to recreate the error and hopefully figure out what I was doing wrong at the same time.</p>
<p>It took a bit of extra work but I was able to recreate the issue with a very simple Makefile.  First the error message:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">NOTE: package hello-native-1.0-r0: task do_populate_sysroot: Started
ERROR: Error executing a python function in /home/build/poky-edison-6.0/meta-test/recipes-test/helloworld/hello_1.0.bb:
CalledProcessError: Command 'tar -cf - -C /home/build/poky-edison-6.0/build/tmp/work/i686-linux/hello-native-1.0-r0/sysroot-destdir///home/build/poky-edison-6.0/build/tmp/sysroots/i\
686-linux -ps . | tar -xf - -C /home/build/poky-edison-6.0/build/tmp/sysroots/i686-linux' returned non-zero exit status 2 with output tar: /home/build/poky-edison-6.0/build/tmp/work\
/i686-linux/hello-native-1.0-r0/sysroot-destdir///home/build/poky-edison-6.0/build/tmp/sysroots/i686-linux: Cannot chdir: No such file or directory
tar: Error is not recoverable: exiting now
tar: This does not look like a tar archive
tar: Exiting with failure status due to previous errors
&nbsp;
&nbsp;
ERROR: The stack trace of python calls that resulted in this exception/failure was:
ERROR:   File &quot;sstate_task_postfunc&quot;, line 10, in &lt;module&gt;
ERROR:
ERROR:   File &quot;sstate_task_postfunc&quot;, line 4, in sstate_task_postfunc
ERROR:
ERROR:   File &quot;sstate.bbclass&quot;, line 19, in sstate_install
ERROR:
ERROR:   File &quot;/home/build/poky-edison-6.0/meta/lib/oe/path.py&quot;, line 59, in copytree
ERROR:     check_output(cmd, shell=True, stderr=subprocess.STDOUT)
ERROR:
ERROR:   File &quot;/home/build/poky-edison-6.0/meta/lib/oe/path.py&quot;, line 121, in check_output
ERROR:     raise CalledProcessError(retcode, cmd, output=output)
ERROR:
ERROR: The code that was being executed was:
ERROR:      0006:        bb.build.exec_func(intercept, d)
ERROR:      0007:    sstate_package(shared_state, d)
ERROR:      0008:
ERROR:      0009:
ERROR:  *** 0010:sstate_task_postfunc(d)
ERROR:      0011:
ERROR: (file: 'sstate_task_postfunc', lineno: 10, function: &lt;module&gt;)
ERROR:      0001:
ERROR:      0002:def sstate_task_postfunc(d):
ERROR:      0003:    shared_state = sstate_state_fromvars(d)
ERROR:  *** 0004:    sstate_install(shared_state, d)
ERROR:      0005:    for intercept in shared_state['interceptfuncs']:
ERROR:      0006:        bb.build.exec_func(intercept, d)
ERROR:      0007:    sstate_package(shared_state, d)
ERROR:      0008:
ERROR: (file: 'sstate_task_postfunc', lineno: 4, function: sstate_task_postfunc)
ERROR: Function 'sstate_task_postfunc' failed
ERROR: Logfile of failure stored in: /home/build/poky-edison-6.0/build/tmp/work/i686-linux/hello-native-1.0-r0/temp/log.do_populate_sysroot.30718
Log data follows:
| NOTE: QA checking staging
| ERROR: Error executing a python function in /home/build/poky-edison-6.0/meta-test/recipes-test/helloworld/hello_1.0.bb:
| CalledProcessError: Command 'tar -cf - -C /home/build/poky-edison-6.0/build/tmp/work/i686-linux/hello-native-1.0-r0/sysroot-destdir///home/build/poky-edison-6.0/build/tmp/sysroots\
/i686-linux -ps . | tar -xf - -C /home/build/poky-edison-6.0/build/tmp/sysroots/i686-linux' returned non-zero exit status 2 with output tar: /home/build/poky-edison-6.0/build/tmp/wo\
rk/i686-linux/hello-native-1.0-r0/sysroot-destdir///home/build/poky-edison-6.0/build/tmp/sysroots/i686-linux: Cannot chdir: No such file or directory
| tar: Error is not recoverable: exiting now
| tar: This does not look like a tar archive
| tar: Exiting with failure status due to previous errors
|
|
| ERROR: The stack trace of python calls that resulted in this exception/failure was:
| ERROR:   File &quot;sstate_task_postfunc&quot;, line 10, in &lt;module&gt;
| ERROR:
| ERROR:   File &quot;sstate_task_postfunc&quot;, line 4, in sstate_task_postfunc
| ERROR:
| ERROR:   File &quot;sstate.bbclass&quot;, line 19, in sstate_install
| ERROR:
| ERROR:   File &quot;/home/build/poky-edison-6.0/meta/lib/oe/path.py&quot;, line 59, in copytree
| ERROR:     check_output(cmd, shell=True, stderr=subprocess.STDOUT)
| ERROR:
| ERROR:   File &quot;/home/build/poky-edison-6.0/meta/lib/oe/path.py&quot;, line 121, in check_output
| ERROR:     raise CalledProcessError(retcode, cmd, output=output)
| ERROR:
| ERROR: The code that was being executed was:
| ERROR:      0006:        bb.build.exec_func(intercept, d)
| ERROR:      0007:    sstate_package(shared_state, d)
| ERROR:      0008:
| ERROR:      0009:
| ERROR:  *** 0010:sstate_task_postfunc(d)
| ERROR:      0011:
| ERROR: (file: 'sstate_task_postfunc', lineno: 10, function: &lt;module&gt;)
| ERROR:      0001:
| ERROR:      0002:def sstate_task_postfunc(d):
| ERROR:      0003:    shared_state = sstate_state_fromvars(d)
| ERROR:  *** 0004:    sstate_install(shared_state, d)
| ERROR:      0005:    for intercept in shared_state['interceptfuncs']:
| ERROR:      0006:        bb.build.exec_func(intercept, d)
| ERROR:      0007:    sstate_package(shared_state, d)
| ERROR:      0008:
| ERROR: (file: 'sstate_task_postfunc', lineno: 4, function: sstate_task_postfunc)
| ERROR: Function 'sstate_task_postfunc' failed
NOTE: package hello-native-1.0-r0: task do_populate_sysroot: Failed
ERROR: Task 3 (virtual:native:/home/build/poky-edison-6.0/meta-test/recipes-test/helloworld/hello_1.0.bb, do_populate_sysroot) failed with exit code '1'
ERROR: 'virtual:native:/home/build/poky-edison-6.0/meta-test/recipes-test/helloworld/hello_1.0.bb' failed</pre></div></div>

<p>So even with the most simple Makefile I could cause a native recipe build to blow up.  Here&#8217;s the Makefile:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">.PHONY : all clean install uninstall
&nbsp;
PREFIX ?= $(DESTDIR)/usr
BINDIR ?= $(PREFIX)/bin
&nbsp;
HELLO_src = hello.c
HELLO_bin = hello
HELLO_tgt = $(BINDIR)/$(HELLO_bin)
&nbsp;
all : $(HELLO_bin)
&nbsp;
$(HELLO_bin) : $(HELLO_src)
&nbsp;
$(HELLO_tgt) : $(HELLO_bin)
	install -d $(BINDIR)
	install -m 0755 $^ $@
&nbsp;
clean :
	rm $(HELLO_bin)
&nbsp;
install : $(HELLO_tgt)
&nbsp;
uninstall :
	rm $(BINDIR)/$(HELLO_TGT)</pre></div></div>

<p>And here&#8217;s the relevant install method from the bitbake recipe:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">do_install () {
    oe_runmake DESTDIR=${D} install
}</pre></div></div>

<p>Notice I&#8217;m using the variable <code>DESTDIR</code> to tell the Makefile the root (not just /) to install things to.  This should work right?  It works for a regular package but not for a native one!  This drove me nuts for a full day.</p>
<p>The solution to this problem lies in some weirdness in the Yocto <code>native</code> class when combined with the <code>populate_sysroot</code> method.  The way I figured this out was by inspecting the differences in the environment when building <code>hello</code> vs <code>hello-native</code>.  When building the regular package for the target architecture variables like <code>bindir</code> and <code>sbindir</code> were what I would expect them to be:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">bindir=&quot;/usr/bin&quot;
sbindir=&quot;/usr/sbin&quot;</pre></div></div>

<p>but when building <code>hello-native</code> they get a bit crazy:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">bindir=&quot;/home/build/poky-edison-6.0/build/tmp/sysroots/i686-linux/usr/bin&quot;
sbindir=&quot;/home/build/poky-edison-6.0/build/tmp/sysroots/i686-linux/usr/sbin&quot;</pre></div></div>

<p>This is a hint at the source of crazy path that staging is trying to tar up above in the error message.  Further if you look in the build directory for a regular target arch package you&#8217;ll see your files where you expect in <code>${D}sysroot-destdir/usr/bin</code> but for a native build you&#8217;ll see stuff in <code>${D}sysroot-destdir/home/build/poky-edison-6.0/build/tmp/sysroots/i686-linux/usr/bin</code>.  Pretty crazy right?  I&#8217;m sure there&#8217;s a technical reason for this but it&#8217;s beyond me.</p>
<p>So the way you can work around this is by telling your <code>Makefile</code>s about paths like <code>bindir</code> through the recipe.  A fixed <code>do_install</code> would look like this:</p>

<div class="wp_syntax"><div class="code"><pre class="text" style="font-family:monospace;">do_install () {
    oe_runmake DESTDIR=${D} BINDIR=${D}${bindir} install
}</pre></div></div>

<p>For more complicated Makefiles you can probably specify a <code>PREFIX</code> and set this equal to the <code>${prefix}</code> variable but YMMV.  I&#8217;ll be trying this out to keep my recipes as simple as possible.</p>
<p>If you want to download my example the <a href="http://twobit.us/files/2012/04/hello_1.0.bb.gz">recipe is here</a>.  This will pull down the hello world source code and build the whole thing for you.</p>
]]></content:encoded>
			<wfw:commentRss>http://twobit.us/blog/2012/04/openembedded-yocto-native-hello-world/feed/</wfw:commentRss>
		<slash:comments>4</slash:comments>
		</item>
		<item>
		<title>Linux bridge forward EAPOL 8021x frames</title>
		<link>http://twobit.us/blog/2012/03/linux-bridge-forward-eapol-8021x-frames/</link>
		<comments>http://twobit.us/blog/2012/03/linux-bridge-forward-eapol-8021x-frames/#comments</comments>
		<pubDate>Thu, 29 Mar 2012 02:08:05 +0000</pubDate>
		<dc:creator>Philip</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[Linux]]></category>
		<category><![CDATA[XenClient]]></category>

		<guid isPermaLink="false">http://twobit.us/blog/?p=1435</guid>
		<description><![CDATA[XenClient is no different from other Xen configurations in that the networking hardware is shared between guests through a bridge hosted in dom0 (or a network driver domain in the case of XenClient XT). For most use cases the standard Linux bridge will route your traffic as expected. We ran into an interesting problem however [...]]]></description>
			<content:encoded><![CDATA[<p>XenClient is no different from other Xen configurations in that the networking hardware is shared between guests through a bridge hosted in dom0 (or a <a href="http://twobit.us/blog/2010/07/xen-network-driver-domain-how/">network driver domain</a> in the case of XenClient XT).  For most use cases the standard Linux bridge will route your traffic as expected.  We ran into an interesting problem however when a customer doing a pilot on XenClient XT tried to authenticate their guest VMs using EAPOL (8021x auth over ethernet).  The bridge gobbled up their packets and we got some pretty strange bug reports as a result.</p>
<p>Just throwing &#8220;linux bridge EAPOL 8021x&#8221; into a search engine will return a <a href="http://forum.soft32.com/linux/EAPOL-bridging-ftopict523493.html">number</a> <a href="http://lkml.indiana.edu/hypermail/linux/kernel/1010.2/00890.html">of</a> <a href="http://www.gremwell.com/dot1x-transparent-linux-bridge">hits</a> from various mailing lists where users report similar issues.  <a href="https://lists.linux-foundation.org/pipermail/bridge/2010-October/007378.html">The fix</a> is literally a one line change that drops a check on the destination MAC address.  This check is to ensure compliance with the 8021d standard which requires layer 2 bridges to drop packets from the &#8220;<a href="standards.ieee.org/develop/regauth/tut/macgrp.pdf">bridge filter MAC address group</a>&#8220;.  Since XenClient is a commercial product and the fix is in code that is responsible for our guest networking (which is pretty important) we wanted to code up a way to selectively enable this feature on a per-bridge basis using a sysfs node.  We / I also tested the hell out of it for a few days straight.</p>
<p>The end result is a neat little patch that allows users to selectively pass EAPOL packets from their guests across the layer 2 bridge in dom0 / ndvm and out to their authentication infrastructure.  The patch is available opensource just like the kernel and is available on the XenClient source CD.  It&#8217;s also <a href='/files/2012/03/break_8021d.gz'>available here</a> for your convenience <img src='http://twobit.us/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://twobit.us/blog/2012/03/linux-bridge-forward-eapol-8021x-frames/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>OE-Core Yocto gcc timeout</title>
		<link>http://twobit.us/blog/2012/03/oe-core-yocto-gcc-timeout/</link>
		<comments>http://twobit.us/blog/2012/03/oe-core-yocto-gcc-timeout/#comments</comments>
		<pubDate>Mon, 19 Mar 2012 03:55:56 +0000</pubDate>
		<dc:creator>Philip</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[OE]]></category>
		<category><![CDATA[Yocto]]></category>

		<guid isPermaLink="false">http://twobit.us/blog/?p=1428</guid>
		<description><![CDATA[I&#8217;ve been thrashing around trying to get the upstream OE to build an image for me. Today I finally made a concerted effort over a few hours to dive deep and do this right. It turns out I was using the &#8220;old&#8221; OE repos when I should have been using the &#8220;new&#8221; build system from [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been thrashing around trying to get the upstream OE to build an image for me.  Today I finally made a concerted effort over a few hours to dive deep and do this right.  It turns out I was using the &#8220;old&#8221; OE repos when I should have been using the &#8220;new&#8221; build system from the <a href="http://www.yoctoproject.org/">Yocto Project</a>.  Their documentation is excellent but still, my first build failed.</p>
<p>What&#8217;s this?  The GCC recipe failing because of a network timeout?  Oddly enough it actually downloaded some of the sources but not all of &#8216;em.<br />
<code><br />
| svn: REPORT of '/svn/gcc/!svn/vcc/default': Could not read response body: connection was closed by server (http://gcc.gnu.org)<br />
NOTE: package gcc-cross-initial-4.6.1+svnr175454-r10: task do_fetch: Failed<br />
ERROR: Task 5 (/home/build/poky-edison-6.0/meta/recipes-devtools/gcc/gcc-cross-initial_4.6.bb, do_fetch) failed with exit code '1'<br />
ERROR: '/home/build/poky-edison-6.0/meta/recipes-devtools/gcc/gcc-cross-initial_4.6.bb' failed<br />
</code></p>
<p>At this point I just tried again and it failed in the same place but had checked out more of the code.  A quick search turns up a similar error is common when checking out code from SVN servers over HTTP.  Apache just has a tendency to timeout when checking out large repositories with mod-svn.  The suggested fix is to increase the timeout value in your Apache configs &#8230; except these configs are on the GNU web servers and we can&#8217;t change them.</p>
<p>What we can change though is the protocol bitbake uses when getting the sources.  Just change the proto from &#8216;http&#8217; to &#8216;svn&#8217; in the SRC_URI in gcc-4.6.inc (found at <code>/meta/recipes-devtools/gcc/gcc-4.6.inc</code> and we&#8217;re almost good.  It&#8217;ll look like this when you&#8217;re done.</p>
<p><code><br />
SRC_URI = "svn://gcc.gnu.org/svn/gcc/branches;module=${BRANCH};proto=svn \<br />
</code></p>
<p>It still timed out for me a few times but it ran for much longer than the HTTP protocol option.  HTTP timed out after about 10 minutes, SVN made it almost an hour before timing out &#8230; You&#8217;d think there would be a tarball of these sources mirrored somewhere so we didn&#8217;t have to kill the GNU SVN servers on every fresh build.  Something to look into I guess.  Either way gcc is building now, hopefully I&#8217;ll have a build running soon &#8230;</p>
<p>UPDATE: With some advice from Scott below I used the poky distro by including: <code>DISTRO="poky"</code> in my local.conf file.  As promised bitbake then doesn&#8217;t try to check out the gcc svn repository directly from gnu.org.  Instead it grabs a tarball from one ob the Yocto mirrors and the build takes mere minutes.  Thanks Scott!</p>
]]></content:encoded>
			<wfw:commentRss>http://twobit.us/blog/2012/03/oe-core-yocto-gcc-timeout/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>LaTeX for your Resume / CV</title>
		<link>http://twobit.us/blog/2012/03/latex-for-your-resume-cv/</link>
		<comments>http://twobit.us/blog/2012/03/latex-for-your-resume-cv/#comments</comments>
		<pubDate>Mon, 05 Mar 2012 02:10:32 +0000</pubDate>
		<dc:creator>Philip</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[LaTeX]]></category>

		<guid isPermaLink="false">http://twobit.us/blog/?p=1417</guid>
		<description><![CDATA[I&#8217;m far from a ninja when it comes to but I&#8217;m a big fan. I&#8217;ve written a bit about formatting logical expressions for past homework exercises. I&#8217;ve also used it in blog posts for doing the same. It&#8217;s a very useful tool even if you&#8217;re just a using basic templates like me. A major driver [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;m far from a ninja when it comes to <img src='http://s.wordpress.com/latex.php?latex=%5CLaTeX&#038;bg=ffffff&#038;fg=000000&#038;s=0' alt='\LaTeX' title='\LaTeX' class='latex' /> but I&#8217;m a big fan.  I&#8217;ve written a bit about <a href="http://twobit.us/blog/2010/10/latex-for-your-logic-homework/">formatting logical expressions</a> for past homework exercises.  I&#8217;ve also used it in blog posts <a href="http://twobit.us/blog/2011/05/understanding-multi-level-security-part-1/">for</a> <a href="http://twobit.us/blog/2011/06/understanding-multi-level-security-part-2//">doing</a> <a href="http://twobit.us/blog/2011/07/understanding-multi-level-security-part-3/">the</a> <a href="http://twobit.us/blog/2011/07/understanding-multi-level-security-part-4/">same</a>.  It&#8217;s a very useful tool even if you&#8217;re just a using basic templates like me.</p>
<p>A major driver behind my work on this website was the desire to get some of my technical work out into the public domain.  Around the same time I started blogging I told myself that I should host my resume on this site as an incentive to keep it up to date.  I failed pretty miserably there.</p>
<p>But when I took my position with Citrix nearly a year ago I updated my CV and now I&#8217;m resolving to keep it that way.  It&#8217;s never an easy task to drag an old CV into the modern age and mine had been formatted using a very old style called <a href="http://www.rpi.edu/dept/arc/training/latex/resumes/">res from RPI</a>.  Instead of struggling to keep the style usable on a modern toolchain I took on migrating to the newer <a href="http://tug.ctan.org/pkg/tucv">tucv from CTAN</a>.</p>
<p>This was a catalyst for all sorts of useful stuff like getting my CV into a git repo and generally refreshing the content.  I&#8217;ll be putting together an &#8216;about&#8217; page this site where I&#8217;ll host it and make the source available as well.</p>
<p>Till then here&#8217;s a quick set of instructions for getting tucv working on Debian Wheezy:<br />
Unfortunately I wasn&#8217;t ablt to find tucv in any of the Debian latex / texlive packages.  So to get tucv working I had to get the basic latex and texlive packages.  Once this was done I had to download the .dtx and ,ins files manually.</p>
<p>Figuring out how to generate a style file from these sources and where to put them was the next trick.  A bit of web searching turned up a manual describing <a href="http://people.debian.org/~preining/TeX/TeX-on-Debian/ch4.html">how to use LaTeX on Debian</a>:</p>
<ol>
<li>Just copy these files to /usr/local/share/texmf/tex/latex/tucv.</li>
<li>Compile both files using <code>latex</code></li>
<p> to generate the package and documentation.</p>
<li>Registering the new style using <code>mktexlsr</code> or <code>texhash</code>.</li>
</ol>
<p>Then all you have to do is make your resume!  Following the <a href="http://tug.ctan.org/tex-archive/macros/latex/contrib/tucv">examples from the CTAN website</a> is the best way to go.  Personally I already had significant amount of content so most of my time was spent playing with layout.</p>
<p>It&#8217;s not perfect and I&#8217;ll be playing around to see if I can get better spacing in some of the sections that have a two column layout.  The right most column is too narrow and forces date ranges on to multiple lines and I&#8217;m not a big fan of how that looks.</p>
]]></content:encoded>
			<wfw:commentRss>http://twobit.us/blog/2012/03/latex-for-your-resume-cv/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>sVirt in XenClient</title>
		<link>http://twobit.us/blog/2012/02/svirt-in-xenclient/</link>
		<comments>http://twobit.us/blog/2012/02/svirt-in-xenclient/#comments</comments>
		<pubDate>Sat, 25 Feb 2012 20:33:50 +0000</pubDate>
		<dc:creator>Philip</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[MastersProject]]></category>
		<category><![CDATA[security]]></category>
		<category><![CDATA[SELinux]]></category>
		<category><![CDATA[Xen]]></category>

		<guid isPermaLink="false">http://twobit.us/blog/?p=1411</guid>
		<description><![CDATA[It&#8217;s been 5 months since my last post about my on-going project required by my masters program at SU. With the hope of eventually getting my degree, this is my last post on the subject. In my previous post on this topic I described a quick prototype I coded up to test an example program [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been 5 months since my last post about my on-going project required by my masters program at SU.  With the hope of eventually getting my degree, this is my last post on the subject.  In my previous post on this topic I described a quick prototype I coded up to test an example program and SELinux policy to demonstrate the sVirt architecture.  This was a simple example of how categories from the MCS policy can be used to separate multiple instances of the same program.  The logical step after implementing a prototype is coding up the real thing so in this post I&#8217;ll go into some detail describing an implementation of the sVirt architecture I coded for the XenClient XT platform.  While it may have taken me far too long to write up a description of this project, it&#8217;s already running in a commercial product &#8230; so I&#8217;ve got that going for me <img src='http://twobit.us/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<h2>Background</h2>
<p>XenClient is a bit different than the upstream Xen in that the management stack has been completely rewritten.  Instead of the xend process which was written in python, XenClient uses a toolstack that&#8217;s rewritten in Haskell.  This posed two significant hurdles.  First I&#8217;ve done little more than read the first few pages from a text book on Haskell so the sVirt code, though not complex, would be a bit over my skill level.  Second SELinux has no Haskell bindings which would be required by the sVirt code.</p>
<p>Taking on the task of learning a new functional programming language and writing bindings for a relatively complex API in this language would have taken far longer than reasonable.  Though we do intend to integrate sVirt into the toolstack proper, putting this work on the so called &#8220;critical path&#8221; would have been prohibitively expensive.  Instead we implemented the sVirt code as a C program that is interposed between the toolstack and the QEMU instances it is intended to separate.  Thus the toolstack (the xenmgr process) invokes the svirt-interpose program each time a QEMU process needs to be started for a VM.  The svirt-interpose process then does all of the necessary functions to prepare the environment for the separation of the QEMU instance requested from the others currently running.</p>
<p>The remainder of this document describes the svirt-interpose program in detail.  We begin by describing the interfaces down the call chain between the xenmgr, svirt-interpose and QEMU.<br />
We then go into detail describing the internal workings of the svirt-interpose code.  This includes the algorithm used to assign categories to QEMU processes and to label the system objects used by these processes.  We conclude with a brief analysis of the remaining pieces of the system that could benefit from similar separation.  In my <a href="http://twobit.us/blog/2011/05/another-go-at-my-masters-project/">first post</a> on this topic I describe possible attacks we&#8217;re defending against so I&#8217;ll not repeat that here.</p>
<h2>Call Chain</h2>
<p>As we&#8217;re unable to integrate the sVirt code directly into the toolstack we must interpose the execution of the sVirt binary between the toolstack and QEMU.  We do this by having the toolstack invoke the sVirt binary and then have sVirt invoke QEMU after performing the necessary SELinux operations.  For simplicity we leave the command line that the toolstack would normally pass to QEMU unchanged and simply extract the small piece of information we need from it in the sVirt code.  All sVirt requires to do it&#8217;s job is the domain id (domid) of the VM it&#8217;s starting a QEMU instance for.  This value is the first parameter so extracting it is quite simple.</p>
<p>The final bit that must be implemented is in policy.  Here we must be sure that the policy we write reflects this call chain explicitly.  This means removing the ability for the toolstack (xend_t) to invoke QEMU (qemu_t) directly and replacing this with allowing the toolstack to execute the svirt-interpose program (svirt_t) while allowing the svirt-interpose domain to transition to the QEMU domain.  This is an important part of the process as it prevents the toolstack from bypassing the svirt code.  Many will find protections like this superfluous as it implies protections from a malicious toolstack and the toolstack is a central component of the systems TCB.  There is a grain of truth in this argument though it represents a rather misguided analysis.  It is  very important to limit the permissions granted to a process to limit a possible vulnerability even if the process we&#8217;re confining is largely a &#8220;trusted&#8221; system component.</p>
<h2>Category Selection</h2>
<p>The central piece of this architecture is to select a unique MCS category for each QEMU process and assign this category to the resources belonging to said process.  Before a category can be assigned to a resource we must first chose the category.  The only requirement we have when selecting categories is that they are unique (not used by another QEMU process).<br />
Thus there is no special meaning in a category number.  Thus it makes sense to select the category number at random.</p>
<p>We&#8217;re presented with an interesting challenge here based on the nature of the svirt-interpose program.  If this code was integrated with the toolstack directly it would be reasonable to maintain a data structure mapping the running virtual machines to their assigned categories.  We could then select a random category number for a new QEMU instance and quickly walk this in-memory structure to be sure this category number hasn&#8217;t already been assigned to another process.  But as was described previously, the svirt-interpose code is a short lived utility that is invoked by the toolstack and dies shortly after it starts up a QEMU process.  Thus we need persistent storage to maintain this association.</p>
<p>The use of the XenStore is reasonable for such data and we use the key &#8216;selinux-mcs&#8217; under the /local/domain/$domid node (where $domid is the domain id of a running VM) to store the value.  Thus we randomly select a category and then walk the XenStore tree examining this key for each running VM.  If a conflict is detected a new value is selected and the search continues.  This is a very naive algorithm and we discuss ways in which it can be improved in the section on future work.</p>
<h2>Object labeling</h2>
<p>Once we&#8217;ve successfully interposed our svirt code between the toolstack and QEMU and implemented our category selection algorithm we have two tasks remaining.  First we must enumerate the objects that belong to this QEMU instance and label them appropriately.  Second we must perform the steps necessary to ensure the QEMU process will be labeled properly before we fork and exec it.</p>
<p>Determining the devices assigned to a VM by exploring the XenStore structures is tedious.  The information we begin with is the domid of the VM we&#8217;re configuring QEMU for.  From this we can examine the virtual block devices (VBDs) that belong to this VM but the structure in the VM specific configuration space rooted at /local/domain/$domid only contains information about the backend hosting the device.  To find the OS objects associated with the device we need to determine the backend, then examine the configuration space for that backend.</p>
<p>We begin by listing the VBDs assigned to a VM by enumerating the /local/domain/$domid/device/vbd XenStore directory.  This will yeild a number of paths in of the form /local/domain/$domid/device/vbd/$vbd_num where $vbd_num is the numeric id assigned to a virtual block device.  VMs can be assigned any number of VBDs so we must process all VBDs listed in this directory.</p>
<p>From these paths representing each VBD assigned to a VM we get closer to the backing store by extracting the path to the backend of the split xen block driver.  This path is contained in the key /local/domain/$domid/device/vbd/$vbd_num/backend.  Once this path is extracted we check to see if the device in dom0 is writable by reading the &#8216;mode&#8217; value.  If the mode is &#8216;w&#8217; the device is writable and we must apply the proper MCS label to it.  We ignore read only VBDs as XenClient only assigns CDROMs as read only, all hard disks are allocated as read/write.</p>
<p>Once we&#8217;ve determined the device is writable we now need to extract the dom0 object (usually a block or loopback device file) that&#8217;s backing the device.  The location of the device path in XenStore depends on the backend storage type in use.  XenClient uses blktap processes to expose VHDs through device nodes in /dev and loopback devices to expose files that contain raw file systems.  If a loopback device is in use the path to the device node will be stored in the XenStore key &#8216;loop-device&#8217; in the corresponding VBD backend directory.  Similarly if a bit more cryptic, the device node for a blktap device for a VHD will be in the XenStore key &#8216;params&#8217;.</p>
<p>Once these paths have been extracted the devices can be labeled using the SELinux API.  To do so, we first need to know what the label should be.  Through the SELinux API we can determine the current context for the file.  We then set the MCS category calculated for the VM on this context and then change the file context to the resultant label.  Important to note here is that both a sensitivity level and a category must be set on the security context.  The SELinux API doesn&#8217;t shield us from the internals of the policy here and even though the MCS policy doesn&#8217;t reason about sensitivities there is a single sensitivity defined that must be assigned to every object (s0).</p>
<p>Assigning a category to the QEMU process is a bit different.  Unlike file system objects there isn&#8217;t an objct that we can query for a label.  Instead we can ask the security server to calculate the resultant label of a transition from the current process (sVirt) to the destination process (QEMU).  There is an alteernative method available however and this allows us to deterine the type for the QEMU process directly.  SELinux has added some native support for virtualization and one such bit was the addition of the API call &#8216;selinux_virtual_domain_context_path&#8217;.  This function returns the path of a file in the SELinux configuration directory that contains the type to be assigned to domains used for virtualization.</p>
<p>Once we have this type the category calculated earlier is then applied and the full context is obtained.  SELinux has a specific API call that allows the caller to request the security server apply a specific context to the process produced by the next exec performed by the calling process (<a href="http://linux.die.net/man/3/setexeccon">setexeccon</a>).  Once this has been done successfully the sVirt process cleans up the environment (closes file descriptors etc) and execs the QEMU program passing it the unmodified command line that was provided by the toolstack.</p>
<h2>Conclusion</h2>
<p>Applying an MCS category to a QEMU process and its resources is fairly straight forward task.  There are a few details that must be attended to to ensure that proper error handling is in place but the code is relatively short (~600 LOC) and quite easy to audit.  There are some places where the QEMU processes must overlap however.  XenClient is all about multiplexing shared hardware between multiple virtual machines on the same PC / Laptop.  Sharing devices like the CD-ROM that is proxied to clients via QEMU requires some compromise.</p>
<p>As we state above the CD-ROM is read-only so an MCS category is not applied to the device itself but XenClient must ensure the accesses to the device are exclusive.  This is achieved by QEMU obtaining an exclusive lock on a file in /var/lock before claiming the CD-ROM.  All QEMU processes must be able to take this lock so the file must be created without any categories.  This may seem like a minor detail but it&#8217;s quite tedious to implement in practice and it does represent path for data to be transmitted from one QEMU process to another.  Transmission through this lock file would require collusion between QEMU processes so it&#8217;s considered a minimal threat.</p>
<h2>Future Work</h2>
<p>This is my last post in this series that has nearly spanned a year.  I&#8217;m a bit ashamed it&#8217;s taken me this long to write up my masters project but it did end up taking on a life of its own getting me a job with Citrix on the XenClient team.  There&#8217;s still a lot of work to be done and I&#8217;m hoping to continue documenting it here.  Firstly I have to collect the 8 blog posts that document this work and roll them up into a single document I can submit to my adviser to satisfy my degree requirements.</p>
<p>In parallel I&#8217;ll be working all things XenClient hopefully learning Haskell and integrating the sVirt architecture directly into our toolstack.  Having this code in the toolstack directly will have a number of benefits.  Most obviously it&#8217;ll remove a few forks so VM loading will be quicker.  More interestingly though it will open up the possibility of applying MCS category labeling to devices  (both PCI and USB) that are assigned to VMs.  The end goal, as always, is strengthening the separation between the system components that need to remain separate thus improving the security of the system.</p>
]]></content:encoded>
			<wfw:commentRss>http://twobit.us/blog/2012/02/svirt-in-xenclient/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Troubles with Ovi Store after upgrading N8 to Anna</title>
		<link>http://twobit.us/blog/2012/01/troubles-with-ovi-store-after-upgrading-n8-to-anna/</link>
		<comments>http://twobit.us/blog/2012/01/troubles-with-ovi-store-after-upgrading-n8-to-anna/#comments</comments>
		<pubDate>Thu, 19 Jan 2012 00:38:34 +0000</pubDate>
		<dc:creator>Philip</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[Hobby]]></category>
		<category><![CDATA[HowTo]]></category>
		<category><![CDATA[N8]]></category>
		<category><![CDATA[Nokia]]></category>

		<guid isPermaLink="false">http://twobit.us/blog/?p=1408</guid>
		<description><![CDATA[I took some time yesterday to upgrade my beloved Nokia N8 to the new(ish) Symbian^3 Anna build and it wasn&#8217;t a smooth upgrade. Upgrading through the Ovi Suite went well enough but applications like the Ovi Store just wouldn&#8217;t work after the upgrade. The Ovi Store application would install and start but would sit on [...]]]></description>
			<content:encoded><![CDATA[<p>I took some time yesterday to upgrade my beloved Nokia N8 to the new(ish) Symbian^3 Anna build and it wasn&#8217;t a smooth upgrade.  Upgrading through the Ovi Suite went well enough but applications like the Ovi Store just wouldn&#8217;t work after the upgrade.  The Ovi Store application would install and start but would sit on the splash screen showing the &#8220;Loading &#8230;&#8221; message.  At this point I did a <a href="http://mynokiablog.com/2010/10/12/how-to-hard-reset-your-nokia-n8/">hard reset</a> that did nothing.</p>
<p>After combing through a hand full of forum posts I ran across <a href="http://discussions.europe.nokia.com/t5/Software-Updates/Ovi-Store-Hangs-on-loading-after-recent-Update/m-p/1088529#M92621">this one</a> in the Nokia Europe discussion boards.  Initially I had no idea what this guy was talking about.  I guess I&#8217;m used to my phone being an appliance so downgrading packages seemed pretty crazy, especially since I had no idea where to obtain the packages (sis files) described in the post.  A few web searches later and I ran across the &#8220;<a href="http://fixqt.com/">Fix Symbian</a>&#8221; site.  Pretty encouraging name all things considered.  Anyways all I did was download the sis files from the post titled &#8220;S^3 QT 4.7.3 MOBILITY 1.1.3&#8243; which downgrades a number of components in the &#8221; Notifications Support Package Symbian3 v1.1.11120&#8243; package.  Once quick reboot and Ovi Store was back up and running.</p>
<p>So I guess the Anna upgrade that Nokia is shipping is broken?  Pretty strange really but not something that can&#8217;t be worked around thanks to some contributions from the interwebs.  Unfortunately the upgrade to Anna didn&#8217;t fix the problems I&#8217;ve had with my N8 and my wireless access point.  I&#8217;ll debug this sooner or later, likely when I upgrade my home network with the ALIX boards I got in the mail last week.</p>
]]></content:encoded>
			<wfw:commentRss>http://twobit.us/blog/2012/01/troubles-with-ovi-store-after-upgrading-n8-to-anna/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>ALIX3D2 Arrives</title>
		<link>http://twobit.us/blog/2012/01/alix3d2-arrives/</link>
		<comments>http://twobit.us/blog/2012/01/alix3d2-arrives/#comments</comments>
		<pubDate>Mon, 09 Jan 2012 20:21:47 +0000</pubDate>
		<dc:creator>Philip</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[ALIX]]></category>

		<guid isPermaLink="false">http://twobit.us/blog/?p=1394</guid>
		<description><![CDATA[I&#8217;ve been hoping to upgrade my older ALIX2D3 router / firewall / wireless access point for a while now. While taking a few hours off from work over the holiday I surfed over to PCEngines and bought myself a Christmas present: a matching pair of ALIX3D2 boards and a Compex WLM200N5-23 MiniPCI card (802.11an) plus [...]]]></description>
			<content:encoded><![CDATA[<p>I&#8217;ve been hoping to upgrade my older ALIX2D3 router / firewall / wireless access point for a while now.  While taking a few hours off from work over the holiday I surfed over to <a href="http://pcengines.ch/">PCEngines</a> and bought myself a Christmas present: a matching pair of ALIX3D2 boards and a Compex WLM200N5-23 MiniPCI card (802.11an) plus the necessary wires / cables / 5GHz antenna and enclosures etc.</p>
<p>Everything showed up in the mail today:<br />
<a href="/files/2012/01/ALIX3D2_web.jpg"><img src="/files/2012/01/ALIX3D2_web-300x168.jpg" alt="" title="ALIX3D2" width="300" height="168" class="size-medium wp-image-1395" /></a><br />
Unfortunately<br />
one board arrived with minor damage to the CF socket.  Bent pins suck:<br />
<a href="/files/2012/01/BentATA_web.jpg"><img src="/files/2012/01/BentATA_web-239x300.jpg" alt="" title="BentCF" width="239" height="300" class="size-medium wp-image-1396" /></a><br />
I&#8217;m waiting to hear back from the folks over at PCEngines to see how they want to handle a repair / return.  I really want to just bend it back and hope it works but I&#8217;m worried if I break it off they won&#8217;t accept a return.  Glad I bought two so I still have one to play with in the meantime.</p>
<p>My next post should be about me finally complete Masters project, but likely it&#8217;ll be about building OE for this device <img src='http://twobit.us/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
<p><b>Update:</b><br />
PC Engines support was super quick to respond.  They gave me permission to try to bend the pin back myself and ensured me that if my attempted repair failed they&#8217;d still replace the board.  The pin bent back into place easily enough.  I&#8217;m hoping to do an install tomorrow to be sure the CF slot is functional.</p>
]]></content:encoded>
			<wfw:commentRss>http://twobit.us/blog/2012/01/alix3d2-arrives/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Atom Based Home NFS</title>
		<link>http://twobit.us/blog/2011/12/atom-based-home-nfs/</link>
		<comments>http://twobit.us/blog/2011/12/atom-based-home-nfs/#comments</comments>
		<pubDate>Tue, 06 Dec 2011 04:59:39 +0000</pubDate>
		<dc:creator>Philip</dc:creator>
				<category><![CDATA[Computer]]></category>
		<category><![CDATA[DIY]]></category>
		<category><![CDATA[SysAdmin]]></category>

		<guid isPermaLink="false">http://twobit.us/blog/?p=1387</guid>
		<description><![CDATA[It&#8217;s been a while since I&#8217;ve posted any new content but that&#8217;s not because I haven&#8217;t been doing anything worthy of mention. During the few breaks I&#8217;ve had from my day job I took the time to replace my QNAP 419p NAS with a custom system to host NFS shares. Here&#8217;s just a quick laundry [...]]]></description>
			<content:encoded><![CDATA[<p>It&#8217;s been a while since I&#8217;ve posted any new content but that&#8217;s not because I haven&#8217;t been doing anything worthy of mention.  During the few breaks I&#8217;ve had from my day job I took the time to replace my QNAP 419p NAS with a custom system to host NFS shares.  Here&#8217;s just a quick laundry list of the parts I settled on after quite a bit of shopping.</p>
<p>My requirements for this system were really basic.  All it does is host NFS shares and run rTorrent from time to time.  There was no need to use a full desktop grade processor but I still wanted something x86 compatible with a good bit of ram and a PCI-E port so I could use a real hardware RAID card.  </p>
<h3>Motherboard</h3>
<p>The <a href="http://www.supermicro.com/products/motherboard/ATOM/ICH9/X7SPE-HF-D525.cfm">Super Micro MBD-X7SPE-HF-D525</a> was a good fit.  It has a sweet little <a href="http://ark.intel.com/products/49490">Atom D525</a> soldered on to the board and it&#8217;s surprisingly quick (1.8GHz) though it&#8217;s no work horse.  There&#8217;s only one 16x PCI-E port but that&#8217;s all I need.  It supports up to 4G of ram though it&#8217;s pretty low end laptop memory.  It also has two NICs so you can bond them for more throughput if you want to get fancy.</p>
<p><a href="/files/2011/12/SuperMicro_web.jpg"><img src="/files/2011/12/SuperMicro_web-300x225.jpg" alt="" title="SuperMicro" width="300" height="225" class="alignnone size-medium wp-image-1388" /></a></p>
<p>If you check out the Super Micro site you&#8217;ll see they advertise this board as having RAID on board.  It&#8217;s still not hardware RAID though and since the RAID is done in firmware / driver the Atom processor on this board would have a very hard time keeping up with parity calculations under heavy usage.  There&#8217;s plenty of literature out there about &#8220;<a href="http://en.wikipedia.org/wiki/RAID#Firmware.2Fdriver-based_RAID">fake RAID</a>&#8221; so don&#8217;t be fooled.</p>
<h3>RAID Card</h3>
<p>I&#8217;ve had excellent luck with 3ware in the past so when they were bought out by LSI I was skeptical.  Some of their older cards are still branded 3ware and I tracked down a <a href="http://www.lsi.com/products/storagecomponents/Pages/3ware9650SE-8LPML.aspx">3ware 9650SE 8LPML</a> on ebay for under 300 &#8230; since I couldn&#8217;t afford it new at close to $500 when I was looking 3 months back.</p>
<p>The Linux drivers for this card and the management software are still great.  Setting up RAID 6 was easy though the card requires 5 drives to do this RAID level where theoretically it should only need 4.</p>
<h3>RAM</h3>
<p>The memory for the Super Micro board is practically free.  I tracked down two 2G SODIMMs of Kingston ValueRAM for like $30.  Not the fastest ram in the world but it works.</p>
<h3>Disks</h3>
<p>Buying 5 hard disks is not cheep.  This is especially true if you want to get big drives and ones that will be fast enough to last.  I went with 5 Western Digital AV-GP WD20EURS 2TB 3.0Gb/s drives.  They&#8217;re nice and big, pretty fast and quiet.  User reviews on sites like Newegg are a good way to check up on products before you buy.  This one had particularly good reviews and so far they&#8217;ve been great.  None were DOA as drives have a tendency to do.  They&#8217;re also very quiet and run relatively cool.</p>
<h3>Drive Enclosure</h3>
<p>With this many drives it&#8217;s worth investing in an enclosure to hold them.  You won&#8217;t have to rig fans on the drives to keep air moving over them and you&#8217;ll have the luxury of easy swapping if it something goes wrong and you need to swap out drives.  There isn&#8217;t much available in this space so your choices are limited.  I went with 2x <a href="http://www.icydock.com/goods.php?id=47">ICY DOCK MB453SPF-B 3 in 2</a> enclosures.</p>
<p>I was a bit pissed when one of the enclosures showed up DOA but Newegg was pretty good about doing a quick exchange.  It cost me a few extra bucks in shipping but it could have been worse &#8230; ::shrug::</p>
<h3>Case</h3>
<p>I had an old case from <a href="http://www.lian-li.com/v2/index.html">Lian Li</a> and a small power supply that have been sitting in my basement unused for several years.  Luckily the case it had the 4 5.25 bays that I need to hold these enclosures.  Fitting enclosures into cases never goes as planned though.</p>
<p><a href="/files/2011/12/LianLi_web.jpg"><img src="/files/2011/12/LianLi_web-300x225.jpg" alt="" title="LianLi" width="300" height="225" class="alignnone size-medium wp-image-1389" /></a></p>
<p>The case is super nice but it had these little tabs that stuck out into the drive bays.  These were intended to support individual 5.25 drives but they just got in the way of these enclosures.  They were easy enough to remove with a saw and a file.</p>
<p>That&#8217;s about all there is to it.  Setting up the RAID so I could boot Linux from the 3ware card was a bit of a pain and I wish I had documented the process.  Setting it up through the firmware interface took some experimentation but it is possible.  Then just install Debian and an NFS server and you&#8217;re done.</p>
]]></content:encoded>
			<wfw:commentRss>http://twobit.us/blog/2011/12/atom-based-home-nfs/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Spanish Thruxton</title>
		<link>http://twobit.us/blog/2011/10/spanish-thruxton/</link>
		<comments>http://twobit.us/blog/2011/10/spanish-thruxton/#comments</comments>
		<pubDate>Fri, 28 Oct 2011 13:06:33 +0000</pubDate>
		<dc:creator>Philip</dc:creator>
				<category><![CDATA[Hobby]]></category>
		<category><![CDATA[Motorcycle]]></category>
		<category><![CDATA[Thruxton]]></category>

		<guid isPermaLink="false">http://twobit.us/blog/?p=1379</guid>
		<description><![CDATA[I travel a bunch but I&#8217;ve only traveled internationally twice now. Interestingly enough in my short trips to both the UK and Spain I&#8217;ve ran into my Thruxton&#8217;s foreign relatives. Naturally, the Spanish Thruxton I came across this week in Barcelona is red.]]></description>
			<content:encoded><![CDATA[<p>I travel a bunch but I&#8217;ve only traveled internationally twice now.  Interestingly enough in my short trips to both the UK and Spain I&#8217;ve ran into my Thruxton&#8217;s foreign relatives.  Naturally, the Spanish Thruxton I came across this week in Barcelona is red.</p>
<p><a href="/files/2011/10/spanish-thruxton.jpg"><img src="/files/2011/10/spanish-thruxton-300x168.jpg" alt="" title="spanish-thruxton" width="300" height="168" class="alignnone size-medium wp-image-1380" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://twobit.us/blog/2011/10/spanish-thruxton/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

