hc
2024-02-20 102a0743326a03cd1a1202ceda21e175b7d3575c
kernel/security/selinux/selinuxfs.c
....@@ -1,3 +1,4 @@
1
+// SPDX-License-Identifier: GPL-2.0-only
12 /* Updated: Karl MacMillan <kmacmillan@tresys.com>
23 *
34 * Added conditional policy language extensions
....@@ -9,9 +10,6 @@
910 * Copyright (C) 2007 Hewlett-Packard Development Company, L.P.
1011 * Copyright (C) 2003 - 2004 Tresys Technology, LLC
1112 * Copyright (C) 2004 Red Hat, Inc., James Morris <jmorris@redhat.com>
12
- * This program is free software; you can redistribute it and/or modify
13
- * it under the terms of the GNU General Public License as published by
14
- * the Free Software Foundation, version 2.
1513 */
1614
1715 #include <linux/kernel.h>
....@@ -19,8 +17,10 @@
1917 #include <linux/slab.h>
2018 #include <linux/vmalloc.h>
2119 #include <linux/fs.h>
20
+#include <linux/fs_context.h>
2221 #include <linux/mount.h>
2322 #include <linux/mutex.h>
23
+#include <linux/namei.h>
2424 #include <linux/init.h>
2525 #include <linux/string.h>
2626 #include <linux/security.h>
....@@ -75,7 +75,6 @@
7575 unsigned long last_class_ino;
7676 bool policy_opened;
7777 struct dentry *policycap_dir;
78
- struct mutex mutex;
7978 unsigned long last_ino;
8079 struct selinux_state *state;
8180 struct super_block *sb;
....@@ -89,7 +88,6 @@
8988 if (!fsi)
9089 return -ENOMEM;
9190
92
- mutex_init(&fsi->mutex);
9391 fsi->last_ino = SEL_INO_NEXT - 1;
9492 fsi->state = &selinux_state;
9593 fsi->sb = sb;
....@@ -117,6 +115,10 @@
117115 #define SEL_CLASS_INO_OFFSET 0x04000000
118116 #define SEL_POLICYCAP_INO_OFFSET 0x08000000
119117 #define SEL_INO_MASK 0x00ffffff
118
+
119
+#define BOOL_DIR_NAME "booleans"
120
+#define CLASS_DIR_NAME "class"
121
+#define POLICYCAP_DIR_NAME "policy_capabilities"
120122
121123 #define TMPBUFLEN 12
122124 static ssize_t sel_read_enforce(struct file *filp, char __user *buf,
....@@ -169,18 +171,17 @@
169171 goto out;
170172 audit_log(audit_context(), GFP_KERNEL, AUDIT_MAC_STATUS,
171173 "enforcing=%d old_enforcing=%d auid=%u ses=%u"
172
- " enabled=%d old-enabled=%d lsm=selinux res=1",
174
+ " enabled=1 old-enabled=1 lsm=selinux res=1",
173175 new_value, old_value,
174176 from_kuid(&init_user_ns, audit_get_loginuid(current)),
175
- audit_get_sessionid(current),
176
- selinux_enabled, selinux_enabled);
177
+ audit_get_sessionid(current));
177178 enforcing_set(state, new_value);
178179 if (new_value)
179180 avc_ss_reset(state->avc, 0);
180181 selnl_notify_setenforce(new_value);
181182 selinux_status_update_setenforce(state, new_value);
182183 if (!new_value)
183
- call_lsm_notifier(LSM_POLICY_CHANGE, NULL);
184
+ call_blocking_lsm_notifier(LSM_POLICY_CHANGE, NULL);
184185 }
185186 length = count;
186187 out:
....@@ -283,6 +284,13 @@
283284 int new_value;
284285 int enforcing;
285286
287
+ /* NOTE: we are now officially considering runtime disable as
288
+ * deprecated, and using it will become increasingly painful
289
+ * (e.g. sleeping/blocking) as we progress through future
290
+ * kernel releases until eventually it is removed
291
+ */
292
+ pr_err("SELinux: Runtime disable is deprecated, use selinux=0 on the kernel cmdline.\n");
293
+
286294 if (count >= PAGE_SIZE)
287295 return -ENOMEM;
288296
....@@ -305,10 +313,10 @@
305313 goto out;
306314 audit_log(audit_context(), GFP_KERNEL, AUDIT_MAC_STATUS,
307315 "enforcing=%d old_enforcing=%d auid=%u ses=%u"
308
- " enabled=%d old-enabled=%d lsm=selinux res=1",
316
+ " enabled=0 old-enabled=1 lsm=selinux res=1",
309317 enforcing, enforcing,
310318 from_kuid(&init_user_ns, audit_get_loginuid(current)),
311
- audit_get_sessionid(current), 0, 1);
319
+ audit_get_sessionid(current));
312320 }
313321
314322 length = count;
....@@ -341,13 +349,23 @@
341349 };
342350
343351 /* declaration for sel_write_load */
344
-static int sel_make_bools(struct selinux_fs_info *fsi);
345
-static int sel_make_classes(struct selinux_fs_info *fsi);
346
-static int sel_make_policycap(struct selinux_fs_info *fsi);
352
+static int sel_make_bools(struct selinux_policy *newpolicy, struct dentry *bool_dir,
353
+ unsigned int *bool_num, char ***bool_pending_names,
354
+ unsigned int **bool_pending_values);
355
+static int sel_make_classes(struct selinux_policy *newpolicy,
356
+ struct dentry *class_dir,
357
+ unsigned long *last_class_ino);
347358
348359 /* declaration for sel_make_class_dirs */
349360 static struct dentry *sel_make_dir(struct dentry *dir, const char *name,
350361 unsigned long *ino);
362
+
363
+/* declaration for sel_make_policy_nodes */
364
+static struct dentry *sel_make_disconnected_dir(struct super_block *sb,
365
+ unsigned long *ino);
366
+
367
+/* declaration for sel_make_policy_nodes */
368
+static void sel_remove_entries(struct dentry *de);
351369
352370 static ssize_t sel_read_mls(struct file *filp, char __user *buf,
353371 size_t count, loff_t *ppos)
....@@ -380,7 +398,7 @@
380398
381399 BUG_ON(filp->private_data);
382400
383
- mutex_lock(&fsi->mutex);
401
+ mutex_lock(&fsi->state->policy_mutex);
384402
385403 rc = avc_has_perm(&selinux_state,
386404 current_sid(), SECINITSID_SECURITY,
....@@ -397,25 +415,25 @@
397415 if (!plm)
398416 goto err;
399417
400
- if (i_size_read(inode) != security_policydb_len(state)) {
401
- inode_lock(inode);
402
- i_size_write(inode, security_policydb_len(state));
403
- inode_unlock(inode);
404
- }
405
-
406418 rc = security_read_policy(state, &plm->data, &plm->len);
407419 if (rc)
408420 goto err;
421
+
422
+ if ((size_t)i_size_read(inode) != plm->len) {
423
+ inode_lock(inode);
424
+ i_size_write(inode, plm->len);
425
+ inode_unlock(inode);
426
+ }
409427
410428 fsi->policy_opened = 1;
411429
412430 filp->private_data = plm;
413431
414
- mutex_unlock(&fsi->mutex);
432
+ mutex_unlock(&fsi->state->policy_mutex);
415433
416434 return 0;
417435 err:
418
- mutex_unlock(&fsi->mutex);
436
+ mutex_unlock(&fsi->state->policy_mutex);
419437
420438 if (plm)
421439 vfree(plm->data);
....@@ -503,29 +521,94 @@
503521 .llseek = generic_file_llseek,
504522 };
505523
506
-static int sel_make_policy_nodes(struct selinux_fs_info *fsi)
524
+static void sel_remove_old_bool_data(unsigned int bool_num, char **bool_names,
525
+ unsigned int *bool_values)
507526 {
508
- int ret;
527
+ u32 i;
509528
510
- ret = sel_make_bools(fsi);
529
+ /* bool_dir cleanup */
530
+ for (i = 0; i < bool_num; i++)
531
+ kfree(bool_names[i]);
532
+ kfree(bool_names);
533
+ kfree(bool_values);
534
+}
535
+
536
+static int sel_make_policy_nodes(struct selinux_fs_info *fsi,
537
+ struct selinux_policy *newpolicy)
538
+{
539
+ int ret = 0;
540
+ struct dentry *tmp_parent, *tmp_bool_dir, *tmp_class_dir, *old_dentry;
541
+ unsigned int tmp_bool_num, old_bool_num;
542
+ char **tmp_bool_names, **old_bool_names;
543
+ unsigned int *tmp_bool_values, *old_bool_values;
544
+ unsigned long tmp_ino = fsi->last_ino; /* Don't increment last_ino in this function */
545
+
546
+ tmp_parent = sel_make_disconnected_dir(fsi->sb, &tmp_ino);
547
+ if (IS_ERR(tmp_parent))
548
+ return PTR_ERR(tmp_parent);
549
+
550
+ tmp_ino = fsi->bool_dir->d_inode->i_ino - 1; /* sel_make_dir will increment and set */
551
+ tmp_bool_dir = sel_make_dir(tmp_parent, BOOL_DIR_NAME, &tmp_ino);
552
+ if (IS_ERR(tmp_bool_dir)) {
553
+ ret = PTR_ERR(tmp_bool_dir);
554
+ goto out;
555
+ }
556
+
557
+ tmp_ino = fsi->class_dir->d_inode->i_ino - 1; /* sel_make_dir will increment and set */
558
+ tmp_class_dir = sel_make_dir(tmp_parent, CLASS_DIR_NAME, &tmp_ino);
559
+ if (IS_ERR(tmp_class_dir)) {
560
+ ret = PTR_ERR(tmp_class_dir);
561
+ goto out;
562
+ }
563
+
564
+ ret = sel_make_bools(newpolicy, tmp_bool_dir, &tmp_bool_num,
565
+ &tmp_bool_names, &tmp_bool_values);
511566 if (ret) {
512567 pr_err("SELinux: failed to load policy booleans\n");
513
- return ret;
568
+ goto out;
514569 }
515570
516
- ret = sel_make_classes(fsi);
571
+ ret = sel_make_classes(newpolicy, tmp_class_dir,
572
+ &fsi->last_class_ino);
517573 if (ret) {
518574 pr_err("SELinux: failed to load policy classes\n");
519
- return ret;
575
+ goto out;
520576 }
521577
522
- ret = sel_make_policycap(fsi);
523
- if (ret) {
524
- pr_err("SELinux: failed to load policy capabilities\n");
525
- return ret;
526
- }
578
+ /* booleans */
579
+ old_dentry = fsi->bool_dir;
580
+ lock_rename(tmp_bool_dir, old_dentry);
581
+ d_exchange(tmp_bool_dir, fsi->bool_dir);
527582
528
- return 0;
583
+ old_bool_num = fsi->bool_num;
584
+ old_bool_names = fsi->bool_pending_names;
585
+ old_bool_values = fsi->bool_pending_values;
586
+
587
+ fsi->bool_num = tmp_bool_num;
588
+ fsi->bool_pending_names = tmp_bool_names;
589
+ fsi->bool_pending_values = tmp_bool_values;
590
+
591
+ sel_remove_old_bool_data(old_bool_num, old_bool_names, old_bool_values);
592
+
593
+ fsi->bool_dir = tmp_bool_dir;
594
+ unlock_rename(tmp_bool_dir, old_dentry);
595
+
596
+ /* classes */
597
+ old_dentry = fsi->class_dir;
598
+ lock_rename(tmp_class_dir, old_dentry);
599
+ d_exchange(tmp_class_dir, fsi->class_dir);
600
+ fsi->class_dir = tmp_class_dir;
601
+ unlock_rename(tmp_class_dir, old_dentry);
602
+
603
+out:
604
+ /* Since the other temporary dirs are children of tmp_parent
605
+ * this will handle all the cleanup in the case of a failure before
606
+ * the swapover
607
+ */
608
+ sel_remove_entries(tmp_parent);
609
+ dput(tmp_parent); /* d_genocide() only handles the children */
610
+
611
+ return ret;
529612 }
530613
531614 static ssize_t sel_write_load(struct file *file, const char __user *buf,
....@@ -533,10 +616,11 @@
533616
534617 {
535618 struct selinux_fs_info *fsi = file_inode(file)->i_sb->s_fs_info;
619
+ struct selinux_load_state load_state;
536620 ssize_t length;
537621 void *data = NULL;
538622
539
- mutex_lock(&fsi->mutex);
623
+ mutex_lock(&fsi->state->policy_mutex);
540624
541625 length = avc_has_perm(&selinux_state,
542626 current_sid(), SECINITSID_SECURITY,
....@@ -549,10 +633,6 @@
549633 if (*ppos != 0)
550634 goto out;
551635
552
- length = -EFBIG;
553
- if (count > 64 * 1024 * 1024)
554
- goto out;
555
-
556636 length = -ENOMEM;
557637 data = vmalloc(count);
558638 if (!data)
....@@ -562,25 +642,28 @@
562642 if (copy_from_user(data, buf, count) != 0)
563643 goto out;
564644
565
- length = security_load_policy(fsi->state, data, count);
645
+ length = security_load_policy(fsi->state, data, count, &load_state);
566646 if (length) {
567647 pr_warn_ratelimited("SELinux: failed to load policy\n");
568648 goto out;
569649 }
570650
571
- length = sel_make_policy_nodes(fsi);
572
- if (length)
573
- goto out1;
651
+ length = sel_make_policy_nodes(fsi, load_state.policy);
652
+ if (length) {
653
+ selinux_policy_cancel(fsi->state, &load_state);
654
+ goto out;
655
+ }
656
+
657
+ selinux_policy_commit(fsi->state, &load_state);
574658
575659 length = count;
576660
577
-out1:
578661 audit_log(audit_context(), GFP_KERNEL, AUDIT_MAC_POLICY_LOAD,
579662 "auid=%u ses=%u lsm=selinux res=1",
580663 from_kuid(&init_user_ns, audit_get_loginuid(current)),
581664 audit_get_sessionid(current));
582665 out:
583
- mutex_unlock(&fsi->mutex);
666
+ mutex_unlock(&fsi->state->policy_mutex);
584667 vfree(data);
585668 return length;
586669 }
....@@ -633,7 +716,8 @@
633716 char tmpbuf[TMPBUFLEN];
634717 ssize_t length;
635718
636
- length = scnprintf(tmpbuf, TMPBUFLEN, "%u", fsi->state->checkreqprot);
719
+ length = scnprintf(tmpbuf, TMPBUFLEN, "%u",
720
+ checkreqprot_get(fsi->state));
637721 return simple_read_from_buffer(buf, count, ppos, tmpbuf, length);
638722 }
639723
....@@ -667,7 +751,15 @@
667751 if (sscanf(page, "%u", &new_value) != 1)
668752 goto out;
669753
670
- fsi->state->checkreqprot = new_value ? 1 : 0;
754
+ if (new_value) {
755
+ char comm[sizeof(current->comm)];
756
+
757
+ memcpy(comm, current->comm, sizeof(comm));
758
+ pr_warn_once("SELinux: %s (%d) set checkreqprot to 1. This is deprecated and will be rejected in a future kernel release.\n",
759
+ comm, current->pid);
760
+ }
761
+
762
+ checkreqprot_set(fsi->state, (new_value ? 1 : 0));
671763 length = count;
672764 out:
673765 kfree(page);
....@@ -1177,7 +1269,7 @@
11771269 unsigned index = file_inode(filep)->i_ino & SEL_INO_MASK;
11781270 const char *name = filep->f_path.dentry->d_name.name;
11791271
1180
- mutex_lock(&fsi->mutex);
1272
+ mutex_lock(&fsi->state->policy_mutex);
11811273
11821274 ret = -EINVAL;
11831275 if (index >= fsi->bool_num || strcmp(name,
....@@ -1196,14 +1288,14 @@
11961288 }
11971289 length = scnprintf(page, PAGE_SIZE, "%d %d", cur_enforcing,
11981290 fsi->bool_pending_values[index]);
1199
- mutex_unlock(&fsi->mutex);
1291
+ mutex_unlock(&fsi->state->policy_mutex);
12001292 ret = simple_read_from_buffer(buf, count, ppos, page, length);
12011293 out_free:
12021294 free_page((unsigned long)page);
12031295 return ret;
12041296
12051297 out_unlock:
1206
- mutex_unlock(&fsi->mutex);
1298
+ mutex_unlock(&fsi->state->policy_mutex);
12071299 goto out_free;
12081300 }
12091301
....@@ -1228,7 +1320,7 @@
12281320 if (IS_ERR(page))
12291321 return PTR_ERR(page);
12301322
1231
- mutex_lock(&fsi->mutex);
1323
+ mutex_lock(&fsi->state->policy_mutex);
12321324
12331325 length = avc_has_perm(&selinux_state,
12341326 current_sid(), SECINITSID_SECURITY,
....@@ -1253,7 +1345,7 @@
12531345 length = count;
12541346
12551347 out:
1256
- mutex_unlock(&fsi->mutex);
1348
+ mutex_unlock(&fsi->state->policy_mutex);
12571349 kfree(page);
12581350 return length;
12591351 }
....@@ -1284,7 +1376,7 @@
12841376 if (IS_ERR(page))
12851377 return PTR_ERR(page);
12861378
1287
- mutex_lock(&fsi->mutex);
1379
+ mutex_lock(&fsi->state->policy_mutex);
12881380
12891381 length = avc_has_perm(&selinux_state,
12901382 current_sid(), SECINITSID_SECURITY,
....@@ -1306,7 +1398,7 @@
13061398 length = count;
13071399
13081400 out:
1309
- mutex_unlock(&fsi->mutex);
1401
+ mutex_unlock(&fsi->state->policy_mutex);
13101402 kfree(page);
13111403 return length;
13121404 }
....@@ -1322,49 +1414,37 @@
13221414 shrink_dcache_parent(de);
13231415 }
13241416
1325
-#define BOOL_DIR_NAME "booleans"
1326
-
1327
-static int sel_make_bools(struct selinux_fs_info *fsi)
1417
+static int sel_make_bools(struct selinux_policy *newpolicy, struct dentry *bool_dir,
1418
+ unsigned int *bool_num, char ***bool_pending_names,
1419
+ unsigned int **bool_pending_values)
13281420 {
1329
- int i, ret;
1421
+ int ret;
13301422 ssize_t len;
13311423 struct dentry *dentry = NULL;
1332
- struct dentry *dir = fsi->bool_dir;
13331424 struct inode *inode = NULL;
13341425 struct inode_security_struct *isec;
13351426 char **names = NULL, *page;
1336
- int num;
1427
+ u32 i, num;
13371428 int *values = NULL;
13381429 u32 sid;
1339
-
1340
- /* remove any existing files */
1341
- for (i = 0; i < fsi->bool_num; i++)
1342
- kfree(fsi->bool_pending_names[i]);
1343
- kfree(fsi->bool_pending_names);
1344
- kfree(fsi->bool_pending_values);
1345
- fsi->bool_num = 0;
1346
- fsi->bool_pending_names = NULL;
1347
- fsi->bool_pending_values = NULL;
1348
-
1349
- sel_remove_entries(dir);
13501430
13511431 ret = -ENOMEM;
13521432 page = (char *)get_zeroed_page(GFP_KERNEL);
13531433 if (!page)
13541434 goto out;
13551435
1356
- ret = security_get_bools(fsi->state, &num, &names, &values);
1436
+ ret = security_get_bools(newpolicy, &num, &names, &values);
13571437 if (ret)
13581438 goto out;
13591439
13601440 for (i = 0; i < num; i++) {
13611441 ret = -ENOMEM;
1362
- dentry = d_alloc_name(dir, names[i]);
1442
+ dentry = d_alloc_name(bool_dir, names[i]);
13631443 if (!dentry)
13641444 goto out;
13651445
13661446 ret = -ENOMEM;
1367
- inode = sel_make_inode(dir->d_sb, S_IFREG | S_IRUGO | S_IWUSR);
1447
+ inode = sel_make_inode(bool_dir->d_sb, S_IFREG | S_IRUGO | S_IWUSR);
13681448 if (!inode) {
13691449 dput(dentry);
13701450 goto out;
....@@ -1378,8 +1458,8 @@
13781458 goto out;
13791459 }
13801460
1381
- isec = (struct inode_security_struct *)inode->i_security;
1382
- ret = security_genfs_sid(fsi->state, "selinuxfs", page,
1461
+ isec = selinux_inode(inode);
1462
+ ret = selinux_policy_genfs_sid(newpolicy, "selinuxfs", page,
13831463 SECCLASS_FILE, &sid);
13841464 if (ret) {
13851465 pr_warn_ratelimited("SELinux: no sid found, defaulting to security isid for %s\n",
....@@ -1393,9 +1473,9 @@
13931473 inode->i_ino = i|SEL_BOOL_INO_OFFSET;
13941474 d_add(dentry, inode);
13951475 }
1396
- fsi->bool_num = num;
1397
- fsi->bool_pending_names = names;
1398
- fsi->bool_pending_values = values;
1476
+ *bool_num = num;
1477
+ *bool_pending_names = names;
1478
+ *bool_pending_values = values;
13991479
14001480 free_page((unsigned long)page);
14011481 return 0;
....@@ -1408,7 +1488,7 @@
14081488 kfree(names);
14091489 }
14101490 kfree(values);
1411
- sel_remove_entries(dir);
1491
+ sel_remove_entries(bool_dir);
14121492
14131493 return ret;
14141494 }
....@@ -1692,7 +1772,11 @@
16921772 for (i = 1; i <= SECINITSID_NUM; i++) {
16931773 struct inode *inode;
16941774 struct dentry *dentry;
1695
- dentry = d_alloc_name(dir, security_get_initial_sid_context(i));
1775
+ const char *s = security_get_initial_sid_context(i);
1776
+
1777
+ if (!s)
1778
+ continue;
1779
+ dentry = d_alloc_name(dir, s);
16961780 if (!dentry)
16971781 return -ENOMEM;
16981782
....@@ -1735,7 +1819,7 @@
17351819 {
17361820 unsigned long ino = file_inode(file)->i_ino;
17371821 char res[TMPBUFLEN];
1738
- ssize_t len = snprintf(res, sizeof(res), "%d", sel_ino_to_class(ino));
1822
+ ssize_t len = scnprintf(res, sizeof(res), "%d", sel_ino_to_class(ino));
17391823 return simple_read_from_buffer(buf, count, ppos, res, len);
17401824 }
17411825
....@@ -1749,7 +1833,7 @@
17491833 {
17501834 unsigned long ino = file_inode(file)->i_ino;
17511835 char res[TMPBUFLEN];
1752
- ssize_t len = snprintf(res, sizeof(res), "%d", sel_ino_to_perm(ino));
1836
+ ssize_t len = scnprintf(res, sizeof(res), "%d", sel_ino_to_perm(ino));
17531837 return simple_read_from_buffer(buf, count, ppos, res, len);
17541838 }
17551839
....@@ -1778,14 +1862,14 @@
17781862 .llseek = generic_file_llseek,
17791863 };
17801864
1781
-static int sel_make_perm_files(char *objclass, int classvalue,
1782
- struct dentry *dir)
1865
+static int sel_make_perm_files(struct selinux_policy *newpolicy,
1866
+ char *objclass, int classvalue,
1867
+ struct dentry *dir)
17831868 {
1784
- struct selinux_fs_info *fsi = dir->d_sb->s_fs_info;
17851869 int i, rc, nperms;
17861870 char **perms;
17871871
1788
- rc = security_get_permissions(fsi->state, objclass, &perms, &nperms);
1872
+ rc = security_get_permissions(newpolicy, objclass, &perms, &nperms);
17891873 if (rc)
17901874 return rc;
17911875
....@@ -1818,8 +1902,9 @@
18181902 return rc;
18191903 }
18201904
1821
-static int sel_make_class_dir_entries(char *classname, int index,
1822
- struct dentry *dir)
1905
+static int sel_make_class_dir_entries(struct selinux_policy *newpolicy,
1906
+ char *classname, int index,
1907
+ struct dentry *dir)
18231908 {
18241909 struct super_block *sb = dir->d_sb;
18251910 struct selinux_fs_info *fsi = sb->s_fs_info;
....@@ -1845,39 +1930,38 @@
18451930 if (IS_ERR(dentry))
18461931 return PTR_ERR(dentry);
18471932
1848
- rc = sel_make_perm_files(classname, index, dentry);
1933
+ rc = sel_make_perm_files(newpolicy, classname, index, dentry);
18491934
18501935 return rc;
18511936 }
18521937
1853
-static int sel_make_classes(struct selinux_fs_info *fsi)
1938
+static int sel_make_classes(struct selinux_policy *newpolicy,
1939
+ struct dentry *class_dir,
1940
+ unsigned long *last_class_ino)
18541941 {
18551942
18561943 int rc, nclasses, i;
18571944 char **classes;
18581945
1859
- /* delete any existing entries */
1860
- sel_remove_entries(fsi->class_dir);
1861
-
1862
- rc = security_get_classes(fsi->state, &classes, &nclasses);
1946
+ rc = security_get_classes(newpolicy, &classes, &nclasses);
18631947 if (rc)
18641948 return rc;
18651949
18661950 /* +2 since classes are 1-indexed */
1867
- fsi->last_class_ino = sel_class_to_ino(nclasses + 2);
1951
+ *last_class_ino = sel_class_to_ino(nclasses + 2);
18681952
18691953 for (i = 0; i < nclasses; i++) {
18701954 struct dentry *class_name_dir;
18711955
1872
- class_name_dir = sel_make_dir(fsi->class_dir, classes[i],
1873
- &fsi->last_class_ino);
1956
+ class_name_dir = sel_make_dir(class_dir, classes[i],
1957
+ last_class_ino);
18741958 if (IS_ERR(class_name_dir)) {
18751959 rc = PTR_ERR(class_name_dir);
18761960 goto out;
18771961 }
18781962
18791963 /* i+1 since class values are 1-indexed */
1880
- rc = sel_make_class_dir_entries(classes[i], i + 1,
1964
+ rc = sel_make_class_dir_entries(newpolicy, classes[i], i + 1,
18811965 class_name_dir);
18821966 if (rc)
18831967 goto out;
....@@ -1895,8 +1979,6 @@
18951979 unsigned int iter;
18961980 struct dentry *dentry = NULL;
18971981 struct inode *inode = NULL;
1898
-
1899
- sel_remove_entries(fsi->policycap_dir);
19001982
19011983 for (iter = 0; iter <= POLICYDB_CAPABILITY_MAX; iter++) {
19021984 if (iter < ARRAY_SIZE(selinux_policycap_names))
....@@ -1949,9 +2031,25 @@
19492031 return dentry;
19502032 }
19512033
2034
+static struct dentry *sel_make_disconnected_dir(struct super_block *sb,
2035
+ unsigned long *ino)
2036
+{
2037
+ struct inode *inode = sel_make_inode(sb, S_IFDIR | S_IRUGO | S_IXUGO);
2038
+
2039
+ if (!inode)
2040
+ return ERR_PTR(-ENOMEM);
2041
+
2042
+ inode->i_op = &simple_dir_inode_operations;
2043
+ inode->i_fop = &simple_dir_operations;
2044
+ inode->i_ino = ++(*ino);
2045
+ /* directory inodes start off with i_nlink == 2 (for "." entry) */
2046
+ inc_nlink(inode);
2047
+ return d_obtain_alias(inode);
2048
+}
2049
+
19522050 #define NULL_FILE_NAME "null"
19532051
1954
-static int sel_fill_super(struct super_block *sb, void *data, int silent)
2052
+static int sel_fill_super(struct super_block *sb, struct fs_context *fc)
19552053 {
19562054 struct selinux_fs_info *fsi;
19572055 int ret;
....@@ -2011,7 +2109,7 @@
20112109 }
20122110
20132111 inode->i_ino = ++fsi->last_ino;
2014
- isec = (struct inode_security_struct *)inode->i_security;
2112
+ isec = selinux_inode(inode);
20152113 isec->sid = SECINITSID_DEVNULL;
20162114 isec->sclass = SECCLASS_CHR_FILE;
20172115 isec->initialized = LABEL_INITIALIZED;
....@@ -2026,6 +2124,8 @@
20262124 }
20272125
20282126 ret = sel_make_avc_files(dentry);
2127
+ if (ret)
2128
+ goto err;
20292129
20302130 dentry = sel_make_dir(sb->s_root, "ss", &fsi->last_ino);
20312131 if (IS_ERR(dentry)) {
....@@ -2047,14 +2147,14 @@
20472147 if (ret)
20482148 goto err;
20492149
2050
- fsi->class_dir = sel_make_dir(sb->s_root, "class", &fsi->last_ino);
2150
+ fsi->class_dir = sel_make_dir(sb->s_root, CLASS_DIR_NAME, &fsi->last_ino);
20512151 if (IS_ERR(fsi->class_dir)) {
20522152 ret = PTR_ERR(fsi->class_dir);
20532153 fsi->class_dir = NULL;
20542154 goto err;
20552155 }
20562156
2057
- fsi->policycap_dir = sel_make_dir(sb->s_root, "policy_capabilities",
2157
+ fsi->policycap_dir = sel_make_dir(sb->s_root, POLICYCAP_DIR_NAME,
20582158 &fsi->last_ino);
20592159 if (IS_ERR(fsi->policycap_dir)) {
20602160 ret = PTR_ERR(fsi->policycap_dir);
....@@ -2062,9 +2162,12 @@
20622162 goto err;
20632163 }
20642164
2065
- ret = sel_make_policy_nodes(fsi);
2066
- if (ret)
2165
+ ret = sel_make_policycap(fsi);
2166
+ if (ret) {
2167
+ pr_err("SELinux: failed to load policy capabilities\n");
20672168 goto err;
2169
+ }
2170
+
20682171 return 0;
20692172 err:
20702173 pr_err("SELinux: %s: failed while creating inodes\n",
....@@ -2075,10 +2178,19 @@
20752178 return ret;
20762179 }
20772180
2078
-static struct dentry *sel_mount(struct file_system_type *fs_type,
2079
- int flags, const char *dev_name, void *data)
2181
+static int sel_get_tree(struct fs_context *fc)
20802182 {
2081
- return mount_single(fs_type, flags, data, sel_fill_super);
2183
+ return get_tree_single(fc, sel_fill_super);
2184
+}
2185
+
2186
+static const struct fs_context_operations sel_context_ops = {
2187
+ .get_tree = sel_get_tree,
2188
+};
2189
+
2190
+static int sel_init_fs_context(struct fs_context *fc)
2191
+{
2192
+ fc->ops = &sel_context_ops;
2193
+ return 0;
20822194 }
20832195
20842196 static void sel_kill_sb(struct super_block *sb)
....@@ -2089,7 +2201,7 @@
20892201
20902202 static struct file_system_type sel_fs_type = {
20912203 .name = "selinuxfs",
2092
- .mount = sel_mount,
2204
+ .init_fs_context = sel_init_fs_context,
20932205 .kill_sb = sel_kill_sb,
20942206 };
20952207
....@@ -2102,7 +2214,7 @@
21022214 sizeof(NULL_FILE_NAME)-1);
21032215 int err;
21042216
2105
- if (!selinux_enabled)
2217
+ if (!selinux_enabled_boot)
21062218 return 0;
21072219
21082220 err = sysfs_create_mount_point(fs_kobj, "selinux");