> Source: https://docs.cyberelements.io/saas/no/Security/SystemHardening/SystemKernelAndNetwork/

# 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](#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**: 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.

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
```

### Recommended system parameters

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
```

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

```
1
2
```

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 OVAs.

### Recommended IPv4 network parameters

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
```

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
```

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 components. They must be validated in a representative environment before being applied in production.

### Application and checking

```
1
2
```

Examples:

```
1
2
3
4
5
6
7
```

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](https://docs.cyberelements.io/saas/no/Security/Classification/#reserved-or-to-be-validated) appendix.

## R14. Disabling or controlling IPv6

**Applies to**: Edge Gateway ✅

Where the IPv6 protocol is not used in the CyberElements 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
```

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

```
1
```

Example configuration where IPv6 is not used:

```
1
2
```

```
1
```

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

```
1
2
3
```

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
```

> **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](#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**: 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 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
```

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

```
1
```

The line currently configured can be checked with:

```
1
```

Then edit the file:

```
1
```

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 an Edge Gateway, `vsyscall=emulate` is not required:

```
1
```

> **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 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
```

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 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
```

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

```
1
```

The GRUB configuration currently defined can finally be checked with:

```
1
```

> **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](https://docs.cyberelements.io/saas/no/Security/Classification/#reserved-or-to-be-validated) appendix.

## R16. Password on the GRUB boot loader

**Applies to**: 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
```

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

```
1
2
```

```
1
```

> **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](https://docs.cyberelements.io/saas/no/Security/Classification/#reserved-or-to-be-validated) appendix.

## Out of scope for CyberElements 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 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](https://docs.cyberelements.io/saas/no/Security/SystemHardening/SystemInstallation/#r2), [R6](https://docs.cyberelements.io/saas/no/Security/SystemHardening/SystemInstallation/#r6), [R7](https://docs.cyberelements.io/saas/no/Security/SystemHardening/SystemInstallation/#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.
