@@ -124,24 +124,48 @@ static bool __init lsm_order_exists(struct lsm_info *lsm)
124124 return false;
125125}
126126
127- /* Append an LSM to the list of ordered LSMs to initialize. */
128- static int last_lsm __initdata ;
129- static void __init append_ordered_lsm (struct lsm_info * lsm , const char * from )
127+ /**
128+ * lsm_order_append - Append a LSM to the ordered list
129+ * @lsm: LSM definition
130+ * @src: source of the addition
131+ *
132+ * Append @lsm to the enabled LSM array after ensuring that it hasn't been
133+ * explicitly disabled, is a duplicate entry, or would run afoul of the
134+ * LSM_FLAG_EXCLUSIVE logic.
135+ */
136+ static void __init lsm_order_append (struct lsm_info * lsm , const char * src )
130137{
131138 /* Ignore duplicate selections. */
132139 if (lsm_order_exists (lsm ))
133140 return ;
134141
135- if (WARN (last_lsm == MAX_LSM_COUNT , "%s: out of LSM static calls!?\n" , from ))
136- return ;
142+ /* Skip explicitly disabled LSMs. */
143+ if (lsm -> enabled && !lsm_is_enabled (lsm ))
144+ goto out ;
137145
138- /* Enable this LSM, if it is not already set. */
139- if (!lsm -> enabled )
140- lsm -> enabled = & lsm_enabled_true ;
141- lsm_order [last_lsm ] = lsm ;
142- lsm_idlist [last_lsm ++ ] = lsm -> id ;
146+ if (WARN (lsm_active_cnt == MAX_LSM_COUNT ,
147+ "%s: out of LSM static calls!?\n" , src )) {
148+ lsm_enabled_set (lsm , false);
149+ goto out ;
150+ }
151+
152+ if (lsm -> flags & LSM_FLAG_EXCLUSIVE ) {
153+ if (lsm_exclusive ) {
154+ init_debug ("exclusive disabled: %s\n" , lsm -> id -> name );
155+ lsm_enabled_set (lsm , false);
156+ goto out ;
157+ } else {
158+ init_debug ("exclusive chosen: %s\n" , lsm -> id -> name );
159+ lsm_exclusive = lsm ;
160+ }
161+ }
143162
144- init_debug ("%s ordered: %s (%s)\n" , from , lsm -> id -> name ,
163+ lsm_enabled_set (lsm , true);
164+ lsm_order [lsm_active_cnt ] = lsm ;
165+ lsm_idlist [lsm_active_cnt ++ ] = lsm -> id ;
166+
167+ out :
168+ init_debug ("%s ordered: %s (%s)\n" , src , lsm -> id -> name ,
145169 lsm_is_enabled (lsm ) ? "enabled" : "disabled" );
146170}
147171
@@ -163,26 +187,12 @@ static void __init lsm_set_blob_size(int *need, int *lbs)
163187 */
164188static void __init lsm_prepare (struct lsm_info * lsm )
165189{
166- struct lsm_blob_sizes * blobs ;
190+ struct lsm_blob_sizes * blobs = lsm -> blobs ;
167191
168- if (!lsm_is_enabled (lsm )) {
169- lsm_enabled_set (lsm , false);
170- return ;
171- } else if ((lsm -> flags & LSM_FLAG_EXCLUSIVE ) && lsm_exclusive ) {
172- init_debug ("exclusive disabled: %s\n" , lsm -> id -> name );
173- lsm_enabled_set (lsm , false);
192+ if (!blobs )
174193 return ;
175- }
176-
177- /* Mark the LSM as enabled. */
178- lsm_enabled_set (lsm , true);
179- if ((lsm -> flags & LSM_FLAG_EXCLUSIVE ) && !lsm_exclusive ) {
180- init_debug ("exclusive chosen: %s\n" , lsm -> id -> name );
181- lsm_exclusive = lsm ;
182- }
183194
184195 /* Register the LSM blob sizes. */
185- blobs = lsm -> blobs ;
186196 lsm_set_blob_size (& blobs -> lbs_cred , & blob_sizes .lbs_cred );
187197 lsm_set_blob_size (& blobs -> lbs_file , & blob_sizes .lbs_file );
188198 lsm_set_blob_size (& blobs -> lbs_ib , & blob_sizes .lbs_ib );
@@ -227,7 +237,7 @@ static void __init ordered_lsm_parse(const char *order, const char *origin)
227237 /* LSM_ORDER_FIRST is always first. */
228238 lsm_for_each_raw (lsm ) {
229239 if (lsm -> order == LSM_ORDER_FIRST )
230- append_ordered_lsm (lsm , " first" );
240+ lsm_order_append (lsm , " first" );
231241 }
232242
233243 /* Process "security=", if given. */
@@ -259,7 +269,7 @@ static void __init ordered_lsm_parse(const char *order, const char *origin)
259269 lsm_for_each_raw (lsm ) {
260270 if (strcmp (lsm -> id -> name , name ) == 0 ) {
261271 if (lsm -> order == LSM_ORDER_MUTABLE )
262- append_ordered_lsm (lsm , origin );
272+ lsm_order_append (lsm , origin );
263273 found = true;
264274 }
265275 }
@@ -275,14 +285,14 @@ static void __init ordered_lsm_parse(const char *order, const char *origin)
275285 if (lsm_order_exists (lsm ))
276286 continue ;
277287 if (strcmp (lsm -> id -> name , lsm_order_legacy ) == 0 )
278- append_ordered_lsm (lsm , "security=" );
288+ lsm_order_append (lsm , "security=" );
279289 }
280290 }
281291
282292 /* LSM_ORDER_LAST is always last. */
283293 lsm_for_each_raw (lsm ) {
284294 if (lsm -> order == LSM_ORDER_LAST )
285- append_ordered_lsm (lsm , " last" );
295+ lsm_order_append (lsm , " last" );
286296 }
287297
288298 /* Disable all LSMs not in the ordered list. */
@@ -415,8 +425,8 @@ int __init early_security_init(void)
415425 struct lsm_info * lsm ;
416426
417427 lsm_early_for_each_raw (lsm ) {
418- if (! lsm -> enabled )
419- lsm -> enabled = & lsm_enabled_true ;
428+ lsm_enabled_set ( lsm , true);
429+ lsm_order_append ( lsm , "early" ) ;
420430 lsm_prepare (lsm );
421431 initialize_lsm (lsm );
422432 }
0 commit comments