[PATCH 18/20] evm: added kernel parameter for disabling EVM

From: Dmitry Kasatkin
Date: Wed Apr 23 2014 - 09:38:09 EST


EVM remained to be disabled until evm-key is initialized via sysfs.
When the key is loaded from the kernel, EVM becomes enabled from start.
Distributions might want to compile EVM support, but leave for the user
to decide if to enable or disable EVM functionality.

This patch provides kernel parameter 'evm=off' that allows to disable EVM.

Signed-off-by: Dmitry Kasatkin <d.kasatkin@xxxxxxxxxxx>
---
security/integrity/evm/evm.h | 5 +++++
security/integrity/evm/evm_main.c | 19 +++++++++++++------
security/integrity/evm/evm_secfs.c | 3 ++-
3 files changed, 20 insertions(+), 7 deletions(-)

diff --git a/security/integrity/evm/evm.h b/security/integrity/evm/evm.h
index 88bfe77..1db78b8 100644
--- a/security/integrity/evm/evm.h
+++ b/security/integrity/evm/evm.h
@@ -21,6 +21,11 @@

#include "../integrity.h"

+#define EVM_MODE_OFF 0
+#define EVM_MODE_ON 1
+#define EVM_MODE_FIX 2
+
+extern int evm_mode;
extern int evm_initialized;
extern char *evm_hmac;
extern char *evm_hash;
diff --git a/security/integrity/evm/evm_main.c b/security/integrity/evm/evm_main.c
index 0f1b489..ad5e641 100644
--- a/security/integrity/evm/evm_main.c
+++ b/security/integrity/evm/evm_main.c
@@ -53,14 +53,17 @@ char *evm_config_xattrnames[] = {
NULL
};

-static int evm_fixmode;
-static int __init evm_set_fixmode(char *str)
+int evm_mode = EVM_MODE_ON;
+
+static int __init evm_setup(char *str)
{
- if (strncmp(str, "fix", 3) == 0)
- evm_fixmode = 1;
+ if (strncmp(str, "off", 3) == 0)
+ evm_mode = EVM_MODE_OFF;
+ else if (strncmp(str, "fix", 3) == 0)
+ evm_mode = EVM_MODE_FIX;
return 0;
}
-__setup("evm=", evm_set_fixmode);
+__setup("evm=", evm_setup);

static void __init evm_init_config(void)
{
@@ -249,7 +252,8 @@ static enum integrity_status evm_verify_current_integrity(struct dentry *dentry)
{
struct inode *inode = dentry->d_inode;

- if (!evm_initialized || !S_ISREG(inode->i_mode) || evm_fixmode)
+ if (!evm_initialized || !S_ISREG(inode->i_mode) ||
+ evm_mode == EVM_MODE_FIX)
return 0;
return evm_verify_hmac(dentry, NULL, NULL, 0, NULL);
}
@@ -445,6 +449,9 @@ static int __init init_evm(void)
{
int error;

+ if (evm_mode == EVM_MODE_OFF)
+ return 0;
+
evm_init_config();

integrity_init_keyring(INTEGRITY_KEYRING_EVM);
diff --git a/security/integrity/evm/evm_secfs.c b/security/integrity/evm/evm_secfs.c
index cf12a04..4c81ef6 100644
--- a/security/integrity/evm/evm_secfs.c
+++ b/security/integrity/evm/evm_secfs.c
@@ -64,7 +64,8 @@ static ssize_t evm_write_key(struct file *file, const char __user *buf,
char temp[80];
int i, error;

- if (!capable(CAP_SYS_ADMIN) || evm_initialized)
+ if (!capable(CAP_SYS_ADMIN) || evm_initialized ||
+ evm_mode == EVM_MODE_OFF)
return -EPERM;

if (count >= sizeof(temp) || count == 0)
--
1.8.3.2

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/