aboutsummaryrefslogtreecommitdiffstats
path: root/security
diff options
context:
space:
mode:
authorLinus Torvalds <torvalds@linux-foundation.org>2016-03-17 14:33:45 -0400
committerLinus Torvalds <torvalds@linux-foundation.org>2016-03-17 14:33:45 -0400
commitbb7aeae3d680c2c777f54274b0270ced0599f33d (patch)
tree4801a103c2b157b5019cf38a19dc67d54bf38453 /security
parent70477371dc350746d10431d74f0f213a8d59924c (diff)
parent88a1b564a20e371e6be41b39b85673e9c1959491 (diff)
Merge branch 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security
Pull security layer updates from James Morris: "There are a bunch of fixes to the TPM, IMA, and Keys code, with minor fixes scattered across the subsystem. IMA now requires signed policy, and that policy is also now measured and appraised" * 'next' of git://git.kernel.org/pub/scm/linux/kernel/git/jmorris/linux-security: (67 commits) X.509: Make algo identifiers text instead of enum akcipher: Move the RSA DER encoding check to the crypto layer crypto: Add hash param to pkcs1pad sign-file: fix build with CMS support disabled MAINTAINERS: update tpmdd urls MODSIGN: linux/string.h should be #included to get memcpy() certs: Fix misaligned data in extra certificate list X.509: Handle midnight alternative notation in GeneralizedTime X.509: Support leap seconds Handle ISO 8601 leap seconds and encodings of midnight in mktime64() X.509: Fix leap year handling again PKCS#7: fix unitialized boolean 'want' firmware: change kernel read fail to dev_dbg() KEYS: Use the symbol value for list size, updated by scripts/insert-sys-cert KEYS: Reserve an extra certificate symbol for inserting without recompiling modsign: hide openssl output in silent builds tpm_tis: fix build warning with tpm_tis_resume ima: require signed IMA policy ima: measure and appraise the IMA policy itself ima: load policy using path ...
Diffstat (limited to 'security')
-rw-r--r--security/integrity/Kconfig2
-rw-r--r--security/integrity/digsig_asymmetric.c16
-rw-r--r--security/integrity/iint.c4
-rw-r--r--security/integrity/ima/ima.h49
-rw-r--r--security/integrity/ima/ima_api.c25
-rw-r--r--security/integrity/ima/ima_appraise.c69
-rw-r--r--security/integrity/ima/ima_crypto.c120
-rw-r--r--security/integrity/ima/ima_fs.c53
-rw-r--r--security/integrity/ima/ima_init.c2
-rw-r--r--security/integrity/ima/ima_main.c92
-rw-r--r--security/integrity/ima/ima_policy.c115
-rw-r--r--security/integrity/ima/ima_template.c2
-rw-r--r--security/integrity/ima/ima_template_lib.c1
-rw-r--r--security/integrity/integrity.h17
-rw-r--r--security/keys/big_key.c15
-rw-r--r--security/keys/key.c2
-rw-r--r--security/keys/trusted.c11
-rw-r--r--security/security.c34
-rw-r--r--security/selinux/Makefile2
-rw-r--r--security/smack/smack_lsm.c46
20 files changed, 450 insertions, 227 deletions
diff --git a/security/integrity/Kconfig b/security/integrity/Kconfig
index 21d756832b75..979be65d22c4 100644
--- a/security/integrity/Kconfig
+++ b/security/integrity/Kconfig
@@ -36,6 +36,7 @@ config INTEGRITY_ASYMMETRIC_KEYS
36 select ASYMMETRIC_KEY_TYPE 36 select ASYMMETRIC_KEY_TYPE
37 select ASYMMETRIC_PUBLIC_KEY_SUBTYPE 37 select ASYMMETRIC_PUBLIC_KEY_SUBTYPE
38 select PUBLIC_KEY_ALGO_RSA 38 select PUBLIC_KEY_ALGO_RSA
39 select CRYPTO_RSA
39 select X509_CERTIFICATE_PARSER 40 select X509_CERTIFICATE_PARSER
40 help 41 help
41 This option enables digital signature verification using 42 This option enables digital signature verification using
@@ -45,7 +46,6 @@ config INTEGRITY_TRUSTED_KEYRING
45 bool "Require all keys on the integrity keyrings be signed" 46 bool "Require all keys on the integrity keyrings be signed"
46 depends on SYSTEM_TRUSTED_KEYRING 47 depends on SYSTEM_TRUSTED_KEYRING
47 depends on INTEGRITY_ASYMMETRIC_KEYS 48 depends on INTEGRITY_ASYMMETRIC_KEYS
48 select KEYS_DEBUG_PROC_KEYS
49 default y 49 default y
50 help 50 help
51 This option requires that all keys added to the .ima and 51 This option requires that all keys added to the .ima and
diff --git a/security/integrity/digsig_asymmetric.c b/security/integrity/digsig_asymmetric.c
index 5ade2a7517a6..80052ed8d467 100644
--- a/security/integrity/digsig_asymmetric.c
+++ b/security/integrity/digsig_asymmetric.c
@@ -16,6 +16,7 @@
16#include <linux/ratelimit.h> 16#include <linux/ratelimit.h>
17#include <linux/key-type.h> 17#include <linux/key-type.h>
18#include <crypto/public_key.h> 18#include <crypto/public_key.h>
19#include <crypto/hash_info.h>
19#include <keys/asymmetric-type.h> 20#include <keys/asymmetric-type.h>
20#include <keys/system_keyring.h> 21#include <keys/system_keyring.h>
21 22
@@ -94,7 +95,7 @@ int asymmetric_verify(struct key *keyring, const char *sig,
94 if (siglen != __be16_to_cpu(hdr->sig_size)) 95 if (siglen != __be16_to_cpu(hdr->sig_size))
95 return -EBADMSG; 96 return -EBADMSG;
96 97
97 if (hdr->hash_algo >= PKEY_HASH__LAST) 98 if (hdr->hash_algo >= HASH_ALGO__LAST)
98 return -ENOPKG; 99 return -ENOPKG;
99 100
100 key = request_asymmetric_key(keyring, __be32_to_cpu(hdr->keyid)); 101 key = request_asymmetric_key(keyring, __be32_to_cpu(hdr->keyid));
@@ -103,16 +104,13 @@ int asymmetric_verify(struct key *keyring, const char *sig,
103 104
104 memset(&pks, 0, sizeof(pks)); 105 memset(&pks, 0, sizeof(pks));
105 106
106 pks.pkey_hash_algo = hdr->hash_algo; 107 pks.pkey_algo = "rsa";
108 pks.hash_algo = hash_algo_name[hdr->hash_algo];
107 pks.digest = (u8 *)data; 109 pks.digest = (u8 *)data;
108 pks.digest_size = datalen; 110 pks.digest_size = datalen;
109 pks.nr_mpi = 1; 111 pks.s = hdr->sig;
110 pks.rsa.s = mpi_read_raw_data(hdr->sig, siglen); 112 pks.s_size = siglen;
111 113 ret = verify_signature(key, &pks);
112 if (pks.rsa.s)
113 ret = verify_signature(key, &pks);
114
115 mpi_free(pks.rsa.s);
116 key_put(key); 114 key_put(key);
117 pr_debug("%s() = %d\n", __func__, ret); 115 pr_debug("%s() = %d\n", __func__, ret);
118 return ret; 116 return ret;
diff --git a/security/integrity/iint.c b/security/integrity/iint.c
index 8f1ab37f2897..345b75997e4c 100644
--- a/security/integrity/iint.c
+++ b/security/integrity/iint.c
@@ -77,7 +77,7 @@ static void iint_free(struct integrity_iint_cache *iint)
77 iint->ima_file_status = INTEGRITY_UNKNOWN; 77 iint->ima_file_status = INTEGRITY_UNKNOWN;
78 iint->ima_mmap_status = INTEGRITY_UNKNOWN; 78 iint->ima_mmap_status = INTEGRITY_UNKNOWN;
79 iint->ima_bprm_status = INTEGRITY_UNKNOWN; 79 iint->ima_bprm_status = INTEGRITY_UNKNOWN;
80 iint->ima_module_status = INTEGRITY_UNKNOWN; 80 iint->ima_read_status = INTEGRITY_UNKNOWN;
81 iint->evm_status = INTEGRITY_UNKNOWN; 81 iint->evm_status = INTEGRITY_UNKNOWN;
82 kmem_cache_free(iint_cache, iint); 82 kmem_cache_free(iint_cache, iint);
83} 83}
@@ -157,7 +157,7 @@ static void init_once(void *foo)
157 iint->ima_file_status = INTEGRITY_UNKNOWN; 157 iint->ima_file_status = INTEGRITY_UNKNOWN;
158 iint->ima_mmap_status = INTEGRITY_UNKNOWN; 158 iint->ima_mmap_status = INTEGRITY_UNKNOWN;
159 iint->ima_bprm_status = INTEGRITY_UNKNOWN; 159 iint->ima_bprm_status = INTEGRITY_UNKNOWN;
160 iint->ima_module_status = INTEGRITY_UNKNOWN; 160 iint->ima_read_status = INTEGRITY_UNKNOWN;
161 iint->evm_status = INTEGRITY_UNKNOWN; 161 iint->evm_status = INTEGRITY_UNKNOWN;
162} 162}
163 163
diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
index 585af61ed399..5d0f61163d98 100644
--- a/security/integrity/ima/ima.h
+++ b/security/integrity/ima/ima.h
@@ -19,10 +19,12 @@
19 19
20#include <linux/types.h> 20#include <linux/types.h>
21#include <linux/crypto.h> 21#include <linux/crypto.h>
22#include <linux/fs.h>
22#include <linux/security.h> 23#include <linux/security.h>
23#include <linux/hash.h> 24#include <linux/hash.h>
24#include <linux/tpm.h> 25#include <linux/tpm.h>
25#include <linux/audit.h> 26#include <linux/audit.h>
27#include <crypto/hash_info.h>
26 28
27#include "../integrity.h" 29#include "../integrity.h"
28 30
@@ -106,6 +108,8 @@ int ima_add_template_entry(struct ima_template_entry *entry, int violation,
106 const char *op, struct inode *inode, 108 const char *op, struct inode *inode,
107 const unsigned char *filename); 109 const unsigned char *filename);
108int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash); 110int ima_calc_file_hash(struct file *file, struct ima_digest_data *hash);
111int ima_calc_buffer_hash(const void *buf, loff_t len,
112 struct ima_digest_data *hash);
109int ima_calc_field_array_hash(struct ima_field_data *field_data, 113int ima_calc_field_array_hash(struct ima_field_data *field_data,
110 struct ima_template_desc *desc, int num_fields, 114 struct ima_template_desc *desc, int num_fields,
111 struct ima_digest_data *hash); 115 struct ima_digest_data *hash);
@@ -136,13 +140,25 @@ static inline unsigned long ima_hash_key(u8 *digest)
136 return hash_long(*digest, IMA_HASH_BITS); 140 return hash_long(*digest, IMA_HASH_BITS);
137} 141}
138 142
143enum ima_hooks {
144 FILE_CHECK = 1,
145 MMAP_CHECK,
146 BPRM_CHECK,
147 POST_SETATTR,
148 MODULE_CHECK,
149 FIRMWARE_CHECK,
150 KEXEC_KERNEL_CHECK,
151 KEXEC_INITRAMFS_CHECK,
152 POLICY_CHECK,
153 MAX_CHECK
154};
155
139/* LIM API function definitions */ 156/* LIM API function definitions */
140int ima_get_action(struct inode *inode, int mask, int function); 157int ima_get_action(struct inode *inode, int mask, enum ima_hooks func);
141int ima_must_measure(struct inode *inode, int mask, int function); 158int ima_must_measure(struct inode *inode, int mask, enum ima_hooks func);
142int ima_collect_measurement(struct integrity_iint_cache *iint, 159int ima_collect_measurement(struct integrity_iint_cache *iint,
143 struct file *file, 160 struct file *file, void *buf, loff_t size,
144 struct evm_ima_xattr_data **xattr_value, 161 enum hash_algo algo);
145 int *xattr_len);
146void ima_store_measurement(struct integrity_iint_cache *iint, struct file *file, 162void ima_store_measurement(struct integrity_iint_cache *iint, struct file *file,
147 const unsigned char *filename, 163 const unsigned char *filename,
148 struct evm_ima_xattr_data *xattr_value, 164 struct evm_ima_xattr_data *xattr_value,
@@ -157,8 +173,6 @@ void ima_free_template_entry(struct ima_template_entry *entry);
157const char *ima_d_path(struct path *path, char **pathbuf); 173const char *ima_d_path(struct path *path, char **pathbuf);
158 174
159/* IMA policy related functions */ 175/* IMA policy related functions */
160enum ima_hooks { FILE_CHECK = 1, MMAP_CHECK, BPRM_CHECK, MODULE_CHECK, FIRMWARE_CHECK, POST_SETATTR };
161
162int ima_match_policy(struct inode *inode, enum ima_hooks func, int mask, 176int ima_match_policy(struct inode *inode, enum ima_hooks func, int mask,
163 int flags); 177 int flags);
164void ima_init_policy(void); 178void ima_init_policy(void);
@@ -178,23 +192,25 @@ int ima_policy_show(struct seq_file *m, void *v);
178#define IMA_APPRAISE_LOG 0x04 192#define IMA_APPRAISE_LOG 0x04
179#define IMA_APPRAISE_MODULES 0x08 193#define IMA_APPRAISE_MODULES 0x08
180#define IMA_APPRAISE_FIRMWARE 0x10 194#define IMA_APPRAISE_FIRMWARE 0x10
195#define IMA_APPRAISE_POLICY 0x20
181 196
182#ifdef CONFIG_IMA_APPRAISE 197#ifdef CONFIG_IMA_APPRAISE
183int ima_appraise_measurement(int func, struct integrity_iint_cache *iint, 198int ima_appraise_measurement(enum ima_hooks func,
199 struct integrity_iint_cache *iint,
184 struct file *file, const unsigned char *filename, 200 struct file *file, const unsigned char *filename,
185 struct evm_ima_xattr_data *xattr_value, 201 struct evm_ima_xattr_data *xattr_value,
186 int xattr_len, int opened); 202 int xattr_len, int opened);
187int ima_must_appraise(struct inode *inode, int mask, enum ima_hooks func); 203int ima_must_appraise(struct inode *inode, int mask, enum ima_hooks func);
188void ima_update_xattr(struct integrity_iint_cache *iint, struct file *file); 204void ima_update_xattr(struct integrity_iint_cache *iint, struct file *file);
189enum integrity_status ima_get_cache_status(struct integrity_iint_cache *iint, 205enum integrity_status ima_get_cache_status(struct integrity_iint_cache *iint,
190 int func); 206 enum ima_hooks func);
191void ima_get_hash_algo(struct evm_ima_xattr_data *xattr_value, int xattr_len, 207enum hash_algo ima_get_hash_algo(struct evm_ima_xattr_data *xattr_value,
192 struct ima_digest_data *hash); 208 int xattr_len);
193int ima_read_xattr(struct dentry *dentry, 209int ima_read_xattr(struct dentry *dentry,
194 struct evm_ima_xattr_data **xattr_value); 210 struct evm_ima_xattr_data **xattr_value);
195 211
196#else 212#else
197static inline int ima_appraise_measurement(int func, 213static inline int ima_appraise_measurement(enum ima_hooks func,
198 struct integrity_iint_cache *iint, 214 struct integrity_iint_cache *iint,
199 struct file *file, 215 struct file *file,
200 const unsigned char *filename, 216 const unsigned char *filename,
@@ -216,15 +232,16 @@ static inline void ima_update_xattr(struct integrity_iint_cache *iint,
216} 232}
217 233
218static inline enum integrity_status ima_get_cache_status(struct integrity_iint_cache 234static inline enum integrity_status ima_get_cache_status(struct integrity_iint_cache
219 *iint, int func) 235 *iint,
236 enum ima_hooks func)
220{ 237{
221 return INTEGRITY_UNKNOWN; 238 return INTEGRITY_UNKNOWN;
222} 239}
223 240
224static inline void ima_get_hash_algo(struct evm_ima_xattr_data *xattr_value, 241static inline enum hash_algo
225 int xattr_len, 242ima_get_hash_algo(struct evm_ima_xattr_data *xattr_value, int xattr_len)
226 struct ima_digest_data *hash)
227{ 243{
244 return ima_hash_algo;
228} 245}
229 246
230static inline int ima_read_xattr(struct dentry *dentry, 247static inline int ima_read_xattr(struct dentry *dentry,
diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
index 1d950fbb2aec..370e42dfc5c5 100644
--- a/security/integrity/ima/ima_api.c
+++ b/security/integrity/ima/ima_api.c
@@ -18,7 +18,7 @@
18#include <linux/fs.h> 18#include <linux/fs.h>
19#include <linux/xattr.h> 19#include <linux/xattr.h>
20#include <linux/evm.h> 20#include <linux/evm.h>
21#include <crypto/hash_info.h> 21
22#include "ima.h" 22#include "ima.h"
23 23
24/* 24/*
@@ -156,7 +156,7 @@ err_out:
156 * ima_get_action - appraise & measure decision based on policy. 156 * ima_get_action - appraise & measure decision based on policy.
157 * @inode: pointer to inode to measure 157 * @inode: pointer to inode to measure
158 * @mask: contains the permission mask (MAY_READ, MAY_WRITE, MAY_EXECUTE) 158 * @mask: contains the permission mask (MAY_READ, MAY_WRITE, MAY_EXECUTE)
159 * @function: calling function (FILE_CHECK, BPRM_CHECK, MMAP_CHECK, MODULE_CHECK) 159 * @func: caller identifier
160 * 160 *
161 * The policy is defined in terms of keypairs: 161 * The policy is defined in terms of keypairs:
162 * subj=, obj=, type=, func=, mask=, fsmagic= 162 * subj=, obj=, type=, func=, mask=, fsmagic=
@@ -168,13 +168,13 @@ err_out:
168 * Returns IMA_MEASURE, IMA_APPRAISE mask. 168 * Returns IMA_MEASURE, IMA_APPRAISE mask.
169 * 169 *
170 */ 170 */
171int ima_get_action(struct inode *inode, int mask, int function) 171int ima_get_action(struct inode *inode, int mask, enum ima_hooks func)
172{ 172{
173 int flags = IMA_MEASURE | IMA_AUDIT | IMA_APPRAISE; 173 int flags = IMA_MEASURE | IMA_AUDIT | IMA_APPRAISE;
174 174
175 flags &= ima_policy_flag; 175 flags &= ima_policy_flag;
176 176
177 return ima_match_policy(inode, function, mask, flags); 177 return ima_match_policy(inode, func, mask, flags);
178} 178}
179 179
180/* 180/*
@@ -188,9 +188,8 @@ int ima_get_action(struct inode *inode, int mask, int function)
188 * Return 0 on success, error code otherwise 188 * Return 0 on success, error code otherwise
189 */ 189 */
190int ima_collect_measurement(struct integrity_iint_cache *iint, 190int ima_collect_measurement(struct integrity_iint_cache *iint,
191 struct file *file, 191 struct file *file, void *buf, loff_t size,
192 struct evm_ima_xattr_data **xattr_value, 192 enum hash_algo algo)
193 int *xattr_len)
194{ 193{
195 const char *audit_cause = "failed"; 194 const char *audit_cause = "failed";
196 struct inode *inode = file_inode(file); 195 struct inode *inode = file_inode(file);
@@ -201,9 +200,6 @@ int ima_collect_measurement(struct integrity_iint_cache *iint,
201 char digest[IMA_MAX_DIGEST_SIZE]; 200 char digest[IMA_MAX_DIGEST_SIZE];
202 } hash; 201 } hash;
203 202
204 if (xattr_value)
205 *xattr_len = ima_read_xattr(file->f_path.dentry, xattr_value);
206
207 if (!(iint->flags & IMA_COLLECTED)) { 203 if (!(iint->flags & IMA_COLLECTED)) {
208 u64 i_version = file_inode(file)->i_version; 204 u64 i_version = file_inode(file)->i_version;
209 205
@@ -213,13 +209,10 @@ int ima_collect_measurement(struct integrity_iint_cache *iint,
213 goto out; 209 goto out;
214 } 210 }
215 211
216 /* use default hash algorithm */ 212 hash.hdr.algo = algo;
217 hash.hdr.algo = ima_hash_algo;
218
219 if (xattr_value)
220 ima_get_hash_algo(*xattr_value, *xattr_len, &hash.hdr);
221 213
222 result = ima_calc_file_hash(file, &hash.hdr); 214 result = (!buf) ? ima_calc_file_hash(file, &hash.hdr) :
215 ima_calc_buffer_hash(buf, size, &hash.hdr);
223 if (!result) { 216 if (!result) {
224 int length = sizeof(hash.hdr) + hash.hdr.length; 217 int length = sizeof(hash.hdr) + hash.hdr.length;
225 void *tmpbuf = krealloc(iint->ima_hash, length, 218 void *tmpbuf = krealloc(iint->ima_hash, length,
diff --git a/security/integrity/ima/ima_appraise.c b/security/integrity/ima/ima_appraise.c
index 1873b5536f80..6b4694aedae8 100644
--- a/security/integrity/ima/ima_appraise.c
+++ b/security/integrity/ima/ima_appraise.c
@@ -15,7 +15,6 @@
15#include <linux/magic.h> 15#include <linux/magic.h>
16#include <linux/ima.h> 16#include <linux/ima.h>
17#include <linux/evm.h> 17#include <linux/evm.h>
18#include <crypto/hash_info.h>
19 18
20#include "ima.h" 19#include "ima.h"
21 20
@@ -68,25 +67,25 @@ static int ima_fix_xattr(struct dentry *dentry,
68 67
69/* Return specific func appraised cached result */ 68/* Return specific func appraised cached result */
70enum integrity_status ima_get_cache_status(struct integrity_iint_cache *iint, 69enum integrity_status ima_get_cache_status(struct integrity_iint_cache *iint,
71 int func) 70 enum ima_hooks func)
72{ 71{
73 switch (func) { 72 switch (func) {
74 case MMAP_CHECK: 73 case MMAP_CHECK:
75 return iint->ima_mmap_status; 74 return iint->ima_mmap_status;
76 case BPRM_CHECK: 75 case BPRM_CHECK:
77 return iint->ima_bprm_status; 76 return iint->ima_bprm_status;
78 case MODULE_CHECK:
79 return iint->ima_module_status;
80 case FIRMWARE_CHECK:
81 return iint->ima_firmware_status;
82 case FILE_CHECK: 77 case FILE_CHECK:
83 default: 78 case POST_SETATTR:
84 return iint->ima_file_status; 79 return iint->ima_file_status;
80 case MODULE_CHECK ... MAX_CHECK - 1:
81 default:
82 return iint->ima_read_status;
85 } 83 }
86} 84}
87 85
88static void ima_set_cache_status(struct integrity_iint_cache *iint, 86static void ima_set_cache_status(struct integrity_iint_cache *iint,
89 int func, enum integrity_status status) 87 enum ima_hooks func,
88 enum integrity_status status)
90{ 89{
91 switch (func) { 90 switch (func) {
92 case MMAP_CHECK: 91 case MMAP_CHECK:
@@ -95,20 +94,19 @@ static void ima_set_cache_status(struct integrity_iint_cache *iint,
95 case BPRM_CHECK: 94 case BPRM_CHECK:
96 iint->ima_bprm_status = status; 95 iint->ima_bprm_status = status;
97 break; 96 break;
98 case MODULE_CHECK:
99 iint->ima_module_status = status;
100 break;
101 case FIRMWARE_CHECK:
102 iint->ima_firmware_status = status;
103 break;
104 case FILE_CHECK: 97 case FILE_CHECK:
105 default: 98 case POST_SETATTR:
106 iint->ima_file_status = status; 99 iint->ima_file_status = status;
107 break; 100 break;
101 case MODULE_CHECK ... MAX_CHECK - 1:
102 default:
103 iint->ima_read_status = status;
104 break;
108 } 105 }
109} 106}
110 107
111static void ima_cache_flags(struct integrity_iint_cache *iint, int func) 108static void ima_cache_flags(struct integrity_iint_cache *iint,
109 enum ima_hooks func)
112{ 110{
113 switch (func) { 111 switch (func) {
114 case MMAP_CHECK: 112 case MMAP_CHECK:
@@ -117,49 +115,51 @@ static void ima_cache_flags(struct integrity_iint_cache *iint, int func)
117 case BPRM_CHECK: 115 case BPRM_CHECK:
118 iint->flags |= (IMA_BPRM_APPRAISED | IMA_APPRAISED); 116 iint->flags |= (IMA_BPRM_APPRAISED | IMA_APPRAISED);
119 break; 117 break;
120 case MODULE_CHECK:
121 iint->flags |= (IMA_MODULE_APPRAISED | IMA_APPRAISED);
122 break;
123 case FIRMWARE_CHECK:
124 iint->flags |= (IMA_FIRMWARE_APPRAISED | IMA_APPRAISED);
125 break;
126 case FILE_CHECK: 118 case FILE_CHECK:
127 default: 119 case POST_SETATTR:
128 iint->flags |= (IMA_FILE_APPRAISED | IMA_APPRAISED); 120 iint->flags |= (IMA_FILE_APPRAISED | IMA_APPRAISED);
129 break; 121 break;
122 case MODULE_CHECK ... MAX_CHECK - 1:
123 default:
124 iint->flags |= (IMA_READ_APPRAISED | IMA_APPRAISED);
125 break;
130 } 126 }
131} 127}
132 128
133void ima_get_hash_algo(struct evm_ima_xattr_data *xattr_value, int xattr_len, 129enum hash_algo ima_get_hash_algo(struct evm_ima_xattr_data *xattr_value,
134 struct ima_digest_data *hash) 130 int xattr_len)
135{ 131{
136 struct signature_v2_hdr *sig; 132 struct signature_v2_hdr *sig;
137 133
138 if (!xattr_value || xattr_len < 2) 134 if (!xattr_value || xattr_len < 2)
139 return; 135 /* return default hash algo */
136 return ima_hash_algo;
140 137
141 switch (xattr_value->type) { 138 switch (xattr_value->type) {
142 case EVM_IMA_XATTR_DIGSIG: 139 case EVM_IMA_XATTR_DIGSIG:
143 sig = (typeof(sig))xattr_value; 140 sig = (typeof(sig))xattr_value;
144 if (sig->version != 2 || xattr_len <= sizeof(*sig)) 141 if (sig->version != 2 || xattr_len <= sizeof(*sig))
145 return; 142 return ima_hash_algo;
146 hash->algo = sig->hash_algo; 143 return sig->hash_algo;
147 break; 144 break;
148 case IMA_XATTR_DIGEST_NG: 145 case IMA_XATTR_DIGEST_NG:
149 hash->algo = xattr_value->digest[0]; 146 return xattr_value->digest[0];
150 break; 147 break;
151 case IMA_XATTR_DIGEST: 148 case IMA_XATTR_DIGEST:
152 /* this is for backward compatibility */ 149 /* this is for backward compatibility */
153 if (xattr_len == 21) { 150 if (xattr_len == 21) {
154 unsigned int zero = 0; 151 unsigned int zero = 0;
155 if (!memcmp(&xattr_value->digest[16], &zero, 4)) 152 if (!memcmp(&xattr_value->digest[16], &zero, 4))
156 hash->algo = HASH_ALGO_MD5; 153 return HASH_ALGO_MD5;
157 else 154 else
158 hash->algo = HASH_ALGO_SHA1; 155 return HASH_ALGO_SHA1;
159 } else if (xattr_len == 17) 156 } else if (xattr_len == 17)
160 hash->algo = HASH_ALGO_MD5; 157 return HASH_ALGO_MD5;
161 break; 158 break;
162 } 159 }
160
161 /* return default hash algo */
162 return ima_hash_algo;
163} 163}
164 164
165int ima_read_xattr(struct dentry *dentry, 165int ima_read_xattr(struct dentry *dentry,
@@ -182,7 +182,8 @@ int ima_read_xattr(struct dentry *dentry,
182 * 182 *
183 * Return 0 on success, error code otherwise 183 * Return 0 on success, error code otherwise
184 */ 184 */
185int ima_appraise_measurement(int func, struct integrity_iint_cache *iint, 185int ima_appraise_measurement(enum ima_hooks func,
186 struct integrity_iint_cache *iint,
186 struct file *file, const unsigned char *filename, 187 struct file *file, const unsigned char *filename,
187 struct evm_ima_xattr_data *xattr_value, 188 struct evm_ima_xattr_data *xattr_value,
188 int xattr_len, int opened) 189 int xattr_len, int opened)
@@ -296,7 +297,7 @@ void ima_update_xattr(struct integrity_iint_cache *iint, struct file *file)
296 if (iint->flags & IMA_DIGSIG) 297 if (iint->flags & IMA_DIGSIG)
297 return; 298 return;
298 299
299 rc = ima_collect_measurement(iint, file, NULL, NULL); 300 rc = ima_collect_measurement(iint, file, NULL, 0, ima_hash_algo);
300 if (rc < 0) 301 if (rc < 0)
301 return; 302 return;
302 303
diff --git a/security/integrity/ima/ima_crypto.c b/security/integrity/ima/ima_crypto.c
index 6eb62936c672..38f2ed830dd6 100644
--- a/security/integrity/ima/ima_crypto.c
+++ b/security/integrity/ima/ima_crypto.c
@@ -24,7 +24,7 @@
24#include <linux/err.h> 24#include <linux/err.h>
25#include <linux/slab.h> 25#include <linux/slab.h>
26#include <crypto/hash.h> 26#include <crypto/hash.h>
27#include <crypto/hash_info.h> 27
28#include "ima.h" 28#include "ima.h"
29 29
30struct ahash_completion { 30struct ahash_completion {
@@ -519,6 +519,124 @@ int ima_calc_field_array_hash(struct ima_field_data *field_data,
519 return rc; 519 return rc;
520} 520}
521 521
522static int calc_buffer_ahash_atfm(const void *buf, loff_t len,
523 struct ima_digest_data *hash,
524 struct crypto_ahash *tfm)
525{
526 struct ahash_request *req;
527 struct scatterlist sg;
528 struct ahash_completion res;
529 int rc, ahash_rc = 0;
530
531 hash->length = crypto_ahash_digestsize(tfm);
532
533 req = ahash_request_alloc(tfm, GFP_KERNEL);
534 if (!req)
535 return -ENOMEM;
536
537 init_completion(&res.completion);
538 ahash_request_set_callback(req, CRYPTO_TFM_REQ_MAY_BACKLOG |
539 CRYPTO_TFM_REQ_MAY_SLEEP,
540 ahash_complete, &res);
541
542 rc = ahash_wait(crypto_ahash_init(req), &res);
543 if (rc)
544 goto out;
545
546 sg_init_one(&sg, buf, len);
547 ahash_request_set_crypt(req, &sg, NULL, len);
548
549 ahash_rc = crypto_ahash_update(req);
550
551 /* wait for the update request to complete */
552 rc = ahash_wait(ahash_rc, &res);
553 if (!rc) {
554 ahash_request_set_crypt(req, NULL, hash->digest, 0);
555 rc = ahash_wait(crypto_ahash_final(req), &res);
556 }
557out:
558 ahash_request_free(req);
559 return rc;
560}
561
562static int calc_buffer_ahash(const void *buf, loff_t len,
563 struct ima_digest_data *hash)
564{
565 struct crypto_ahash *tfm;
566 int rc;
567
568 tfm = ima_alloc_atfm(hash->algo);
569 if (IS_ERR(tfm))
570 return PTR_ERR(tfm);
571
572 rc = calc_buffer_ahash_atfm(buf, len, hash, tfm);
573
574 ima_free_atfm(tfm);
575
576 return rc;
577}
578
579static int calc_buffer_shash_tfm(const void *buf, loff_t size,
580 struct ima_digest_data *hash,
581 struct crypto_shash *tfm)
582{
583 SHASH_DESC_ON_STACK(shash, tfm);
584 unsigned int len;
585 int rc;
586
587 shash->tfm = tfm;
588 shash->flags = 0;
589
590 hash->length = crypto_shash_digestsize(tfm);
591
592 rc = crypto_shash_init(shash);
593 if (rc != 0)
594 return rc;
595
596 while (size) {
597 len = size < PAGE_SIZE ? size : PAGE_SIZE;
598 rc = crypto_shash_update(shash, buf, len);
599 if (rc)
600 break;
601 buf += len;
602 size -= len;
603 }
604
605 if (!rc)
606 rc = crypto_shash_final(shash, hash->digest);
607 return rc;
608}
609
610static int calc_buffer_shash(const void *buf, loff_t len,
611 struct ima_digest_data *hash)
612{
613 struct crypto_shash *tfm;
614 int rc;
615
616 tfm = ima_alloc_tfm(hash->algo);
617 if (IS_ERR(tfm))
618 return PTR_ERR(tfm);
619
620 rc = calc_buffer_shash_tfm(buf, len, hash, tfm);
621
622 ima_free_tfm(tfm);
623 return rc;
624}
625
626int ima_calc_buffer_hash(const void *buf, loff_t len,
627 struct ima_digest_data *hash)
628{
629 int rc;
630
631 if (ima_ahash_minsize && len >= ima_ahash_minsize) {
632 rc = calc_buffer_ahash(buf, len, hash);
633 if (!rc)
634 return 0;
635 }
636
637 return calc_buffer_shash(buf, len, hash);
638}
639
522static void __init ima_pcrread(int idx, u8 *pcr) 640static void __init ima_pcrread(int idx, u8 *pcr)
523{ 641{
524 if (!ima_used_chip) 642 if (!ima_used_chip)
diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
index f355231997b4..60d011aaec38 100644
--- a/security/integrity/ima/ima_fs.c
+++ b/security/integrity/ima/ima_fs.c
@@ -22,6 +22,7 @@
22#include <linux/rculist.h> 22#include <linux/rculist.h>
23#include <linux/rcupdate.h> 23#include <linux/rcupdate.h>
24#include <linux/parser.h> 24#include <linux/parser.h>
25#include <linux/vmalloc.h>
25 26
26#include "ima.h" 27#include "ima.h"
27 28
@@ -258,6 +259,43 @@ static const struct file_operations ima_ascii_measurements_ops = {
258 .release = seq_release, 259 .release = seq_release,
259}; 260};
260 261
262static ssize_t ima_read_policy(char *path)
263{
264 void *data;
265 char *datap;
266 loff_t size;
267 int rc, pathlen = strlen(path);
268
269 char *p;
270
271 /* remove \n */
272 datap = path;
273 strsep(&datap, "\n");
274
275 rc = kernel_read_file_from_path(path, &data, &size, 0, READING_POLICY);
276 if (rc < 0) {
277 pr_err("Unable to open file: %s (%d)", path, rc);
278 return rc;
279 }
280
281 datap = data;
282 while (size > 0 && (p = strsep(&datap, "\n"))) {
283 pr_debug("rule: %s\n", p);
284 rc = ima_parse_add_rule(p);
285 if (rc < 0)
286 break;
287 size -= rc;
288 }
289
290 vfree(data);
291 if (rc < 0)
292 return rc;
293 else if (size)
294 return -EINVAL;
295 else
296 return pathlen;
297}
298
261static ssize_t ima_write_policy(struct file *file, const char __user *buf, 299static ssize_t ima_write_policy(struct file *file, const char __user *buf,
262 size_t datalen, loff_t *ppos) 300 size_t datalen, loff_t *ppos)
263{ 301{
@@ -286,9 +324,20 @@ static ssize_t ima_write_policy(struct file *file, const char __user *buf,
286 result = mutex_lock_interruptible(&ima_write_mutex); 324 result = mutex_lock_interruptible(&ima_write_mutex);
287 if (result < 0) 325 if (result < 0)
288 goto out_free; 326 goto out_free;
289 result = ima_parse_add_rule(data);
290 mutex_unlock(&ima_write_mutex);
291 327
328 if (data[0] == '/') {
329 result = ima_read_policy(data);
330 } else if (ima_appraise & IMA_APPRAISE_POLICY) {
331 pr_err("IMA: signed policy file (specified as an absolute pathname) required\n");
332 integrity_audit_msg(AUDIT_INTEGRITY_STATUS, NULL, NULL,
333 "policy_update", "signed policy required",
334 1, 0);
335 if (ima_appraise & IMA_APPRAISE_ENFORCE)
336 result = -EACCES;
337 } else {
338 result = ima_parse_add_rule(data);
339 }
340 mutex_unlock(&ima_write_mutex);
292out_free: 341out_free:
293 kfree(data); 342 kfree(data);
294out: 343out:
diff --git a/security/integrity/ima/ima_init.c b/security/integrity/ima/ima_init.c
index bd79f254d204..5d679a685616 100644
--- a/security/integrity/ima/ima_init.c
+++ b/security/integrity/ima/ima_init.c
@@ -21,7 +21,7 @@
21#include <linux/scatterlist.h> 21#include <linux/scatterlist.h>
22#include <linux/slab.h> 22#include <linux/slab.h>
23#include <linux/err.h> 23#include <linux/err.h>
24#include <crypto/hash_info.h> 24
25#include "ima.h" 25#include "ima.h"
26 26
27/* name for boot aggregate entry */ 27/* name for boot aggregate entry */
diff --git a/security/integrity/ima/ima_main.c b/security/integrity/ima/ima_main.c
index 9d96551d0196..391f41751021 100644
--- a/security/integrity/ima/ima_main.c
+++ b/security/integrity/ima/ima_main.c
@@ -24,7 +24,6 @@
24#include <linux/slab.h> 24#include <linux/slab.h>
25#include <linux/xattr.h> 25#include <linux/xattr.h>
26#include <linux/ima.h> 26#include <linux/ima.h>
27#include <crypto/hash_info.h>
28 27
29#include "ima.h" 28#include "ima.h"
30 29
@@ -154,8 +153,8 @@ void ima_file_free(struct file *file)
154 ima_check_last_writer(iint, inode, file); 153 ima_check_last_writer(iint, inode, file);
155} 154}
156 155
157static int process_measurement(struct file *file, int mask, int function, 156static int process_measurement(struct file *file, char *buf, loff_t size,
158 int opened) 157 int mask, enum ima_hooks func, int opened)
159{ 158{
160 struct inode *inode = file_inode(file); 159 struct inode *inode = file_inode(file);
161 struct integrity_iint_cache *iint = NULL; 160 struct integrity_iint_cache *iint = NULL;
@@ -163,9 +162,10 @@ static int process_measurement(struct file *file, int mask, int function,
163 char *pathbuf = NULL; 162 char *pathbuf = NULL;
164 const char *pathname = NULL; 163 const char *pathname = NULL;
165 int rc = -ENOMEM, action, must_appraise; 164 int rc = -ENOMEM, action, must_appraise;
166 struct evm_ima_xattr_data *xattr_value = NULL, **xattr_ptr = NULL; 165 struct evm_ima_xattr_data *xattr_value = NULL;
167 int xattr_len = 0; 166 int xattr_len = 0;
168 bool violation_check; 167 bool violation_check;
168 enum hash_algo hash_algo;
169 169
170 if (!ima_policy_flag || !S_ISREG(inode->i_mode)) 170 if (!ima_policy_flag || !S_ISREG(inode->i_mode))
171 return 0; 171 return 0;
@@ -174,8 +174,8 @@ static int process_measurement(struct file *file, int mask, int function,
174 * bitmask based on the appraise/audit/measurement policy. 174 * bitmask based on the appraise/audit/measurement policy.
175 * Included is the appraise submask. 175 * Included is the appraise submask.
176 */ 176 */
177 action = ima_get_action(inode, mask, function); 177 action = ima_get_action(inode, mask, func);
178 violation_check = ((function == FILE_CHECK || function == MMAP_CHECK) && 178 violation_check = ((func == FILE_CHECK || func == MMAP_CHECK) &&
179 (ima_policy_flag & IMA_MEASURE)); 179 (ima_policy_flag & IMA_MEASURE));
180 if (!action && !violation_check) 180 if (!action && !violation_check)
181 return 0; 181 return 0;
@@ -184,7 +184,7 @@ static int process_measurement(struct file *file, int mask, int function,
184 184
185 /* Is the appraise rule hook specific? */ 185 /* Is the appraise rule hook specific? */
186 if (action & IMA_FILE_APPRAISE) 186 if (action & IMA_FILE_APPRAISE)
187 function = FILE_CHECK; 187 func = FILE_CHECK;
188 188
189 inode_lock(inode); 189 inode_lock(inode);
190 190
@@ -214,16 +214,19 @@ static int process_measurement(struct file *file, int mask, int function,
214 /* Nothing to do, just return existing appraised status */ 214 /* Nothing to do, just return existing appraised status */
215 if (!action) { 215 if (!action) {
216 if (must_appraise) 216 if (must_appraise)
217 rc = ima_get_cache_status(iint, function); 217 rc = ima_get_cache_status(iint, func);
218 goto out_digsig; 218 goto out_digsig;
219 } 219 }
220 220
221 template_desc = ima_template_desc_current(); 221 template_desc = ima_template_desc_current();
222 if ((action & IMA_APPRAISE_SUBMASK) || 222 if ((action & IMA_APPRAISE_SUBMASK) ||
223 strcmp(template_desc->name, IMA_TEMPLATE_IMA_NAME) != 0) 223 strcmp(template_desc->name, IMA_TEMPLATE_IMA_NAME) != 0)
224 xattr_ptr = &xattr_value; 224 /* read 'security.ima' */
225 xattr_len = ima_read_xattr(file->f_path.dentry, &xattr_value);
225 226
226 rc = ima_collect_measurement(iint, file, xattr_ptr, &xattr_len); 227 hash_algo = ima_get_hash_algo(xattr_value, xattr_len);
228
229 rc = ima_collect_measurement(iint, file, buf, size, hash_algo);
227 if (rc != 0) { 230 if (rc != 0) {
228 if (file->f_flags & O_DIRECT) 231 if (file->f_flags & O_DIRECT)
229 rc = (iint->flags & IMA_PERMIT_DIRECTIO) ? 0 : -EACCES; 232 rc = (iint->flags & IMA_PERMIT_DIRECTIO) ? 0 : -EACCES;
@@ -237,7 +240,7 @@ static int process_measurement(struct file *file, int mask, int function,
237 ima_store_measurement(iint, file, pathname, 240 ima_store_measurement(iint, file, pathname,
238 xattr_value, xattr_len); 241 xattr_value, xattr_len);
239 if (action & IMA_APPRAISE_SUBMASK) 242 if (action & IMA_APPRAISE_SUBMASK)
240 rc = ima_appraise_measurement(function, iint, file, pathname, 243 rc = ima_appraise_measurement(func, iint, file, pathname,
241 xattr_value, xattr_len, opened); 244 xattr_value, xattr_len, opened);
242 if (action & IMA_AUDIT) 245 if (action & IMA_AUDIT)
243 ima_audit_measurement(iint, pathname); 246 ima_audit_measurement(iint, pathname);
@@ -270,7 +273,8 @@ out:
270int ima_file_mmap(struct file *file, unsigned long prot) 273int ima_file_mmap(struct file *file, unsigned long prot)
271{ 274{
272 if (file && (prot & PROT_EXEC)) 275 if (file && (prot & PROT_EXEC))
273 return process_measurement(file, MAY_EXEC, MMAP_CHECK, 0); 276 return process_measurement(file, NULL, 0, MAY_EXEC,
277 MMAP_CHECK, 0);
274 return 0; 278 return 0;
275} 279}
276 280
@@ -289,7 +293,8 @@ int ima_file_mmap(struct file *file, unsigned long prot)
289 */ 293 */
290int ima_bprm_check(struct linux_binprm *bprm) 294int ima_bprm_check(struct linux_binprm *bprm)
291{ 295{
292 return process_measurement(bprm->file, MAY_EXEC, BPRM_CHECK, 0); 296 return process_measurement(bprm->file, NULL, 0, MAY_EXEC,
297 BPRM_CHECK, 0);
293} 298}
294 299
295/** 300/**
@@ -304,24 +309,26 @@ int ima_bprm_check(struct linux_binprm *bprm)
304 */ 309 */
305int ima_file_check(struct file *file, int mask, int opened) 310int ima_file_check(struct file *file, int mask, int opened)
306{ 311{
307 return process_measurement(file, 312 return process_measurement(file, NULL, 0,
308 mask & (MAY_READ | MAY_WRITE | MAY_EXEC), 313 mask & (MAY_READ | MAY_WRITE | MAY_EXEC),
309 FILE_CHECK, opened); 314 FILE_CHECK, opened);
310} 315}
311EXPORT_SYMBOL_GPL(ima_file_check); 316EXPORT_SYMBOL_GPL(ima_file_check);
312 317
313/** 318/**
314 * ima_module_check - based on policy, collect/store/appraise measurement. 319 * ima_read_file - pre-measure/appraise hook decision based on policy
315 * @file: pointer to the file to be measured/appraised 320 * @file: pointer to the file to be measured/appraised/audit
321 * @read_id: caller identifier
316 * 322 *
317 * Measure/appraise kernel modules based on policy. 323 * Permit reading a file based on policy. The policy rules are written
324 * in terms of the policy identifier. Appraising the integrity of
325 * a file requires a file descriptor.
318 * 326 *
319 * On success return 0. On integrity appraisal error, assuming the file 327 * For permission return 0, otherwise return -EACCES.
320 * is in policy and IMA-appraisal is in enforcing mode, return -EACCES.
321 */ 328 */
322int ima_module_check(struct file *file) 329int ima_read_file(struct file *file, enum kernel_read_file_id read_id)
323{ 330{
324 if (!file) { 331 if (!file && read_id == READING_MODULE) {
325#ifndef CONFIG_MODULE_SIG_FORCE 332#ifndef CONFIG_MODULE_SIG_FORCE
326 if ((ima_appraise & IMA_APPRAISE_MODULES) && 333 if ((ima_appraise & IMA_APPRAISE_MODULES) &&
327 (ima_appraise & IMA_APPRAISE_ENFORCE)) 334 (ima_appraise & IMA_APPRAISE_ENFORCE))
@@ -329,18 +336,53 @@ int ima_module_check(struct file *file)
329#endif 336#endif
330 return 0; /* We rely on module signature checking */ 337 return 0; /* We rely on module signature checking */
331 } 338 }
332 return process_measurement(file, MAY_EXEC, MODULE_CHECK, 0); 339 return 0;
333} 340}
334 341
335int ima_fw_from_file(struct file *file, char *buf, size_t size) 342static int read_idmap[READING_MAX_ID] = {
343 [READING_FIRMWARE] = FIRMWARE_CHECK,
344 [READING_MODULE] = MODULE_CHECK,
345 [READING_KEXEC_IMAGE] = KEXEC_KERNEL_CHECK,
346 [READING_KEXEC_INITRAMFS] = KEXEC_INITRAMFS_CHECK,
347 [READING_POLICY] = POLICY_CHECK
348};
349
350/**
351 * ima_post_read_file - in memory collect/appraise/audit measurement
352 * @file: pointer to the file to be measured/appraised/audit
353 * @buf: pointer to in memory file contents
354 * @size: size of in memory file contents
355 * @read_id: caller identifier
356 *
357 * Measure/appraise/audit in memory file based on policy. Policy rules
358 * are written in terms of a policy identifier.
359 *
360 * On success return 0. On integrity appraisal error, assuming the file
361 * is in policy and IMA-appraisal is in enforcing mode, return -EACCES.
362 */
363int ima_post_read_file(struct file *file, void *buf, loff_t size,
364 enum kernel_read_file_id read_id)
336{ 365{
337 if (!file) { 366 enum ima_hooks func;
367
368 if (!file && read_id == READING_FIRMWARE) {
338 if ((ima_appraise & IMA_APPRAISE_FIRMWARE) && 369 if ((ima_appraise & IMA_APPRAISE_FIRMWARE) &&
339 (ima_appraise & IMA_APPRAISE_ENFORCE)) 370 (ima_appraise & IMA_APPRAISE_ENFORCE))
340 return -EACCES; /* INTEGRITY_UNKNOWN */ 371 return -EACCES; /* INTEGRITY_UNKNOWN */
341 return 0; 372 return 0;
342 } 373 }
343 return process_measurement(file, MAY_EXEC, FIRMWARE_CHECK, 0); 374
375 if (!file && read_id == READING_MODULE) /* MODULE_SIG_FORCE enabled */
376 return 0;
377
378 if (!file || !buf || size == 0) { /* should never happen */
379 if (ima_appraise & IMA_APPRAISE_ENFORCE)
380 return -EACCES;
381 return 0;
382 }
383
384 func = read_idmap[read_id] ?: FILE_CHECK;
385 return process_measurement(file, buf, size, MAY_READ, func, 0);
344} 386}
345 387
346static int __init init_ima(void) 388static int __init init_ima(void)
diff --git a/security/integrity/ima/ima_policy.c b/security/integrity/ima/ima_policy.c
index 0a3b781f18e5..be09e2cacf82 100644
--- a/security/integrity/ima/ima_policy.c
+++ b/security/integrity/ima/ima_policy.c
@@ -12,6 +12,7 @@
12 */ 12 */
13#include <linux/module.h> 13#include <linux/module.h>
14#include <linux/list.h> 14#include <linux/list.h>
15#include <linux/fs.h>
15#include <linux/security.h> 16#include <linux/security.h>
16#include <linux/magic.h> 17#include <linux/magic.h>
17#include <linux/parser.h> 18#include <linux/parser.h>
@@ -113,6 +114,7 @@ static struct ima_rule_entry default_measurement_rules[] = {
113 .uid = GLOBAL_ROOT_UID, .flags = IMA_FUNC | IMA_INMASK | IMA_UID}, 114 .uid = GLOBAL_ROOT_UID, .flags = IMA_FUNC | IMA_INMASK | IMA_UID},
114 {.action = MEASURE, .func = MODULE_CHECK, .flags = IMA_FUNC}, 115 {.action = MEASURE, .func = MODULE_CHECK, .flags = IMA_FUNC},
115 {.action = MEASURE, .func = FIRMWARE_CHECK, .flags = IMA_FUNC}, 116 {.action = MEASURE, .func = FIRMWARE_CHECK, .flags = IMA_FUNC},
117 {.action = MEASURE, .func = POLICY_CHECK, .flags = IMA_FUNC},
116}; 118};
117 119
118static struct ima_rule_entry default_appraise_rules[] = { 120static struct ima_rule_entry default_appraise_rules[] = {
@@ -127,6 +129,10 @@ static struct ima_rule_entry default_appraise_rules[] = {
127 {.action = DONT_APPRAISE, .fsmagic = SELINUX_MAGIC, .flags = IMA_FSMAGIC}, 129 {.action = DONT_APPRAISE, .fsmagic = SELINUX_MAGIC, .flags = IMA_FSMAGIC},
128 {.action = DONT_APPRAISE, .fsmagic = NSFS_MAGIC, .flags = IMA_FSMAGIC}, 130 {.action = DONT_APPRAISE, .fsmagic = NSFS_MAGIC, .flags = IMA_FSMAGIC},
129 {.action = DONT_APPRAISE, .fsmagic = CGROUP_SUPER_MAGIC, .flags = IMA_FSMAGIC}, 131 {.action = DONT_APPRAISE, .fsmagic = CGROUP_SUPER_MAGIC, .flags = IMA_FSMAGIC},
132#ifdef CONFIG_IMA_WRITE_POLICY
133 {.action = APPRAISE, .func = POLICY_CHECK,
134 .flags = IMA_FUNC | IMA_DIGSIG_REQUIRED},
135#endif
130#ifndef CONFIG_IMA_APPRAISE_SIGNED_INIT 136#ifndef CONFIG_IMA_APPRAISE_SIGNED_INIT
131 {.action = APPRAISE, .fowner = GLOBAL_ROOT_UID, .flags = IMA_FOWNER}, 137 {.action = APPRAISE, .fowner = GLOBAL_ROOT_UID, .flags = IMA_FOWNER},
132#else 138#else
@@ -207,8 +213,8 @@ static void ima_lsm_update_rules(void)
207 * 213 *
208 * Returns true on rule match, false on failure. 214 * Returns true on rule match, false on failure.
209 */ 215 */
210static bool ima_match_rules(struct ima_rule_entry *rule, 216static bool ima_match_rules(struct ima_rule_entry *rule, struct inode *inode,
211 struct inode *inode, enum ima_hooks func, int mask) 217 enum ima_hooks func, int mask)
212{ 218{
213 struct task_struct *tsk = current; 219 struct task_struct *tsk = current;
214 const struct cred *cred = current_cred(); 220 const struct cred *cred = current_cred();
@@ -289,7 +295,7 @@ retry:
289 * In addition to knowing that we need to appraise the file in general, 295 * In addition to knowing that we need to appraise the file in general,
290 * we need to differentiate between calling hooks, for hook specific rules. 296 * we need to differentiate between calling hooks, for hook specific rules.
291 */ 297 */
292static int get_subaction(struct ima_rule_entry *rule, int func) 298static int get_subaction(struct ima_rule_entry *rule, enum ima_hooks func)
293{ 299{
294 if (!(rule->flags & IMA_FUNC)) 300 if (!(rule->flags & IMA_FUNC))
295 return IMA_FILE_APPRAISE; 301 return IMA_FILE_APPRAISE;
@@ -299,13 +305,12 @@ static int get_subaction(struct ima_rule_entry *rule, int func)
299 return IMA_MMAP_APPRAISE; 305 return IMA_MMAP_APPRAISE;
300 case BPRM_CHECK: 306 case BPRM_CHECK:
301 return IMA_BPRM_APPRAISE; 307 return IMA_BPRM_APPRAISE;
302 case MODULE_CHECK:
303 return IMA_MODULE_APPRAISE;
304 case FIRMWARE_CHECK:
305 return IMA_FIRMWARE_APPRAISE;
306 case FILE_CHECK: 308 case FILE_CHECK:
307 default: 309 case POST_SETATTR:
308 return IMA_FILE_APPRAISE; 310 return IMA_FILE_APPRAISE;
311 case MODULE_CHECK ... MAX_CHECK - 1:
312 default:
313 return IMA_READ_APPRAISE;
309 } 314 }
310} 315}
311 316
@@ -411,13 +416,16 @@ void __init ima_init_policy(void)
411 for (i = 0; i < appraise_entries; i++) { 416 for (i = 0; i < appraise_entries; i++) {
412 list_add_tail(&default_appraise_rules[i].list, 417 list_add_tail(&default_appraise_rules[i].list,
413 &ima_default_rules); 418 &ima_default_rules);
419 if (default_appraise_rules[i].func == POLICY_CHECK)
420 temp_ima_appraise |= IMA_APPRAISE_POLICY;
414 } 421 }
415 422
416 ima_rules = &ima_default_rules; 423 ima_rules = &ima_default_rules;
424 ima_update_policy_flag();
417} 425}
418 426
419/* Make sure we have a valid policy, at least containing some rules. */ 427/* Make sure we have a valid policy, at least containing some rules. */
420int ima_check_policy() 428int ima_check_policy(void)
421{ 429{
422 if (list_empty(&ima_temp_rules)) 430 if (list_empty(&ima_temp_rules))
423 return -EINVAL; 431 return -EINVAL;
@@ -612,6 +620,14 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
612 entry->func = MMAP_CHECK; 620 entry->func = MMAP_CHECK;
613 else if (strcmp(args[0].from, "BPRM_CHECK") == 0) 621 else if (strcmp(args[0].from, "BPRM_CHECK") == 0)
614 entry->func = BPRM_CHECK; 622 entry->func = BPRM_CHECK;
623 else if (strcmp(args[0].from, "KEXEC_KERNEL_CHECK") ==
624 0)
625 entry->func = KEXEC_KERNEL_CHECK;
626 else if (strcmp(args[0].from, "KEXEC_INITRAMFS_CHECK")
627 == 0)
628 entry->func = KEXEC_INITRAMFS_CHECK;
629 else if (strcmp(args[0].from, "POLICY_CHECK") == 0)
630 entry->func = POLICY_CHECK;
615 else 631 else
616 result = -EINVAL; 632 result = -EINVAL;
617 if (!result) 633 if (!result)
@@ -770,6 +786,8 @@ static int ima_parse_rule(char *rule, struct ima_rule_entry *entry)
770 temp_ima_appraise |= IMA_APPRAISE_MODULES; 786 temp_ima_appraise |= IMA_APPRAISE_MODULES;
771 else if (entry->func == FIRMWARE_CHECK) 787 else if (entry->func == FIRMWARE_CHECK)
772 temp_ima_appraise |= IMA_APPRAISE_FIRMWARE; 788 temp_ima_appraise |= IMA_APPRAISE_FIRMWARE;
789 else if (entry->func == POLICY_CHECK)
790 temp_ima_appraise |= IMA_APPRAISE_POLICY;
773 audit_log_format(ab, "res=%d", !result); 791 audit_log_format(ab, "res=%d", !result);
774 audit_log_end(ab); 792 audit_log_end(ab);
775 return result; 793 return result;
@@ -855,7 +873,9 @@ static char *mask_tokens[] = {
855 873
856enum { 874enum {
857 func_file = 0, func_mmap, func_bprm, 875 func_file = 0, func_mmap, func_bprm,
858 func_module, func_firmware, func_post 876 func_module, func_firmware, func_post,
877 func_kexec_kernel, func_kexec_initramfs,
878 func_policy
859}; 879};
860 880
861static char *func_tokens[] = { 881static char *func_tokens[] = {
@@ -864,6 +884,9 @@ static char *func_tokens[] = {
864 "BPRM_CHECK", 884 "BPRM_CHECK",
865 "MODULE_CHECK", 885 "MODULE_CHECK",
866 "FIRMWARE_CHECK", 886 "FIRMWARE_CHECK",
887 "KEXEC_KERNEL_CHECK",
888 "KEXEC_INITRAMFS_CHECK",
889 "POLICY_CHECK",
867 "POST_SETATTR" 890 "POST_SETATTR"
868}; 891};
869 892
@@ -903,6 +926,49 @@ void ima_policy_stop(struct seq_file *m, void *v)
903#define mt(token) mask_tokens[token] 926#define mt(token) mask_tokens[token]
904#define ft(token) func_tokens[token] 927#define ft(token) func_tokens[token]
905 928
929/*
930 * policy_func_show - display the ima_hooks policy rule
931 */
932static void policy_func_show(struct seq_file *m, enum ima_hooks func)
933{
934 char tbuf[64] = {0,};
935
936 switch (func) {
937 case FILE_CHECK:
938 seq_printf(m, pt(Opt_func), ft(func_file));
939 break;
940 case MMAP_CHECK:
941 seq_printf(m, pt(Opt_func), ft(func_mmap));
942 break;
943 case BPRM_CHECK:
944 seq_printf(m, pt(Opt_func), ft(func_bprm));
945 break;
946 case MODULE_CHECK:
947 seq_printf(m, pt(Opt_func), ft(func_module));
948 break;
949 case FIRMWARE_CHECK:
950 seq_printf(m, pt(Opt_func), ft(func_firmware));
951 break;
952 case POST_SETATTR:
953 seq_printf(m, pt(Opt_func), ft(func_post));
954 break;
955 case KEXEC_KERNEL_CHECK:
956 seq_printf(m, pt(Opt_func), ft(func_kexec_kernel));
957 break;
958 case KEXEC_INITRAMFS_CHECK:
959 seq_printf(m, pt(Opt_func), ft(func_kexec_initramfs));
960 break;
961 case POLICY_CHECK:
962 seq_printf(m, pt(Opt_func), ft(func_policy));
963 break;
964 default:
965 snprintf(tbuf, sizeof(tbuf), "%d", func);
966 seq_printf(m, pt(Opt_func), tbuf);
967 break;
968 }
969 seq_puts(m, " ");
970}
971
906int ima_policy_show(struct seq_file *m, void *v) 972int ima_policy_show(struct seq_file *m, void *v)
907{ 973{
908 struct ima_rule_entry *entry = v; 974 struct ima_rule_entry *entry = v;
@@ -924,33 +990,8 @@ int ima_policy_show(struct seq_file *m, void *v)
924 990
925 seq_puts(m, " "); 991 seq_puts(m, " ");
926 992
927 if (entry->flags & IMA_FUNC) { 993 if (entry->flags & IMA_FUNC)
928 switch (entry->func) { 994 policy_func_show(m, entry->func);
929 case FILE_CHECK:
930 seq_printf(m, pt(Opt_func), ft(func_file));
931 break;
932 case MMAP_CHECK:
933 seq_printf(m, pt(Opt_func), ft(func_mmap));
934 break;
935 case BPRM_CHECK:
936 seq_printf(m, pt(Opt_func), ft(func_bprm));
937 break;
938 case MODULE_CHECK:
939 seq_printf(m, pt(Opt_func), ft(func_module));
940 break;
941 case FIRMWARE_CHECK:
942 seq_printf(m, pt(Opt_func), ft(func_firmware));
943 break;
944 case POST_SETATTR:
945 seq_printf(m, pt(Opt_func), ft(func_post));
946 break;
947 default:
948 snprintf(tbuf, sizeof(tbuf), "%d", entry->func);
949 seq_printf(m, pt(Opt_func), tbuf);
950 break;
951 }
952 seq_puts(m, " ");
953 }
954 995
955 if (entry->flags & IMA_MASK) { 996 if (entry->flags & IMA_MASK) {
956 if (entry->mask & MAY_EXEC) 997 if (entry->mask & MAY_EXEC)
diff --git a/security/integrity/ima/ima_template.c b/security/integrity/ima/ima_template.c
index 0b7404ebfa80..febd12ed9b55 100644
--- a/security/integrity/ima/ima_template.c
+++ b/security/integrity/ima/ima_template.c
@@ -15,8 +15,6 @@
15 15
16#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt 16#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
17 17
18#include <crypto/hash_info.h>
19
20#include "ima.h" 18#include "ima.h"
21#include "ima_template_lib.h" 19#include "ima_template_lib.h"
22 20
diff --git a/security/integrity/ima/ima_template_lib.c b/security/integrity/ima/ima_template_lib.c
index 2934e3d377f1..f9bae04ba176 100644
--- a/security/integrity/ima/ima_template_lib.c
+++ b/security/integrity/ima/ima_template_lib.c
@@ -12,7 +12,6 @@
12 * File: ima_template_lib.c 12 * File: ima_template_lib.c
13 * Library of supported template fields. 13 * Library of supported template fields.
14 */ 14 */
15#include <crypto/hash_info.h>
16 15
17#include "ima_template_lib.h" 16#include "ima_template_lib.h"
18 17
diff --git a/security/integrity/integrity.h b/security/integrity/integrity.h
index 5efe2ecc538d..e08935cf343f 100644
--- a/security/integrity/integrity.h
+++ b/security/integrity/integrity.h
@@ -45,16 +45,12 @@
45#define IMA_MMAP_APPRAISED 0x00000800 45#define IMA_MMAP_APPRAISED 0x00000800
46#define IMA_BPRM_APPRAISE 0x00001000 46#define IMA_BPRM_APPRAISE 0x00001000
47#define IMA_BPRM_APPRAISED 0x00002000 47#define IMA_BPRM_APPRAISED 0x00002000
48#define IMA_MODULE_APPRAISE 0x00004000 48#define IMA_READ_APPRAISE 0x00004000
49#define IMA_MODULE_APPRAISED 0x00008000 49#define IMA_READ_APPRAISED 0x00008000
50#define IMA_FIRMWARE_APPRAISE 0x00010000
51#define IMA_FIRMWARE_APPRAISED 0x00020000
52#define IMA_APPRAISE_SUBMASK (IMA_FILE_APPRAISE | IMA_MMAP_APPRAISE | \ 50#define IMA_APPRAISE_SUBMASK (IMA_FILE_APPRAISE | IMA_MMAP_APPRAISE | \
53 IMA_BPRM_APPRAISE | IMA_MODULE_APPRAISE | \ 51 IMA_BPRM_APPRAISE | IMA_READ_APPRAISE)
54 IMA_FIRMWARE_APPRAISE)
55#define IMA_APPRAISED_SUBMASK (IMA_FILE_APPRAISED | IMA_MMAP_APPRAISED | \ 52#define IMA_APPRAISED_SUBMASK (IMA_FILE_APPRAISED | IMA_MMAP_APPRAISED | \
56 IMA_BPRM_APPRAISED | IMA_MODULE_APPRAISED | \ 53 IMA_BPRM_APPRAISED | IMA_READ_APPRAISED)
57 IMA_FIRMWARE_APPRAISED)
58 54
59enum evm_ima_xattr_type { 55enum evm_ima_xattr_type {
60 IMA_XATTR_DIGEST = 0x01, 56 IMA_XATTR_DIGEST = 0x01,
@@ -94,7 +90,7 @@ struct ima_digest_data {
94struct signature_v2_hdr { 90struct signature_v2_hdr {
95 uint8_t type; /* xattr type */ 91 uint8_t type; /* xattr type */
96 uint8_t version; /* signature format version */ 92 uint8_t version; /* signature format version */
97 uint8_t hash_algo; /* Digest algorithm [enum pkey_hash_algo] */ 93 uint8_t hash_algo; /* Digest algorithm [enum hash_algo] */
98 uint32_t keyid; /* IMA key identifier - not X509/PGP specific */ 94 uint32_t keyid; /* IMA key identifier - not X509/PGP specific */
99 uint16_t sig_size; /* signature size */ 95 uint16_t sig_size; /* signature size */
100 uint8_t sig[0]; /* signature payload */ 96 uint8_t sig[0]; /* signature payload */
@@ -109,8 +105,7 @@ struct integrity_iint_cache {
109 enum integrity_status ima_file_status:4; 105 enum integrity_status ima_file_status:4;
110 enum integrity_status ima_mmap_status:4; 106 enum integrity_status ima_mmap_status:4;
111 enum integrity_status ima_bprm_status:4; 107 enum integrity_status ima_bprm_status:4;
112 enum integrity_status ima_module_status:4; 108 enum integrity_status ima_read_status:4;
113 enum integrity_status ima_firmware_status:4;
114 enum integrity_status evm_status:4; 109 enum integrity_status evm_status:4;
115 struct ima_digest_data *ima_hash; 110 struct ima_digest_data *ima_hash;
116}; 111};
diff --git a/security/keys/big_key.c b/security/keys/big_key.c
index 907c1522ee46..c721e398893a 100644
--- a/security/keys/big_key.c
+++ b/security/keys/big_key.c
@@ -9,7 +9,6 @@
9 * 2 of the Licence, or (at your option) any later version. 9 * 2 of the Licence, or (at your option) any later version.
10 */ 10 */
11 11
12#include <linux/module.h>
13#include <linux/init.h> 12#include <linux/init.h>
14#include <linux/seq_file.h> 13#include <linux/seq_file.h>
15#include <linux/file.h> 14#include <linux/file.h>
@@ -18,8 +17,6 @@
18#include <keys/user-type.h> 17#include <keys/user-type.h>
19#include <keys/big_key-type.h> 18#include <keys/big_key-type.h>
20 19
21MODULE_LICENSE("GPL");
22
23/* 20/*
24 * Layout of key payload words. 21 * Layout of key payload words.
25 */ 22 */
@@ -212,18 +209,8 @@ long big_key_read(const struct key *key, char __user *buffer, size_t buflen)
212 return ret; 209 return ret;
213} 210}
214 211
215/*
216 * Module stuff
217 */
218static int __init big_key_init(void) 212static int __init big_key_init(void)
219{ 213{
220 return register_key_type(&key_type_big_key); 214 return register_key_type(&key_type_big_key);
221} 215}
222 216device_initcall(big_key_init);
223static void __exit big_key_cleanup(void)
224{
225 unregister_key_type(&key_type_big_key);
226}
227
228module_init(big_key_init);
229module_exit(big_key_cleanup);
diff --git a/security/keys/key.c b/security/keys/key.c
index 09ef276c4bdc..b28755131687 100644
--- a/security/keys/key.c
+++ b/security/keys/key.c
@@ -296,6 +296,8 @@ struct key *key_alloc(struct key_type *type, const char *desc,
296 key->flags |= 1 << KEY_FLAG_IN_QUOTA; 296 key->flags |= 1 << KEY_FLAG_IN_QUOTA;
297 if (flags & KEY_ALLOC_TRUSTED) 297 if (flags & KEY_ALLOC_TRUSTED)
298 key->flags |= 1 << KEY_FLAG_TRUSTED; 298 key->flags |= 1 << KEY_FLAG_TRUSTED;
299 if (flags & KEY_ALLOC_BUILT_IN)
300 key->flags |= 1 << KEY_FLAG_BUILTIN;
299 301
300#ifdef KEY_DEBUGGING 302#ifdef KEY_DEBUGGING
301 key->magic = KEY_DEBUG_MAGIC; 303 key->magic = KEY_DEBUG_MAGIC;
diff --git a/security/keys/trusted.c b/security/keys/trusted.c
index 0dcab20cdacd..90d61751ff12 100644
--- a/security/keys/trusted.c
+++ b/security/keys/trusted.c
@@ -744,6 +744,7 @@ static int getoptions(char *c, struct trusted_key_payload *pay,
744 unsigned long handle; 744 unsigned long handle;
745 unsigned long lock; 745 unsigned long lock;
746 unsigned long token_mask = 0; 746 unsigned long token_mask = 0;
747 unsigned int digest_len;
747 int i; 748 int i;
748 int tpm2; 749 int tpm2;
749 750
@@ -752,7 +753,6 @@ static int getoptions(char *c, struct trusted_key_payload *pay,
752 return tpm2; 753 return tpm2;
753 754
754 opt->hash = tpm2 ? HASH_ALGO_SHA256 : HASH_ALGO_SHA1; 755 opt->hash = tpm2 ? HASH_ALGO_SHA256 : HASH_ALGO_SHA1;
755 opt->digest_len = hash_digest_size[opt->hash];
756 756
757 while ((p = strsep(&c, " \t"))) { 757 while ((p = strsep(&c, " \t"))) {
758 if (*p == '\0' || *p == ' ' || *p == '\t') 758 if (*p == '\0' || *p == ' ' || *p == '\t')
@@ -812,8 +812,6 @@ static int getoptions(char *c, struct trusted_key_payload *pay,
812 for (i = 0; i < HASH_ALGO__LAST; i++) { 812 for (i = 0; i < HASH_ALGO__LAST; i++) {
813 if (!strcmp(args[0].from, hash_algo_name[i])) { 813 if (!strcmp(args[0].from, hash_algo_name[i])) {
814 opt->hash = i; 814 opt->hash = i;
815 opt->digest_len =
816 hash_digest_size[opt->hash];
817 break; 815 break;
818 } 816 }
819 } 817 }
@@ -825,13 +823,14 @@ static int getoptions(char *c, struct trusted_key_payload *pay,
825 } 823 }
826 break; 824 break;
827 case Opt_policydigest: 825 case Opt_policydigest:
828 if (!tpm2 || 826 digest_len = hash_digest_size[opt->hash];
829 strlen(args[0].from) != (2 * opt->digest_len)) 827 if (!tpm2 || strlen(args[0].from) != (2 * digest_len))
830 return -EINVAL; 828 return -EINVAL;
831 res = hex2bin(opt->policydigest, args[0].from, 829 res = hex2bin(opt->policydigest, args[0].from,
832 opt->digest_len); 830 digest_len);
833 if (res < 0) 831 if (res < 0)
834 return -EINVAL; 832 return -EINVAL;
833 opt->policydigest_len = digest_len;
835 break; 834 break;
836 case Opt_policyhandle: 835 case Opt_policyhandle:
837 if (!tpm2) 836 if (!tpm2)
diff --git a/security/security.c b/security/security.c
index e8ffd92ae2eb..3644b0344d29 100644
--- a/security/security.c
+++ b/security/security.c
@@ -884,31 +884,33 @@ int security_kernel_create_files_as(struct cred *new, struct inode *inode)
884 return call_int_hook(kernel_create_files_as, 0, new, inode); 884 return call_int_hook(kernel_create_files_as, 0, new, inode);
885} 885}
886 886
887int security_kernel_fw_from_file(struct file *file, char *buf, size_t size) 887int security_kernel_module_request(char *kmod_name)
888{
889 return call_int_hook(kernel_module_request, 0, kmod_name);
890}
891
892int security_kernel_read_file(struct file *file, enum kernel_read_file_id id)
888{ 893{
889 int ret; 894 int ret;
890 895
891 ret = call_int_hook(kernel_fw_from_file, 0, file, buf, size); 896 ret = call_int_hook(kernel_read_file, 0, file, id);
892 if (ret) 897 if (ret)
893 return ret; 898 return ret;
894 return ima_fw_from_file(file, buf, size); 899 return ima_read_file(file, id);
895}
896EXPORT_SYMBOL_GPL(security_kernel_fw_from_file);
897
898int security_kernel_module_request(char *kmod_name)
899{
900 return call_int_hook(kernel_module_request, 0, kmod_name);
901} 900}
901EXPORT_SYMBOL_GPL(security_kernel_read_file);
902 902
903int security_kernel_module_from_file(struct file *file) 903int security_kernel_post_read_file(struct file *file, char *buf, loff_t size,
904 enum kernel_read_file_id id)
904{ 905{
905 int ret; 906 int ret;
906 907
907 ret = call_int_hook(kernel_module_from_file, 0, file); 908 ret = call_int_hook(kernel_post_read_file, 0, file, buf, size, id);
908 if (ret) 909 if (ret)
909 return ret; 910 return ret;
910 return ima_module_check(file); 911 return ima_post_read_file(file, buf, size, id);
911} 912}
913EXPORT_SYMBOL_GPL(security_kernel_post_read_file);
912 914
913int security_task_fix_setuid(struct cred *new, const struct cred *old, 915int security_task_fix_setuid(struct cred *new, const struct cred *old,
914 int flags) 916 int flags)
@@ -1691,12 +1693,12 @@ struct security_hook_heads security_hook_heads = {
1691 LIST_HEAD_INIT(security_hook_heads.kernel_act_as), 1693 LIST_HEAD_INIT(security_hook_heads.kernel_act_as),
1692 .kernel_create_files_as = 1694 .kernel_create_files_as =
1693 LIST_HEAD_INIT(security_hook_heads.kernel_create_files_as), 1695 LIST_HEAD_INIT(security_hook_heads.kernel_create_files_as),
1694 .kernel_fw_from_file =
1695 LIST_HEAD_INIT(security_hook_heads.kernel_fw_from_file),
1696 .kernel_module_request = 1696 .kernel_module_request =
1697 LIST_HEAD_INIT(security_hook_heads.kernel_module_request), 1697 LIST_HEAD_INIT(security_hook_heads.kernel_module_request),
1698 .kernel_module_from_file = 1698 .kernel_read_file =
1699 LIST_HEAD_INIT(security_hook_heads.kernel_module_from_file), 1699 LIST_HEAD_INIT(security_hook_heads.kernel_read_file),
1700 .kernel_post_read_file =
1701 LIST_HEAD_INIT(security_hook_heads.kernel_post_read_file),
1700 .task_fix_setuid = 1702 .task_fix_setuid =
1701 LIST_HEAD_INIT(security_hook_heads.task_fix_setuid), 1703 LIST_HEAD_INIT(security_hook_heads.task_fix_setuid),
1702 .task_setpgid = LIST_HEAD_INIT(security_hook_heads.task_setpgid), 1704 .task_setpgid = LIST_HEAD_INIT(security_hook_heads.task_setpgid),
diff --git a/security/selinux/Makefile b/security/selinux/Makefile
index ad5cd76ec231..3411c33e2a44 100644
--- a/security/selinux/Makefile
+++ b/security/selinux/Makefile
@@ -13,7 +13,7 @@ selinux-$(CONFIG_SECURITY_NETWORK_XFRM) += xfrm.o
13 13
14selinux-$(CONFIG_NETLABEL) += netlabel.o 14selinux-$(CONFIG_NETLABEL) += netlabel.o
15 15
16ccflags-y := -Isecurity/selinux -Isecurity/selinux/include 16ccflags-y := -I$(srctree)/security/selinux -I$(srctree)/security/selinux/include
17 17
18$(addprefix $(obj)/,$(selinux-y)): $(obj)/flask.h 18$(addprefix $(obj)/,$(selinux-y)): $(obj)/flask.h
19 19
diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
index 2d6e9bdea398..11f79013ae1f 100644
--- a/security/smack/smack_lsm.c
+++ b/security/smack/smack_lsm.c
@@ -1442,9 +1442,13 @@ static int smack_inode_removexattr(struct dentry *dentry, const char *name)
1442 * Don't do anything special for these. 1442 * Don't do anything special for these.
1443 * XATTR_NAME_SMACKIPIN 1443 * XATTR_NAME_SMACKIPIN
1444 * XATTR_NAME_SMACKIPOUT 1444 * XATTR_NAME_SMACKIPOUT
1445 * XATTR_NAME_SMACKEXEC
1446 */ 1445 */
1447 if (strcmp(name, XATTR_NAME_SMACK) == 0) 1446 if (strcmp(name, XATTR_NAME_SMACK) == 0) {
1447 struct super_block *sbp = d_backing_inode(dentry)->i_sb;
1448 struct superblock_smack *sbsp = sbp->s_security;
1449
1450 isp->smk_inode = sbsp->smk_default;
1451 } else if (strcmp(name, XATTR_NAME_SMACKEXEC) == 0)
1448 isp->smk_task = NULL; 1452 isp->smk_task = NULL;
1449 else if (strcmp(name, XATTR_NAME_SMACKMMAP) == 0) 1453 else if (strcmp(name, XATTR_NAME_SMACKMMAP) == 0)
1450 isp->smk_mmap = NULL; 1454 isp->smk_mmap = NULL;
@@ -1545,12 +1549,8 @@ static void smack_inode_getsecid(struct inode *inode, u32 *secid)
1545 * File Hooks 1549 * File Hooks
1546 */ 1550 */
1547 1551
1548/** 1552/*
1549 * smack_file_permission - Smack check on file operations 1553 * There is no smack_file_permission hook
1550 * @file: unused
1551 * @mask: unused
1552 *
1553 * Returns 0
1554 * 1554 *
1555 * Should access checks be done on each read or write? 1555 * Should access checks be done on each read or write?
1556 * UNICOS and SELinux say yes. 1556 * UNICOS and SELinux say yes.
@@ -1559,10 +1559,6 @@ static void smack_inode_getsecid(struct inode *inode, u32 *secid)
1559 * I'll say no for now. Smack does not do the frequent 1559 * I'll say no for now. Smack does not do the frequent
1560 * label changing that SELinux does. 1560 * label changing that SELinux does.
1561 */ 1561 */
1562static int smack_file_permission(struct file *file, int mask)
1563{
1564 return 0;
1565}
1566 1562
1567/** 1563/**
1568 * smack_file_alloc_security - assign a file security blob 1564 * smack_file_alloc_security - assign a file security blob
@@ -4503,16 +4499,10 @@ static int smack_audit_rule_match(u32 secid, u32 field, u32 op, void *vrule,
4503 return 0; 4499 return 0;
4504} 4500}
4505 4501
4506/** 4502/*
4507 * smack_audit_rule_free - free smack rule representation 4503 * There is no need for a smack_audit_rule_free hook.
4508 * @vrule: rule to be freed.
4509 *
4510 * No memory was allocated. 4504 * No memory was allocated.
4511 */ 4505 */
4512static void smack_audit_rule_free(void *vrule)
4513{
4514 /* No-op */
4515}
4516 4506
4517#endif /* CONFIG_AUDIT */ 4507#endif /* CONFIG_AUDIT */
4518 4508
@@ -4563,16 +4553,11 @@ static int smack_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
4563 return 0; 4553 return 0;
4564} 4554}
4565 4555
4566/** 4556/*
4567 * smack_release_secctx - don't do anything. 4557 * There used to be a smack_release_secctx hook
4568 * @secdata: unused 4558 * that did nothing back when hooks were in a vector.
4569 * @seclen: unused 4559 * Now that there's a list such a hook adds cost.
4570 *
4571 * Exists to make sure nothing gets done, and properly
4572 */ 4560 */
4573static void smack_release_secctx(char *secdata, u32 seclen)
4574{
4575}
4576 4561
4577static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen) 4562static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
4578{ 4563{
@@ -4631,7 +4616,6 @@ static struct security_hook_list smack_hooks[] = {
4631 LSM_HOOK_INIT(inode_listsecurity, smack_inode_listsecurity), 4616 LSM_HOOK_INIT(inode_listsecurity, smack_inode_listsecurity),
4632 LSM_HOOK_INIT(inode_getsecid, smack_inode_getsecid), 4617 LSM_HOOK_INIT(inode_getsecid, smack_inode_getsecid),
4633 4618
4634 LSM_HOOK_INIT(file_permission, smack_file_permission),
4635 LSM_HOOK_INIT(file_alloc_security, smack_file_alloc_security), 4619 LSM_HOOK_INIT(file_alloc_security, smack_file_alloc_security),
4636 LSM_HOOK_INIT(file_free_security, smack_file_free_security), 4620 LSM_HOOK_INIT(file_free_security, smack_file_free_security),
4637 LSM_HOOK_INIT(file_ioctl, smack_file_ioctl), 4621 LSM_HOOK_INIT(file_ioctl, smack_file_ioctl),
@@ -4726,13 +4710,11 @@ static struct security_hook_list smack_hooks[] = {
4726 LSM_HOOK_INIT(audit_rule_init, smack_audit_rule_init), 4710 LSM_HOOK_INIT(audit_rule_init, smack_audit_rule_init),
4727 LSM_HOOK_INIT(audit_rule_known, smack_audit_rule_known), 4711 LSM_HOOK_INIT(audit_rule_known, smack_audit_rule_known),
4728 LSM_HOOK_INIT(audit_rule_match, smack_audit_rule_match), 4712 LSM_HOOK_INIT(audit_rule_match, smack_audit_rule_match),
4729 LSM_HOOK_INIT(audit_rule_free, smack_audit_rule_free),
4730#endif /* CONFIG_AUDIT */ 4713#endif /* CONFIG_AUDIT */
4731 4714
4732 LSM_HOOK_INIT(ismaclabel, smack_ismaclabel), 4715 LSM_HOOK_INIT(ismaclabel, smack_ismaclabel),
4733 LSM_HOOK_INIT(secid_to_secctx, smack_secid_to_secctx), 4716 LSM_HOOK_INIT(secid_to_secctx, smack_secid_to_secctx),
4734 LSM_HOOK_INIT(secctx_to_secid, smack_secctx_to_secid), 4717 LSM_HOOK_INIT(secctx_to_secid, smack_secctx_to_secid),
4735 LSM_HOOK_INIT(release_secctx, smack_release_secctx),
4736 LSM_HOOK_INIT(inode_notifysecctx, smack_inode_notifysecctx), 4718 LSM_HOOK_INIT(inode_notifysecctx, smack_inode_notifysecctx),
4737 LSM_HOOK_INIT(inode_setsecctx, smack_inode_setsecctx), 4719 LSM_HOOK_INIT(inode_setsecctx, smack_inode_setsecctx),
4738 LSM_HOOK_INIT(inode_getsecctx, smack_inode_getsecctx), 4720 LSM_HOOK_INIT(inode_getsecctx, smack_inode_getsecctx),