Hardened/FAQ

Frequently Asked Questions that arise on the #gentoo-hardened IRC channel and the gentoo-hardened mailing list.

Introduction
The following is a collection of questions collected from #gentoo-hardened IRC channel and the gentoo-hardened mailing list. As such, is geared towards answering fast and concisely rather than providing a whole insight on the technologies behind Gentoo Hardened. It is advisable reading the rest of the documentation on the Gentoo Hardened Project page and that on the projects' home pages in order to get a better insight.

What exactly is the "toolchain"?
The term "toolchain" refers to the combination of software packages commonly used to build and develop for a particular architecture. The toolchain you may hear referred to in the gentoo-hardened IRC channel consists of the GNU Compiler Collection (GCC), binutils, and the GNU C library (glibc).

What should I use: Grsecurity's RBAC or SELinux?
The answer to this question is highly subjective, and very dependent on your requisites so the hardened Gentoo project simply tries to lay out each technology and leave the choice up to the user. This decision requires a lot of research that we have hopefully provided clearly in the hardened documentation. However, if you have any specific questions about the security model that each provides, feel free to question the relevant developer in our IRC channel or on the mailing list.

Is it possible to use Grsecurity, SELinux and PaX all at the same time?
Yes, this combination is quite possible as PaX and some of Grsecurity's features work with Grsecurity's RBAC and SELinux. The only conflict that arises is you can only use one access control system (be it RBAC or SELinux).

Do I need to pass any flags to LDFLAGS/CFLAGS in order to turn on hardened building?
No, the current toolchain implements the equivalent of  automatically through GCC's built-in spec and using the specfiles to disable them which is a more proper solution. For older hardened-gcc users the best approach is switch to the hardened profile and then upgrade following the steps on the

Can I add -fstack-protector-all or -fstack-protector in the CFLAGS at make.conf?
No, they will likely break the building of many packages, amongst others glibc. It's better that you leave the profiles do its job.

How do I turn off hardened building?
You can use  to accomplish this:

To turn off PIE building switch to the hardenednopie profile:

To turn off SSP building switch to the hardenednossp profile:

To turn off SSP and PIE building switch to the hardenednopiessp profile:

To turn off all hardened building switch to the vanilla profile:

You need to run this on the active sessions to set the changes

Alternatively you can achieve the same by changing your CFLAGS:

To turn off default SSP building when using the hardened toolchain, append  to your CFLAGS.

If you want to turn off default PIE building then append  to your   and your   (as LDFLAGS is used with no CFLAGS when using gcc to link the object files).

If you want to turn off default now binding append  to your.

If you want to turn off default relro binding append  to your.

I just found out about the hardened project; do I have to install everything on the project page in order to install Hardened Gentoo?
No, the Hardened Gentoo Project is a collection of subprojects that all have common security minded goals. While many of these projects can be installed alongside one another, some conflict as well such as several of the ACL implementations that Hardened Gentoo offers.

Why don't my programs work when I use CFLAGS="-O3" and hardened gcc?
Using the gcc optimization flag  has been known to be problematic with stack-smashing protector (SSP) and on vanilla builds in some situations. This optimization flag is not officially supported and is, therefore, discouraged by the hardened team. Compile issues where a user uses  may be closed as INVALID/CANTFIX and/or ignored.

How do I switch to the hardened profile?
To change your profile use eselect to choose it.

Of course replace 8 with the desired hardened profile.

After setting up your profile, you should recompile your system using a hardened toolchain so that you have a consistent base:

Make sure the hardened toolchain is being used (gcc version may vary):

If the hardened version isn't chosen select it

Now keep emerging the system

The  option is added to ensure emerge won't stop in case any package fails to build. If that occurs however, you need to make sure that the remainder of the packages is built. You can check the output of emerge at the end to find out which packages were not rebuilt.

How do I debug with gdb?
We have written a document on how to debug with Gentoo Hardened, so following the recommendations there should fix your problem.

Why is the jit and orc flag disabled in the hardened profile?
JIT means Just In Time Compilation and consist on taking some code meant to be interpreted (like Java bytecode or JavaScript code) compile it into native binary code in memory and then executing the compiled code. This means that the program need a section of memory which has write and execution permissions to write and then execute the code which is denied by PaX, unless the mprotect flag is unset for the executable. As a result, we disabled the JIT use flag by default to avoid complaints and security problems. ORC use Just In Time Compilation (jit).

You should bear in mind that having a section which is written and then executed can be a serious security problem as the attacker needs to be able to exploit a bug between the write and execute stages to write in that section in order to execute any code it wants to.

