diff options
author | Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com> | 2017-06-07 21:49:10 -0400 |
---|---|---|
committer | Mimi Zohar <zohar@linux.vnet.ibm.com> | 2017-06-21 14:37:12 -0400 |
commit | bb543e3959b5909e7b5db4a216018c634a9d9898 (patch) | |
tree | 9538abab1c0dbe1c43c595d03fb661af52f5ab2e | |
parent | e4586c79d4ba24a02f63a17e49207007c3bbdaea (diff) |
integrity: Small code improvements
These changes are too small to warrant their own patches:
The keyid and sig_size members of struct signature_v2_hdr are in BE format,
so use a type that makes this assumption explicit. Also, use beXX_to_cpu
instead of __beXX_to_cpu to read them.
Change integrity_kernel_read to take a void * buffer instead of char *
buffer, so that callers don't have to use a cast if they provide a buffer
that isn't a char *.
Add missing #endif comment in ima.h pointing out which macro it refers to.
Add missing fall through comment in ima_appraise.c.
Constify mask_tokens and func_tokens arrays.
Signed-off-by: Thiago Jung Bauermann <bauerman@linux.vnet.ibm.com>
Signed-off-by: Mimi Zohar <zohar@linux.vnet.ibm.com>
-rw-r--r-- | security/integrity/digsig_asymmetric.c | 4 | ||||
-rw-r--r-- | security/integrity/iint.c | 2 | ||||
-rw-r--r-- | security/integrity/ima/ima.h | 2 | ||||
-rw-r--r-- | security/integrity/ima/ima_appraise.c | 1 | ||||
-rw-r--r-- | security/integrity/ima/ima_policy.c | 4 | ||||
-rw-r--r-- | security/integrity/integrity.h | 7 |
6 files changed, 11 insertions, 9 deletions
diff --git a/security/integrity/digsig_asymmetric.c b/security/integrity/digsig_asymmetric.c index 80052ed8d467..ab6a029062a1 100644 --- a/security/integrity/digsig_asymmetric.c +++ b/security/integrity/digsig_asymmetric.c | |||
@@ -92,13 +92,13 @@ int asymmetric_verify(struct key *keyring, const char *sig, | |||
92 | 92 | ||
93 | siglen -= sizeof(*hdr); | 93 | siglen -= sizeof(*hdr); |
94 | 94 | ||
95 | if (siglen != __be16_to_cpu(hdr->sig_size)) | 95 | if (siglen != be16_to_cpu(hdr->sig_size)) |
96 | return -EBADMSG; | 96 | return -EBADMSG; |
97 | 97 | ||
98 | if (hdr->hash_algo >= HASH_ALGO__LAST) | 98 | if (hdr->hash_algo >= HASH_ALGO__LAST) |
99 | return -ENOPKG; | 99 | return -ENOPKG; |
100 | 100 | ||
101 | key = request_asymmetric_key(keyring, __be32_to_cpu(hdr->keyid)); | 101 | key = request_asymmetric_key(keyring, be32_to_cpu(hdr->keyid)); |
102 | if (IS_ERR(key)) | 102 | if (IS_ERR(key)) |
103 | return PTR_ERR(key); | 103 | return PTR_ERR(key); |
104 | 104 | ||
diff --git a/security/integrity/iint.c b/security/integrity/iint.c index c710d22042f9..6fc888ca468e 100644 --- a/security/integrity/iint.c +++ b/security/integrity/iint.c | |||
@@ -182,7 +182,7 @@ security_initcall(integrity_iintcache_init); | |||
182 | * | 182 | * |
183 | */ | 183 | */ |
184 | int integrity_kernel_read(struct file *file, loff_t offset, | 184 | int integrity_kernel_read(struct file *file, loff_t offset, |
185 | char *addr, unsigned long count) | 185 | void *addr, unsigned long count) |
186 | { | 186 | { |
187 | mm_segment_t old_fs; | 187 | mm_segment_t old_fs; |
188 | char __user *buf = (char __user *)addr; | 188 | char __user *buf = (char __user *)addr; |
diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h index d26a30e37d13..215a93c41b51 100644 --- a/security/integrity/ima/ima.h +++ b/security/integrity/ima/ima.h | |||
@@ -284,7 +284,7 @@ static inline int ima_read_xattr(struct dentry *dentry, | |||
284 | return 0; | 284 | return 0; |
285 | } | 285 | } |
286 | 286 | ||
287 | #endif | 287 | #endif /* CONFIG_IMA_APPRAISE */ |
288 | 288 | ||
289 | /* LSM based policy rules require audit */ | 289 | /* LSM based policy rules require audit */ |
290 | #ifdef CONFIG_IMA_LSM_RULES | 290 | #ifdef CONFIG_IMA_LSM_RULES |
diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c index 7fe0566142d8..ea36a4f134f4 100644 --- a/security/integrity/ima/ima_appraise.c +++ b/security/integrity/ima/ima_appraise.c | |||
@@ -240,6 +240,7 @@ int ima_appraise_measurement(enum ima_hooks func, | |||
240 | case IMA_XATTR_DIGEST_NG: | 240 | case IMA_XATTR_DIGEST_NG: |
241 | /* first byte contains algorithm id */ | 241 | /* first byte contains algorithm id */ |
242 | hash_start = 1; | 242 | hash_start = 1; |
243 | /* fall through */ | ||
243 | case IMA_XATTR_DIGEST: | 244 | case IMA_XATTR_DIGEST: |
244 | if (iint->flags & IMA_DIGSIG_REQUIRED) { | 245 | if (iint->flags & IMA_DIGSIG_REQUIRED) { |
245 | cause = "IMA-signature-required"; | 246 | cause = "IMA-signature-required"; |
diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c index 0acd68decb17..949ad3858327 100644 --- a/security/integrity/ima/ima_policy.c +++ b/security/integrity/ima/ima_policy.c | |||
@@ -965,7 +965,7 @@ enum { | |||
965 | mask_exec = 0, mask_write, mask_read, mask_append | 965 | mask_exec = 0, mask_write, mask_read, mask_append |
966 | }; | 966 | }; |
967 | 967 | ||
968 | static char *mask_tokens[] = { | 968 | static const char *const mask_tokens[] = { |
969 | "MAY_EXEC", | 969 | "MAY_EXEC", |
970 | "MAY_WRITE", | 970 | "MAY_WRITE", |
971 | "MAY_READ", | 971 | "MAY_READ", |
@@ -979,7 +979,7 @@ enum { | |||
979 | func_policy | 979 | func_policy |
980 | }; | 980 | }; |
981 | 981 | ||
982 | static char *func_tokens[] = { | 982 | static const char *const func_tokens[] = { |
983 | "FILE_CHECK", | 983 | "FILE_CHECK", |
984 | "MMAP_CHECK", | 984 | "MMAP_CHECK", |
985 | "BPRM_CHECK", | 985 | "BPRM_CHECK", |
diff --git a/security/integrity/integrity.h b/security/integrity/integrity.h index 24520b4ef3b0..a53e7e4ab06c 100644 --- a/security/integrity/integrity.h +++ b/security/integrity/integrity.h | |||
@@ -92,8 +92,8 @@ struct signature_v2_hdr { | |||
92 | uint8_t type; /* xattr type */ | 92 | uint8_t type; /* xattr type */ |
93 | uint8_t version; /* signature format version */ | 93 | uint8_t version; /* signature format version */ |
94 | uint8_t hash_algo; /* Digest algorithm [enum hash_algo] */ | 94 | uint8_t hash_algo; /* Digest algorithm [enum hash_algo] */ |
95 | uint32_t keyid; /* IMA key identifier - not X509/PGP specific */ | 95 | __be32 keyid; /* IMA key identifier - not X509/PGP specific */ |
96 | uint16_t sig_size; /* signature size */ | 96 | __be16 sig_size; /* signature size */ |
97 | uint8_t sig[0]; /* signature payload */ | 97 | uint8_t sig[0]; /* signature payload */ |
98 | } __packed; | 98 | } __packed; |
99 | 99 | ||
@@ -118,7 +118,8 @@ struct integrity_iint_cache { | |||
118 | struct integrity_iint_cache *integrity_iint_find(struct inode *inode); | 118 | struct integrity_iint_cache *integrity_iint_find(struct inode *inode); |
119 | 119 | ||
120 | int integrity_kernel_read(struct file *file, loff_t offset, | 120 | int integrity_kernel_read(struct file *file, loff_t offset, |
121 | char *addr, unsigned long count); | 121 | void *addr, unsigned long count); |
122 | |||
122 | int __init integrity_read_file(const char *path, char **data); | 123 | int __init integrity_read_file(const char *path, char **data); |
123 | 124 | ||
124 | #define INTEGRITY_KEYRING_EVM 0 | 125 | #define INTEGRITY_KEYRING_EVM 0 |