aboutsummaryrefslogtreecommitdiffstats
path: root/security/integrity/evm/evm_secfs.c
diff options
context:
space:
mode:
Diffstat (limited to 'security/integrity/evm/evm_secfs.c')
-rw-r--r--security/integrity/evm/evm_secfs.c20
1 files changed, 17 insertions, 3 deletions
diff --git a/security/integrity/evm/evm_secfs.c b/security/integrity/evm/evm_secfs.c
index 319cf16d6603..feba03bbedae 100644
--- a/security/integrity/evm/evm_secfs.c
+++ b/security/integrity/evm/evm_secfs.c
@@ -40,7 +40,7 @@ static ssize_t evm_read_key(struct file *filp, char __user *buf,
40 if (*ppos != 0) 40 if (*ppos != 0)
41 return 0; 41 return 0;
42 42
43 sprintf(temp, "%d", (evm_initialized & ~EVM_SETUP)); 43 sprintf(temp, "%d", (evm_initialized & ~EVM_SETUP_COMPLETE));
44 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp)); 44 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
45 45
46 return rc; 46 return rc;
@@ -63,7 +63,7 @@ static ssize_t evm_write_key(struct file *file, const char __user *buf,
63{ 63{
64 int i, ret; 64 int i, ret;
65 65
66 if (!capable(CAP_SYS_ADMIN) || (evm_initialized & EVM_SETUP)) 66 if (!capable(CAP_SYS_ADMIN) || (evm_initialized & EVM_SETUP_COMPLETE))
67 return -EPERM; 67 return -EPERM;
68 68
69 ret = kstrtoint_from_user(buf, count, 0, &i); 69 ret = kstrtoint_from_user(buf, count, 0, &i);
@@ -75,16 +75,30 @@ static ssize_t evm_write_key(struct file *file, const char __user *buf,
75 if (!i || (i & ~EVM_INIT_MASK) != 0) 75 if (!i || (i & ~EVM_INIT_MASK) != 0)
76 return -EINVAL; 76 return -EINVAL;
77 77
78 /* Don't allow a request to freshly enable metadata writes if
79 * keys are loaded.
80 */
81 if ((i & EVM_ALLOW_METADATA_WRITES) &&
82 ((evm_initialized & EVM_KEY_MASK) != 0) &&
83 !(evm_initialized & EVM_ALLOW_METADATA_WRITES))
84 return -EPERM;
85
78 if (i & EVM_INIT_HMAC) { 86 if (i & EVM_INIT_HMAC) {
79 ret = evm_init_key(); 87 ret = evm_init_key();
80 if (ret != 0) 88 if (ret != 0)
81 return ret; 89 return ret;
82 /* Forbid further writes after the symmetric key is loaded */ 90 /* Forbid further writes after the symmetric key is loaded */
83 i |= EVM_SETUP; 91 i |= EVM_SETUP_COMPLETE;
84 } 92 }
85 93
86 evm_initialized |= i; 94 evm_initialized |= i;
87 95
96 /* Don't allow protected metadata modification if a symmetric key
97 * is loaded
98 */
99 if (evm_initialized & EVM_INIT_HMAC)
100 evm_initialized &= ~(EVM_ALLOW_METADATA_WRITES);
101
88 return count; 102 return count;
89} 103}
90 104