How do I enable the jit or orc flag?
If you need it, we recommend enabling the flag in a per package basis using

Example /etc/portage/package.use enabling JIT in some libraries

Anyway, you can enable the use flag globally using

Example /etc/make.conf with JIT enabled

Where is the homepage for PaX?
That is the homepage for PaX.

What Gentoo documentation exists about PaX?
Currently the only Gentoo documentation that exists about PaX is a PaX quickstart guide.

How do PaX markings work?
PaX markings are a way to tell PaX which features should enable (or disable) for a certain binary.

Features can either be enabled, disabled or not set. Enabling or disabling them will supersede the kernel action, so a binary with a feature enabled will always use the feature and one with a feature disabled won't ever used it.

When the feature status is not set the kernel will choose whether to enable or disable it. By default, the hardened kernel will enable those features with only two exceptions, the feature is not supported by the architecture/kernel or PaX is running in Soft Mode. In those two cases, it will be disabled.

I keep getting the message: "error while loading shared libraries: cannot make segment writable for relocation: Permission denied." What does this mean?
Text relocations are a way in which references in the executable code to addresses not known at link time are solved. Basically they just write the appropriate address at runtime marking the code segment writable in order to change the address then unmarking it. This can be a problem as an attacker could try to exploit a bug when the text relocation happens in order to be able to write arbitrary code in the text segment which would be executed. As this also means that code will be loaded on fixed addresses (not be position independent) this can also be exploited to pass over the randomization features provided by PaX.

As this can be triggered for example by adding a library with text relocations to the ones loaded by the executable, PaX offers the option CONFIG_PAX_NOELFRELOCS in order to avoid them. This option is enabled like this:

If you are using the gentoo hardened toolchain, typically compiling your programs will create PIC ELF libraries that do not contain text relocations. However, certain libraries still contain text relocations for various reasons (often ones that contain assembly that is handled incorrectly). This can be a security vulnerability as an attacker can use non-PIC libraries to execute his shellcode. Non-PIC libraries are also bad for memory consumption as they defeat the code sharing purpose of shared libraries.

To disable this error and allow your program to run, you must sacrifice security and allow runtime code generation for that program. The PaX feature that allows you to do that is called MPROTECT. You must disable MPROTECT on whatever executable is using the non-PIC library.

To check your system for textrels, you can use the program  from. For information on how to use the  package please consult the Gentoo PaX Utilities Guide.

Ever since I started using PaX I can't get Java/JIT code working, why?
As part of its design, the Java virtual machine creates a considerable amount of code at runtime which does not make PaX happy. Although, with current versions of portage and java, portage will mark the binaries automatically, you still need to enable PaX marking so PaX can do an exception with them and have paxctl installed so the markings can be applied to the binaries (an reemerge them so they are applied).

This of course can't be applied to all packages linking with libraries with JIT code, so if it doesn't, there are two ways to correct this problem:

When you already have  emerged you can do:

This option will slightly modify the ELF header in order to correctly set the PAX flags on the binaries.

The other way is using your security implementation to do this using the kernel hooks.

Can I disable PaX features at boot?
Although this is not advised except when used to rescue the system or for debugging purposes, it is possible to change a few of PaX behaviours on boot via the kernel command line.

Passing  in the kernel cmdline will disable uderef which can cause problems on certain virtualization environments and cause some bugs (at times) at the expense leaving the kernel unprotected against unwanted userspace dereferences.

Passing  in the kernel cmdline will enable the softmode which can be useful when booting a not prepared system with a PaX kernel. In soft mode PaX will disable most features by default unless told otherwise via the markings. In a similar way,  will disable the softmode if it was enabled in the config.

Where is the homepage for Grsecurity?
That is the homepage for Grsecurity.

What Gentoo documentation exists about Grsecurity?
The most current documentation for Grsecurity is a Grsecurity2 quickstart guide.

How does TPE work?
We have written a document with some information on how TPE works in the different settings.

Can I use Grsecurity with a recent kernel not on the Gentoo main tree?
Usually we release a new version of hardened sources not long after a new PaX/Grsecurity patch is released, so the best option is just waiting a bit for the kernel team to adapt the patches and then test them. Remind that we won't support kernel sources not coming from the portage tree.

Where can I find SELinux related frequently asked questions?
There is a SELinux specific FAQ.

Acknowledgements
We would like to thank the following authors and editors for their contributions to this guide:


 * Adam Mondl
 * solar
 * Guillaume Destuynder
 * The PaX Team
 * klondike
 * Magnus Granberg
 * Anthony G. Basile