Gå til indholdet

Kernel, network and boot

ANSSI-BP-028 v2.0 reference: R9, R11 to R14 (M/I levels) for the sysctl parameters; R10 (disabling the loading of kernel modules) is examined but not retained by default, see the box in R13; R5, R7, R8 (M/I levels) for the advanced boot and kernel measures.

This section covers the sysctl parameters for system and network hardening, the control of IPv6, then the advanced measures relating to boot and kernel.

Information

The comments inside the configuration blocks are reproduced as they appear in the security hardening guide, in French: they are lines to be copied into the files of the system.

R13. sysctl parameters for system and network hardening

Applies to: Mediation Controller · Edge Gateway

Some Linux kernel parameters can be configured through sysctl so as to limit the exposure of sensitive kernel information, to strengthen certain file system protections, to limit unwanted network behaviours, to reduce the attack surface exposed by the network stack, and to apply certain hardening recommendations from ANSSI-BP-028 v2.0 where they are compatible with the operational context of CyberElements Bastion.

These parameters must be adapted to the role of the server, to the deployed architecture and to operational constraints. Particular attention must be paid to multi-interface environments, to cluster architectures and to specific network configurations. The configuration should be placed in a dedicated file, which makes maintenance, review and rollback easier than modifying /etc/sysctl.conf directly:

1
/etc/sysctl.d/99-cyberelements-bastion-hardening.conf

The following parameters limit the exposure of sensitive information and strengthen some protection mechanisms of the system:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# Restricts access to the dmesg buffer for unprivileged users
kernel.dmesg_restrict = 1
# Hides the kernel addresses exposed through /proc and other interfaces
kernel.kptr_restrict = 2
# Limits the maximum number of process identifiers
kernel.pid_max = 65536
# Restricts the use of the perf subsystem
kernel.perf_cpu_time_max_percent = 1
kernel.perf_event_max_sample_rate = 1
kernel.perf_event_paranoid = 2
# Enables ASLR
kernel.randomize_va_space = 2
# Disables the Magic SysRq key combinations
kernel.sysrq = 0
# Restricts kernel BPF to privileged users
kernel.unprivileged_bpf_disabled = 1
# Restricts the use of ptrace between processes
kernel.yama.ptrace_scope = 1
# Disables core dumps for setuid executables
fs.suid_dumpable = 0
# Strengthens protection against some symbolic link and hard link abuse
fs.protected_symlinks = 1
fs.protected_hardlinks = 1
# Protects FIFOs and regular files in sticky directories
fs.protected_fifos = 2
fs.protected_regular = 2

The following parameter can also be assessed, but must be validated against the availability policy:

1
2
# Halts the system on unexpected kernel behaviour
kernel.panic_on_oops = 1

That parameter can strengthen security in case of unexpected kernel behaviour, but it can also cause the system to halt. It must therefore be tested before being applied in production.

Information

ANSSI-BP-028 (R10) also recommends kernel.modules_disabled = 1, which forbids any kernel module from being loaded once enabled, including by root. That parameter is not retained by default in this recommendation: it is not reversible without a reboot, it requires every needed module to be loaded before it is enabled, and an omission would block a support operation requiring an unanticipated module. It remains a measure to be assessed case by case for a reinforced security context (the Renforcé level in ANSSI-BP-028), outside the baseline applied by default on CyberElements Bastion OVAs.

The following parameters limit certain unwanted network behaviours:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# Mitigates the risks of the BPF JIT
net.core.bpf_jit_harden = 2
# Treats as invalid the packets received from outside with a source in the 127/8 network
net.ipv4.conf.all.accept_local = 0
# Refuses incoming ICMP redirect packets
net.ipv4.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv4.conf.all.secure_redirects = 0
net.ipv4.conf.default.secure_redirects = 0
# Refuses source routing information
net.ipv4.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
# Refuses sending ICMP redirects
net.ipv4.conf.all.send_redirects = 0
net.ipv4.conf.default.send_redirects = 0
# Refuses routing packets to the loopback
net.ipv4.conf.all.route_localnet = 0
# Disables the use and reception of shared media redirects
net.ipv4.conf.all.shared_media = 0
net.ipv4.conf.default.shared_media = 0
# Ignores ICMP responses that do not comply with RFC 1122
net.ipv4.icmp_ignore_bogus_error_responses = 1
# Enables SYN cookies against some SYN flood attacks
net.ipv4.tcp_syncookies = 1
# Widens the ephemeral port range
net.ipv4.ip_local_port_range = 32768 65535
# Protects against some legacy TCP behaviours
net.ipv4.tcp_rfc1337 = 1

Some parameters may not be available depending on the Linux kernel version in use. If a parameter is unknown to the system, it must be analysed before being kept in the configuration.

Parameters to be validated against the architecture

Warning!

