<?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>etbe - Russell Coker &#187; Security</title>
	<atom:link href="http://etbe.coker.com.au/category/security/feed/" rel="self" type="application/rss+xml" />
	<link>http://etbe.coker.com.au</link>
	<description>Linux, politics, and other interesting things</description>
	<lastBuildDate>Thu, 02 Sep 2010 04:18:32 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0.1</generator>
		<item>
		<title>Creating a SE Linux Chroot environment</title>
		<link>http://etbe.coker.com.au/2010/07/26/se-linux-chroot-environment/</link>
		<comments>http://etbe.coker.com.au/2010/07/26/se-linux-chroot-environment/#comments</comments>
		<pubDate>Mon, 26 Jul 2010 09:00:43 +0000</pubDate>
		<dc:creator>etbe</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Selinux]]></category>
		<guid isPermaLink="false">http://etbe.coker.com.au/?p=2327</guid>
		<description><![CDATA[Why use a Chroot environment? A large part of the use of chroot environments is for the purpose of security, it used to be the only way of isolating a user from a section of the files on a server. In many of the cases where a chroot used to be used for security it [...]]]></description>
			<content:encoded><![CDATA[<h3>Why use a Chroot environment?</h3>
<p>A large part of the use of chroot environments is for the purpose of security, it used to be the only way of isolating a user from a section of the files on a server.  In many of the cases where a chroot used to be used for security it is now common practice to use a virtual server.  Also another thing to note is that SE Linux provides greater access restrictions to most daemons than a chroot environment would so in many case using SE Linux with a sensible policy is a better option than using a chroot environment to restrict a daemon.  So it seems to me that the security benefits that can be obtained by using a chroot environment have been dramatically decreased over the last 5+ years.</p>
<p>One significant benefit of a chroot environment is that of running multiple different versions of software on one system.  If for example you have several daemons that won&#8217;t run correctly on the same distribution and if you don&#8217;t want to have separate virtual machines (either because you don&#8217;t run a virtualisation technology or because the resources/expense of having multiple virtual servers is unacceptable) then running multiple chroot environments is a reasonable option.</p>
<h3>The Simplest Solution</h3>
<p>The simplest case is when all the chroot environments are equally trusted, that means among many other things that they all have the latest security patches applied.  Then you can run them all with the same labels, so every file in the chroot environment will have the same label as it&#8217;s counterpart in the real root &#8211; this will mean that for example a user from the real root could run /chroot/bin/passwd and possibly get results you don&#8217;t desire.  But it&#8217;s generally regarded that the correct thing to do is to have a chroot environment on a filesystem that&#8217;s mounted <b>nosuid</b> which will deal with most instances of such problems.  One thing to note however is that the <b>nosuid</b> mount option also prevents SE Linux domain transitions, so it&#8217;s not such a good option when you use SE Linux as domain transitions are often used to reduce the privileges assigned to the process.</p>
<p>There are two programs for labeling files in SE Linux, <b>restorecon</b> is the most commonly used one but there is also <b>setfiles</b> which although being the same executable (restorecon is a symlink to setfiles) has some different command-line options.  The following command on a default configuration of a Debian/Lenny system will label a chroot environment under <b>/chroot</b> with the same labels as the main environment:</p>
<p><b>setfiles -r /chroot /etc/selinux/default/contexts/files/file_contexts /chroot</b></p>
<p>I am considering adding an option to support chroot environments to <b>restorecon</b>, if I do that then I will probably back-port it to Lenny, but that won&#8217;t happen for a while.</p>
<p>For a simple chroot once the filesystem is labelled it&#8217;s ready to go, then you can start daemons in the chroot environment in the usual way.</p>
<h3>Less trusted Chroot environments</h3>
<p>A reasonably common case is where the chroot environment is not as trusted.  One example is when you run an image of an old server in a chroot environment.  A good way of dealing with this is to selectively label parts of the filesystem as required.  The following shell code instructs <b>semanage</b> to add file contexts entries for a chroot environment that is used for the purpose of running Apache.  Note that I have given specific labels to device nodes <b>null</b> and <b>urandom</b> and the socket file <b>log</b> in the <b>/dev</b> directory of the chroot environment (these are the only things that are really required under /dev), and I have also put in a rule to specify that no other files or devices under /dev should be labelled.  If /dev is bind mounted to /chroot/dev then it&#8217;s important to not relabel all the devices to avoid messing up the real root environment &#8211; and it&#8217;s impractical to put in a specific rule for every possible device node.  Note that the following is for a RHEL4 chroot environment, other distributions will vary a little some of the file names.</p>
<p><b>semanage -i &#8211; &lt;&lt; END<br />
fcontext -a -t root_t -f -d /chroot<br />
fcontext -a -t bin_t &#8220;/chroot/bin.*&#8221;<br />
fcontext -a -t usr_t &#8220;/chroot/usr.*&#8221;<br />
fcontext -a -t usr_t &#8220;/chroot/opt.*&#8221;<br />
fcontext -a -f -d /chroot/dev<br />
fcontext -a -f -s -t devlog_t /chroot/dev/log<br />
fcontext -a -f -c -t null_device_t /chroot/dev/null<br />
fcontext -a -f -c -t urandom_device_t /chroot/dev/urandom<br />
fcontext -a -t &#34;&lt;&lt;none&gt;&gt;&#34; &#34;/chroot/dev/.*&#34;<br />
fcontext -a -t &#34;&lt;&lt;none&gt;&gt;&#34; &#34;/chroot/proc.*&#34;<br />
fcontext -a -t lib_t &#8220;/chroot/lib.*&#8221;<br />
fcontext -a -t lib_t &#8220;/chroot/usr/lib.*&#8221;<br />
fcontext -a -t bin_t &#8220;/chroot/usr/bin.*&#8221;<br />
fcontext -a -t httpd_exec_t -d &#8212; /chroot/usr/bin/httpd<br />
fcontext -a -t var_t &#8220;/chroot/var.*&#8221;<br />
fcontext -a -t var_lib_t &#8220;/chroot/var/lib.*&#8221;<br />
fcontext -a -t httpd_var_lib_t &#8220;/chroot/var/lib/php.*&#8221;<br />
fcontext -a -t var_log_t &#8220;/chroot/var/log.*&#8221;<br />
fcontext -a -t var_log_t -f &#8212; &#8220;/chroot/var/log/horde.log.*&#8221;<br />
fcontext -a -t httpd_log_t &#8220;/chroot/var/log/httpd.*&#8221;<br />
fcontext -a -t var_run_t &#8220;/chroot/var/run.*&#8221;<br />
fcontext -a -t httpd_var_run_t -f &#8212; /chroot/var/run/httpd.pid<br />
fcontext -a -t httpd_sys_content_t &#8220;/chroot/var/www.*&#8221;<br />
END<br />
</b></p>
<p>You could create a shell script to run the above commands multiple times for multiple separate Apache chroot environments.</p>
<p>If there is a need to isolate the various Apache instances from each other (as opposed to just protecting the rest of the system from a rogue Apache process) then you could start each copy of Apache with a different MCS sensitivity label which will provide adequate isolation for most purposes as long as no sensitivity label dominates the low level of any of the others.  If you do that then the semanage commands require the <b>-r</b> option to specify the range.  You could have one chroot environment under <b>/chroot-0</b> with the sensitivity label of <b>s0:c0</b> for it&#8217;s files and another under <b>/chroot-1</b> with the sensitivity label of <b>s0:c1</b> for it&#8217;s files.  To start one environment you would use a command such as the following:</p>
<p><b>runcon -l s0:c0 setsid chroot /chroot-0 /usr/sbin/httpd</b></p>
]]></content:encoded>
			<wfw:commentRss>http://etbe.coker.com.au/2010/07/26/se-linux-chroot-environment/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>SE Linux status in Debian/Squeeze</title>
		<link>http://etbe.coker.com.au/2010/07/25/se-linux-status-squeeze/</link>
		<comments>http://etbe.coker.com.au/2010/07/25/se-linux-status-squeeze/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 12:38:12 +0000</pubDate>
		<dc:creator>etbe</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Selinux]]></category>
		<guid isPermaLink="false">http://etbe.coker.com.au/?p=2332</guid>
		<description><![CDATA[ffmpeg I&#8217;ve updated my SE Linux repository for Squeeze to include a modified version of the ffmpeg packages without MMX support for the i386 architecture. When MMX support is enabled it uses assembler code which requires text relocations (see Ulrich Drepper&#8217;s documentation for the explanation of this [1]). This makes it possible to run programs [...]]]></description>
			<content:encoded><![CDATA[<h3>ffmpeg</h3>
<p>I&#8217;ve updated my SE Linux repository for Squeeze to include a modified version of the ffmpeg packages without MMX support for the i386 architecture.  When MMX support is enabled it uses assembler code which requires text relocations (<a href="http://people.redhat.com/drepper/selinux-mem.html">see Ulrich Drepper&#8217;s documentation for the explanation of this [1]</a>).  This makes it possible to run programs such as mplayer under SE Linux without granting excessive access &#8211; something which we really desire because mplayer will usually be dealing with untrusted data.  In my past tests with such changes to ffmpeg on my EeePC701 have resulted in no difference to my ability to watch movies from my collection, the ones that could be played without quality loss on a system with such a slow CPU could still be viewed correctly with the patched ffmpeg.</p>
<p><b>$ mplayer<br />
mplayer: error while loading shared libraries: /usr/lib/i686/cmov/libswscale.so.0: cannot restore segment prot after reloc: Permission denied</b></p>
<p>The AMD64 architecture has no need for such patches, presumably due to having plenty of registers.  I don&#8217;t know whether other architectures need such patches, they might &#8211; the symptom is having mplayer abort with an error such as the above when running in Enforcing Mode.</p>
<p>The below apt <b>sources.list</b> line can be used to add my SE Linux repository:</p>
<p><b>deb http://www.coker.com.au squeeze selinux</b></p>
<h3>dpkg</h3>
<p>In my repository for i386 and AMD64 architectures I have included a build of <b>dpkg</b> that fixes bug <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=587949">#587949</a>.  This bug causes some sym-links and directories to be given the wrong label by dpkg when a package is installed.  Usually this doesn&#8217;t impact the operation of the system and I was unable to think of a situation where it could be a security hole, but it can deny access in situations where it should be granted.  I would appreciate some help in getting the patch in a form that can be accepted by the main dpkg developers, the patch I sent in the bug report probably isn&#8217;t ideal even though it works quite well &#8211; someone who knows absolutely nothing about SE Linux but is a good C coder with some knowledge of dpkg could beat it into shape.</p>
<p>In my repository I don&#8217;t currently provide any support for architectures other than i386 and AMD64.  I could be persuaded to do so if there is a demand.  How many people are using Debian SE Linux on other architectures?  Of course there&#8217;s nothing stopping someone from downloading the source from my AMD64 repository and building it for another architecture, I would be happy to refer people to an APT repository that someone established for the purpose of porting my SE Linux packages to another architecture.</p>
<h3>Policy</h3>
<p>selinux-policy-default version 20100524-2 is now in Testing.  It&#8217;s got a lot of little fixes and among other things allows <b>sepolgen-ifgen</b> to work without error which allows using the <b>-R</b> option of <b>audit2allow</b> &#8211; <a href="http://etbe.coker.com.au/2010/07/25/audit2allow-r-milter/">see my post about audit2allow and creating the policy for milters for defails [2]</a>.</p>
<p>I have uploaded selinux-policy-default version 20100524-3 to Unstable.  It has a bunch of little fixes that are mostly related to desktop use.  You can now run KDE4 on Unstable in enforcing mode, login via <b>kdm</b> and expect that everything will work &#8211; probably some things won&#8217;t work, but some of my desktop systems work well with it.  I have to admit that not all of my desktop systems run my latest SE Linux code, I simply can&#8217;t have all my systems run unstable and risk outages.</p>
<p>Let me know if you find any problems with desktop use of the latest SE Linux code, it&#8217;s the focus of my current work.  But if you find problems with <b>chrome</b> (from Google) or the Debian package <b>chromium-browser</b> then don&#8217;t report them to me.  They each use their own version of ffmpeg in the shared object <b>/usr/lib/chromium-browser/libffmpegsumo.so</b> which has text relocations and I don&#8217;t have time to rebuild chromium-browser without text relocations &#8211; I&#8217;ll make sure it does the right thing when they get it working with the standard ffmpeg libraries.  That said the text relocation problem doesn&#8217;t seem to impact the use of Chromium, Youtube doesn&#8217;t work even when the browser is run in permissive mode.</p>
<p>GNOME is a lower priority than KDE for me at this time.  But the only area where problems are likely to occur is with <b>gdm</b> and everything associated with logging in.  Once your X session starts up GNOME and KDE look pretty similar in terms of access control.  I would appreciate it if someone could test <b>gdm</b> and let me know how it goes.  I&#8217;ll do it eventually if no-one else does, but I&#8217;ve got some other things to fix first.</p>
<ul>
<li>[1]<a href="http://people.redhat.com/drepper/selinux-mem.html"> http://people.redhat.com/drepper/selinux-mem.html</a></li>
<li>[2]<a href="http://etbe.coker.com.au/2010/07/25/audit2allow-r-milter/"> http://etbe.coker.com.au/2010/07/25/audit2allow-r-milter/</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://etbe.coker.com.au/2010/07/25/se-linux-status-squeeze/feed/</wfw:commentRss>
		<slash:comments>3</slash:comments>
		</item>
		<item>
		<title>SE Linux audit2allow -R and Milter policy</title>
		<link>http://etbe.coker.com.au/2010/07/25/audit2allow-r-milter/</link>
		<comments>http://etbe.coker.com.au/2010/07/25/audit2allow-r-milter/#comments</comments>
		<pubDate>Sun, 25 Jul 2010 02:00:18 +0000</pubDate>
		<dc:creator>etbe</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Selinux]]></category>
		<guid isPermaLink="false">http://etbe.coker.com.au/?p=2323</guid>
		<description><![CDATA[Since the earliest days there has been a command named audit2allow that takes audit messages of operations that SE Linux denied and produces policy that will permit those operations. A lesser known option for this program is the &#8220;-R&#8221; option to use the interfaces from the Reference Policy (the newer version of the policy that [...]]]></description>
			<content:encoded><![CDATA[<p>Since the earliest days there has been a command named <b>audit2allow</b> that takes audit messages of operations that SE Linux denied and produces policy that will permit those operations.  A lesser known option for this program is the &#8220;<b>-R</b>&#8221; option to use the interfaces from the Reference Policy (the newer version of the policy that was introduced a few years ago).  I have updated <a href="http://etbe.coker.com.au/2008/07/31/installing-se-linux-on-lenny/">my SE Linux repository for Lenny [1]</a> with new packages of policy and <b>python-sepolgen</b> that fix some bugs that stopped this from being usable.</p>
<p>To use the -R option you have to install the <b>selinux-policy-dev</b> package and then run the command <b>sepolgen-ifgen</b> to generate the list of interfaces (for Squeeze I will probably make the postinst script of <b>selinux-policy-dev</b> do this).  Doing this on Lenny requires <b>selinux-policy-default</b> version <b>0.0.20080702-20</b> or better and doing this on Debian/Unstable now requires <b>selinux-policy-default</b> version <b>0.2.20100524-2</b> (which is now in Testing) or better.</p>
<p>Would it be useful if I maintained my own repository of SE Linux packages from Debian/Unstable that can be used with Debian/Testing?  You can use preferences to get a few packages from Unstable with the majority from Testing, but that&#8217;s inconvenient and anyone who wants to test the latest SE Linux stuff would need to include all SE Linux related packages to avoid missing an important update.  If I was to use my own repository I would only include packages that provide a significant difference and let the trivial changes migrate through Testing in the normal way.</p>
<p>The new Lenny policy includes a back-port of the new Milter policy from Unstable, this makes it a lot easier to write policy for milters.  Here is an example of the basic policy for two milters, it allows the milters (with domains <b>foo_milter_t</b> and <b>bar_milter_t</b>) to start, to receive connections from mail servers, and to create PID files and Unix domain sockets.</p>
<p><b>policy_module(localmilter,1.0.0)<br />
<br />milter_template(foo)<br />
files_pid_filetrans(foo_milter_t, foo_milter_data_t, { sock_file file })<br />
<br />milter_template(bar)<br />
files_pid_filetrans(bar_milter_t, bar_milter_data_t, { sock_file file })<br />
allow bar_milter_t self:process signull;<br />
type bar_milter_tmp_t;<br />
files_tmp_file(bar_milter_tmp_t)<br />
files_tmp_filetrans(bar_milter_t, bar_milter_tmp_t, file)<br />
manage_files_pattern(bar_milter_t, tmp_t, bar_milter_tmp_t)</b></p>
<p>After generating that policy I ran a test system in permissive mode and sent a test message.  I ran <b>audit2allow</b> on the resulting AVC messages from <b>/var/log/audit/audit.log</b> and got the following output:</p>
<p><b>#============= bar_milter_t ==============<br />
allow bar_milter_t bin_t:dir search;<br />
allow bar_milter_t bin_t:file getattr;<br />
allow bar_milter_t home_root_t:dir search;<br />
allow bar_milter_t ld_so_cache_t:file { read getattr };<br />
allow bar_milter_t lib_t:file execute;<br />
allow bar_milter_t mysqld_port_t:tcp_socket name_connect;<br />
allow bar_milter_t net_conf_t:file { read getattr ioctl };<br />
allow bar_milter_t self:process signal;<br />
allow bar_milter_t self:tcp_socket { read write create connect setopt };<br />
allow bar_milter_t unlabeled_t:association { recvfrom sendto };<br />
allow bar_milter_t unlabeled_t:packet { recv send };<br />
allow bar_milter_t urandom_device_t:chr_file read;<br />
allow bar_milter_t usr_t:file { read getattr ioctl };<br />
allow bar_milter_t usr_t:lnk_file read;<br />
#============= foo_milter_t ==============<br />
allow foo_milter_t ld_so_cache_t:file { read getattr };<br />
allow foo_milter_t lib_t:file execute;<br />
allow foo_milter_t mysqld_port_t:tcp_socket name_connect;<br />
allow foo_milter_t net_conf_t:file { read getattr };<br />
allow foo_milter_t self:capability { setuid setgid };<br />
allow foo_milter_t self:tcp_socket { write setopt shutdown read create connect };<br />
allow foo_milter_t unlabeled_t:association { recvfrom sendto };<br />
allow foo_milter_t unlabeled_t:packet { recv send };</b></p>
<p>Running the <b>audit2allow</b> command with the &#8220;<b>-R</b>&#8221; option gives the following output, it includes the <b>require</b> section that is needed for generating policy modules:<br />
<b>require {<br />
        type sshd_t;<br />
        type ld_so_cache_t;<br />
        type bar_milter_t;<br />
        type foo_milter_t;<br />
        class process signal;<br />
        class tcp_socket { setopt read create write connect shutdown };<br />
        class capability { setuid setgid };<br />
        class fd use;<br />
        class file { read getattr };<br />
}<br />
#============= bar_milter_t ==============<br />
allow bar_milter_t ld_so_cache_t:file { read getattr };<br />
allow bar_milter_t self:process signal;<br />
allow bar_milter_t self:tcp_socket { read write create connect setopt };<br />
corecmd_getattr_sbin_files(bar_milter_t)<br />
corecmd_search_sbin(bar_milter_t)<br />
corenet_sendrecv_unlabeled_packets(bar_milter_t)<br />
corenet_tcp_connect_mysqld_port(bar_milter_t)<br />
dev_read_urand(bar_milter_t)<br />
files_read_usr_files(bar_milter_t)<br />
files_read_usr_symlinks(bar_milter_t)<br />
files_search_home(bar_milter_t)<br />
kernel_sendrecv_unlabeled_association(bar_milter_t)<br />
libs_exec_lib_files(bar_milter_t)<br />
sysnet_read_config(bar_milter_t)<br />
#============= foo_milter_t ==============<br />
allow foo_milter_t ld_so_cache_t:file { read getattr };<br />
allow foo_milter_t self:capability { setuid setgid };<br />
allow foo_milter_t self:tcp_socket { write setopt shutdown read create connect };<br />
corenet_sendrecv_unlabeled_packets(foo_milter_t)<br />
corenet_tcp_connect_mysqld_port(foo_milter_t)<br />
kernel_sendrecv_unlabeled_association(foo_milter_t)<br />
libs_exec_lib_files(foo_milter_t)<br />
sysnet_read_config(foo_milter_t)</b></p>
<p>To get this working I removed the <b>require</b> lines for <b>foo_milter_t</b> and <b>bar_milter_t</b> as it&#8217;s not permitted to both define a type and require it in the same module.  Then I replaced the set of <b>tcp_socket</b> operations <b>{ write setopt shutdown read create connect }</b> with <b>create_socket_perms</b> as it&#8217;s easiest to allow all the operations in that set and doesn&#8217;t give any security risks.</p>
<p>Finally I replaced the mysql lines such as <b>corenet_tcp_connect_mysqld_port(foo_milter_t)</b> with sections such as the following:<br />
<b>mysql_tcp_connect(foo_milter_t)<br />
optional_policy(`<br />
  mysql_stream_connect(foo_milter_t)<br />
&#8216;)</b></p>
<p>This gives it all the access it needs and additionally the optional policy will allow Unix domain socket connections for the case where the mysqld is running on localhost.</p>
<ul>
<li>[1]<a href="http://etbe.coker.com.au/2008/07/31/installing-se-linux-on-lenny/"> http://etbe.coker.com.au/2008/07/31/installing-se-linux-on-lenny/</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://etbe.coker.com.au/2010/07/25/audit2allow-r-milter/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Tracking down Write/Execute mmap() calls with LD_PRELOAD</title>
		<link>http://etbe.coker.com.au/2010/07/12/write-execute-mmap-ld-preload/</link>
		<comments>http://etbe.coker.com.au/2010/07/12/write-execute-mmap-ld-preload/#comments</comments>
		<pubDate>Mon, 12 Jul 2010 10:16:36 +0000</pubDate>
		<dc:creator>etbe</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Selinux]]></category>
		<guid isPermaLink="false">http://etbe.coker.com.au/?p=2324</guid>
		<description><![CDATA[One of the access controls in SE Linux is for execmem &#8211; which is used to stop processes from creating memory regions that are writable and executable (as they make it easier to compromise programs and get them to execute supplied code). When the SE Linux audit log tells you that a program is attempting [...]]]></description>
			<content:encoded><![CDATA[<p>One of the access controls in SE Linux is for <b>execmem</b> &#8211; which is used to stop processes from creating memory regions that are writable and executable (as they make it easier to compromise programs and get them to execute supplied code).  When the SE Linux audit log tells you that a program is attempting such access it&#8217;s sometimes difficult to discover where in the code such an access occurs, for example if you have a large code base and <b>mmap()</b> is called in many places it can be difficult to determine which one is the culprit.  Especially if you have a source package that contains multiple binaries that use a common shared library and you don&#8217;t know which bits of library code are called by each executable.</p>
<p>To solve this problem in the case of <b>freshclam</b> to provide extra information for <a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=588599">Debian bug report #588599 [1]</a> I wrote the following little shared object which can be compiled with &#8220;<b>gcc -shared -g -fPIC mmap.c -o mmap.so</b>&#8221; and used with &#8220;<b>LD_PRELOAD=./mmap.so whatever</b>&#8220;.  Then when the program in question (or any non-SUID program it executes) calls mmap() with both <b>PROT_EXEC</b> and <b>PROT_WRITE</b> set the program will abort.  If you run this through <b>gdb</b> then the program will break and you will get a back-trace of the function calls that led to the undesired mmap().</p>
<p>One thing to note is that this method only catches direct calls to a library function outside libc.  When the libc code calls the library function (EG all the fwrite() etc code that calls mmap()) the LD_PRELOAD hack won&#8217;t catch it.  Thanks to Keith Owens for pointing this out.</p>
<p>#include &lt;dlfcn.h&gt;<br />
#include &lt;stdio.h&gt;<br />
#include &lt;sys/mman.h&gt;<br />
#include &lt;stdlib.h&gt;<br />
#undef NDEBUG<br />
#include &lt;assert.h&gt;</p>
<p>void *libc6 = NULL;</p>
<p>void *(*real_mmap)(void *, size_t, int, int, int, off_t);</p>
<p>void do_init()<br />
{<br />
&nbsp; libc6 = dlopen(&#34;libc.so.6&#34;, RTLD_LAZY | RTLD_GLOBAL);<br />
&nbsp; if(!libc6)<br />
&nbsp; {<br />
&nbsp; &nbsp; printf(&#34;Aieee\n&#34;);<br />
&nbsp; &nbsp; exit(1);<br />
&nbsp; }<br />
&nbsp; real_mmap = (void * (*)(void *, size_t, int, int, int, off_t))dlsym(libc6, &#34;mmap&#34;);<br />
}</p>
<p>void *mmap(void *addr, size_t length, int prot, int flags, int fd, off_t offset)<br />
{<br />
&nbsp; if(!real_mmap)<br />
&nbsp; &nbsp; do_init();<br />
&nbsp; assert(!(prot &amp; PROT_EXEC) || !(prot &amp; PROT_WRITE));<br />
&nbsp; return real_mmap(addr, length, prot, flags, fd, offset);<br />
}</p>
<ul>
<li>[1]<a href="http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=588599"> http://bugs.debian.org/cgi-bin/bugreport.cgi?bug=588599</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://etbe.coker.com.au/2010/07/12/write-execute-mmap-ld-preload/feed/</wfw:commentRss>
		<slash:comments>2</slash:comments>
		</item>
		<item>
		<title>Play Machine Online Again with Xen 4.0</title>
		<link>http://etbe.coker.com.au/2010/06/29/play-machine-online-xen-4-0/</link>
		<comments>http://etbe.coker.com.au/2010/06/29/play-machine-online-xen-4-0/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 11:38:10 +0000</pubDate>
		<dc:creator>etbe</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Selinux]]></category>
		<guid isPermaLink="false">http://etbe.coker.com.au/?p=2290</guid>
		<description><![CDATA[My SE Linux Play Machine [1] has been offline for almost a month (it went offline late May 30 and has just gone online again). It&#8217;s the sort of downtime that can happen when you use Debian/Unstable. For a while I&#8217;ve been using a HP E-PC (a SFF desktop system with 256M of RAM and [...]]]></description>
			<content:encoded><![CDATA[<p>My <a href="http://www.coker.com.au/selinux/play.html">SE Linux Play Machine [1]</a> has been offline for almost a month (it went offline late May 30 and has just gone online again).  It&#8217;s the sort of downtime that can happen when you use Debian/Unstable.</p>
<p>For a while I&#8217;ve been using a HP E-PC (a SFF desktop system with 256M of RAM and a P3-800 CPU) to run my SE Linux Play Machine.  I run it under Xen to make it easier for me to watch what happens.  I&#8217;ve had <a href="http://etbe.coker.com.au/2010/03/21/xen-debian-squeeze/">some problems with increased memory use in the Xen Dom0 in Squeeze [2]</a>.  The latest installment of the memory problems is when I discovered that I can&#8217;t run two copies of tcpdump (for tracing separate interfaces) at once on a Xen Dom0 that has ~110M of RAM &#8211; this seems unreasonable, I&#8217;m sure that back when a big server had 128M of RAM I could have done such things!  So now I&#8217;m using a Thinkpad T20 with 512M of RAM for my new SE Linux Play Machine, it uses less power than most systems (probably even less than the HP E-PC) and is very quiet.</p>
<p>I was forced to install on a new system when I broke my GRUB configuration.  GRUB-2 in Debian currently has no support for generating a configuration that will boot a Xen Dom0.  You can manually edit the GRUB configuration to get this working, but if you get it wrong then you can make GRUB not even display a prompt and force a reinstall (as I did).  As an aside it would be really handy if someone would create a CD or USB bootable image that does nothing but install GRUB.  Such an image would ideally allow replacing the configuration of an existing GRUB, overwriting an existing GRUB installation (all files in /boot/grub get replaced), or formatting a spare partition (default swap space) and installing GRUB there.</p>
<p>My current solution to the GRUB problems is to use the old version of GRUB in the <b>grub-legacy</b> package.  The old version of GRUB has always done everything I want so I don&#8217;t seem to be missing anything by not using the new version.  I&#8217;m happy to refrain from using Ext4 for /boot and have no desire to have /boot on an LVM volume.</p>
<p>Most of the month of down-time for my Play Machine was caused by bugs in the SE Linux policy I&#8217;m developing for Squeeze, while they weren&#8217;t difficult bugs I haven&#8217;t had much time to work on them consistently.  I&#8217;m still running the Play Machine on Lenny, but the Dom0 is running Unstable.</p>
<ul>
<li>[1]<a href="http://www.coker.com.au/selinux/play.html"> http://www.coker.com.au/selinux/play.html</a></li>
<li>[2]<a href="http://etbe.coker.com.au/2010/03/21/xen-debian-squeeze/"> http://etbe.coker.com.au/2010/03/21/xen-debian-squeeze/</a></li>
</ul>
]]></content:encoded>
			<wfw:commentRss>http://etbe.coker.com.au/2010/06/29/play-machine-online-xen-4-0/feed/</wfw:commentRss>
		<slash:comments>1</slash:comments>
		</item>
		<item>
		<title>New SE Linux Policy for Squeeze</title>
		<link>http://etbe.coker.com.au/2010/06/29/se-linux-policy-squeeze/</link>
		<comments>http://etbe.coker.com.au/2010/06/29/se-linux-policy-squeeze/#comments</comments>
		<pubDate>Tue, 29 Jun 2010 03:28:30 +0000</pubDate>
		<dc:creator>etbe</dc:creator>
				<category><![CDATA[Security]]></category>
		<category><![CDATA[Selinux]]></category>
		<guid isPermaLink="false">http://etbe.coker.com.au/?p=2295</guid>
		<description><![CDATA[I have just uploaded refpolicy version 0.2.20100524-1 to Unstable. This policy is not well tested (a SE Linux policy package ending in &#8220;-1&#8221; is not something that tends to work well for all people) and in particular lacks testing for Desktop environments. But for servers it should work reasonably well. I expect to have a [...]]]></description>
			<content:encoded><![CDATA[<p>I have just uploaded refpolicy version 0.2.20100524-1 to Unstable.  This policy is not well tested (a SE Linux policy package ending in &#8220;<b>-1</b>&#8221; is not something that tends to work well for all people) and in particular lacks testing for Desktop environments.  But for servers it should work reasonably well.</p>
<p>I expect to have a better version uploaded before this one gets out of Unstable.</p>
<p>Note that the <b>selinux-policy-default</b> package in this release lacks support for roles, it&#8217;s a <b>targeted</b> policy only.  I plan to fix this soon.</p>
]]></content:encoded>
			<wfw:commentRss>http://etbe.coker.com.au/2010/06/29/se-linux-policy-squeeze/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
