{"id":97,"date":"2009-03-07T02:16:11","date_gmt":"2009-03-07T01:16:11","guid":{"rendered":"http:\/\/klondike.xiscosoft.es\/klog\/?p=97"},"modified":"2010-06-27T19:00:31","modified_gmt":"2010-06-27T18:00:31","slug":"gentoo-hardened-and-gcc-4x-i-installation","status":"publish","type":"post","link":"https:\/\/klondike.es\/klog\/2009\/03\/07\/gentoo-hardened-and-gcc-4x-i-installation\/","title":{"rendered":"Gentoo hardened and gcc-4.x (I) Installation"},"content":{"rendered":"<p>As I wrote previously, I&#8217;m going to use a virtualized environment to run my desktop machine and the Direct Connect server for the Campus Party. In this first document I&#8217;ll try to cover a hardened multilib amd64 installation using gcc-4.x from a stage 3 following the gentoo handbook.<\/p>\n<p><!--more-->As usual we got through chapters 1 to 4 to get a working system from a Live CD, then configure its network connection and partition its hard disks (as a side note I like to comment that I have made boot being in the same partition as the main gentoo system).<\/p>\n<p>After that I downloaded the hardened multilib stage3 (remember it can be found at the hardened directory inside the stages dir)  file and uncompressed it following the instructions in the handbook.<\/p>\n<p>Next thing I did was installing portage and then configuring the make.conf to my likes.<\/p>\n<p>After that I selected a Mirror and followed the chroot process explained at section 6.a<\/p>\n<p>Next, was changing the profile to the appropriate one (<span style=\"text-decoration: line-through;\">hardened\/amd64\/multilib\/<\/span> now it is hardened\/linux\/amd64\/10.0) as indicated at 6.b <span style=\"text-decoration: line-through;\">I also added the multilib USE as it doesn&#8217;t seems to work properly with that profile (see <a title=\"Bug #261482\" href=\"http:\/\/bugs.gentoo.org\/show_bug.cgi?id=261482\" target=\"_blank\">BUG #261482<\/a>).<\/span> Now adding the multilib USE seem unnecessary as the bug was fixed. And generated the appropriate locales (es-ES in my case).<\/p>\n<p><span style=\"text-decoration: line-through;\">After that and following part 6 I passed to adding gcc-4* to my system before going for the kernel.<\/span><\/p>\n<p><span style=\"text-decoration: line-through;\">First thing you need is layman and git so start by emerging both:<\/span><\/p>\n<blockquote><p><span style=\"text-decoration: line-through;\"># emerge -v dev-util\/git app-portage\/layman<\/span><\/p><\/blockquote>\n<p><span style=\"text-decoration: line-through;\">Also you should configure your make.conf so it reads data from layman:<\/span><\/p>\n<blockquote><p><span style=\"text-decoration: line-through;\"><del datetime=\"2009-06-01T01:32:16+00:00\"># echo &#8220;source \/usr\/portage\/local\/layman\/make.conf&#8221; &gt;&gt; \/etc\/make.conf<\/del><\/span><\/p><\/blockquote>\n<p><span style=\"text-decoration: line-through;\">On new versions of layman this moved so use:<\/span><\/p>\n<blockquote><p><span style=\"text-decoration: line-through;\"># echo &#8220;source \/usr\/local\/portage\/layman\/make.conf&#8221; &gt;&gt; \/etc\/make.conf<\/span><\/p><\/blockquote>\n<p><span style=\"text-decoration: line-through;\">After that we added the overlay using layman:<\/span><\/p>\n<blockquote><p><span style=\"text-decoration: line-through;\"><del datetime=\"2009-09-12T16:35:00+00:00\"># layman -o http:\/\/github.com\/Xake\/toolchain-overlay.git\/xake-toolchain.xml -fa xake-toolchain<\/del><\/span><\/p><\/blockquote>\n<p><span style=\"text-decoration: line-through;\">As the overlay has moved,you&#8217;d better use<\/span><\/p>\n<blockquote><p><span style=\"text-decoration: line-through;\"># layman -kfa hardened-development<\/span><\/p><\/blockquote>\n<p><span style=\"text-decoration: line-through;\">Then we add a few thing to our make.conf to solve a few problems:<\/span><\/p>\n<blockquote><p><span style=\"text-decoration: line-through;\"># echo &#8216;FEATURES=&#8221;metadata-transfer&#8221;&#8216; &gt;&gt; \/etc\/make.conf<br \/>\n#echo &#8216;PORTAGE_ECLASS_WARNING_ENABLE=&#8221;0&#8243; &gt;&gt; \/etc\/make.conf<\/span><\/p><\/blockquote>\n<p>As of today the gcc-4.x with  PIE and SSP is available on &gt;=sys-devel\/gcc-4.4.4-r1 and &gt;=sys-devel\/gcc-4.4.3-r3 for the 4.4.4 and 4.4.3 versions respectively. So the overlay is not required.<\/p>\n<p><span style=\"text-decoration: line-through;\">And we unmask the 4.3 version of gcc (as 4.2 is gone) and the required glibc-2.7* version we also unmask a few packages required by the toolchain to work properly:<\/span><\/p>\n<blockquote><p><span style=\"text-decoration: line-through;\"># echo =sys-devel\/gcc-4.3* &gt;&gt; \/etc\/portage\/package.unmask<br \/>\n# echo =sys-libs\/glibc-2.7* &gt;&gt; \/etc\/portage\/package.unmask<br \/>\n# echo =sys-devel\/gcc-4.3* &gt;&gt; \/etc\/portage\/package.keywords<br \/>\n# echo =sys-libs\/glibc-2.7* &gt;&gt; \/etc\/portage\/package.keywords<br \/>\n# echo &#8220;=sys-devel\/binutils-2.18-r4&#8221; &gt;&gt;\/etc\/portage\/package.keywords<br \/>\n# echo &#8220;=sys-boot\/grub-0.97-r10&#8221; &gt;&gt;\/etc\/portage\/package.keywords<\/span><\/p><\/blockquote>\n<p>As of today only removing the keyword is removed and if no bug is filled against those versions in less than a month this won&#8217;t even be necessary.<\/p>\n<p>For gcc-4.4.4 We should use:<\/p>\n<blockquote><p># echo =sys-devel\/gcc-4.4.4-r1 &gt;&gt; \/etc\/portage\/package.keywords<br \/>\n# echo &#8220;=sys-boot\/grub-0.97-r10&#8221; &gt;&gt;\/etc\/portage\/package.keywords<\/p><\/blockquote>\n<p>And for gcc-4.4.3 use instead:<\/p>\n<blockquote><p># echo =sys-devel\/gcc-4.4.3-r3 &gt;&gt; \/etc\/portage\/package.keywords<br \/>\n# echo &#8220;=sys-boot\/grub-0.97-r10&#8221; &gt;&gt;\/etc\/portage\/package.keywords<\/p><\/blockquote>\n<p>Now we build our fancy new toolchain:<\/p>\n<blockquote><p># emerge gcc-config linux-headers glibc binutils gcc portage -1<\/p><\/blockquote>\n<p>And set up the system so it uses it. For gcc 4.4.4:<\/p>\n<blockquote><p># gcc-config x86_64-pc-linux-gnu-4.4.4<br \/>\n# source \/etc\/profile<br \/>\n# export PS1=&#8221;(chroot) $PS1&#8243;<\/p><\/blockquote>\n<p>Or for gcc 4.4.3:<\/p>\n<blockquote><p># gcc-config x86_64-pc-linux-gnu-4.4.3<br \/>\n# source \/etc\/profile<br \/>\n# export PS1=&#8221;(chroot) $PS1&#8243;<\/p><\/blockquote>\n<p>So now we have a hardened install with a gcc-4.3 compiler. We could remove the old gcc version but we are keeping it just in case.<\/p>\n<p>With our new gcc version it would be a good idea recompiling our stage3 so it uses the new gcc version, SSP and PIE. For that we&#8217;d run:<\/p>\n<blockquote><p># emerge -ev1 world<\/p><\/blockquote>\n<p>Next steep is following chapter 7 (configure and compile the kernel).<\/p>\n<p>After following step 7.a to set the time we got the hardened sources:<\/p>\n<blockquote><p>emerge hardened-sources<\/p><\/blockquote>\n<p>And then jumped to step 7.c  to configure the hardened kernel where I enabled PAX and Grsec.<\/p>\n<p>After that (as I didn&#8217;t use modules) I jumped to chapter 8. and followed until the end.<\/p>\n<p>I&#8217;ll report on how well or bad it works as it ends compiling kde \ud83d\ude09<\/p>\n<p>As report I have to say that I have been used this hardened system since I wrote this article without any major problems \ud83d\ude00<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As I wrote previously, I&#8217;m going to use a virtualized environment to run my desktop machine and the Direct Connect server for the Campus Party. In this first document I&#8217;ll try to cover a hardened multilib amd64 installation using gcc-4.x from a stage 3 following the gentoo handbook.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-97","post","type-post","status-publish","format-standard","hentry","category-otras-cosas"],"_links":{"self":[{"href":"https:\/\/klondike.es\/klog\/wp-json\/wp\/v2\/posts\/97","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/klondike.es\/klog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/klondike.es\/klog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/klondike.es\/klog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/klondike.es\/klog\/wp-json\/wp\/v2\/comments?post=97"}],"version-history":[{"count":7,"href":"https:\/\/klondike.es\/klog\/wp-json\/wp\/v2\/posts\/97\/revisions"}],"predecessor-version":[{"id":99,"href":"https:\/\/klondike.es\/klog\/wp-json\/wp\/v2\/posts\/97\/revisions\/99"}],"wp:attachment":[{"href":"https:\/\/klondike.es\/klog\/wp-json\/wp\/v2\/media?parent=97"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/klondike.es\/klog\/wp-json\/wp\/v2\/categories?post=97"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/klondike.es\/klog\/wp-json\/wp\/v2\/tags?post=97"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}