diff options
author | Mimi Zohar <zohar@linux.vnet.ibm.com> | 2012-01-09 22:59:36 -0500 |
---|---|---|
committer | Mimi Zohar <zohar@linux.vnet.ibm.com> | 2012-09-07 14:57:47 -0400 |
commit | 5a44b41207174e1882ce0c24a752f4cfb65dab07 (patch) | |
tree | a5426be63a4f165f3ce15d1e61d8fd10f37fd8c3 /security/integrity | |
parent | 42c63330f2b05aa6077c1bfc2798c04afe54f6b2 (diff) |
ima: add support for different security.ima data types
IMA-appraisal currently verifies the integrity of a file based on a
known 'good' measurement value. This patch reserves the first byte
of 'security.ima' as a place holder for the type of method used for
verifying file data integrity.
Changelog v1:
- Use the newly defined 'struct evm_ima_xattr_data'
Signed-off-by: Dmitry Kasatkin <dmitry.kasatkin@nokia.com>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
Diffstat (limited to 'security/integrity')
-rw-r--r-- | security/integrity/ima/ima_api.c | 6 | ||||
-rw-r--r-- | security/integrity/ima/ima_appraise.c | 23 | ||||
-rw-r--r-- | security/integrity/integrity.h | 2 |
3 files changed, 17 insertions, 14 deletions
diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c index 41cce84416c..33d46859753 100644 --- a/security/integrity/ima/ima_api.c +++ b/security/integrity/ima/ima_api.c | |||
@@ -147,8 +147,8 @@ int ima_collect_measurement(struct integrity_iint_cache *iint, | |||
147 | if (!(iint->flags & IMA_COLLECTED)) { | 147 | if (!(iint->flags & IMA_COLLECTED)) { |
148 | u64 i_version = file->f_dentry->d_inode->i_version; | 148 | u64 i_version = file->f_dentry->d_inode->i_version; |
149 | 149 | ||
150 | memset(iint->digest, 0, IMA_DIGEST_SIZE); | 150 | iint->ima_xattr.type = IMA_XATTR_DIGEST; |
151 | result = ima_calc_hash(file, iint->digest); | 151 | result = ima_calc_hash(file, iint->ima_xattr.digest); |
152 | if (!result) { | 152 | if (!result) { |
153 | iint->version = i_version; | 153 | iint->version = i_version; |
154 | iint->flags |= IMA_COLLECTED; | 154 | iint->flags |= IMA_COLLECTED; |
@@ -196,7 +196,7 @@ void ima_store_measurement(struct integrity_iint_cache *iint, | |||
196 | return; | 196 | return; |
197 | } | 197 | } |
198 | memset(&entry->template, 0, sizeof(entry->template)); | 198 | memset(&entry->template, 0, sizeof(entry->template)); |
199 | memcpy(entry->template.digest, iint->digest, IMA_DIGEST_SIZE); | 199 | memcpy(entry->template.digest, iint->ima_xattr.digest, IMA_DIGEST_SIZE); |
200 | strcpy(entry->template.file_name, | 200 | strcpy(entry->template.file_name, |
201 | (strlen(filename) > IMA_EVENT_NAME_LEN_MAX) ? | 201 | (strlen(filename) > IMA_EVENT_NAME_LEN_MAX) ? |
202 | file->f_dentry->d_name.name : filename); | 202 | file->f_dentry->d_name.name : filename); |
diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c index becc7e09116..f9979976aa5 100644 --- a/security/integrity/ima/ima_appraise.c +++ b/security/integrity/ima/ima_appraise.c | |||
@@ -45,9 +45,9 @@ int ima_must_appraise(struct inode *inode, enum ima_hooks func, int mask) | |||
45 | static void ima_fix_xattr(struct dentry *dentry, | 45 | static void ima_fix_xattr(struct dentry *dentry, |
46 | struct integrity_iint_cache *iint) | 46 | struct integrity_iint_cache *iint) |
47 | { | 47 | { |
48 | iint->digest[0] = IMA_XATTR_DIGEST; | 48 | iint->ima_xattr.type = IMA_XATTR_DIGEST; |
49 | __vfs_setxattr_noperm(dentry, XATTR_NAME_IMA, | 49 | __vfs_setxattr_noperm(dentry, XATTR_NAME_IMA, (u8 *)&iint->ima_xattr, |
50 | iint->digest, IMA_DIGEST_SIZE + 1, 0); | 50 | sizeof iint->ima_xattr, 0); |
51 | } | 51 | } |
52 | 52 | ||
53 | /* | 53 | /* |
@@ -63,7 +63,7 @@ int ima_appraise_measurement(struct integrity_iint_cache *iint, | |||
63 | { | 63 | { |
64 | struct dentry *dentry = file->f_dentry; | 64 | struct dentry *dentry = file->f_dentry; |
65 | struct inode *inode = dentry->d_inode; | 65 | struct inode *inode = dentry->d_inode; |
66 | u8 xattr_value[IMA_DIGEST_SIZE]; | 66 | struct evm_ima_xattr_data xattr_value; |
67 | enum integrity_status status = INTEGRITY_UNKNOWN; | 67 | enum integrity_status status = INTEGRITY_UNKNOWN; |
68 | const char *op = "appraise_data"; | 68 | const char *op = "appraise_data"; |
69 | char *cause = "unknown"; | 69 | char *cause = "unknown"; |
@@ -77,8 +77,8 @@ int ima_appraise_measurement(struct integrity_iint_cache *iint, | |||
77 | if (iint->flags & IMA_APPRAISED) | 77 | if (iint->flags & IMA_APPRAISED) |
78 | return iint->ima_status; | 78 | return iint->ima_status; |
79 | 79 | ||
80 | rc = inode->i_op->getxattr(dentry, XATTR_NAME_IMA, xattr_value, | 80 | rc = inode->i_op->getxattr(dentry, XATTR_NAME_IMA, (u8 *)&xattr_value, |
81 | IMA_DIGEST_SIZE); | 81 | sizeof xattr_value); |
82 | if (rc <= 0) { | 82 | if (rc <= 0) { |
83 | if (rc && rc != -ENODATA) | 83 | if (rc && rc != -ENODATA) |
84 | goto out; | 84 | goto out; |
@@ -89,7 +89,8 @@ int ima_appraise_measurement(struct integrity_iint_cache *iint, | |||
89 | goto out; | 89 | goto out; |
90 | } | 90 | } |
91 | 91 | ||
92 | status = evm_verifyxattr(dentry, XATTR_NAME_IMA, xattr_value, rc, iint); | 92 | status = evm_verifyxattr(dentry, XATTR_NAME_IMA, (u8 *)&xattr_value, |
93 | rc, iint); | ||
93 | if ((status != INTEGRITY_PASS) && (status != INTEGRITY_UNKNOWN)) { | 94 | if ((status != INTEGRITY_PASS) && (status != INTEGRITY_UNKNOWN)) { |
94 | if ((status == INTEGRITY_NOLABEL) | 95 | if ((status == INTEGRITY_NOLABEL) |
95 | || (status == INTEGRITY_NOXATTRS)) | 96 | || (status == INTEGRITY_NOXATTRS)) |
@@ -99,14 +100,16 @@ int ima_appraise_measurement(struct integrity_iint_cache *iint, | |||
99 | goto out; | 100 | goto out; |
100 | } | 101 | } |
101 | 102 | ||
102 | rc = memcmp(xattr_value, iint->digest, IMA_DIGEST_SIZE); | 103 | rc = memcmp(xattr_value.digest, iint->ima_xattr.digest, |
104 | IMA_DIGEST_SIZE); | ||
103 | if (rc) { | 105 | if (rc) { |
104 | status = INTEGRITY_FAIL; | 106 | status = INTEGRITY_FAIL; |
105 | cause = "invalid-hash"; | 107 | cause = "invalid-hash"; |
106 | print_hex_dump_bytes("security.ima: ", DUMP_PREFIX_NONE, | 108 | print_hex_dump_bytes("security.ima: ", DUMP_PREFIX_NONE, |
107 | xattr_value, IMA_DIGEST_SIZE); | 109 | &xattr_value, sizeof xattr_value); |
108 | print_hex_dump_bytes("collected: ", DUMP_PREFIX_NONE, | 110 | print_hex_dump_bytes("collected: ", DUMP_PREFIX_NONE, |
109 | iint->digest, IMA_DIGEST_SIZE); | 111 | (u8 *)&iint->ima_xattr, |
112 | sizeof iint->ima_xattr); | ||
110 | goto out; | 113 | goto out; |
111 | } | 114 | } |
112 | status = INTEGRITY_PASS; | 115 | status = INTEGRITY_PASS; |
diff --git a/security/integrity/integrity.h b/security/integrity/integrity.h index dac6b68e945..91ccef1c704 100644 --- a/security/integrity/integrity.h +++ b/security/integrity/integrity.h | |||
@@ -39,7 +39,7 @@ struct integrity_iint_cache { | |||
39 | struct inode *inode; /* back pointer to inode in question */ | 39 | struct inode *inode; /* back pointer to inode in question */ |
40 | u64 version; /* track inode changes */ | 40 | u64 version; /* track inode changes */ |
41 | unsigned char flags; | 41 | unsigned char flags; |
42 | u8 digest[SHA1_DIGEST_SIZE]; | 42 | struct evm_ima_xattr_data ima_xattr; |
43 | enum integrity_status ima_status; | 43 | enum integrity_status ima_status; |
44 | enum integrity_status evm_status; | 44 | enum integrity_status evm_status; |
45 | }; | 45 | }; |