These parameters must be adapted to the role of the server and to the deployed architecture. Disabling IPv4 routing is not compatible with a cluster deployment, nor with an Edge Gateway on which at least one VPN-type resource is configured.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
# Disables IPv4 routing between interfaces; to be validated against the server role and the Bastion architecture
net.ipv4.ip_forward = 0
# Checks that the source of a packet is consistent with the receiving interface
# To be validated in multi-interface, cluster or asymmetric routing environments
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
# Prevents the kernel from handling the ARP table globally
net.ipv4.conf.all.arp_filter = 1
# Answers ARP requests only if the source and destination addresses are on the same network
net.ipv4.conf.all.arp_ignore = 2
# Ignores gratuitous ARP requests
net.ipv4.conf.all.drop_gratuitous_arp = 1

The ip_forward and rp_filter parameters and some of the ARP parameters must be applied with caution. They may need to be adapted to the role of the server, to the number of network interfaces, to the standalone or cluster mode, and to the flows expected between the CyberElements Bastion components. They must be validated in a representative environment before being applied in production.

Application and checking

1
2
sysctl --system
sysctl <parameter_name>

Examples:

1
2
3
4
5
6
7
sysctl kernel.dmesg_restrict
sysctl kernel.kptr_restrict
sysctl kernel.yama.ptrace_scope
sysctl kernel.unprivileged_bpf_disabled
sysctl net.core.bpf_jit_harden
sysctl net.ipv4.conf.all.accept_redirects
sysctl net.ipv4.conf.all.rp_filter

Before application in production, the parameters should be tested in a pre-production environment or on a server representative of the role concerned. Any change must be documented and brought into the security maintenance procedures.

Classification

To be validated: Network parameters "to be validated against the architecture" (ip_forward, rp_filter, arp_*). See the Classification of recommendations appendix.

R14. Disabling or controlling IPv6

Applies to: Mediation Controller · Edge Gateway

Where the IPv6 protocol is not used in the CyberElements Bastion architecture, it should be disabled or filtered explicitly. A network protocol that is active but unused can increase the attack surface of the server, notably where the filtering, monitoring or logging rules only cover IPv4 flows.

The presence of IPv6 addresses can be checked with the following commands:

1
2
ip -6 addr
ss -tulpn -6

IPv6 can be disabled through a dedicated sysctl configuration file, for example:

1
/etc/sysctl.d/99-cyberelements-bastion-ipv6.conf

Example configuration where IPv6 is not used:

1
2
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
1
sysctl --system

That the configuration has been taken into account can be checked with the following commands:

1
2
3
sysctl net.ipv6.conf.all.disable_ipv6
sysctl net.ipv6.conf.default.disable_ipv6
ip -6 addr

Where IPv6 is used, or may be used, in the environment, it must not be disabled without prior validation. In that case, the filtering, monitoring and logging rules must explicitly cover IPv6 flows. It is notably recommended to check that the exposed services are not reachable over IPv6 without suitable filtering:

1
ss -tulpn -6

Warning!

Disabling IPv6 completely through the boot loader (the ipv6.disable=1 parameter) must be considered an advanced measure requiring a reboot and prior validation: see R15.

Information

In a virtualised environment or in the case of an OVA, the use of IPv6 must be consistent with the networks attached to the virtual machine, with the filtering rules applied by the hosting infrastructure and with the network policies in force.

R15. Advanced boot and kernel hardening (kernel options)

Applies to: Mediation Controller · Edge Gateway

Information

ANSSI-BP-028 v2.0 (R7) provides for enabling an IOMMU where the hardware and the architecture allow it. That measure is not retained in the CyberElements Bastion hardening baseline and no enabling procedure is supplied in this guide, since its behaviour depends on the hardware, on the hypervisor and on the configuration of the virtual machine. It may nevertheless be enabled as part of a specific hardening policy, after validation in a representative environment.

Configuring the boot options

The advanced kernel hardening options are configured in the following file:

1
/etc/default/grub

Before any change, the existing configuration should be backed up:

1
cp -a /etc/default/grub /etc/default/grub.bak

The line currently configured can be checked with:

1
grep '^GRUB_CMDLINE_LINUX_DEFAULT=' /etc/default/grub

Then edit the file:

1
nano /etc/default/grub

The parameters must be added to the existing GRUB_CMDLINE_LINUX_DEFAULT directive. That line must not be replaced without having first identified the parameters already present.

For a Mediation Controller installed with the CyberElements Gate console (see CyberElements Gate console), the vsyscall=emulate option must be kept:

1
GRUB_CMDLINE_LINUX_DEFAULT="quiet vsyscall=emulate page_poison=on slab_nomerge=yes page_alloc.shuffle=1 rng_core.default_quality=500"

