Skip to contentSkip to conversation

kconfig: add hardened defconfig helpers

PATCH In review Salvatore Mesoraca 4 participants 7 messages Sep 9, 2018 – Sep 16, 2018

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH v2 1/1 kconfig: add hardened defconfig helpers

Adds 4 new defconfig helpers (hardenedlowconfig, hardenedmediumconfig, hardenedhighconfig, hardenedextremeconfig) to enable various hardening features.
The list of config options to enable is based on KSPP's Recommended Settings and on kconfig-hardened-check, with some modifications. These options are divided into 4 levels (low, medium, high, extreme) based on their negative side effects, not on their usefulness. 'Low' level collects all those protections that have (almost) no negative side effects.
'Extreme' level collects those protections that may have so many negative side effects that most people wouldn't want to enable them. Every feature in each level is briefly documented in Documentation/security/hardenedconfig.rst, this file also contain a better explanation of what every level means.
To prevent this file from drifting from what the various defconfigs actually do, it is used to dynamically generate the config fragments.

---
Changes in v2:
- Moved generated config fragments to "generated/" subdirectory. (Suggested by Kees Cook)
- Dropped CONFIG_BUG, CONFIG_DEFAULT_MMAP_MIN_ADDR, CONFIG_STATIC_USERMODEHELPER, CONFIG_X86_INTEL_MPX. (Suggested by Kees Cook)
- Dropped CONFIG_THREAD_INFO_IN_TASK. (Suggested by Jann Horn)
- Improved CONFIG_BPF_JIT description. (Suggested by Jann Horn)
- Improved CONFIG_USER_NS description.
(Suggested by Eric W. Biederman)
- Make build_hardened_fragment.sh print help to stderr. (Suggested by Kees Cook)
- Dropped whitespace only change in make help text. (Suggested by Kees Cook)
- Various changes to levels. (Suggested by Kees Cook)
- Various changes to protection types. (Suggested by Kees Cook)

---
 .gitignore                                 |   3 +
 Documentation/security/hardenedconfig.rst  | 971 +++++++++++++++++++++++++++++
 Documentation/security/index.rst           |   1 +
 Makefile                                   |   3 +-
 scripts/kconfig/Makefile                   |  29 +
 scripts/kconfig/build_hardened_fragment.sh |  54 ++
 6 files changed, 1060 insertions(+), 1 deletion(-)
 create mode 100644 Documentation/security/hardenedconfig.rst
 create mode 100755 scripts/kconfig/build_hardened_fragment.sh
.gitignore +3 -0
index 97ba6b7..cbc1856 100644
@@ -132,3 +132,6 @@ all.config
 
 # Kdevelop4
 *.kdev4
+
+# Generated config fragments
+kernel/configs/generated
Documentation/security/hardenedconfig.rst new file +971 -0

971 lines not on this page · raw message

Documentation/security/index.rst +1 -0
index 85492bf..01b8265 100644
@@ -13,3 +13,4 @@ Security Documentation
    SELinux-sctp
    self-protection
    tpm/index
+   hardenedconfig
Makefile +2 -1
index 19948e5..fc6fcff 100644
@@ -1311,7 +1311,8 @@ MRPROPER_FILES += .config .config.old .version \
 		  Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
 		  signing_key.pem signing_key.priv signing_key.x509	\
 		  x509.genkey extra_certificates signing_key.x509.keyid	\
