@@ -169,6 +169,76 @@ static void __init lsm_order_append(struct lsm_info *lsm, const char *src)
169169 lsm_pr_dbg ("enabling LSM %s:%s\n" , src , lsm -> id -> name );
170170}
171171
172+ /**
173+ * lsm_order_parse - Parse the comma delimited LSM list
174+ * @list: LSM list
175+ * @src: source of the list
176+ */
177+ static void __init lsm_order_parse (const char * list , const char * src )
178+ {
179+ struct lsm_info * lsm ;
180+ char * sep , * name , * next ;
181+
182+ /* Handle any Legacy LSM exclusions if one was specified. */
183+ if (lsm_order_legacy ) {
184+ /*
185+ * To match the original "security=" behavior, this explicitly
186+ * does NOT fallback to another Legacy Major if the selected
187+ * one was separately disabled: disable all non-matching
188+ * Legacy Major LSMs.
189+ */
190+ lsm_for_each_raw (lsm ) {
191+ if ((lsm -> flags & LSM_FLAG_LEGACY_MAJOR ) &&
192+ strcmp (lsm -> id -> name , lsm_order_legacy )) {
193+ lsm_enabled_set (lsm , false);
194+ lsm_pr_dbg ("skip legacy LSM conflict %s:%s\n" ,
195+ src , lsm -> id -> name );
196+ }
197+ }
198+ }
199+
200+ /* LSM_ORDER_FIRST */
201+ lsm_for_each_raw (lsm ) {
202+ if (lsm -> order == LSM_ORDER_FIRST )
203+ lsm_order_append (lsm , "first" );
204+ }
205+
206+ /* Normal or "mutable" LSMs */
207+ sep = kstrdup (list , GFP_KERNEL );
208+ next = sep ;
209+ /* Walk the list, looking for matching LSMs. */
210+ while ((name = strsep (& next , "," )) != NULL ) {
211+ lsm_for_each_raw (lsm ) {
212+ if (!strcmp (lsm -> id -> name , name ) &&
213+ lsm -> order == LSM_ORDER_MUTABLE )
214+ lsm_order_append (lsm , src );
215+ }
216+ }
217+ kfree (sep );
218+
219+ /* Legacy LSM if specified. */
220+ if (lsm_order_legacy ) {
221+ lsm_for_each_raw (lsm ) {
222+ if (!strcmp (lsm -> id -> name , lsm_order_legacy ))
223+ lsm_order_append (lsm , src );
224+ }
225+ }
226+
227+ /* LSM_ORDER_LAST */
228+ lsm_for_each_raw (lsm ) {
229+ if (lsm -> order == LSM_ORDER_LAST )
230+ lsm_order_append (lsm , "last" );
231+ }
232+
233+ /* Disable all LSMs not previously enabled. */
234+ lsm_for_each_raw (lsm ) {
235+ if (lsm_order_exists (lsm ))
236+ continue ;
237+ lsm_enabled_set (lsm , false);
238+ lsm_pr_dbg ("skip disabled LSM %s:%s\n" , src , lsm -> id -> name );
239+ }
240+ }
241+
172242/**
173243 * lsm_blob_size_update - Update the LSM blob size and offset information
174244 * @sz_req: the requested additional blob size
@@ -241,76 +311,6 @@ static void __init lsm_init_single(struct lsm_info *lsm)
241311 WARN (ret , "%s failed to initialize: %d\n" , lsm -> id -> name , ret );
242312}
243313
244- /**
245- * lsm_order_parse - Parse the comma delimited LSM list
246- * @list: LSM list
247- * @src: source of the list
248- */
249- static void __init lsm_order_parse (const char * list , const char * src )
250- {
251- struct lsm_info * lsm ;
252- char * sep , * name , * next ;
253-
254- /* Handle any Legacy LSM exclusions if one was specified. */
255- if (lsm_order_legacy ) {
256- /*
257- * To match the original "security=" behavior, this explicitly
258- * does NOT fallback to another Legacy Major if the selected
259- * one was separately disabled: disable all non-matching
260- * Legacy Major LSMs.
261- */
262- lsm_for_each_raw (lsm ) {
263- if ((lsm -> flags & LSM_FLAG_LEGACY_MAJOR ) &&
264- strcmp (lsm -> id -> name , lsm_order_legacy )) {
265- lsm_enabled_set (lsm , false);
266- lsm_pr_dbg ("skip legacy LSM conflict %s:%s\n" ,
267- src , lsm -> id -> name );
268- }
269- }
270- }
271-
272- /* LSM_ORDER_FIRST */
273- lsm_for_each_raw (lsm ) {
274- if (lsm -> order == LSM_ORDER_FIRST )
275- lsm_order_append (lsm , "first" );
276- }
277-
278- /* Normal or "mutable" LSMs */
279- sep = kstrdup (list , GFP_KERNEL );
280- next = sep ;
281- /* Walk the list, looking for matching LSMs. */
282- while ((name = strsep (& next , "," )) != NULL ) {
283- lsm_for_each_raw (lsm ) {
284- if (!strcmp (lsm -> id -> name , name ) &&
285- lsm -> order == LSM_ORDER_MUTABLE )
286- lsm_order_append (lsm , src );
287- }
288- }
289- kfree (sep );
290-
291- /* Legacy LSM if specified. */
292- if (lsm_order_legacy ) {
293- lsm_for_each_raw (lsm ) {
294- if (!strcmp (lsm -> id -> name , lsm_order_legacy ))
295- lsm_order_append (lsm , src );
296- }
297- }
298-
299- /* LSM_ORDER_LAST */
300- lsm_for_each_raw (lsm ) {
301- if (lsm -> order == LSM_ORDER_LAST )
302- lsm_order_append (lsm , "last" );
303- }
304-
305- /* Disable all LSMs not previously enabled. */
306- lsm_for_each_raw (lsm ) {
307- if (lsm_order_exists (lsm ))
308- continue ;
309- lsm_enabled_set (lsm , false);
310- lsm_pr_dbg ("skip disabled LSM %s:%s\n" , src , lsm -> id -> name );
311- }
312- }
313-
314314/**
315315 * lsm_static_call_init - Initialize a LSM's static calls
316316 * @hl: LSM hook list
0 commit comments