security: remove needless usage of module header
Subsystems (8)
cover security: remove needless usage of module header
The most important thing to note here, is these clean-ups make no changes to the object files or the final generated run-time.
The work here represents a scan over the security dir, looking for files that have nothing to do with a modular use case, but are using modular infrastructure regardless.
We are trying to make driver code consistent with the Makefiles/Kconfigs that control them. This means not using modular functions/macros for drivers that can never be built as a module. This has been done in quite a lot of other mainline subsystem dirs already.
Using modular infrastructure in non-modules might seem harmless, but some of the downfalls this leads to are:
(1) it is easy to accidentally write unused module_exit and remove code
(2) it can be misleading when reading the source, thinking it can be modular when the Makefile and/or Kconfig prohibit it
(3) it requires the include of the module.h header file which in turn includes nearly everything else, thus adding to CPP overhead.
(4) it gets copied/replicated into other drivers and spreads quickly.
As a data point for #3 above, an empty C file that just includes the module.h header generates over 750kB of CPP output. Repeating the same experiment with init.h and the result is less than 12kB; with export.h it is only about 1/2kB; with both it still is less than 12kB.
We start with the simple ones - removing <linux/module.h> from where it simply isn't required. Then we remove the no-op MODULE_ macros from non-modular files, in order to remove module.h from there as well. Overall, we get rid of about 28 instances of <linux/module.h> here.
Build tested on v4.20-rc5 for allmodconfig on x86-64 and ARM-64.
Paul.
---
Paul Gortmaker (5):
security: audit and remove any unnecessary uses of module.h
keys: remove needless modular infrastructure from ecryptfs_format
security: fs: make inode explicitly non-modular
security: integrity: make evm_main explicitly non-modular
security: integrity: make ima_main explicitly non-modular
security/apparmor/apparmorfs.c | 2 +- security/commoncap.c | 1 - security/inode.c | 6 ++---- security/integrity/evm/evm_crypto.c | 2 +- security/integrity/evm/evm_main.c | 5 +---- security/integrity/evm/evm_posix_acl.c | 1 - security/integrity/evm/evm_secfs.c | 2 +- security/integrity/iint.c | 2 +- security/integrity/ima/ima_api.c | 1 - security/integrity/ima/ima_appraise.c | 2 +- security/integrity/ima/ima_fs.c | 2 +- security/integrity/ima/ima_init.c | 2 +- security/integrity/ima/ima_main.c | 7 +++---- security/integrity/ima/ima_policy.c | 2 +- security/integrity/ima/ima_queue.c | 1 - security/keys/encrypted-keys/ecryptfs_format.c | 5 ++--- security/keys/encrypted-keys/masterkey_trusted.c | 1 - security/keys/gc.c | 1 - security/keys/key.c | 2 +- security/keys/keyctl.c | 1 - security/keys/keyring.c | 2 +- security/keys/permission.c | 2 +- security/keys/proc.c | 1 - security/keys/process_keys.c | 1 - security/keys/request_key.c | 2 +- security/keys/request_key_auth.c | 1 - security/keys/user_defined.c | 2 +- security/security.c | 2 +- 28 files changed, 22 insertions(+), 39 deletions(-)
Signature · 1 line
2.7.4
PATCH 1/5 security: audit and remove any unnecessary uses of module.h
Historically a lot of these existed because we did not have a distinction between what was modular code and what was providing support to modules via EXPORT_SYMBOL and friends. That changed when we forked out support for the latter into the export.h file. This means we should be able to reduce the usage of module.h in code that is obj-y Makefile or bool Kconfig.
The advantage in removing such instances is that module.h itself sources about 15 other headers; adding significantly to what we feed cpp, and it can obscure what headers we are effectively using.
Since module.h might have been the implicit source for init.h (for __init) and for export.h (for EXPORT_SYMBOL) we consider each instance for the presence of either and replace as needed.
--- security/apparmor/apparmorfs.c | 2 +- security/commoncap.c | 1 - security/integrity/evm/evm_crypto.c | 2 +- security/integrity/evm/evm_posix_acl.c | 1 - security/integrity/evm/evm_secfs.c | 2 +- security/integrity/iint.c | 2 +- security/integrity/ima/ima_api.c | 1 - security/integrity/ima/ima_appraise.c | 2 +- security/integrity/ima/ima_fs.c | 2 +- security/integrity/ima/ima_init.c | 2 +- security/integrity/ima/ima_policy.c | 2 +- security/integrity/ima/ima_queue.c | 1 - security/keys/encrypted-keys/masterkey_trusted.c | 1 - security/keys/gc.c | 1 - security/keys/key.c | 2 +- security/keys/keyctl.c | 1 - security/keys/keyring.c | 2 +- security/keys/permission.c | 2 +- security/keys/proc.c | 1 - security/keys/process_keys.c | 1 - security/keys/request_key.c | 2 +- security/keys/request_key_auth.c | 1 - security/keys/user_defined.c | 2 +- security/security.c | 2 +- 24 files changed, 14 insertions(+), 24 deletions(-)
security/apparmor/apparmorfs.c +1 -1
@@ -15,7 +15,7 @@#include <linux/ctype.h> #include <linux/security.h> #include <linux/vmalloc.h> -#include <linux/module.h> +#include <linux/init.h> #include <linux/seq_file.h> #include <linux/uaccess.h> #include <linux/mount.h>
security/commoncap.c +0 -1
@@ -9,7 +9,6 @@#include <linux/capability.h> #include <linux/audit.h> -#include <linux/module.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/lsm_hooks.h>
security/integrity/evm/evm_crypto.c +1 -1
@@ -15,7 +15,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/module.h> +#include <linux/export.h> #include <linux/crypto.h> #include <linux/xattr.h> #include <linux/evm.h>
security/integrity/evm/evm_posix_acl.c +0 -1
@@ -9,7 +9,6 @@* the Free Software Foundation, version 2 of the License. */ -#include <linux/module.h> #include <linux/xattr.h> #include <linux/evm.h>
security/integrity/evm/evm_secfs.c +1 -1
@@ -17,7 +17,7 @@#include <linux/audit.h> #include <linux/uaccess.h> -#include <linux/module.h> +#include <linux/init.h> #include <linux/mutex.h> #include "evm.h"
security/integrity/iint.c +1 -1
@@ -16,7 +16,7 @@* using a rbtree tree. */ #include <linux/slab.h> -#include <linux/module.h> +#include <linux/init.h> #include <linux/spinlock.h> #include <linux/rbtree.h> #include <linux/file.h>
security/integrity/ima/ima_api.c +0 -1
@@ -12,7 +12,6 @@* Implements must_appraise_or_measure, collect_measurement, * appraise_measurement, store_measurement and store_template. */ -#include <linux/module.h> #include <linux/slab.h> #include <linux/file.h> #include <linux/fs.h>
security/integrity/ima/ima_appraise.c +1 -1
@@ -8,7 +8,7 @@* it under the terms of the GNU General Public License as published by * the Free Software Foundation, version 2 of the License. */ -#include <linux/module.h> +#include <linux/init.h> #include <linux/file.h> #include <linux/fs.h> #include <linux/xattr.h>
security/integrity/ima/ima_fs.c +1 -1
@@ -20,7 +20,7 @@#include <linux/fcntl.h> #include <linux/slab.h> -#include <linux/module.h> +#include <linux/init.h> #include <linux/seq_file.h> #include <linux/rculist.h> #include <linux/rcupdate.h>
security/integrity/ima/ima_init.c +1 -1
@@ -17,7 +17,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/module.h> +#include <linux/init.h> #include <linux/scatterlist.h> #include <linux/slab.h> #include <linux/err.h>
security/integrity/ima/ima_policy.c +1 -1
@@ -10,7 +10,7 @@* - initialize default measure policy rules * */ -#include <linux/module.h> +#include <linux/init.h> #include <linux/list.h> #include <linux/fs.h> #include <linux/security.h>
security/integrity/ima/ima_queue.c +0 -1
@@ -21,7 +21,6 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/module.h> #include <linux/rculist.h> #include <linux/slab.h> #include "ima.h"
security/keys/encrypted-keys/masterkey_trusted.c +0 -1
@@ -15,7 +15,6 @@*/ #include <linux/uaccess.h> -#include <linux/module.h> #include <linux/err.h> #include <keys/trusted-type.h> #include <keys/encrypted-type.h>
security/keys/gc.c +0 -1
@@ -9,7 +9,6 @@* 2 of the Licence, or (at your option) any later version. */ -#include <linux/module.h> #include <linux/slab.h> #include <linux/security.h> #include <keys/keyring-type.h>
security/keys/key.c +1 -1
@@ -9,7 +9,7 @@* 2 of the License, or (at your option) any later version. */ -#include <linux/module.h> +#include <linux/export.h> #include <linux/init.h> #include <linux/poison.h> #include <linux/sched.h>
security/keys/keyctl.c +0 -1
@@ -9,7 +9,6 @@* 2 of the License, or (at your option) any later version. */ -#include <linux/module.h> #include <linux/init.h> #include <linux/sched.h> #include <linux/sched/task.h>
security/keys/keyring.c +1 -1
@@ -9,7 +9,7 @@* 2 of the License, or (at your option) any later version. */ -#include <linux/module.h> +#include <linux/export.h> #include <linux/init.h> #include <linux/sched.h> #include <linux/slab.h>
security/keys/permission.c +1 -1
@@ -9,7 +9,7 @@* 2 of the License, or (at your option) any later version. */ -#include <linux/module.h> +#include <linux/export.h> #include <linux/security.h> #include "internal.h"
security/keys/proc.c +0 -1
@@ -9,7 +9,6 @@* 2 of the License, or (at your option) any later version. */ -#include <linux/module.h> #include <linux/init.h> #include <linux/sched.h> #include <linux/fs.h>
security/keys/process_keys.c +0 -1
@@ -9,7 +9,6 @@* 2 of the License, or (at your option) any later version. */ -#include <linux/module.h> #include <linux/init.h> #include <linux/sched.h> #include <linux/sched/user.h>
security/keys/request_key.c +1 -1
@@ -11,7 +11,7 @@* See Documentation/security/keys/request-key.rst */ -#include <linux/module.h> +#include <linux/export.h> #include <linux/sched.h> #include <linux/kmod.h> #include <linux/err.h>
security/keys/request_key_auth.c +0 -1
@@ -11,7 +11,6 @@* See Documentation/security/keys/request-key.rst */ -#include <linux/module.h> #include <linux/sched.h> #include <linux/err.h> #include <linux/seq_file.h>
security/keys/user_defined.c +1 -1
@@ -9,7 +9,7 @@* 2 of the License, or (at your option) any later version. */ -#include <linux/module.h> +#include <linux/export.h> #include <linux/init.h> #include <linux/slab.h> #include <linux/seq_file.h>
security/security.c +1 -1
@@ -17,7 +17,7 @@#include <linux/bpf.h> #include <linux/capability.h> #include <linux/dcache.h> -#include <linux/module.h> +#include <linux/export.h> #include <linux/init.h> #include <linux/kernel.h> #include <linux/lsm_hooks.h>
Signature · 1 line
2.7.4
PATCH 2/5 keys: remove needless modular infrastructure from ecryptfs_format
In reply to Paul GortmakerEven though the support can be modular, only one file needs to use all the macros like MODULE_AUTHOR, MODULE_LICENSE etc. Only the one responsible for registering/removal with module_init/module_exit needs to declare these. In this case, that file is "encrypted.c" and it already has the MODULE_LICENSE that we are removing here.
Since the file does EXPORT_SYMBOL, we add export.h - and build tests show that module.h (which includes everything) was hiding an implicit use of string.h - so that is added as well.
--- security/keys/encrypted-keys/ecryptfs_format.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-)
security/keys/encrypted-keys/ecryptfs_format.c +2 -3
@@ -15,7 +15,8 @@* the Free Software Foundation, version 2 of the License. */ -#include <linux/module.h> +#include <linux/export.h> +#include <linux/string.h> #include "ecryptfs_format.h" u8 *ecryptfs_get_auth_tok_key (struct ecryptfs_auth_tok *auth_tok)
@@ -77,5 +78,3 @@ int ecryptfs_fill_auth_tok(struct ecryptfs_auth_tok *auth_tok,return 0 ; }EXPORT_SYMBOL (ecryptfs_fill_auth_tok); - -MODULE_LICENSE ("GPL" );
Signature · 1 line
2.7.4
PATCH 4/5 security: integrity: make evm_main explicitly non-modular
In reply to Paul GortmakerThe Makefile/Kconfig entry controlling compilation of this code is:
obj-$(CONFIG_EVM) += evm.o
evm-y := evm_main.o evm_crypto.o evm_secfs.o
security/integrity/evm/Kconfig:config EVM security/integrity/evm/Kconfig: bool "EVM support"
...meaning that it currently is not being built as a module by anyone.
Lets remove the couple traces of modular infrastructure use, so that when reading the driver there is no doubt it is builtin-only.
We also delete the MODULE_LICENSE tag etc. since all that information is already contained at the top of the file in the comments.
--- security/integrity/evm/evm_main.c | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-)
security/integrity/evm/evm_main.c +1 -4
@@ -16,7 +16,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/module.h> +#include <linux/init.h> #include <linux/crypto.h> #include <linux/audit.h> #include <linux/xattr.h>
@@ -592,6 +592,3 @@ static int __init init_evm(void) }late_initcall (init_evm); - -MODULE_DESCRIPTION ("Extended Verification Module" ); -MODULE_LICENSE ("GPL" );
Signature · 1 line
2.7.4
PATCH 5/5 security: integrity: make ima_main explicitly non-modular
In reply to Paul GortmakerThe Makefile/Kconfig entry controlling compilation of this code is:
obj-$(CONFIG_IMA) += ima.o
ima-y := ima_fs.o ima_queue.o ima_init.o ima_main.o ima_crypto.o ima_api.o \
ima_policy.o ima_template.o ima_template_lib.o
security/integrity/ima/Kconfig:config IMA security/integrity/ima/Kconfig- bool "Integrity Measurement Architecture(IMA)"
...meaning that it currently is not being built as a module by anyone.
Lets remove the couple traces of modular infrastructure use, so that when reading the driver there is no doubt it is builtin-only.
We also delete the MODULE_LICENSE tag etc. since all that information is already contained at the top of the file in the comments.
--- security/integrity/ima/ima_main.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-)
security/integrity/ima/ima_main.c +3 -4
@@ -1,4 +1,6 @@/* +* Integrity Measurement Architecture +* * Copyright (C) 2005,2006,2007,2008 IBM Corporation * * Authors:
@@ -19,7 +21,7 @@#define pr_fmt (fmt) KBUILD_MODNAME ": " fmt -#include <linux/module.h> +#include <linux/init.h> #include <linux/file.h> #include <linux/binfmts.h> #include <linux/mount.h>
@@ -560,6 +562,3 @@ static int __init init_ima(void) }late_initcall (init_ima);/* Start IMA after the TPM is available */ - -MODULE_DESCRIPTION ("Integrity Measurement Architecture" ); -MODULE_LICENSE ("GPL" );
Signature · 1 line
2.7.4
PATCH 3/5 security: fs: make inode explicitly non-modular
In reply to Paul GortmakerThe Makefile/Kconfig entry controlling compilation of this code is:
security/Makefile:obj-$(CONFIG_SECURITYFS) += inode.o
security/Kconfig:config SECURITYFSsecurity/Kconfig: bool "Enable the securityfs filesystem"
...meaning that it currently is not being built as a module by anyone.
Lets remove the couple traces of modular infrastructure use, so that when reading the driver there is no doubt it is builtin-only.
We also delete the MODULE_LICENSE tag etc. since all that information is already contained at the top of the file in the comments.
The removal of module.h uncovered a couple previously hidden implicit header requirements which are now included explicitly.
--- security/inode.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-)
security/inode.c +2 -4
@@ -13,7 +13,8 @@*/ /* #define DEBUG */ -#include <linux/module.h> +#include <linux/sysfs.h> +#include <linux/kobject.h> #include <linux/fs.h> #include <linux/mount.h> #include <linux/pagemap.h>
@@ -341,7 +342,4 @@ static int __init securityfs_init(void)#endif return 0 ; } -core_initcall (securityfs_init); -MODULE_LICENSE ("GPL" ); -
Signature · 1 line
2.7.4
James Morris
maintainerQuoted 6 lines · Paul Gortmaker
Paul Gortmaker (5):
security: audit and remove any unnecessary uses ofmodule.h
keys: remove needless modular infrastructure fromecryptfs_format
security: fs: make inode explicitly non-modular
security: integrity: makeevm_mainexplicitly non-modular
security: integrity: makeima_mainexplicitly non-modular
All applied togit://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security.git next-general and next-general
Signature · 2 lines
James Morris <[email protected]>