GNU/Linux System Configuration Guide
GNU/Linux System Configuration Guide
OF A GNU/LINUX SYSTEM
ANSSI GUIDELINES
ANSSI-BP-028-EN
03/10/2022
TARGETED AUDIENCE:
Warning
This document, written by ANSSI, the French National Information Security Agency,
presents the “Configuration recommendations of a GNU/LINUX system”. It is freely avail-
able at [Link]/en/.
It is an original creation from ANSSI and it is placed under the “Open Licence v2.0” published
by the Etalab mission [15].
According to the Open Licence v2.0, this guide can be freely reused, subject to mentioning its
paternity (source and date of last update). Reuse means the right to communicate, distribute,
redistribute, publish, transmit, reproduce, copy, adapt, modify, extract, transform and use,
including for commercial purposes.
These recommendations are provided as is and are related to threats known at the publi-
cation time. Considering the information systems diversity, ANSSI cannot guarantee direct
application of these recommendations on targeted information systems. Applying the fol-
lowing recommendations shall be, at first, validated by IT administrators and/or IT security
managers.
This document is a courtesy translation of the initial French document “Recommandations
de configuration d’un système GNU/Linux”, available at [Link]. In case of con-
flicts between these two documents, the latter is considered as the only reference.
Document changelog:
VERSION DATE CHANGELOG
1.0 08/10/2015 Initial version
1.1 12/08/2016 Minor revision
1.2 22/02/2019 Minor revision and transition to the
new ANSSI model. English version
based on a courtesy translation
provided by Red Hat
2.0 03/10/2022 Integration of the hardening elements
of the Linux Kernel and reorganization
of the chapters. English version based
on a courtesy translation provided by
Red Hat
CONFIGURATION RECOMMENDATIONS OF A GNU/LINUX SYSTEM –1
Contents
1 Preamble 4
1.1 Foreword . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
1.2 Hardening Level . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4
4 Hardware configuration 10
4.1 Hardware support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.2 BIOS/UEFI . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10
4.3 UEFI secure boot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.3.1 Preloaded keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11
4.3.2 New keys . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
4.4 Measured Boot . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12
6 System configuration 32
6.1 Partitioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 32
6.2 Accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
6.2.1 User accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 34
6.2.2 Administrator accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 35
6.2.3 Service accounts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 36
6.3 Access control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.3.1 Unix traditional model . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 37
6.3.2 AppArmor . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 42
6.3.3 SELinux . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 43
6.4 Files and directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
6.4.1 Sensitive files and directories . . . . . . . . . . . . . . . . . . . . . . . . . . . . 48
6.4.2 Named IPC, sockets or pipes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 49
7 Services configuration 55
7.1 Partitioning . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 57
7.2 System services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 58
7.2.1 Pluggable Authentication Module . . . . . . . . . . . . . . . . . . . . . . . . 58
7.2.2 Name Service Switch . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 61
7.2.3 Logging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62
7.2.4 Messaging . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 64
7.2.5 File System monitoring . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 65
7.3 Network services . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 66
Recommendation List 68
Bibliography 79
1.1 Foreword
Today Unix operating systems and derivatives, including GNU/Linux, are playing an important
role in the ecosystem of equipments, systems, networks and telecommunications. They are widely
deployed in several equipments (switches, routers, TV systems, vehicles…).
Their diversity and their composition are such that they are used according to a large number of
possible combinations. Addressing in detail each possible use case is not the point of this guide.
However some configuration rules allow to get a reasonably safe system if certain fundamental
principles are respected, and to methodologically verify that they are properly applied, by using
(for example) a checklist.
This guide targets system administrators and designer of products based on Linux who want to re-
inforce the security of their systems. It focuses mainly on generic system configuration guidelines
and on common sense principles that need to be applied during the deployment of services on a
GNU/Linux system. The configuration of these services themselves can be subject to a dedicated
technical note, for example the Recommandations pour la sécurisation des sites Web [5] or (Open)SSH
secure use recommendations [3] on the ANSSI website. The reader is invited to refer to the docu-
ment Recommandations pour la mise en place de cloisonnement système [8] for a more specific and
detailed approach of this subject.
It is advisable to study the applicability and the maintainability of each recommendation in the
context of the considered use case. It is also strongly recommended to have recourse to the skills
of an expert in GNU/Linux systems for the implementation of these good practices.
The recommendations of this guide are given based on an estimated level of hardening. This level
does not necessarily depend on the difficulty and time required to deploy a given recommendation,
elements that can only be appreciated after an audit in a given context. These levels should be seen
as guiding principles to help in the system administration.
For example, hardening the kernel will be very beneficial to systems hosting containers because
these rely on kernel functionalities as their partitioning primitives. However, a kernel not updated
regularly due to a lack of human resources will degrade considerably the level of security of the
system, exposing it to the many vulnerabilities found and disclosed each day.
Level Description
Minimal level recommendations. To be implemented system-
M
atically on every system.
Intermediary level recommendations. To be implemented as
M I soon as possible on most systems once the minimal level rec-
ommendations are applied.
Enhanced level recommendations. To be implemented on sys-
M I E tems in need of stronger security or that have multiple applica-
tions that must be isolated from each other.
High level recommendations. To be implemented only if the
internal resources have enough skills and time to maintain
M I E H them, otherwise the security of the system may be degraded.
However, these recommendations can bring huge security im-
provements.
Table 1 – Hardening Level Reading Table
Based on the targeted hardening level, the recommendations apply from the minimum level up to
the targeted level.
Operating systems have therefore developed different mechanisms to protect themselves against
malicious applications or users, but also to separate the resources of the different applications and
limit the impact of a vulnerability.
The threats being extremely varied, we will classify them here by objective.
n The availability, or rather the fact of making unavailable the targeted system is the easiest
objective for an attacker to achieve. The overload of one of the resources (network, file sys-
tem, memory…) can affect the entire system. The exploitation of some vulnerabilities can also
cripple a resource, for instance by forcing an application to constantly restart.
The objective of an attacker may be to prevent the use of a business-specific application, but also
to interfere with the proper functioning of the security functions of an information system. A
denial of service on a log aggregation server will for example prevent the reception of logs from
other machines, hiding the malicious activity of an attacker and preventing any remediation.
n The confidentiality or data theft is another goal of attackers. Business data theft (databases,
files…) or identity theft may have a direct profit motive. Finally, machine account theft and
privilege escalation can allow an attacker to lateralize and access new resources. The initially
corrupted machine is then used as a gateway to reach unexposed and more critical systems.
n The integrity of the system is the last goal of attackers. Its corruption allows an attacker to reuse
the resources at his own profit. It can thus disfigure exposed applications to send a message,
use computing resources for mining cryptocurrencies, or even use it as a gateway to conduct
attacks anonymously.
Changes on the system also often involves setting up means of persistence. These allow the
attacker to come back to the system to modify their malware according to their need or to deploy
it again if it has been detected and deleted. These means of persistence can be implemented at
any level (application, kernel, boot chain…).
Example
Some threats combine several of the objectives described above. For instance, a ran-
somware can exfiltrate data from machines (data theft), then encrypt the machine’s
Protection against these threats involves hardening both the applications and the operating sys-
tem, maintaining them up to date and secure, implementing detection mechanisms and by regu-
larly organizing penetration tests and security audits.
Objective
Guide the installation and configuration of an operating system through different
essential principles.
n Permit a more accessible monitoring activity of systems, the number of components to be mon-
itored being reduced.
The implementation of this principle is sometimes delicate because it can quickly become in con-
tradiction with others, equally important. Only a case study with the help of a system and security
expertise will allow to make reasonable choices. The following chapters give targeted recommen-
dations according to the considered parts of the system.
n the alteration and / or compromise of the system requires an escalation of privileges, less trivial
and unobtrusive to achieve in cases where multiple layers of protection are set up.
Each layer of security is therefore a point of resistance that the attacker must cross. Escaping from
a layer is accompanied by signals, alarms or log messages that allow to detect a suspicious activity
and to be able to react to it. The remediation stage is also facilitated by additional aggregated
information on the context of the compromise.
This principle has indeed a real advantage: detection, ease of remediation, and improvement of
security.
Under Unix and derivative operating systems, defense in depth must be based on a combination
of barriers that must be kept independent of each other.
Example
n authentication required before performing any operation, specifically when they
are privileged;
Objective
Configure certain hardware options in order to harden the base that will be used for
the installation. This configuration should preferably be done before installation so
that the system is able to take this into account as soon as possible.
R1
M I E Choosing and configuring the hardware
It is recommended to apply the configuration recommendations for hardware sup-
port mentioned in the technical note “Recommandations de configuration matérielle
de postes clients et serveurs x86” [2].
4.2 BIOS/UEFI
The BIOS (Basic Input/Output System) or its modern counterpart, the UEFI (Unified Extensible
Firmware Interface) is the main interface for the hardware configuration of the system. This in-
terface is often only accessible during the first moments of starting the machine by typing a com-
bination of keys. The hardware configuration of the machine depends more on the use to which it
will be put than on the operating system installed. However, it should be noted that disabling or
enabling features at the BIOS or UEFI level may block the system from using them. The technical
note “Recommandations de configuration matérielle de postes clients et serveurs x86” [2] discusses the
different options that can be found on a contemporary x86 machine.
R2
M I Configuring the BIOS/UEFI
It is recommended to apply the configuration recommendations for BIOS/UEFI men-
tioned in the technical note “Recommandations de configuration matérielle de postes
clients et serveurs x86” [2].
n bootloaders,
The functioning of UEFI Secure Boot is based on a signature and fingerprint mechanism: a code
whose signature or fingerprint is not recognized by the UEFI or one of the signature verification
entities of the boot chain cannot be loaded.
Information
The UEFI Secure Boot verification mechanism relies on 4 types of variables (UEFI
Specification Version 2.3.1) :
n a db database (Authorized Signature database) which contains the list of sig-
natures, public keys or fingerprints of codes authorized to be loaded,
n a dbx database (Revoked Signature database) which contains the list of signa-
tures, public keys or checksums of revoked codes not authorized,
n one or more KEK keys (Key Exchange Key or Key Enrollment Key) which are
used to verify the signature of the db and dbx databases,
n a PK key (Platform Key) that locks and secures the UEFI firmware against unau-
thorized modifications. This key manages in particular the updates of the KEK and
it is generally provided by the hardware manufacturer.
Information
Most x86 machines come preloaded with Microsoft’s KEK. The UEFI of these ma-
chines therefore authorizes the load of codes signed by the UEFI certification service
hosted by Microsoft. A SHIM signed by this homologation service is developed by the
maintainers of certain distributions, for example the maintainers of distributions de-
rived from Red Hat 2 or Debian 3 who are then in charge of signing each Linux kernel
of the distribution and the bootloader used.
1. [Link]
R3
M I Activating the UEFI secure boot
It is recommended to apply the UEFI Secure Boot configuration of the distribution.
It is possible to replace the preloaded keys with new keys. In this case, the use of a SHIM is no longer
necessary, and it is possible to:
n generate and sign an image of the Linux kernel in EFI format which will be verified and loaded
directly by UEFI without going through a bootloader.
R4
M I E H Replacing of preloaded keys
It is recommended to replace the UEFI preloaded keys with new keys used to sign:
n the bootloader and the Linux kernel, or
Information
To protect the kernel command line parameters detailed in section 5.2 or to load a
rebuilt Linux kernel as detailed in section 5.3, it is necessary to replace the preloaded
keys with new ones.
This secret can be used, for example, as a disk encryption key. In the event of a compromised
boot, Measured Boot will not interrupt the boot process, but the TPM will not unseal the secret,
preventing disk decryption.
Information
Each PCR allows the measurement of one or more components during boot. The
first eight PCR (PCR{0..7}) are used during the boot chain. The definition of the
measurements carried by each PCR is defined by the Trusted Computing Group 4 ,
and some measurements differ depending on the hardware architecture.
Warning
The update of an element of the boot chain that is subject of a measure alters the
value of its hash. On the next boot, the measured values will therefore no longer
correspond to the values of the policy to unseal the secret. Therefore, the values in
the policy must be updated at the same time to reflect the changes. However, some
of these changes can only be observed when the machine reboot and will therefore
change the state of the system. For example, a device’s firmware update will only be
applied on the next reboot, making updating the policy tricky.
4. [Link]
The Linux kernel is a rich kernel, in charge of providing both the set of software
drivers for the platform 5 , a subset of the POSIX interface (supplemented by the
GNU libc) and a whole set of security mechanisms to protect itself and to protect
the system.
Objective
Hardening the Linux kernel, is about improving the protection mechanisms of the
operating system and validating the presence of the self-protection mechanisms of
the kernel, by following the principle of defense in depth. We can provide both
protections or countermeasures to potential software or hardware vulnerabilities of
the platform and at the same time reduce the attack surface of the kernel, initially
very large.
5.1 Bootloader
For reasons equivalent to the BIOS/UEFI setup, the bootloader is an important part of the boot
chain. Today’s ones (GNU GRUB 2 6 , systemd-boot 7 …) are functionally rich: they allow access to
file systems, possibly modify data, boot from external peripherals or change boot options of the
selected kernel.
R5
M I Configuring a password on the bootloader
A bootloader that protects its boot by a password should be preferred. This password
must prevent an ordinary user from changing the bootloader configuration options.
When the bootloader does not offer the possibility to set a password, some other
technical or organizational measures must be set up to block any user to change the
settings.
Information
GNU GRUB 2 (bootloader for x86 architecture) offers the possibility to setup a pass-
word. Consult their respective documentation [16] for more information.
5. with a few exceptions, such as thelibusb in userspace.
6. [Link]
7. [Link]
Command line parameters allow a number of Linux kernel configuration options to be changed
at boot time. They are often used to override defaults or to specify configuration directives.
Information
With GNU GRUB 2, the GRUB_CMDLINE_LINUX option of the configuration file
/etc/default/grub allows you to add or modify the kernel command line parame-
ters.
UEFI secure boot detailed in paragraph 4.3 helps ensure the integrity and authenticity of UEFI
binaries during boot (bootloader, Linux kernel…). However, the kernel command line and the
initramfs (INITial RAM filesystem) are not protected as they are not UEFI binaries. To solve
this, it is possible to create a Unified kernel image which groups together the kernel, the initramfs
and the kernel command line parameters in a single UEFI binary. The signing of the latter will then
be checked at system boot, ensuring the integrity and the authenticity of all these components.
R6
M I E H Protecting the kernel command line parameters and
the initramfs
It is recommended to protect the kernel command line parameters and the
initramfs. They should be verified by the UEFI secure boot.
A number of Linux kernel configuration options can be changed dynamically using the sysctl
command 8
Information
The config file [Link] 9 allows to modify these options of configuration at each
system startup using the service [Link] 10 of the system and ser-
vices manager systemd 11 .
Warning
The scope, use and configuration of the Linux kernel configuration options accessible
by command line parameters or dynamically using the sysctl command line must
be monitored regularly if an administrator wishes to take maximum advantage of
their functionality.
The activation of the functionality depends on the hardware configuration detailed in section 4.1
and the settings of the operating system. Depending on the situation (presence or absence of a
functional IOMMU, amount of memory present on the system ...), the Linux kernel may decide not
to initialize the IOMMU. It must therefore be instructed to force its use through a configuration
directive passed as a parameter during startup.
Warning
Activating the IOMMU on a system can cause hardware instabilities, it is therefore
necessary to ensure that it works properly before deploying such a measure in pro-
duction.
R7
M I E Activating the IOMMU
It is recommended to enable IOMMU by adding the iommu=force directive to the list
kernel parameters during boot in addition to those already present in the bootloader
configuration files.
The memory configuration is relatively generic and should be applicated regardless of the target
use case.
n page_poison=on : activate the poisoning of the pages of the page allocator (buddy
allocator). This functionality fills the freed pages with a pattern and then checks
it on the next reallocation, allowing to reduce the risk of information leaks from
the freed data;
n pti=on : force the use of Page Table Isolation (PTI) including on processors
claiming not to be affected by the Meltdown vulnerability;
> F activates the consistency tests of the metadata of the slab caches;
> Z activates Red Zoning; in a slab cache, add a red zone after each object in
order to detect writes after it. It is important to note that the value used for
the red zone is not random and therefore this is a much lower hardening than
using real canaries;
> P activates the poisoning of objects and padding and causes an error when
accessing poisoned areas;
12. [Link]
R9
M I Configuring the kernel options
The list below shows the recommended kernel configuration options.
It is possible to prevent the loading of new modules (including by root) with the Linux kernel
configuration option kernel.modules_disabled. A kernel module can be loaded explicitly by a
privileged user, but also by an unprivileged user using the on-demand loading. This mechanism al-
lows to load a module only when an action needs it. For instance, the creation of a DCCP (Datagram
Congestion Control Protocol) socket will trigger the loading of the DCCP module by the kernel
if it has not been loaded yet. The option kernel.modules_disabled protects against the explicit
loading of a malicious module, but also against the implicit loading of a vulnerable module (if
not loaded yet). An unprivileged user could indeed trigger the loading of such a module to then
exploit the vulnerability and increase his privileges.
Setting this option has non-trivial consequences on the system. Thus, it is recommended to test it
and ensure that it does not have operational implications.
Especially, the loading of modules being impossible after the option being set, all needed modules
should be loaded before setting it. To do so, it is possible to declare all modules to load at boot
R10
M I E Disabling kernel modules loading
It is recommended to block the loading of kernel modules by activating the
kernel.modules_disabled configuration option.
Warning
Once this option is activated, it cannot be deactivated without rebooting the system.
Thus, the loading of a new kernel module will require rebooting as well.
The security module, Yama, allows the addition of the [Link].ptrace_scope process configu-
ration option which controls access rights to the ptrace system call. This system call is particularly
sensitive because it allows to trace the operation of a process. By default, any user can debug all
the processes belonging to him, which includes the processes storing sensitive elements in their
memory such as keys or passwords (Internet browser, ssh-agent…). Compromising a user process
would recover these sensitive items.
The [Link].ptrace_scope option allows to restrict the use of the ptrace system call:
n =0, , all processes can be debugged as long as they share the same UID (User IDentifier)
n =1, an unprivileged process (not having CAP_SYS_PTRACE) can only debug descendant processes,
unless the target process has explicitly authorized it with the command prctl(PR_SET_PTRACER,
pid,…)
n =2, only a privileged process (owning CAP_SYS_PTRACE) can use ptrace
n =3, no process can use ptrace
R12
M I IPv4 configuration options
The list below shows the IPv4 network configuration options for a typical “server”
host that does not perform routing and has a minimalistic IPv4 configuration (static
addressing).
Most of the time, systems only use IPv4 networks. It is therefore essential, in this case, not to keep
IPv6 unnecessarily active.
R13
M I Disabling IPv6
When IPv6 is not used, it is recommended to disable the IPv6 stack by :
n adding the directive [Link]=1 to the list of kernel boot parameters in ad-
dition to those already present in the configuration files of the bootloader,
Information
With GNU GRUB 2, disabling IPv6 plan is possible by adding the following option in
the configuration file /etc/default/grub:
GRUB_CMDLINE_LINUX =" [Link] =1"
R14
M I File system configuration options
The list below shows the recommended file system configuration options in the
[Link] configuration file format.
These provide a large amount of protection elements for the kernel but also for equipment appli-
cations (principle of minimization, principle of defense in depth,…).
R15
M I E H Compile options for memory management
The list below provides the recommended kernel compile options to harden memory
management.
R16
M I E H Compile options for kernel data structures
The list below provides the recommended kernel compilation options to protect ker-
nel data structures.
There are a number of sensitive data structures within the kernel, hosting important data to se-
curity. These structures are those that are conventionally targeted when a kernel vulnerability is
exploited. It is possible to activate additional validation mechanisms of these structures to help
detect their corruption.
R17
M I E H Compile options for the memory allocator
The list below provides the recommended kernel compilation options to harden the
memory allocator.
It may be necessary to use kernel modules. Indeed, the presence of a heterogeneous fleet may
require activating certain features and drivers in the form of modules in order to limit the number
of kernel images to manage. However, using kernel modules involves additional configuration
considerations. These must be signed with a key generated when the kernel is compiled and their
signature verified at load time. This mechanism is natively supported in the Linux kernel.
A vulnerability exploit often involves the execution of arbitrary code by a given process. This exe-
cution can cause incorrect behavior due to the corruption of certain application data structures. In
the event of a critical error, the kernel generates a call to the BUG() macro, the purpose of which
is to display a logged event and immediately shut down the faulty component of the system. Com-
piling the Linux kernel with the CONFIG_PANIC_ON_OOPS option will result in a complete system
halt in the event of unexpected kernel behavior.
R19
M I E H Compile options for abnormal situations
The list below provides the recommended kernel compilation options to handle ab-
normal situations.
The Linux kernel provides a large number of security mechanisms aimed at protecting application
processes. These are mainly implemented in the form of LSM (Linux Security Module) which
can be executed sequentially to authorize access. Some LSM require centralized configurations in
the equipment, such as AppArmor detailed in paragraph 6.3.2 or SELinux detailed in paragraph
6.3.3. Others correspond to kernel hardening without specific configuration like Yama. The kernel
also provides the possibility to put in place security mechanisms on individual processes such as
seccomp or the namespaces.
R20
M I E H Compile options for kernel security functions
The list below provides the recommended kernel compilation options to configure
kernel security functions.
Since GCC 4.5, it is possible to integrate plugins into the compiler to provide additional hardening
mechanisms when compiling source code. This technique was, for example, used by the PaX 13
patch. There are now a number of plugins present in the Linux kernel sources in order to add
security properties during compilation.
R21
M I E H Compile options for the compiler plugins
The list below provides the recommended kernel compilation options to configure
compiler plugins.
13. [Link]
Most of the time, information systems use only IPv4 networks. It is possible, in this case, to compile
the Linux kernel without the IPv6 stack.
R22
M I E H Compile options of the IP stack
The list below provides the recommended kernel compilation options to configure
the IP stack.
R23
M I E H Compile options for various kernel behaviors
The list below provides the recommended kernel compilation options to configure
various kernel behaviors.
Certain Linux kernel behaviors may unnecessarily increase the attack surface of the kernel. If these
are not absolutely necessary, they should not be activated.
R24
M I E H Compile options for 32 bit architectures
The list below shows the recommended kernel compilation options for 32 bit x86
architectures. They are not all relevant on 64 bit architectures.
R25
M I E H Compile options for x86_64 bit architectures
The list below shows the recommended kernel compilation options for x86_64 archi-
tectures. They are not all relevant on 32 bit architectures.
R26
M I E H Compile options for ARM architectures
The list below shows the recommended kernel compilation options for ARM architec-
tures.
R27
M I E H Compile options for ARM 64 bit architectures
The list below shows the recommended kernel compilation options for ARM 64 bit
architectures
This chapter provides recommendations to follow when installing the system for
the first time. Each GNU / Linux operating system and distribution takes its own
unique path during this stage. There are, however, a few configuration items that
will apply almost universally.
Objective
Apply security settings when installing a GNU / Linux system for the first time.
6.1 Partitioning
It is usual to reserve dedicated partitions for services that can generate a lot of volume in order
to avoid saturating the system partitions. The space to reserve for each partition depends on the
use cases: a file server will need a large volume for /srv or /var/ftp, while a log server will be
more concerned with the usable volume for /var/log. Partitioning must therefore protect and
isolate the various components of the file system. The default is often unsatisfactory: it does not
take sufficient account of nosuid (ignores setuid / setgid bits), nodev (ignores character or block
special files), and noexec (ignores execute rights).
R28
M I Typical partitioning
The recommended typical partitioning is the following:
Information
It should be noted that depending on the systems and distributions, certain mount-
ing options will not be applicable at specific times; for example some utilities, pack-
age managers, or products require that files written to /tmp or /var must be exe-
cutable. In these cases, it is necessary to adapt the partitioning or to put in place
alternative measures; for example for distributions derived from Debian 16 where
/var/lib/dpkg requires execute rights, an alternative would be to implement a
maintenance procedure during which the updates are installed, like what can be
found on other operating systems.
The /boot partition contains the boot kernel as well as the [Link] file(s) holding the symbol
table it uses. This file is often scanned by various malicious software in order to build kernel code
“exploits” more easily. An ideal partitioning requires that this partition not be mounted automat-
ically at startup (noauto option), because its content is not needed during normal use of a system.
However, its mount is essential to perform certain administrative actions, for example updating
the kernel.
14. Need to configure the service systemd-logind from systemd and service manager systemd (cf. [Link]
Hardening#Mounting_.2Fproc_with_hidepid)
15. For distributions under systemd, the service systemd-journald from system and service manager systemd makes it possible
to avoid the saturation of the system partitions, in particular with the options prefixed by “System” (cf. [Link]
org/software/systemd/man/[Link]#SystemMaxUse=)
16. [Link]
Warning
Changing the /boot mount requires adapting the system tools to this specific config-
uration, in particular for the update of the kernel and the boot loader.
Information
The low-level utility, dpkg, which manages packages for Debian-derived distributions
and which is used by the apt utility on which the package managers are based,
aptitute and synaptic, can be configured to perform specific commands before
or after the package installation commands.
6.2 Accounts
The Unix and derivative operating systems, and in particular GNU/Linux, have a separation of
privileges which is based mainly on the notion of access accounts at two levels: the “regular” user
accounts and the system administrator user account (commonly known as root).
This separation lacks granularity, in particular today where a user has fairly wide access to system
primitives (while being increasingly exposed to attacks: theft of accounts and identifiers, leaks of
information…), in-depth expert analysis is often required to highlight residual vulnerabilities in
order to minimize their consequences as much as possible.
R30
M Removing the unused user accounts
Unused user accounts must be deleted from the system.
The password for user accounts must be chosen with great care and in accordance with current
recommendations.
R31
M User password strength
It is recommended to apply the recommendations of the technical note Recomman-
dations relatives à l’authentification multifacteur et aux mots de passe [9].
This password must be unique and specific to each machine.
The system administrator (or root) account is not suitable for these purposes. It gives full power to
the person who has access to it. The use of such a generic account does not facilitate accountability
during an incident, and does not promote a model of fine separation of privileges, for example
between different administration teams.
It is essential to dissociate the roles on the system, in particular for an administrator: simple user
or administrator with privileged rights. In addition, an administrator can intervene in several
technical areas. As a result, separate accounts must be created and used according to the role (user
or administrator) as well as separate administrative accounts by technical area as described in the
guide Recommandations relatives à l’administration sécurisée des systèmes d’information [6].
Logically, and to avoid any replay of a potentially compromised secret, the secrets (PIN, password,
private key…) must be different for each account and never be reused.
R33
M I Ensuring the imputability of administration actions
The administrative actions that need privileges must be logged in order to identify
an administrator account that has a malicious activity.
This can be done in multiple ways. One, the most common, is to use dedicated ac-
counts for each administrator and use sudo to execute any privileged command. A
second one, more powerful, is to identify the user uniquely on the system, then log
all new processes with auditd.
Multiple ways can be used at the same time to get a better traceability.
It is important to anticipate that the log volume generated by this method can be
huge depending on the tasks the system is doing. It is recommended to use this
method combined with a regular log export as recommended in the guide Recom-
mandations de sécurité pour l’architecture d’un système de journalisation [7].
R34
M I Disabling the service accounts
Service accounts must be disabled.
It is important to note that some services can be declared with the nobody account. When several
of them adopt such a behavior, they find themselves sharing the same identifiers and therefore the
same privileges at the level of the operating system. A web server and a directory service using
the nobody account can therefore control each other and alter their execution: modification of
configuration, sending of signals, ptrace privileges…
R35
M I Uniqueness and exclusivity of service accounts
Each business service (nginx, php, mysql, …) must have its own service account
which must be dedicated exclusively to it.
Access control under Unix and derivative systems has historically been based on the notion of user
and group of users. Other mechanisms have appeared, in particular through LSM of which SELinux
detailed in paragraph 6.3.3 and AppArmor detailed in paragraph 6.3.2 are the best known and most
used, in order to allow an additional finer control of rights. But the separation of privileges based
on user and user groups is still the most commonly used. It can be accompanied by partitioning
mechanisms (UNIX compatible mechanisms, container…) or filtering (seccomp) in order to limit
access to the underlying operating system.
Several UID can be grouped together to which a unique identifier can be associated: a GID (Group
IDentifier). The principle of access management remains similar to UID.
This access model is a DAC (Discretionary Access Control). It is discretionary because the user
who owns a resource specifies the access rights, with read, write and execute rights each given for:
n the user owning the resource;
It is not possible to define this value system-wide, but it is possible to do it for each component. It
is important to modify it for the user shells and for some of the system services.
R36
M I E Changing the default value of UMASK
The default value of UMASK for the shells must be set to 0077 in order to allow read
and write access to its owner only. This value can be defined in the configuration
The default value of UMASK for services must be determined for each service, but in
most cases, it should be set to 0027 (or more restrictive). This allows read access to its
owner and its group, and a full access to its owner. For services such as systemd, this
value can be defined directly in the configuration file of the service with the directive
UMask=0027.
The DAC access model is still the majority today and remains applied by default under the Unix
systems and derivatives. However, it has important limitations:
n rights are at the owner’s discretion, which may not be suitable for environments constrained
by a security policy;
n the owner may not be able to provide adequate rights to his resources, which offers access to
confidential data (or even compromises);
n the isolation between users is coarse, the default rights are often too laxist;
n there are only two levels of privileges on the system: “regular” user accounts and the adminis-
trator account (or root). Changing users requires the use of executables with special rights, for
example setuid root;
n it does not allow to withdraw special privileges to a process according to the context: the web
browser and the word processor from the same user will have as many privileges on the re-
sources;
n the attack surface is large, a standard user has access to a lot of information about the underlying
operating system.
Other access models, such as MAC (Mandatory Access Control), offer more possibilities, but at
the cost of higher investment and complexity.
R37
M I E Using Mandatory Access Control fea-
tures
It is recommended to use the Mandatory Access Control (MAC) feature in addi-
tion to the traditional Unix user model, Discretionary Access Control (DAC), or
possibly combine them with partitioning mechanisms.
The limitations of the DAC have contributed to the emergence of rights delegation management
tools, the best known being sudo which is a utility installed when there is a need to delegate rights
and privileges to different users. This delegation is based on the possibility for a given user to
execute a previously defined command with the privileges of another user. In order to achieve
this, sudo is an executable setuid root. It is important to be concerned about its security on two
levels:
n at the level of hardening, to prevent a malicious user to exploit the vulnerabilities of the binary;
n at the configuration level, where giving a user the right to perform specific commands may give
him more privileges and prerogatives than initially necessary.
These recommendations apply equally for cases where sudo is used for the execution of privileged
commands by a “regular” user, or the restriction of privileges when a privileged user (such as root)
wants to run a command with lower rights, as a precautionary measure.
sudo is usually installed by default with open rights and allows any user to use it (execution
right for everyone). sudo being a privileged executable and complex by its configuration, it is
better to restrict its execution rights to a dedicated user group. This reduces the attack surface,
especially when the system and the binary itself are victims of exploitable vulnerabilities, for ex-
ample CVE-2019-14287 (potential bypass of Runas user restrictions 17 ) ou CVE-2021-3156
(buffer overflow in command line unescaping 18 ), by any user.
R38
M I E Creating a group dedicated to the use of sudo
A group dedicated to the use of sudo must be created. Only the members of this
group should have the right to run sudo.
Warning
This modification can be overwritten by an update of the sudo package. Thus, it is
recommended to check the access rights of the file after an update and apply then
again if needed. This operation can be automated with most package managers 19 .
sudo is configured using the /etc/sudoers file with the visudo command. It contains a set of
directives that will allow sudo to know the commands a user is allowed to run or not, this may be
based on the machine hostname.
It is particularly difficult to provide a set of recommendations that can cover all situations where
sudo can be used. Indeed, the number of available commands, the architecture of the informa-
tion system, the installed services and their configurations, makes the establishment of a secure
standard configuration almost impossible.
However, some good practices must be followed in order to avoid, as much as possible, configu-
ration errors that could lead to circumventions of the security policy. The default values of the
17. [Link]
18. [Link]
19. [Link]
R39
M I Sudo configuration guidelines
The following guidelines must be enabled by default:
noexec applies the NOEXEC tag by default on the commands;
requiretty requires the user to have a tty login;
use_pty uses a pseudo-tty when a command is executed;
umask=0077 forces umask to a more restrictive mask;
ignore_dot ignores the “.” in $PATH;
env_reset resets the environment variables;
Then, it is possible to override a default value if needed when an entry is added for
a user (1) or for a group (2).
myuser ALL = EXEC: /usr/bin/mycommand # (1)
Defaults :% admins !noexec # (2)
The remaining of the file is then predominantly composed of rules allowing to declare, for a given
user or group the list of commands he is allowed to execute, all helped with alias specifications
(User_Alias, Runas_Alias…) when the right management policy becomes complex. The veri-
fication of the right to execute or not a command is based on a string comparison between the
command desired by the user and the specification present in the sudoers configuration file. The
simplest model is the following:
user hostname = ( user -target ) command , [...]
It is common that the command to be executed does not require an elevated privilege level (editing
a file whose owner is not root, sending a signal to an unprivileged process,…). In order to limit
any attempt of privilege escalation through a command, it is better to apply regular user rights.
R40
M I Using unprivileged users as target for sudo com-
mands
The targeted users of a rule should be, as much as possible, non privileged users (i.e.:
non root).
Functionally rich commands can be executed via sudo, like text editors (vi). They may allow exe-
cution of sub-commands in the environment created by sudo and thus enable a user to run other
To this end, sudo can override the different functions allowing to execute other softwares. This
allows for example to block the trivial creation of a sub-shell through vi. It is however important
to note that this protection is not perfect and only override the functions allowing to create these
new processes. The process remains free to execute the system calls it wants (including execve)
and so bypass this protection mechanism.
R41
M I E Limiting the number of commands requiring the use
of the EXEC directive
The commands requiring the execution of sub-processes, EXEC directive must be ex-
plicitly listed and their use should be reduced to a strict minimum.
Specifying access right using negation, blacklist approach, is inefficient and can be easily circum-
vented.
Example
It is expected, for example, that a specification of the following type prevents the
execution of the shell :
# To avoid absolutely , this rule can be easily circumvented!
user ALL = ALL ,!/ bin/sh
That’s not the case: just copy the binary /bin/sh to a different name to make it
executable again through the rule directive ALL.
R42
M I Banishing the negations in sudo policies
Policies applied by sudo through the sudoers file should not involve any negation.
Any argument can modify quite significantly the behavior of a program, whether regarding the
realized operation (read, write, delete,…) or accessed resources (path in a file system tree). To
avoid any possibility of misuse of a command by a user, the ambiguities must be removed at the
level of its specification.
R43
M I Defining the arguments in sudo specifications
All commands in the sudoers configuration file must strictly specify the arguments
allowed to be used for a given user.
The use of * (wildcard) in the rules should be avoided as much as possible. The
absence of arguments in a command must be specified by the presence of an empty
Example
On some systems, the kernel events are only accessible by root. If a user nevertheless
must have the privileges to read them, it is necessary to restrict his arguments in
order to prevent the user from reading any arbitrary file through the --file option:
user ALL = dmesg ""
Warning
It is important to note that allowing an unprivileged user to run under the root iden-
tity a software susceptible of making an arbitrary write (made possible by a laxist
rule) is somehow giving root privileges to this user because this one could, by dif-
ferent methods (handling of password files, modification of setuid root binary,…)
obtain the root privileges without the access control and enforcement that sudo al-
lows.
It is quite common to allow a user to edit a file through sudo by calling directly a text editor.
A text editor is a software functionally rich, that can open and edit other files even by internal
commands or even run a shell script. Some editors may offer a full privileged environment to a
user. The sudoedit text editor solves these problems by editing a temporary version of the file
with the current user rights, then replacing the original file by this temporary version once the
operation is finished. The editor runs thus only with the current user rights and never with the
privileges of the target user.
R44
M I Editing files securely with sudo
A file requiring sudo to be edited must be edited through the sudoedit command.
6.3.2 AppArmor
AppArmor is one of the LSM frequently encountered on GNU/Linux, and the one used by default
by variants of SUSE 20 (including OpenSUSE 21 ) and Ubuntu 22 . It is a MAC access model where an
authority decides the access of an application without giving it the capability to alter it.
Its documentation is directly accessible on the project website [11]. Its configuration is based on
specifications of rights based on paths in the file system tree, and applied for each executable.
Thus, it is possible to implement AppArmor profiles for specific applications without having to care
about the interactions between the LSM and the other applications or the system. This makes it
relatively easy to learn and integrate into a system.
In addition to the access specifications, AppArmor allows to block the use of POSIX capabilities, and
also restrict the network use (network directive). These restrictions, however, remain basic and
20. [Link]
21. [Link]
22. [Link]
When an executable under AppArmor calls another executable, its security profile allows to declare
how the transition should take place (inheritance of the current profile, activation of another se-
curity profile, exit from confinement,…)
Although simple to understand for an administrator accustomed to the traditional Unix access
model, AppArmor does not allow attaching security labels to a flow or to messages. It is a framework
that essentially focuses on the specification of access and privileges for executable, the concept of
a security label is absent.
Many of the GNU/Linux distributions that use it provide by default, generally for most sensitive
executables (syslogd, ntpd…), AppArmor profiles in the directory /etc/apparmor.d/, a file per
executable. Operations, including denied access, are recorded by auditd detailed in paragraph
7.2.3 Profiles can be enabled in enforce or complain mode. In the complain mode, the actions
that would have been blocked are recorded without being really blocked.
R45
M I E Activating AppArmor security profiles
Any AppArmor security profile present on the system must be enabled in enforce
mode by default when the distribution supports it and does not use any other security
module than AppArmor.
Information
On recent GNU/Linux distributions, AppArmor is enabled by default. To make sure
that AppArmor is active, use aa-status:
# aa -status
apparmor module is loaded.
40 profiles are loaded.
23 profiles are in enforce mode.
...
14 processes have profiles defined.
12 processes are in enforce mode.
...
0 processes are unconfined but have a profile defined.
In particular, it is necessary to verify that the processes currently running on the sys-
tem and for which a profile is declared are confined in enforce mode by AppArmor.
6.3.3 SELinux
SELinux (for Security-Enhanced Linux) is a widely used LSM in the distributions derived from
Red Hat.
SELinux relies on the use of “labels” assigned to objects (files, processes, sockets,…) that allow,
depending on the domain to which a process is confined, to authorise or deny access to a resource.
23. [Link]
The use of “labels” makes it possible to declare “domains” of responsibility and therefore to know at
every moment the operations that a process can perform on a given resource. SELinux also allows
to define transitions from one domain to another when a user requires specific access privileges.
The granularity of access is much finer than in AppArmor, to the detriment of a greater complexity.
The SELinux documentation is extensive and accessible on the project’s wiki page [19].
This section is limited to giving some checks so that any administrator wishing to use the profiles
provided by its distribution can do it correctly.
n the disabled mode in which SELinux rules are not loaded and no access message is logged;
n the permissive mode in which SELinux rules are loaded and queried but no access is denied,
and access error messages are logged;
minimal (minimal) policy which confines only a very limited number of services;
targeted (called targeted or default) policy partitioning each system service into
a domain. Interactive users are not partitioned;
multi-level (mls) policy including targeted policy and which additionally proposes the use
of hierarchical classification levels (sensitivity).
The use of the minimum policy is discouraged because the elements of the system are not confined
into separate domains. According to its creators, this policy should be used in constrained envi-
ronments (little memory) or for tests [18].
The multi-level policy was created to handle information of different sensitivities on the same
system while ensuring the principle of “need to know”. It is important to note that it does not
allow processing information of a particular sensitivity level on systems with lower or incompatible
sensitivity levels (see document [10] for more information). Its operation will not be discussed here.
The remainder of this section will focus on the default targeted policy. Each system service is
confined into a separate domain. Multiple instances of the same service running in the same
domain can be separated using categories. Interactive users are by default associated with an
R46
M I E H Activating SELinux with the targeted policy
It is recommended to enable SELinux in enforcing mode and to use the targeted
policy when the distribution supports it and does not use any other security module
than SELinux.
3. If SELinux was not in enforcing mode, it is necessary to verify that SELinux labels
are correctly assigned to files system-wide. This check can be programmed to be
executed automatically at the next start with the command:
# fixfiles onboot
4. If the policy used was not the targeted policy, reload the policy used by the kernel
with the command:
# semodule -R
5. It may be necessary to reboot the system for the policy change or SELinux activa-
tion to take effect.
6. Finally, to make sure that SELinux is active and with the correct settings:
# sestatus
SELinux status: enabled
...
Loaded policy name: targeted
Current mode: enforcing
...
By default, the rights of interactive users are not restricted in the targeted policy. But it is possible
to selectively confine users who do not need to perform administrative actions on a system.
Example
The following command associates an interactive user with the SELinux user:
# usermod -Z user_u <utilisateur >
R47
M I E H Containing the unprivileged interactive users
Unprivileged interactive users of the system should be confined by associating them
with a confined SELinux user.
The behavior of a security policy can be modified through boolean variables. Some are useful from
a security standpoint.
n Prevent processes to have a memory area with rights w (write) and x (execute);
Example
For distributions derived from Debian, modifying these security policies involves
modifying the default values of the following variables with the setsebool com-
mand:
#setsebool -P allow_execheap=off
#setsebool -P allow_execmem=off
#setsebool -P allow_execstack=off
#setsebool -P secure_mode_insmod =on
#setsebool -P ssh_sysadm_login=off
There are many others. The getsebool -a or semanage boolean --list commands can be used
to obtain information about the boolean variables defined and their current state in the policy
used on a system.
Information
A large part of these variables are also documented in the CentOS wiki [17].
The use of SELinux policy manipulation and debugging tools should be limited to development
machines, on which the interpretation of an error reported in the SElinux audit logs can be per-
formed.
R49
M I E H Uninstalling SELinux Policy Debugging Tools
SELinux policy manipulation and debugging tools should not be installed on a pro-
duction machine.
Warning
The setroubleshootd service must be disabled and the following packages unin-
stalled:
n setroubleshoot;
n setroubleshoot-plugins;
n to named IPC (Inter-Process Communication) files, such as sockets or pipes, which allow dif-
ferent processes to establish communication between them;
When these files contain system passwords or system password fingerprints, they should only be
readable by root. On the other hand, public files which contain the list of users are readable by
everyone, but can only be modified by root.
Fichiers sensibles
Some examples of files containing sensitive elements:
-rw -r----- root root /etc/gshadow
-rw -r----- root root /etc/shadow
-rw ------- foo users /home/foo/.ssh/id_rsa
...
Even when these files have their content protected by additional measures (encryption, finger-
prints for passwords…), it is nevertheless necessary to restrict access according to the principle of
defense in depth.
R50
M I Limiting the rights to access sensitive files and di-
rectories
Sensitive files and directories should only be readable by users with strict need to
know.
2. sensitive files or directories accessible to a user other than root (for example, the
password base of a Web server) must have as owner that user (for example, the
user associated with the Web server) who must be a member of a dedicated group
(for example, the www-group) and who will have read-only access to that file or
directory;
3. the rest of the users should not have any rights to the sensitive files or directories.
All sensitive files, generated or installed during the installation of the system, and those which
contribute to authentication mechanisms (root authority certificates, public keys, certificates,…)
must be in place as soon as the system is installed.
R51
M I E Changing the secrets and access rights as soon as
possible
All sensitive files and those which contribute to the authentication mechanisms must
be in place as soon as the system is installed. If default secrets are preconfigured,
they must then be replaced during, or immediately after, the installation phase of
the system.
Care must be taken that the access rights that apply to a local socket are those of the directory
containing it and not those of the socket itself. Although some systems will still honor these per-
missions, the Portable Operating System Interface (POSIX) standard does not impose it.
R52
M I Securing access for named sockets and pipes
Named pipes and sockets must be protected by a directory with appropriate rights.
The rights on the socket itself must also restrain the access.
Information
Multiple commands allow to get information about sockets in use on the system.
According to the applied security policy and the loaded modules, the displayed result
may not be exhaustive.
The following commands list all sockets and give information of associated processes
The following command lists the resource usage information for IPC:
# ipcs
The following command lists all virtual memories shared by processes and their as-
sociated access rights:
# ls /dev/shm
The following command provides detailed information on the I/O and IPC for system
processes:
# lsof
Warning
Local sockets should not be created at the root of a temporary directory accessible in
writing to everyone.
R53
M Avoiding files or directories without a known user or
group
Files or directories without a user or group identifiable by the system must be ana-
lyzed and possibly corrected in order to have a known owner or group of the system.
Information
The following command lists all the files that no longer have an associated user or
group:
# find / -type f \( -nouser -o -nogroup \) -ls 2>/dev/null
The directories accessible to all in writing are in most cases used as temporary storage zones, in
which an application saves data for processing. Many applications use them incorrectly. Tempo-
rary files can then be diverted from their primary function and be exploited as a rebound, for
example for a privilege escalation.
A workaround is then to activate the sticky bit on the directory so that only the user or the
application that created the file can delete it.
R54
M Setting the sticky bit on the writable direc-
tories
All directories that are writable by all must have the sticky bit applied.
Warning
It is also necessary to ensure that the owner of the directory is root, otherwise the
owner will be able to modify its content at will, despite the sticky bit.
Information
The following command lists all the directories that can be modified by all and with-
out a sticky bit:
# find / -type d \( -perm -0002 -a \! -perm -1000 \) -ls 2>/dev/null
The following command lists all the directories that can be modified by anyone and
whose owner is not root:
# find / -type d -perm -0002 -a \! -uid 0 -ls 2>/dev/null
The sticky bit does not prevent competitive situations between two applications running simul-
taneously under the same user account.
R55
M I Dedicating temporary directories to users
Each user or application must have their own temporary directory and dispose of it
exclusively.
Information
On recent GNU/Linux distributions, the most direct method to create a temporary
directory specific to each user is to use PAM (Pluggable Authentication Module)
modules, such as pam_mktemp and pam_namespace detailed in section 7.2.1.
When a file must be editable by several users or applications at the same time, a group must be
created and only this group must have write rights on this file.
Information
The following command lists all the files that can be edited by everyone:
# find / -type f -perm -0002 -ls 2>/dev/null
Executables with the setuid or setgid special rights are particularly sensitive because they run
with the privileges of the owning user or of the group to which the owning user belongs and
The presence of setuid or setgid special rights on an executable requires a certain number of
precautions to guard against vulnerabilities linked to changing users, for example, cleaning up its
environment and reinitializing a certain number of elements inherited from the previous context
(signaling masks, open file descriptors…). Most executables do not implement such precautions,
and adding the setuid or setgid special permissions to them would therefore introduce the pos-
sibility of privileges escalation.
R56
M Avoiding using executables with setuid and
setgid rights
Only trusted software from, for example, distribution or official package repositories
and specifically designed for use with setuid or setgid special permissions can have
these permissions set.
Information
The following command lists all the files with the specific rights to the setuid and
setgid present on the system:
# find / -type f -perm /6000 -ls 2>/dev/null
Information
The following command is used to remove the setuid or setgid special rights:
# chmod u-s <fichier > # Remove the special setuid right
# chmod g-s <fichier > # Remove the special setgid right
The most common case is the executable whose owner is root with setuid special rights (setuid
root) or setgid (setgid root) which runs with root privileges and not those of the calling user.
These executables allow an unprivileged user to perform actions for which it has, a priori, no right.
In the presence of vulnerabilities, these executables are exploited to provide a root shell to a mali-
cious user, or at least to hijack the legitimate use of the executable. These executables are therefore
to be studied on a case-by-case basis.
R57
M I E Avoiding using executables with setuid root
and setgid root rights
The executables with the setuid root and setgid root special rights should be as
few as possible. When only administrators are expected to execute them, these spe-
cial rights (setuid or setgid) should be removed and prefer commands like su or
sudo, which can be monitored.
R58
M Installing only strictly necessary packages
The choice of packages should lead to an installation as small as possible, limiting
itself to select only what is required.
Minimalist installation
Sometimes it is easier to achieve a minimalist installation by removing all the pre-
selected packages, and to choose only those necessary for the context of use. For
example, the implementation of a server does not always require the installation of
a local graphical interface (X server).
Warning
Some distributions provide pre-configured “roles”. It is not recommended to base an
installation on these roles since the choices of the maintainers of the distribution do
not match necessarily specific needs, which will require the installation of additional
packages.
These packages usually come from servers called repositories which contain a set of packages ac-
cessible and installable from a package manager. Each distribution has official repositories con-
figured, by default, in the package manager during installation and which are managed by the
maintainers of the distribution. These repositories mainly provide the “base” packages, their up-
date and security updates.
R59
M Using only official package repositories
Only repositories internal to the organisation, or official (from the distribution or
from an editor) should be used.
R60
M I E Using hardened package repositories
When the distribution provides several types of repositories, preference should be
given to those containing packages subject to additional hardening measures. Be-
tween two packages providing the same service, those subject to hardening (at com-
Warning
In some cases, packages are sourced from servers called repository mirrors and con-
figured in the package manager. These mirrors must be exact copies of official, up-
to-date repositories.
Software patches can bring new features to the software environment, thus contributing to increas-
ing its level of security. Others aim to rectify vulnerabilities present on the system. A monitoring
activity on the corrective measures to be applied is essential, because it allows to know the vulner-
abilities to which it is or has been exposed, and thus to lend special attention until a patch becomes
available.
R61
M Updating regularly the system
It is recommended to have a regular and responsive security update procedure.
The monitoring activity can be done by subscribing to mailing lists of the security teams of compo-
nents and applications installed and of their editors, to RSS (Really Simple Syndication) feeds
of CERT (Computer Emergency Response Team), for example CERT-FR website [12].
Objective
Identify essential services and appropriate hardening measures to delay as much as
possible wide scale compromise of the system.
When installing a distribution, some services are installed by default depending on the choice of
the maintainers of the distribution. These services do not necessarily correspond to specific needs.
R62
M Disabling the non-necessary services
Only the components strictly necessary to the service provided by the system should
be installed.
Any service, especially in active listening on the network, is a sensitive element. Only
those known and required for the operation and the maintenance must be installed.
It is recommended to uninstall the services whose presence cannot be justified or to
disable them if their uninstallation is not possible.
Information
For distributions under systemd, the following command lists all the services in-
stalled on the system:
# systemctl list -units --type service
Information
The services commonly installed on the distributions are:
n autoconfiguration services, such as DHCP 24 or ZeroConf 25 , besides the fact that
they can disrupt the network on which they are connected, these services can
receive illegitimate data. Unless there is an operational need, they should not
run on a server;
n RPC services (portmap, [Link], rpcbind…) are used in practice only for a NFS
server;
n the avahi service, used for the publication and automatic discovery of services on
the network. Unless there is an operational need, this service should not run on
a server;
Services are often installed with default configurations that enable features potentially problematic
from a security point of view, for example, SSH port forwarding that are often accepted and then
used to bypass firewall rules, or an Apache web server with directory indexing enabled and allowing
to navigate in the directory tree system.
R63
M I Disabling non-essential features of services
The features configured at the level of launched services should be limited to the
strict minimum.
Warning
The default configuration of the following services is often incomplete: SMTP (Exim,
Postfix), NTP (ntpd) and DNS (Bind).
The Linux kernel subdivides the privileges traditionally associated with the system administrator
(or root) account in separate units, called Linux capabilities 26 . Linux capabilities can be
enabled or disabled independently and are not limited to processes and are also placed on exe-
cutable files.
Warning
The kernel currently supports 41 capabilities. At least 19 of them allow to elevate
trivially your rights to these of the root user (UID=0) (full root) 27 . Most of the others
also can help a lot to gain a root access on the system.
Information
The following command lists all executable files for which one or more Linux
capabilities have been enabled
# find / -type f -perm /111 -exec getcap {} \; 2>/dev/null
As part of the principle of least privilege, it is important to isolate the different services running
on the system.
Information
Some services or executables require to own initially or all the time privileges to start
or operate and to access the resources of the system.
7.1 Partitioning
Partitioning is a technique that aims to isolate the processes running on the same system. Histori-
cally, it was carried out through the chroot utility which allows you to restrict the view of the file
system of a process at a given directory which becomes its root. Once confined or chrooted, the
process can no longer access directories other than the one taken as root as well as its subdirecto-
ries. So he only has a partial view of the file system.
n inability on some operating systems to forbid an unprivileged user to escape its jail with the
complicity of an external process;
n limited partitioning to the file system; the access to other processes, to the network, …are not
blocked;
n filtering with seccomp (SECure COMPuting mode) or seccomp BPF 28 (SECure COMPuting with
Berkeley Packet Filter) which filters the system calls of processes;
n isolation with cgroups (control groups) which make it possible to organize processes into hi-
erarchical systems in order to limit, count and isolate the use of resources (sharing of processor,
memory limit, disk usage …) of the system by the processes.
These mechanisms can be implemented in a granular fashion from initialization systems (or init)
of Unix operating systems and derivatives (systemd, OpenRC 29 …).
28. [Link]
29. [Link]
Nowadays other partitioning solutions exist and offer different levels of abstraction. They are
generally characterized by the partitioning technique:
n with containers, where the kernel is able to handle multiple system instances (LXC 30 , Docker 31 ,
podman 32 …);
n with emulation, where an emulator reproduces a full physical machine (QEMU 33 , VirtualBox 34 …);
n with lightweight hypervisor (or bare-metal) ( Xen 35 …), where the hypervisor will manage pos-
sibly with the help of a host system different virtual machines;
R66
M I E H Hardening the partitioning components
Each component supporting the virtualization must be hardened, especially by ap-
plying technical measures to counter the exploit attempts.
PAM will essentially provide the account management service, i.e. allow the authentication of the
user, the creation of his session and possibly any operation that must take place when attempting
an access:
n environment creation,
n ticket or data recovery,
n access rights,
n password change…
When an application uses PAM to authenticate a user, the operation is directly performed by a
PAM module.
In general, the application submits the authentication elements to the PAM modules. Depending
on the configuration located in various files present in the /etc/ and /etc/pam.d/ directories,
PAM returns the result, failure or success, to the application which then grants or denies access to
the system.
R67
M I Secure remote authentication with PAM
When authentication takes place through a remote application (network), the au-
thentication protocol used by PAM must be secure (flow encryption, remote server
authentication, anti-replay mechanisms,…).
In addition to authentication, PAM allows to load other modules whose features can improve the
security of the architecture, for example:
Example
The following PAM configuration files are located under /etc/pam.d/ and are the
name of the service to which they are associated. Only the configuration directives
concerning are presented.
n /etc/pam.d/su and /etc/pam.d/su-l to limit the usage of su to become root to
the users part of the group wheel only:
# Limit the elevation to root via su to the members of the group 'wheel ' only
auth required pam_wheel.so use_uid root_only
The storage of passwords in plaintext is forbidden because the compromise of the system allows
an attacker to reuse them effortlessly towards other services. Their protection must not only rely
on access rights to a password database.
Information
PAM can be configured to use yescrypt by adding in the file
/etc/pam.d/common-password the following directive:
password required pam_unix.so obscure yescrypt rounds =11
If the system is outdated and does not support yescrypt, it is recommended to use
SHA-512crypt and increase the number of rounds:
password required pam_unix.so obscure sha512 rounds =65536
When user accounts are stored in an external directory (frequently LDAP), NSS will manage the
requests to the directory in order to make the accounts visible from the system. Generally, these
requests are anonymous and carried out with an unprotected communication channel. It is there-
fore possible for an attacker to retrieve a list of valid accounts from the directory or even to spoof
the directory server queried by the NSS.
To access certain administrative databases and more particularly the ones stored on a remote net-
work server, NSS must authenticate using an account. In this case, the account used to access this
database must be separate from system user accounts and he should only have the rights strictly
necessary to query this database.
R70
M I Separating the system accounts and directory ad-
ministrator
It is recommended not to have overlapping accounts between those used by the op-
erating system and those used to administer the directory.
Using directory administrator accounts to perform enumeration queries accounts by
NSS must be prohibited.
7.2.3 Logging
As part of the principle of defense in depth, any system must be monitored in order to detect
suspicious activity and to be able to react to it.
R71
M I E Implementing a logging system
It is recommended to apply the recommendations of the technical note “Recomman-
dations de sécurité pour l’architecture d’un système de journalisation” [7].
The syslog service that is the main logging system used under GNU/Linux can be broken down
into two parts:
n a server (like syslog-ng 37 or rsyslog 38 ), that collects all the system messages in the syslog
format;
n several clients that send messages to the server, mostly through the syslog() function of the
glibc.
A syslog server is therefore a unifying element of logging and accesses a large amount of data from
various system sources. Any service or component may request it in order to record a message,
without authentication.
37. [Link]
38. [Link]
n between services, so that a service cannot manipulate nor access logs recorded by another ser-
vice;
n at the service level, so that in the event of a compromise, it cannot read, erase or alter recorded
events.
R72
M I E Implementing dedicated service activity journals
Each service must have a dedicated event logging journal on the system. This log
must only be accessible by the syslog server, and must not be readable, editable or
deletable by the service directly.
Information
The use of the function syslog() from the glibc is a possible solution. Sending
messages can also be done through the logger 39 command.
The auditd service is an advanced logging service that is often present on GNU/Linux distributions.
It allows to record specific system operations, even to alert an administrator when unplanned
privileged transactions take place.
The recorded events depend on the auditd rules written. When a registration is triggered, a second
service, audispd, will take care of its treatment: syslog event, sending mail, writing to a file, …
n module insertions.
R73
M I E Logging the system activity with auditd
The logging of the system activity must be done through the auditd service.
39. [Link]
Information
The logs thus created by auditd can be verbose especially when many activities are
reported. The aureport tool allows you to select interesting information depending
on very specific criteria:
n context on authentication failures;
n …
7.2.4 Messaging
Messaging is a service commonly used by the system to inform about certain evolutions of its states.
This is usually done by sending an email message to a recipient, often a user account.
Information
A frequent case is the cron service, which systematically submits an email when the
executed task displays data on its error output (stderr).
R74
M I Hardening the local messaging service
When a mail service is installed on the machine, it must be configured so that it
accepts only:
n mails to a local user of the machine;
n connections through the local loop network interface (remote connections to the
mail service must be rejected).
Services using messaging are often configured by default to send messages to destination of the
system administrator (or root) account. In accordance with the recommendation R34, this ac-
count must be disabled. Therefore, and in order not to lose any messages addressed to the system
administrator, the use of “aliases” is recommended.
R75
M I Configuring aliases for service accounts
For each service running on the machine, as well as the root account, an email alias
to an administrator user must be configured to receive notifications and reports sent
via email.
R76
M I E H Sealing and checking files integrity
Any file that is not transient (such as temporary files, databases, …) must be moni-
tored by a sealing software. This includes among others: directories containing exe-
cutables, libraries, configuration files, as well as any files that may contain sensitive
elements (cryptographic keys, passwords, confidential data…).
R77
M I E H Protecting the sealing database
The sealing database must be protected from malicious access by cryptographic sig-
nature mechanisms (with the key used for the signature not locally stored in plain-
text), or possibly stored on a separate machine of the one on which the sealing is
done.
There are many solutions, the most deployed on GNU/Linux systems are Tripwire, Samhain 40 et
AIDE (Advanced Intrusion Detection Environment) 41 .
They are all open doors on the system allowing illegitimate access to it when the service is vulnera-
ble or misconfigured: website to execute arbitrary commands, administrative process that does not
use a reliable authentication mechanism, obsolete network service with exploitable vulnerability,
…
R78
M I E Partitioning the network services
Network services 42 should as much as possible be hosted on isolated environments 43 .
This avoids having other potentially affected services if one of them gets compro-
mised under the same environment.
40. [Link]
41. [Link]
These services must therefore be hardened and monitored, despite the apparent authentication
operation performed by the server. Hardening is a combination of technical measures that aim to
delay or even prevent the compromise of the service. This approach applies from the design phase
(privilege separation study, unambiguous specifications, …) to the implementation (validation of
inputs/outputs, secure configuration, …) and the maintenance.
R79
M I Hardening and monitoring the exposed services
Services exposed to uncontrolled flows must be hardened and particularly moni-
tored.
Monitoring consists of characterizing the behavior of the service, and reporting any
deviation from its nominal operation deduced from the initial expected specifica-
tions.
Example
A Web service based on basic HTTP authentication may be exploitable on different
levels:
1. hardware (firmware, network card drivers…);
3. application (SSL/TLS layer, HTTP headers issued and received before the authen-
tication).
Network services are often configured by default to listen on all interfaces network, unnecessarily
increasing their attack surface.
R80
M Minimizing the attack surface of network services
All network services must be listening on the correct network interfaces.
Information
The following command lists all the services listening on the network:
# sockstat
42. The terminology “service” is to be taken broadly here. Any flaw or exploitable vulnerability before an authentication step is
particularly concerned with this recommendation.
43. Environment is to be taken in the broad sense: it represents all the resources and data available and accessible by the service
according to the privileges it has.
The Kernel Self Protection Project 44 (KSPP) focuses on providing functionality directly in the
kernel that is acceptable for all machines and all uses.
The grsecurity 45 project, as well as the PaX it integrates, has for many years been the benchmark
in terms of kernel hardening. This extremely intrusive and complex patch was never considered
for inclusion in the upstream kernel and is no longer publicly available. It is therefore not covered
here. Several new projects have emerged to fill this void.
The linux-hardened project is one example. The security features provided are complements to
what the KSPP project provides and most of these are taken from PaX:
n the declaration of many __ro_after_init variables, which are therefore no longer writable
after the kernel initialization phase;
n some limitations on using user namespaces and connecting new USB devices.
Information
The extra_latent_entropy recommended configuration option for patches pro-
vided by the linux-hardened project is to be added to the list of kernel parameters
at boot time in addition to those already present in the bootloader configuration file.
It allows a very simple form of latent entropy extracted during system startup and
added to the entropy obtained with GCC_PLUGIN_LATENT_ENTROPY.
44. [Link]
45. [Link]
Information
The list below presents the recommended options for compilation of the patches
provided by the linux-hardened project detailed in this list allow to complete the
static configuration of paragraph 5.3:
# Write canaries at the end of SLAB allocations
CONFIG_SLAB_CANARY =y
# Use maximum random bits in mmap base addresses on
# x86_64 processors. This option also affects the number of bits used
# for the base addresses of the stack;
CONFIG_ARCH_MMAP_RND_BITS =32
# Forbid non -privileged users to use TIOCSTI ioctl for
# execute arbitrary commands in processes that share a
# session tty.
CONFIG_SECURITY_TIOCSTI_RESTRICT =y
# Check that the new pages and the allocated slabs are initialized to 0
# in order to detect typical "write -after -free" bugs
CONFIG_PAGE_SANITIZE_VERIFY =y
CONFIG_SLAB_SANITIZE_VERIFY =y
In the same way as linux-hardened, we can mention Lockdown Linux which is a suite of patches
whose purpose is to lock down access to kernel data from the userland. This suite of patches was
added in Linux 5.4 46 .
n no hibernation;
n no kexec ;
Information
The list below shows the recommended build options associated with the patches
provided by Lockdown Linux:
# Activate the Lockdown Linux patches from the start of the boot ,
# restricting access to features that would allow the user to
# modify the running kernel
CONFIG_SECURITY_LOCKDOWN_LSM =y
CONFIG_SECURITY_LOCKDOWN_LSM_EARLY =y
# Activate privacy mode which extends the above restrictions to
# features that would allow the user to extract information
# confidential contained inside the kernel.
CONFIG_LOCK_DOWN_KERNEL_FORCE_CONFIDENTIALITY =y
Finally, the CLIP OS [13] project developed by ANSSI offers a set of Linux configurations as well
as various hardening patches.
As can be seen from these examples, the security features provided by external patches to the
upstream kernel are diverse and do not overlap. Cascading multiple patches is a difficult task as
they are developed independently of each other and the changes they make to the kernel can
conflict with each other.
Warning
The choice of a possible hardening to add to the kernel must be made with regard
to the intended use of the machine for which the kernel is compiled.
OpenSCAP 47 is the only NIST-certified open source scanner implementation of the SCAP standard.
ComplianceAsCode/content 48 is a project that provides security content in various formats, in-
cluding SCAP, Ansible 49 and Bash. It provides SCAP profiles aligned with the hardening lev-
els presented in this guide and are compatible with distributions derived from Debian and Red
Hat. A list of available security policies and documentation on how to use them can be found at
[Link]
Other initiatives have taken place to make recommendations on the configuration of the Linux
kernel.
The Recommended Settings 50 page of the KSPP project provides recommendations for achieving a
hardened configuration. These recommendations only concern the upstream options of the kernel,
they constitute a sound basis without substituting to the recommendations of this guide.
Warning
These implementations, while handy, are convenient for checking and are not a sub-
stitute for careful and thorough reading with the help of system and security exper-
tise.
47. [Link]
48. [Link]
49. [Link]
50. [Link]
51. [Link]
R3 M I R4 M I E H
R6 M I E H R8 M I
R15 M I E H R16 M I E H
R17 M I E H R18 M I E H
R19 M I E H R20 M I E H
R21 M I E H R22 M I E H
R23 M I E H R24 M I E H
R25 M I E H R26 M I E H
R27 M I E H R53 M
R71 M I E
n Redesign of the chapter4 Hardware configuration to add the UEFI secure boot and measured
boot.
n Addition of the chapter 5 Linux kernel configuration. It includes the command line options of
the kernel and the compilation options of the kernel. The sysctl options were also moved to
this chapter.
n The MIEH level associated to some recommendations was changed, especially due to the redef-
inition of the MIEH levels. The table below in section C.3 lists the changes.
Warning
This matrix is a tool to facilitate reading but is not intended to establish a strict equiv-
alence between the different versions of the guide. Detailed reading of the updated
recommendations is strongly recommended.
[5] Recommandations pour la mise en œuvre d’un site Web : maîtriser les standards de sécurité côté
navigateur.
Guide ANSSI-PA-009 v2.1, ANSSI, avril 2021.
[Link]