For an Edge Gateway, or a Mediation Controller installed without the CyberElements Gate console, vsyscall=emulate is not required:

1
GRUB_CMDLINE_LINUX_DEFAULT="quiet page_poison=on slab_nomerge=yes page_alloc.shuffle=1 rng_core.default_quality=500"

Warning!

The lines above are examples. The parameters already present in GRUB_CMDLINE_LINUX_DEFAULT must be kept where they are needed for the system or for CyberElements Bastion to work. The new options must be merged with the existing configuration and not applied by systematic replacement.

Information

The l1tf=off and mce=0 options are not retained, since they respectively disable or alter certain protection and error reporting mechanisms. The slub_debug=FZP option is not part of the baseline because of its potential impact on memory and performance; it can be used occasionally as part of a validated diagnostic procedure. The mitigation mechanisms for processor vulnerabilities are generally selected automatically by the kernel depending on the processor and on the virtualisation environment detected. Forcing them should be considered only case by case and after assessing their impact.

After changing /etc/default/grub, regenerate the GRUB configuration:

1
update-grub

Check that no error is reported during that operation.

Warning!

The new boot parameters only take effect after the server is rebooted. Before any reboot, check that the machine has a working console access and a rollback mechanism.

The advanced boot options must not be applied systematically in every environment. They may notably:

  • degrade performance;
  • change the behaviour of the kernel;
  • be useless or unsupported depending on the hypervisor;
  • make maintenance or support operations more complex;
  • prevent the server from booting in case of a configuration error;
  • interact with the security or monitoring mechanisms of the environment.

Before application, it is recommended:

  • to take a snapshot or a restore point of the virtual machine;
  • to keep a working console access;
  • to test the configuration in a non-critical or representative environment;
  • to check that the CyberElements Bastion services start correctly;
  • to check the system logs after reboot;
  • to document the parameters actually applied.

After reboot, check the parameters actually passed to the kernel:

1
cat /proc/cmdline

It is also recommended to check the state of the mitigation mechanisms for processor vulnerabilities:

1
grep . /sys/devices/system/cpu/vulnerabilities/*

The GRUB configuration currently defined can finally be checked with:

1
grep '^GRUB_CMDLINE_LINUX_DEFAULT=' /etc/default/grub

Warning!

The /boot/grub/grub.cfg file is generated automatically by GRUB and must not be modified directly. Any change to the boot options must be made in /etc/default/grub, then taken into account with update-grub.

Classification

Reserved for support/project: Advanced boot and kernel hardening (IOMMU, kernel options). See the Classification of recommendations appendix.

R16. Password on the GRUB boot loader

Applies to: Mediation Controller · Edge Gateway

Someone with access to the local or virtual console of the server could change the boot options so as to bypass certain protections or obtain privileged access. Setting a password on GRUB restricts access to the functions that modify the boot loader.

Warning!

A bad GRUB configuration can prevent the server from booting or complicate maintenance, support or recovery operations. In a virtualised environment or in the case of an OVA, this measure must be assessed with regard to the security of the hypervisor, to the access rights to the virtual console, to the applicable support procedures, to the recovery capabilities available and to the level of security expected. The password must be kept in a vault or in a controlled recovery procedure before application.

1
grub-mkpasswd-pbkdf2

Add at the end of /etc/grub.d/40_custom (replacing <user> and <grub_hash> with the values specific to the environment):

1
2
set superusers="<user>"
password_pbkdf2 <user> <grub_hash>
1
update-grub

Warning!

This recommendation must not be applied without prior validation. Should the GRUB password be lost or the configuration be wrong, support or recovery operations can become considerably more complex. This configuration should be validated in pre-production or on a test server before being applied in production.

Classification

Reserved for support/project: Password on the GRUB boot loader. See the Classification of recommendations appendix.

Out of scope for CyberElements Bastion OVAs

ANSSI-BP-028 (R15 to R27) also details a set of kernel compilation options (hardening of memory management, of kernel data structures, of the memory allocator, of modules, of security primitives, of compiler plugins, of the network stack, as well as options specific to 32/64-bit, ARM and ARM64 architectures), which require recompiling and signing the Linux kernel oneself.

Warning!

These recommendations are not retained for CyberElements Bastion and must not be brought into the OVAs. Maintaining a recompiled kernel requires a dedicated build and signing (PKI) infrastructure, manual tracking of security fixes outside the standard Debian update cycle, and a recurring maintenance effort at each kernel evolution. Applied to a product distributed as an OVA to many customers, that model would break security maintenance through the Debian repositories (R2, R6, R7) and would make the operator responsible for tracking a non-standard kernel. The ANSSI itself warns against the operational and security maintenance problems that a recompiled kernel entails: a hardened kernel that has become obsolete and vulnerable would be counter-productive. The risk of such a scenario outweighs the security gain expected in the context of an industrialised product.