-		  signing_key.x509.signer vmlinux-gdb.py
+		  signing_key.x509.signer vmlinux-gdb.py	\
+		  kernel/configs/generated/*
 
 # clean - Delete most, but leave enough to build external modules
 #
scripts/kconfig/Makefile +29 -0
index 67ed9f6..d4f6b2d 100644
@@ -105,6 +105,17 @@ endif
 
 configfiles=$(wildcard $(srctree)/kernel/configs/$@ $(srctree)/arch/$(SRCARCH)/configs/$@)
 
+hardened%.config:
+	mkdir $(srctree)/kernel/configs/generated/ || true
+	$(CONFIG_SHELL) $(srctree)/scripts/kconfig/build_hardened_fragment.sh \
+	$* $(srctree)/Documentation/security/hardenedconfig.rst > \
+	$(srctree)/kernel/configs/generated/hardened$*.config
+	$(eval configfiles += $(srctree)/kernel/configs/generated/hardened$*.config)
+
+	$(if $(call configfiles),, $(error No configuration exists for this target on this architecture))
+	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh -m .config $(configfiles)
+	+$(Q)yes "" | $(MAKE) -f $(srctree)/Makefile oldconfig
+
 %.config: $(obj)/conf
 	$(if $(call configfiles),, $(error No configuration exists for this target on this architecture))
 	$(Q)$(CONFIG_SHELL) $(srctree)/scripts/kconfig/merge_config.sh -m .config $(configfiles)
@@ -122,6 +133,16 @@ PHONY += tinyconfig
 tinyconfig:
 	$(Q)$(MAKE) -f $(srctree)/Makefile allnoconfig tiny.config
 
+PHONY += hardenedlowconfig hardenedmediumconfig hardenedhighconfig hardenedextremeconfig
+hardenedlowconfig: hardenedlow.config
+	@:
+hardenedmediumconfig: hardenedmedium.config
+	@:
+hardenedhighconfig: hardenedhigh.config
+	@:
+hardenedextremeconfig: hardenedextreme.config
+	@:
+
 # CHECK: -o cache_dir=<path> working?
 PHONY += testconfig
 testconfig: $(obj)/conf
@@ -154,6 +175,14 @@ help:
 	@echo  '  xenconfig       - Enable additional options for xen dom0 and guest kernel support'
 	@echo  '  tinyconfig	  - Configure the tiniest possible kernel'
 	@echo  '  testconfig	  - Run Kconfig unit tests (requires python3 and pytest)'
+	@echo  '  hardenedlowconfig     - Update current config using hardened features with'
+	@echo  '                          few negative side effects'
+	@echo  '  hardenedmediumconfig  - Update current config using hardened features with'
+	@echo  '                          some negative side effects'
+	@echo  '  hardenedhighconfig    - Update current config using hardened features with'
+	@echo  '                          many negative side effects'
+	@echo  '  hardenedextremeconfig - Update current config using hardened features with'
+	@echo  '                          even more negative side effects'
 
 # ===========================================================================
 # Shared Makefile for the various kconfig executables:
scripts/kconfig/build_hardened_fragment.sh new file +54 -0

54 lines not on this page · raw message

Signature · 1 line
1.9.1
#1 lore raw

Hi Salvatore.

Quoted 8 lines · Salvatore Mesoraca

Adds 4 new defconfig helpers (hardenedlowconfig, hardenedmediumconfig, hardenedhighconfig, hardenedextremeconfig) to enable various hardening features.
The list of config options to enable is based on KSPP's Recommended Settings and on kconfig-hardened-check, with some modifications. These options are divided into 4 levels (low, medium, high, extreme) based on their negative side effects, not on their usefulness. 'Low' level collects all those protections that have (almost) no

Quoted 8 lines

negative side effects.
'Extreme' level collects those protections that may have so many negative side effects that most people wouldn't want to enable them. Every feature in each level is briefly documented in Documentation/security/hardenedconfig.rst, this file also contain a better explanation of what every level means.
To prevent this file from drifting from what the various defconfigs actually do, it is used to dynamically generate the config fragments.

In the above you nicely describes what is done.
But there is nothing about the target group for this feature. Who will benefit from this?

With respect to the actual implmentation we now
have two ways to handle config fragments.
Current solution is to save the config fragments in kernel/configs. And the new solution is to parse the config fragments from an rst file. The changelog fails to mentions why we need a new way to handle the config fragments.

If we want to go the "parse from rst file" way - can it then be abstracted in a way so this is the only way to handle these in-kernel config fragments?
And then move the current config fragment to the new way.

It most be possible with a little careful design to make this a general solution and not a hardening thing only.

Sam

#2 lore raw

2018-09-10 4:19 GMT+09:00 Sam Ravnborg <[email protected]>:

Quoted 24 lines

Hi Salvatore.

Quoted 8 lines · Salvatore Mesoraca

Adds 4 new defconfig helpers (hardenedlowconfig, hardenedmediumconfig, hardenedhighconfig, hardenedextremeconfig) to enable various hardening features.
The list of config options to enable is based on KSPP's Recommended Settings and on kconfig-hardened-check, with some modifications. These options are divided into 4 levels (low, medium, high, extreme) based on their negative side effects, not on their usefulness. 'Low' level collects all those protections that have (almost) no

Quoted 8 lines

negative side effects.
'Extreme' level collects those protections that may have so many negative side effects that most people wouldn't want to enable them. Every feature in each level is briefly documented in Documentation/security/hardenedconfig.rst, this file also contain a better explanation of what every level means.
To prevent this file from drifting from what the various defconfigs actually do, it is used to dynamically generate the config fragments.

In the above you nicely describes what is done.
But there is nothing about the target group for this feature. Who will benefit from this?

Quoted 6 lines

With respect to the actual implmentation we now
have two ways to handle config fragments.
Current solution is to save the config fragments in kernel/configs. And the new solution is to parse the config fragments from an rst file. The changelog fails to mentions why we need a new way to handle the config fragments.

I agree.

Another new way this patch added is,

CONFIG options are now described in the ReST document, but our current way is to describe the detailed information in the 'help' section in Kconfig files.

Quoted 9 lines

If we want to go the "parse from rst file" way - can it then be abstracted in a way so this is the only way to handle these in-kernel config fragments?
And then move the current config fragment to the new way.

It most be possible with a little careful design to make this a general solution and not a hardening thing only.

Sam

Indeed. The file format is too specific for his purpose; 'Negative side effect level' is a key word
that must be placed 3 lines below the CONFIG entry.

Signature · 2 lines
Best Regards
Masahiro Yamada
#3 lore raw
Quoted 34 lines · Masahiro Yamada

2018-09-10 4:19 GMT+09:00 Sam Ravnborg <[email protected]>:

Quoted 24 lines

Hi Salvatore.

Quoted 8 lines · Salvatore Mesoraca

Adds 4 new defconfig helpers (hardenedlowconfig, hardenedmediumconfig, hardenedhighconfig, hardenedextremeconfig) to enable various hardening features.
The list of config options to enable is based on KSPP's Recommended Settings and on kconfig-hardened-check, with some modifications. These options are divided into 4 levels (low, medium, high, extreme) based on their negative side effects, not on their usefulness. 'Low' level collects all those protections that have (almost) no

Quoted 8 lines

negative side effects.
'Extreme' level collects those protections that may have so many negative side effects that most people wouldn't want to enable them. Every feature in each level is briefly documented in Documentation/security/hardenedconfig.rst, this file also contain a better explanation of what every level means.
To prevent this file from drifting from what the various defconfigs actually do, it is used to dynamically generate the config fragments.

In the above you nicely describes what is done.
But there is nothing about the target group for this feature. Who will benefit from this?

Quoted 6 lines

With respect to the actual implmentation we now
have two ways to handle config fragments.
Current solution is to save the config fragments in kernel/configs. And the new solution is to parse the config fragments from an rst file. The changelog fails to mentions why we need a new way to handle the config fragments.

Quoted 7 lines

I agree.

Another new way this patch added is,

CONFIG options are now described in the ReST document, but our current way is to describe the detailed information in the 'help' section in Kconfig files.

This is true, but hardening features are quite different from other types of features or config options, because they can't be easily found, unless you already know what you are looking for. Many people need a single place that lists them all, clearly explaining why they might want them or not without having to bounce around different Kconfig parts.

Thank you for your time,

Salvatore

#4 lore raw
In reply to Sam Ravnborg
Quoted 2 lines · Sam Ravnborg

Hi Salvatore.

Hi Sam

Quoted 18 lines · Salvatore Mesoraca
Quoted 8 lines

Adds 4 new defconfig helpers (hardenedlowconfig, hardenedmediumconfig, hardenedhighconfig, hardenedextremeconfig) to enable various hardening features.
The list of config options to enable is based on KSPP's Recommended Settings and on kconfig-hardened-check, with some modifications. These options are divided into 4 levels (low, medium, high, extreme) based on their negative side effects, not on their usefulness. 'Low' level collects all those protections that have (almost) no

Quoted 8 lines

negative side effects.
'Extreme' level collects those protections that may have so many negative side effects that most people wouldn't want to enable them. Every feature in each level is briefly documented in Documentation/security/hardenedconfig.rst, this file also contain a better explanation of what every level means.
To prevent this file from drifting from what the various defconfigs actually do, it is used to dynamically generate the config fragments.

Quoted 3 lines

In the above you nicely describes what is done.
But there is nothing about the target group for this feature. Who will benefit from this?

Sometimes people ask about kernel hardening features, that's the reason why the KSPP's list and the kconfig-hardened-check script were written.
Unfortunately, kernel features with security implications have often misleading names and descriptions and are scattered around the menuconfig.
This patchset will help anyone who want to have an "hardened kernel" but isn't following kernel development closely enough to know about all the features.
On one hand, this will provide an official and understandable list of hardening features inside the kernel doc, on the other hand it also provide a fast and easy way to enable those features all at once.

Quoted 6 lines

With respect to the actual implmentation we now
have two ways to handle config fragments.
Current solution is to save the config fragments in kernel/configs. And the new solution is to parse the config fragments from an rst file. The changelog fails to mentions why we need a new way to handle the config fragments.

The reason why I'm doing it like this is that I want both the config fragments and the doc in the kernel.
Generating the fragments from the doc is the best way to make sure that they will always do what the doc says.

Quoted 7 lines

If we want to go the "parse from rst file" way - can it then be abstracted in a way so this is the only way to handle these in-kernel config fragments?
And then move the current config fragment to the new way.

It most be possible with a little careful design to make this a general solution and not a hardening thing only.

I don't know if maintainers of the other fragments care at all about having every single option documented in detail.
For hardening features it makes sense, because people may want to just learn about them and enable them manually.
I don't know if this is common or desirable for other config fragments.

Thank you for you comment,

Salvatore

maintainer
#5 lore raw
In reply to Salvatore Mesoraca
Quoted 22 lines · On Sun, 9 Sep 2018 20:04:17 +0200 Salvatore Mesoraca <[email protected]>…

+===============================

Documentation/security/hardenedconfig.rst new file +21 -0
+Hardening Configuration Options
+===============================
+
+This is a list of configuration options that are useful for hardening purposes.
+These options are divided in 4 levels based on the magnitude of their negative
+side effects, not on their importance or usefulness:
+
+	- **Low**: Negligible performance impact. No user-space breakage.
+	- **Medium**: Some performance impact and/or user-space breakage for
+	  few users.
+	- **High**: Notable performance impact and/or user-space breakage for
+	  many users.
+	- **Extreme**: Big performance impact and/or user-space breakage for
+	  most users.
+
+In other words: **Low** level contains protections that *everybody* can and
+should use; **Medium** level should be usable by *most people* without issues;
+**High** level may cause *some trouble*, especially from a *performance*
+perspective; **Extreme** level contains protections that *few people* may want
+to enable, some people will probably *cherry-pick* some options from here based
+on their needs.

Documentation/security/hardenedconfig.rst line 34

Quoted 10 lines
Documentation/security/hardenedconfig.rst new file +10 -0
+
+For further details about which option is included in each level, please read
+the description below, for more information on any particular option refer to
+their help page.
+
+The content of this list is automatically translated into *config fragments*
+that can be used to apply the suggested hardening options to your current
+configuration.
+To use them you just need to run ``make hardened$LEVELconfig`` (e.g.
+``make hardenedhighconfig``).

Some overall thoughts:

- As Sam asked: who are the users of this feature? Presumably you have some real people out there in mind for each of these levels, or you would not have created them?

- Who will maintain it? The list of hardening-relevant configuration options is always in high flux, as our understanding of the security implications of each. This feature will require some significant ongoing attention or it will quickly become stale. I think it needs a MAINTAINERS entry.

- It's a little strange to see an RST document used as the input for the kernel configuration process. Assuming this is really the best way to do this (and I worry about things like duplicated descriptions of kernel configuration options), you should, at a minimum, carefully document the format of this file at the beginning. Otherwise people will surely break it. In fact, they'll break it anyway, so more checking in the processing script seems indicated.

Without having thought it through in great depth, I suspect that a better approach might be to find a way to mark the hardening level in the Kconfig entries.

- You have ordered the options alphabetically, but that is, I would argue, not the best way. My guess is that people would read this file to answer the question of "just how many bullets will hardening level H put into my foot?" So I would sort them by hardening level as the primary key.

Thanks,

jon

#6 lore raw
Quoted 7 lines · Jonathan Corbet

[omissis]

Some overall thoughts:

- As Sam asked: who are the users of this feature? Presumably you have some real people out there in mind for each of these levels, or you would not have created them?

In general this feature will be useful for all those people who are interested in enabling hardening features on their kernel.
Maybe they are not so many, but they exist and are the reason why KSPP's list and kconfig-hardened-check script were written. Anyway, not everybody is willing to trade a lot of performance for security. I hope that splitting features based on their negative impact will increase the usage of those features which are more "usable", but still not so known by many people.

Quoted 5 lines

- Who will maintain it? The list of hardening-relevant configuration options is always in high flux, as our understanding of the security implications of each. This feature will require some significant ongoing attention or it will quickly become stale. I think it needs a MAINTAINERS entry.

Good, I can add myself as maintainer, I also got Kees permission to add him as designated reviewer too.

Quoted 7 lines

- It's a little strange to see an RST document used as the input for the kernel configuration process. Assuming this is really the best way to do this (and I worry about things like duplicated descriptions of kernel configuration options), you should, at a minimum, carefully document the format of this file at the beginning. Otherwise people will surely break it. In fact, they'll break it anyway, so more checking in the processing script seems indicated.

Yes, this approach is a bit "original". I think your suggestions are sensible. I'll document better the format and add more checks to the script to make it more resilient.

Quoted 3 lines

Without having thought it through in great depth, I suspect that a better approach might be to find a way to mark the hardening level in the Kconfig entries.

The reason why everything starts from an .rst is that I'd like to have a doc page with a detailed list of all the hardening feature. If the fragments aren't going to be generated from the doc we'll a way to make sure that what is written in the doc is coherent with what Kconfig is doing.
I'm don't think that it will be much better.

Quoted 4 lines

- You have ordered the options alphabetically, but that is, I would argue, not the best way. My guess is that people would read this file to answer the question of "just how many bullets will hardening level H put into my foot?" So I would sort them by hardening level as the primary key.

This seems reasonable, I'll change it.

Thank you for your time,

Salvatore