1 // SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2007 Casey Schaufler <casey@schaufler-ca.com>
6 * Casey Schaufler <casey@schaufler-ca.com>
7 * Ahmed S. Darwish <darwish.07@gmail.com>
9 * Special thanks to the authors of selinuxfs.
11 * Karl MacMillan <kmacmillan@tresys.com>
12 * James Morris <jmorris@redhat.com>
15 #include <linux/kernel.h>
16 #include <linux/vmalloc.h>
17 #include <linux/security.h>
18 #include <linux/mutex.h>
19 #include <linux/slab.h>
20 #include <net/net_namespace.h>
21 #include <net/cipso_ipv4.h>
22 #include <linux/seq_file.h>
23 #include <linux/ctype.h>
24 #include <linux/audit.h>
25 #include <linux/magic.h>
28 #define BEBITS (sizeof(__be32) * 8)
30 * smackfs pseudo filesystem.
35 SMK_LOAD = 3, /* load policy */
36 SMK_CIPSO = 4, /* load label -> CIPSO mapping */
37 SMK_DOI = 5, /* CIPSO DOI */
38 SMK_DIRECT = 6, /* CIPSO level indicating direct label */
39 SMK_AMBIENT = 7, /* internet ambient label */
40 SMK_NET4ADDR = 8, /* single label hosts */
41 SMK_ONLYCAP = 9, /* the only "capable" label */
42 SMK_LOGGING = 10, /* logging */
43 SMK_LOAD_SELF = 11, /* task specific rules */
44 SMK_ACCESSES = 12, /* access policy */
45 SMK_MAPPED = 13, /* CIPSO level indicating mapped label */
46 SMK_LOAD2 = 14, /* load policy with long labels */
47 SMK_LOAD_SELF2 = 15, /* load task specific rules with long labels */
48 SMK_ACCESS2 = 16, /* make an access check with long labels */
49 SMK_CIPSO2 = 17, /* load long label -> CIPSO mapping */
50 SMK_REVOKE_SUBJ = 18, /* set rules with subject label to '-' */
51 SMK_CHANGE_RULE = 19, /* change or add rules (long labels) */
52 SMK_SYSLOG = 20, /* change syslog label) */
53 SMK_PTRACE = 21, /* set ptrace rule */
54 #ifdef CONFIG_SECURITY_SMACK_BRINGUP
55 SMK_UNCONFINED = 22, /* define an unconfined label */
57 #if IS_ENABLED(CONFIG_IPV6)
58 SMK_NET6ADDR = 23, /* single label IPv6 hosts */
59 #endif /* CONFIG_IPV6 */
60 SMK_RELABEL_SELF = 24, /* relabel possible without CAP_MAC_ADMIN */
66 static DEFINE_MUTEX(smack_cipso_lock);
67 static DEFINE_MUTEX(smack_ambient_lock);
68 static DEFINE_MUTEX(smk_net4addr_lock);
69 #if IS_ENABLED(CONFIG_IPV6)
70 static DEFINE_MUTEX(smk_net6addr_lock);
71 #endif /* CONFIG_IPV6 */
74 * This is the "ambient" label for network traffic.
75 * If it isn't somehow marked, use this.
76 * It can be reset via smackfs/ambient
78 struct smack_known *smack_net_ambient;
81 * This is the level in a CIPSO header that indicates a
82 * smack label is contained directly in the category set.
83 * It can be reset via smackfs/direct
85 int smack_cipso_direct = SMACK_CIPSO_DIRECT_DEFAULT;
88 * This is the level in a CIPSO header that indicates a
89 * secid is contained directly in the category set.
90 * It can be reset via smackfs/mapped
92 int smack_cipso_mapped = SMACK_CIPSO_MAPPED_DEFAULT;
94 #ifdef CONFIG_SECURITY_SMACK_BRINGUP
96 * Allow one label to be unconfined. This is for
97 * debugging and application bring-up purposes only.
98 * It is bad and wrong, but everyone seems to expect
101 struct smack_known *smack_unconfined;
105 * If this value is set restrict syslog use to the label specified.
106 * It can be reset via smackfs/syslog
108 struct smack_known *smack_syslog_label;
111 * Ptrace current rule
112 * SMACK_PTRACE_DEFAULT regular smack ptrace rules (/proc based)
113 * SMACK_PTRACE_EXACT labels must match, but can be overriden with
115 * SMACK_PTRACE_DRACONIAN lables must match, CAP_SYS_PTRACE has no effect
117 int smack_ptrace_rule = SMACK_PTRACE_DEFAULT;
120 * Certain IP addresses may be designated as single label hosts.
121 * Packets are sent there unlabeled, but only from tasks that
122 * can write to the specified label.
125 LIST_HEAD(smk_net4addr_list);
126 #if IS_ENABLED(CONFIG_IPV6)
127 LIST_HEAD(smk_net6addr_list);
128 #endif /* CONFIG_IPV6 */
131 * Rule lists are maintained for each label.
133 struct smack_parsed_rule {
134 struct smack_known *smk_subject;
135 struct smack_known *smk_object;
140 static int smk_cipso_doi_value = SMACK_CIPSO_DOI_DEFAULT;
143 * Values for parsing cipso rules
144 * SMK_DIGITLEN: Length of a digit field in a rule.
145 * SMK_CIPSOMIN: Minimum possible cipso rule length.
146 * SMK_CIPSOMAX: Maximum possible cipso rule length.
148 #define SMK_DIGITLEN 4
149 #define SMK_CIPSOMIN (SMK_LABELLEN + 2 * SMK_DIGITLEN)
150 #define SMK_CIPSOMAX (SMK_CIPSOMIN + SMACK_CIPSO_MAXCATNUM * SMK_DIGITLEN)
153 * Values for parsing MAC rules
154 * SMK_ACCESS: Maximum possible combination of access permissions
155 * SMK_ACCESSLEN: Maximum length for a rule access field
156 * SMK_LOADLEN: Smack rule length
158 #define SMK_OACCESS "rwxa"
159 #define SMK_ACCESS "rwxatl"
160 #define SMK_OACCESSLEN (sizeof(SMK_OACCESS) - 1)
161 #define SMK_ACCESSLEN (sizeof(SMK_ACCESS) - 1)
162 #define SMK_OLOADLEN (SMK_LABELLEN + SMK_LABELLEN + SMK_OACCESSLEN)
163 #define SMK_LOADLEN (SMK_LABELLEN + SMK_LABELLEN + SMK_ACCESSLEN)
166 * Stricly for CIPSO level manipulation.
167 * Set the category bit number in a smack label sized buffer.
169 static inline void smack_catset_bit(unsigned int cat, char *catsetp)
171 if (cat == 0 || cat > (SMK_CIPSOLEN * 8))
174 catsetp[(cat - 1) / 8] |= 0x80 >> ((cat - 1) % 8);
178 * smk_netlabel_audit_set - fill a netlbl_audit struct
179 * @nap: structure to fill
181 static void smk_netlabel_audit_set(struct netlbl_audit *nap)
183 struct smack_known *skp = smk_of_current();
185 nap->loginuid = audit_get_loginuid(current);
186 nap->sessionid = audit_get_sessionid(current);
187 nap->secid = skp->smk_secid;
191 * Value for parsing single label host rules
194 #define SMK_NETLBLADDRMIN 9
197 * smk_set_access - add a rule to the rule list or replace an old rule
198 * @srp: the rule to add or replace
199 * @rule_list: the list of rules
200 * @rule_lock: the rule list lock
202 * Looks through the current subject/object/access list for
203 * the subject/object pair and replaces the access that was
204 * there. If the pair isn't found add it with the specified
207 * Returns 0 if nothing goes wrong or -ENOMEM if it fails
208 * during the allocation of the new pair to add.
210 static int smk_set_access(struct smack_parsed_rule *srp,
211 struct list_head *rule_list,
212 struct mutex *rule_lock)
214 struct smack_rule *sp;
218 mutex_lock(rule_lock);
221 * Because the object label is less likely to match
222 * than the subject label check it first
224 list_for_each_entry_rcu(sp, rule_list, list) {
225 if (sp->smk_object == srp->smk_object &&
226 sp->smk_subject == srp->smk_subject) {
228 sp->smk_access |= srp->smk_access1;
229 sp->smk_access &= ~srp->smk_access2;
235 sp = kmem_cache_zalloc(smack_rule_cache, GFP_KERNEL);
241 sp->smk_subject = srp->smk_subject;
242 sp->smk_object = srp->smk_object;
243 sp->smk_access = srp->smk_access1 & ~srp->smk_access2;
245 list_add_rcu(&sp->list, rule_list);
249 mutex_unlock(rule_lock);
254 * smk_perm_from_str - parse smack accesses from a text string
255 * @string: a text string that contains a Smack accesses code
257 * Returns an integer with respective bits set for specified accesses.
259 static int smk_perm_from_str(const char *string)
264 for (cp = string; ; cp++)
286 perm |= MAY_TRANSMUTE;
302 * smk_fill_rule - Fill Smack rule from strings
303 * @subject: subject label string
304 * @object: object label string
305 * @access1: access string
306 * @access2: string with permissions to be removed
308 * @import: if non-zero, import labels
309 * @len: label length limit
311 * Returns 0 on success, appropriate error code on failure.
313 static int smk_fill_rule(const char *subject, const char *object,
314 const char *access1, const char *access2,
315 struct smack_parsed_rule *rule, int import,
319 struct smack_known *skp;
322 rule->smk_subject = smk_import_entry(subject, len);
323 if (IS_ERR(rule->smk_subject))
324 return PTR_ERR(rule->smk_subject);
326 rule->smk_object = smk_import_entry(object, len);
327 if (IS_ERR(rule->smk_object))
328 return PTR_ERR(rule->smk_object);
330 cp = smk_parse_smack(subject, len);
333 skp = smk_find_entry(cp);
337 rule->smk_subject = skp;
339 cp = smk_parse_smack(object, len);
342 skp = smk_find_entry(cp);
346 rule->smk_object = skp;
349 rule->smk_access1 = smk_perm_from_str(access1);
351 rule->smk_access2 = smk_perm_from_str(access2);
353 rule->smk_access2 = ~rule->smk_access1;
359 * smk_parse_rule - parse Smack rule from load string
360 * @data: string to be parsed whose size is SMK_LOADLEN
362 * @import: if non-zero, import labels
364 * Returns 0 on success, -1 on errors.
366 static int smk_parse_rule(const char *data, struct smack_parsed_rule *rule,
371 rc = smk_fill_rule(data, data + SMK_LABELLEN,
372 data + SMK_LABELLEN + SMK_LABELLEN, NULL, rule,
373 import, SMK_LABELLEN);
378 * smk_parse_long_rule - parse Smack rule from rule string
379 * @data: string to be parsed, null terminated
380 * @rule: Will be filled with Smack parsed rule
381 * @import: if non-zero, import labels
382 * @tokens: numer of substrings expected in data
384 * Returns number of processed bytes on success, -ERRNO on failure.
386 static ssize_t smk_parse_long_rule(char *data, struct smack_parsed_rule *rule,
387 int import, int tokens)
395 * Parsing the rule in-place, filling all white-spaces with '\0'
397 for (i = 0; i < tokens; ++i) {
398 while (isspace(data[cnt]))
401 if (data[cnt] == '\0')
402 /* Unexpected end of data */
407 while (data[cnt] && !isspace(data[cnt]))
410 while (isspace(data[cnt]))
416 rc = smk_fill_rule(tok[0], tok[1], tok[2], tok[3], rule, import, 0);
417 return rc == 0 ? cnt : rc;
420 #define SMK_FIXED24_FMT 0 /* Fixed 24byte label format */
421 #define SMK_LONG_FMT 1 /* Variable long label format */
422 #define SMK_CHANGE_FMT 2 /* Rule modification format */
424 * smk_write_rules_list - write() for any /smack rule file
425 * @file: file pointer, not actually used
426 * @buf: where to get the data from
428 * @ppos: where to start - must be 0
429 * @rule_list: the list of rules to write to
430 * @rule_lock: lock for the rule list
431 * @format: /smack/load or /smack/load2 or /smack/change-rule format.
433 * Get one smack access rule from above.
434 * The format for SMK_LONG_FMT is:
435 * "subject<whitespace>object<whitespace>access[<whitespace>...]"
436 * The format for SMK_FIXED24_FMT is exactly:
437 * "subject object rwxat"
438 * The format for SMK_CHANGE_FMT is:
439 * "subject<whitespace>object<whitespace>
440 * acc_enable<whitespace>acc_disable[<whitespace>...]"
442 static ssize_t smk_write_rules_list(struct file *file, const char __user *buf,
443 size_t count, loff_t *ppos,
444 struct list_head *rule_list,
445 struct mutex *rule_lock, int format)
447 struct smack_parsed_rule rule;
456 * Enough data must be present.
461 if (format == SMK_FIXED24_FMT) {
463 * Minor hack for backward compatibility
465 if (count < SMK_OLOADLEN || count > SMK_LOADLEN)
468 if (count >= PAGE_SIZE) {
469 count = PAGE_SIZE - 1;
474 data = memdup_user_nul(buf, count);
476 return PTR_ERR(data);
479 * In case of parsing only part of user buf,
480 * avoid having partial rule at the data buffer
483 while (count > 0 && (data[count - 1] != '\n'))
492 tokens = (format == SMK_CHANGE_FMT ? 4 : 3);
493 while (cnt < count) {
494 if (format == SMK_FIXED24_FMT) {
495 rc = smk_parse_rule(data, &rule, 1);
500 rc = smk_parse_long_rule(data + cnt, &rule, 1, tokens);
510 if (rule_list == NULL)
511 rc = smk_set_access(&rule, &rule.smk_subject->smk_rules,
512 &rule.smk_subject->smk_rules_lock);
514 rc = smk_set_access(&rule, rule_list, rule_lock);
527 * Core logic for smackfs seq list operations.
530 static void *smk_seq_start(struct seq_file *s, loff_t *pos,
531 struct list_head *head)
533 struct list_head *list;
537 for (list = rcu_dereference(list_next_rcu(head));
539 list = rcu_dereference(list_next_rcu(list))) {
547 static void *smk_seq_next(struct seq_file *s, void *v, loff_t *pos,
548 struct list_head *head)
550 struct list_head *list = v;
553 list = rcu_dereference(list_next_rcu(list));
555 return (list == head) ? NULL : list;
558 static void smk_seq_stop(struct seq_file *s, void *v)
563 static void smk_rule_show(struct seq_file *s, struct smack_rule *srp, int max)
566 * Don't show any rules with label names too long for
567 * interface file (/smack/load or /smack/load2)
568 * because you should expect to be able to write
569 * anything you read back.
571 if (strlen(srp->smk_subject->smk_known) >= max ||
572 strlen(srp->smk_object->smk_known) >= max)
575 if (srp->smk_access == 0)
578 seq_printf(s, "%s %s",
579 srp->smk_subject->smk_known,
580 srp->smk_object->smk_known);
584 if (srp->smk_access & MAY_READ)
586 if (srp->smk_access & MAY_WRITE)
588 if (srp->smk_access & MAY_EXEC)
590 if (srp->smk_access & MAY_APPEND)
592 if (srp->smk_access & MAY_TRANSMUTE)
594 if (srp->smk_access & MAY_LOCK)
596 if (srp->smk_access & MAY_BRINGUP)
603 * Seq_file read operations for /smack/load
606 static void *load2_seq_start(struct seq_file *s, loff_t *pos)
608 return smk_seq_start(s, pos, &smack_known_list);
611 static void *load2_seq_next(struct seq_file *s, void *v, loff_t *pos)
613 return smk_seq_next(s, v, pos, &smack_known_list);
616 static int load_seq_show(struct seq_file *s, void *v)
618 struct list_head *list = v;
619 struct smack_rule *srp;
620 struct smack_known *skp =
621 list_entry_rcu(list, struct smack_known, list);
623 list_for_each_entry_rcu(srp, &skp->smk_rules, list)
624 smk_rule_show(s, srp, SMK_LABELLEN);
629 static const struct seq_operations load_seq_ops = {
630 .start = load2_seq_start,
631 .next = load2_seq_next,
632 .show = load_seq_show,
633 .stop = smk_seq_stop,
637 * smk_open_load - open() for /smack/load
638 * @inode: inode structure representing file
639 * @file: "load" file pointer
641 * For reading, use load_seq_* seq_file reading operations.
643 static int smk_open_load(struct inode *inode, struct file *file)
645 return seq_open(file, &load_seq_ops);
649 * smk_write_load - write() for /smack/load
650 * @file: file pointer, not actually used
651 * @buf: where to get the data from
653 * @ppos: where to start - must be 0
656 static ssize_t smk_write_load(struct file *file, const char __user *buf,
657 size_t count, loff_t *ppos)
660 * Must have privilege.
662 * Enough data must be present.
664 if (!smack_privileged(CAP_MAC_ADMIN))
667 return smk_write_rules_list(file, buf, count, ppos, NULL, NULL,
671 static const struct file_operations smk_load_ops = {
672 .open = smk_open_load,
675 .write = smk_write_load,
676 .release = seq_release,
680 * smk_cipso_doi - initialize the CIPSO domain
682 static void smk_cipso_doi(void)
685 struct cipso_v4_doi *doip;
686 struct netlbl_audit nai;
688 smk_netlabel_audit_set(&nai);
690 rc = netlbl_cfg_map_del(NULL, PF_INET, NULL, NULL, &nai);
692 printk(KERN_WARNING "%s:%d remove rc = %d\n",
693 __func__, __LINE__, rc);
695 doip = kmalloc(sizeof(struct cipso_v4_doi), GFP_KERNEL);
697 panic("smack: Failed to initialize cipso DOI.\n");
698 doip->map.std = NULL;
699 doip->doi = smk_cipso_doi_value;
700 doip->type = CIPSO_V4_MAP_PASS;
701 doip->tags[0] = CIPSO_V4_TAG_RBITMAP;
702 for (rc = 1; rc < CIPSO_V4_TAG_MAXCNT; rc++)
703 doip->tags[rc] = CIPSO_V4_TAG_INVALID;
705 rc = netlbl_cfg_cipsov4_add(doip, &nai);
707 printk(KERN_WARNING "%s:%d cipso add rc = %d\n",
708 __func__, __LINE__, rc);
712 rc = netlbl_cfg_cipsov4_map_add(doip->doi, NULL, NULL, NULL, &nai);
714 printk(KERN_WARNING "%s:%d map add rc = %d\n",
715 __func__, __LINE__, rc);
722 * smk_unlbl_ambient - initialize the unlabeled domain
723 * @oldambient: previous domain string
725 static void smk_unlbl_ambient(char *oldambient)
728 struct netlbl_audit nai;
730 smk_netlabel_audit_set(&nai);
732 if (oldambient != NULL) {
733 rc = netlbl_cfg_map_del(oldambient, PF_INET, NULL, NULL, &nai);
735 printk(KERN_WARNING "%s:%d remove rc = %d\n",
736 __func__, __LINE__, rc);
738 if (smack_net_ambient == NULL)
739 smack_net_ambient = &smack_known_floor;
741 rc = netlbl_cfg_unlbl_map_add(smack_net_ambient->smk_known, PF_INET,
744 printk(KERN_WARNING "%s:%d add rc = %d\n",
745 __func__, __LINE__, rc);
749 * Seq_file read operations for /smack/cipso
752 static void *cipso_seq_start(struct seq_file *s, loff_t *pos)
754 return smk_seq_start(s, pos, &smack_known_list);
757 static void *cipso_seq_next(struct seq_file *s, void *v, loff_t *pos)
759 return smk_seq_next(s, v, pos, &smack_known_list);
763 * Print cipso labels in format:
764 * label level[/cat[,cat]]
766 static int cipso_seq_show(struct seq_file *s, void *v)
768 struct list_head *list = v;
769 struct smack_known *skp =
770 list_entry_rcu(list, struct smack_known, list);
771 struct netlbl_lsm_catmap *cmp = skp->smk_netlabel.attr.mls.cat;
776 * Don't show a label that could not have been set using
777 * /smack/cipso. This is in support of the notion that
778 * anything read from /smack/cipso ought to be writeable
781 * /smack/cipso2 should be used instead.
783 if (strlen(skp->smk_known) >= SMK_LABELLEN)
786 seq_printf(s, "%s %3d", skp->smk_known, skp->smk_netlabel.attr.mls.lvl);
788 for (i = netlbl_catmap_walk(cmp, 0); i >= 0;
789 i = netlbl_catmap_walk(cmp, i + 1)) {
790 seq_printf(s, "%c%d", sep, i);
799 static const struct seq_operations cipso_seq_ops = {
800 .start = cipso_seq_start,
801 .next = cipso_seq_next,
802 .show = cipso_seq_show,
803 .stop = smk_seq_stop,
807 * smk_open_cipso - open() for /smack/cipso
808 * @inode: inode structure representing file
809 * @file: "cipso" file pointer
811 * Connect our cipso_seq_* operations with /smack/cipso
814 static int smk_open_cipso(struct inode *inode, struct file *file)
816 return seq_open(file, &cipso_seq_ops);
820 * smk_set_cipso - do the work for write() for cipso and cipso2
821 * @file: file pointer, not actually used
822 * @buf: where to get the data from
824 * @ppos: where to start
825 * @format: /smack/cipso or /smack/cipso2
827 * Accepts only one cipso rule per write call.
828 * Returns number of bytes written or error code, as appropriate
830 static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
831 size_t count, loff_t *ppos, int format)
833 struct smack_known *skp;
834 struct netlbl_lsm_secattr ncats;
835 char mapcatset[SMK_CIPSOLEN];
839 ssize_t rc = -EINVAL;
846 * Must have privilege.
848 * Enough data must be present.
850 if (!smack_privileged(CAP_MAC_ADMIN))
854 if (format == SMK_FIXED24_FMT &&
855 (count < SMK_CIPSOMIN || count > SMK_CIPSOMAX))
858 data = memdup_user_nul(buf, count);
860 return PTR_ERR(data);
864 * Only allow one writer at a time. Writes should be
865 * quite rare and small in any case.
867 mutex_lock(&smack_cipso_lock);
869 skp = smk_import_entry(rule, 0);
875 if (format == SMK_FIXED24_FMT)
876 rule += SMK_LABELLEN;
878 rule += strlen(skp->smk_known) + 1;
880 ret = sscanf(rule, "%d", &maplevel);
881 if (ret != 1 || maplevel > SMACK_CIPSO_MAXLEVEL)
884 rule += SMK_DIGITLEN;
885 ret = sscanf(rule, "%d", &catlen);
886 if (ret != 1 || catlen > SMACK_CIPSO_MAXCATNUM)
889 if (format == SMK_FIXED24_FMT &&
890 count != (SMK_CIPSOMIN + catlen * SMK_DIGITLEN))
893 memset(mapcatset, 0, sizeof(mapcatset));
895 for (i = 0; i < catlen; i++) {
896 rule += SMK_DIGITLEN;
897 ret = sscanf(rule, "%u", &cat);
898 if (ret != 1 || cat > SMACK_CIPSO_MAXCATNUM)
901 smack_catset_bit(cat, mapcatset);
904 rc = smk_netlbl_mls(maplevel, mapcatset, &ncats, SMK_CIPSOLEN);
906 netlbl_catmap_free(skp->smk_netlabel.attr.mls.cat);
907 skp->smk_netlabel.attr.mls.cat = ncats.attr.mls.cat;
908 skp->smk_netlabel.attr.mls.lvl = ncats.attr.mls.lvl;
913 mutex_unlock(&smack_cipso_lock);
919 * smk_write_cipso - write() for /smack/cipso
920 * @file: file pointer, not actually used
921 * @buf: where to get the data from
923 * @ppos: where to start
925 * Accepts only one cipso rule per write call.
926 * Returns number of bytes written or error code, as appropriate
928 static ssize_t smk_write_cipso(struct file *file, const char __user *buf,
929 size_t count, loff_t *ppos)
931 return smk_set_cipso(file, buf, count, ppos, SMK_FIXED24_FMT);
934 static const struct file_operations smk_cipso_ops = {
935 .open = smk_open_cipso,
938 .write = smk_write_cipso,
939 .release = seq_release,
943 * Seq_file read operations for /smack/cipso2
947 * Print cipso labels in format:
948 * label level[/cat[,cat]]
950 static int cipso2_seq_show(struct seq_file *s, void *v)
952 struct list_head *list = v;
953 struct smack_known *skp =
954 list_entry_rcu(list, struct smack_known, list);
955 struct netlbl_lsm_catmap *cmp = skp->smk_netlabel.attr.mls.cat;
959 seq_printf(s, "%s %3d", skp->smk_known, skp->smk_netlabel.attr.mls.lvl);
961 for (i = netlbl_catmap_walk(cmp, 0); i >= 0;
962 i = netlbl_catmap_walk(cmp, i + 1)) {
963 seq_printf(s, "%c%d", sep, i);
972 static const struct seq_operations cipso2_seq_ops = {
973 .start = cipso_seq_start,
974 .next = cipso_seq_next,
975 .show = cipso2_seq_show,
976 .stop = smk_seq_stop,
980 * smk_open_cipso2 - open() for /smack/cipso2
981 * @inode: inode structure representing file
982 * @file: "cipso2" file pointer
984 * Connect our cipso_seq_* operations with /smack/cipso2
987 static int smk_open_cipso2(struct inode *inode, struct file *file)
989 return seq_open(file, &cipso2_seq_ops);
993 * smk_write_cipso2 - write() for /smack/cipso2
994 * @file: file pointer, not actually used
995 * @buf: where to get the data from
997 * @ppos: where to start
999 * Accepts only one cipso rule per write call.
1000 * Returns number of bytes written or error code, as appropriate
1002 static ssize_t smk_write_cipso2(struct file *file, const char __user *buf,
1003 size_t count, loff_t *ppos)
1005 return smk_set_cipso(file, buf, count, ppos, SMK_LONG_FMT);
1008 static const struct file_operations smk_cipso2_ops = {
1009 .open = smk_open_cipso2,
1011 .llseek = seq_lseek,
1012 .write = smk_write_cipso2,
1013 .release = seq_release,
1017 * Seq_file read operations for /smack/netlabel
1020 static void *net4addr_seq_start(struct seq_file *s, loff_t *pos)
1022 return smk_seq_start(s, pos, &smk_net4addr_list);
1025 static void *net4addr_seq_next(struct seq_file *s, void *v, loff_t *pos)
1027 return smk_seq_next(s, v, pos, &smk_net4addr_list);
1031 * Print host/label pairs
1033 static int net4addr_seq_show(struct seq_file *s, void *v)
1035 struct list_head *list = v;
1036 struct smk_net4addr *skp =
1037 list_entry_rcu(list, struct smk_net4addr, list);
1038 char *kp = SMACK_CIPSO_OPTION;
1040 if (skp->smk_label != NULL)
1041 kp = skp->smk_label->smk_known;
1042 seq_printf(s, "%pI4/%d %s\n", &skp->smk_host.s_addr,
1043 skp->smk_masks, kp);
1048 static const struct seq_operations net4addr_seq_ops = {
1049 .start = net4addr_seq_start,
1050 .next = net4addr_seq_next,
1051 .show = net4addr_seq_show,
1052 .stop = smk_seq_stop,
1056 * smk_open_net4addr - open() for /smack/netlabel
1057 * @inode: inode structure representing file
1058 * @file: "netlabel" file pointer
1060 * Connect our net4addr_seq_* operations with /smack/netlabel
1063 static int smk_open_net4addr(struct inode *inode, struct file *file)
1065 return seq_open(file, &net4addr_seq_ops);
1069 * smk_net4addr_insert
1070 * @new : netlabel to insert
1072 * This helper insert netlabel in the smack_net4addrs list
1073 * sorted by netmask length (longest to smallest)
1074 * locked by &smk_net4addr_lock in smk_write_net4addr
1077 static void smk_net4addr_insert(struct smk_net4addr *new)
1079 struct smk_net4addr *m;
1080 struct smk_net4addr *m_next;
1082 if (list_empty(&smk_net4addr_list)) {
1083 list_add_rcu(&new->list, &smk_net4addr_list);
1087 m = list_entry_rcu(smk_net4addr_list.next,
1088 struct smk_net4addr, list);
1090 /* the comparison '>' is a bit hacky, but works */
1091 if (new->smk_masks > m->smk_masks) {
1092 list_add_rcu(&new->list, &smk_net4addr_list);
1096 list_for_each_entry_rcu(m, &smk_net4addr_list, list) {
1097 if (list_is_last(&m->list, &smk_net4addr_list)) {
1098 list_add_rcu(&new->list, &m->list);
1101 m_next = list_entry_rcu(m->list.next,
1102 struct smk_net4addr, list);
1103 if (new->smk_masks > m_next->smk_masks) {
1104 list_add_rcu(&new->list, &m->list);
1112 * smk_write_net4addr - write() for /smack/netlabel
1113 * @file: file pointer, not actually used
1114 * @buf: where to get the data from
1115 * @count: bytes sent
1116 * @ppos: where to start
1118 * Accepts only one net4addr per write call.
1119 * Returns number of bytes written or error code, as appropriate
1121 static ssize_t smk_write_net4addr(struct file *file, const char __user *buf,
1122 size_t count, loff_t *ppos)
1124 struct smk_net4addr *snp;
1125 struct sockaddr_in newname;
1127 struct smack_known *skp = NULL;
1129 char *host = (char *)&newname.sin_addr.s_addr;
1131 struct netlbl_audit audit_info;
1132 struct in_addr mask;
1136 u32 mask_bits = (1<<31);
1141 * Must have privilege.
1142 * No partial writes.
1143 * Enough data must be present.
1144 * "<addr/mask, as a.b.c.d/e><space><label>"
1145 * "<addr, as a.b.c.d><space><label>"
1147 if (!smack_privileged(CAP_MAC_ADMIN))
1151 if (count < SMK_NETLBLADDRMIN)
1154 data = memdup_user_nul(buf, count);
1156 return PTR_ERR(data);
1158 smack = kzalloc(count + 1, GFP_KERNEL);
1159 if (smack == NULL) {
1164 rc = sscanf(data, "%hhd.%hhd.%hhd.%hhd/%u %s",
1165 &host[0], &host[1], &host[2], &host[3], &masks, smack);
1167 rc = sscanf(data, "%hhd.%hhd.%hhd.%hhd %s",
1168 &host[0], &host[1], &host[2], &host[3], smack);
1176 if (masks > BEBITS) {
1182 * If smack begins with '-', it is an option, don't import it
1184 if (smack[0] != '-') {
1185 skp = smk_import_entry(smack, 0);
1192 * Only the -CIPSO option is supported for IPv4
1194 if (strcmp(smack, SMACK_CIPSO_OPTION) != 0) {
1200 for (m = masks, temp_mask = 0; m > 0; m--) {
1201 temp_mask |= mask_bits;
1204 mask.s_addr = cpu_to_be32(temp_mask);
1206 newname.sin_addr.s_addr &= mask.s_addr;
1208 * Only allow one writer at a time. Writes should be
1209 * quite rare and small in any case.
1211 mutex_lock(&smk_net4addr_lock);
1213 nsa = newname.sin_addr.s_addr;
1214 /* try to find if the prefix is already in the list */
1216 list_for_each_entry_rcu(snp, &smk_net4addr_list, list) {
1217 if (snp->smk_host.s_addr == nsa && snp->smk_masks == masks) {
1222 smk_netlabel_audit_set(&audit_info);
1225 snp = kzalloc(sizeof(*snp), GFP_KERNEL);
1230 snp->smk_host.s_addr = newname.sin_addr.s_addr;
1231 snp->smk_mask.s_addr = mask.s_addr;
1232 snp->smk_label = skp;
1233 snp->smk_masks = masks;
1234 smk_net4addr_insert(snp);
1238 * Delete the unlabeled entry, only if the previous label
1239 * wasn't the special CIPSO option
1241 if (snp->smk_label != NULL)
1242 rc = netlbl_cfg_unlbl_static_del(&init_net, NULL,
1243 &snp->smk_host, &snp->smk_mask,
1244 PF_INET, &audit_info);
1247 snp->smk_label = skp;
1251 * Now tell netlabel about the single label nature of
1252 * this host so that incoming packets get labeled.
1253 * but only if we didn't get the special CIPSO option
1255 if (rc == 0 && skp != NULL)
1256 rc = netlbl_cfg_unlbl_static_add(&init_net, NULL,
1257 &snp->smk_host, &snp->smk_mask, PF_INET,
1258 snp->smk_label->smk_secid, &audit_info);
1263 mutex_unlock(&smk_net4addr_lock);
1273 static const struct file_operations smk_net4addr_ops = {
1274 .open = smk_open_net4addr,
1276 .llseek = seq_lseek,
1277 .write = smk_write_net4addr,
1278 .release = seq_release,
1281 #if IS_ENABLED(CONFIG_IPV6)
1283 * Seq_file read operations for /smack/netlabel6
1286 static void *net6addr_seq_start(struct seq_file *s, loff_t *pos)
1288 return smk_seq_start(s, pos, &smk_net6addr_list);
1291 static void *net6addr_seq_next(struct seq_file *s, void *v, loff_t *pos)
1293 return smk_seq_next(s, v, pos, &smk_net6addr_list);
1297 * Print host/label pairs
1299 static int net6addr_seq_show(struct seq_file *s, void *v)
1301 struct list_head *list = v;
1302 struct smk_net6addr *skp =
1303 list_entry(list, struct smk_net6addr, list);
1305 if (skp->smk_label != NULL)
1306 seq_printf(s, "%pI6/%d %s\n", &skp->smk_host, skp->smk_masks,
1307 skp->smk_label->smk_known);
1312 static const struct seq_operations net6addr_seq_ops = {
1313 .start = net6addr_seq_start,
1314 .next = net6addr_seq_next,
1315 .show = net6addr_seq_show,
1316 .stop = smk_seq_stop,
1320 * smk_open_net6addr - open() for /smack/netlabel
1321 * @inode: inode structure representing file
1322 * @file: "netlabel" file pointer
1324 * Connect our net6addr_seq_* operations with /smack/netlabel
1327 static int smk_open_net6addr(struct inode *inode, struct file *file)
1329 return seq_open(file, &net6addr_seq_ops);
1333 * smk_net6addr_insert
1334 * @new : entry to insert
1336 * This inserts an entry in the smack_net6addrs list
1337 * sorted by netmask length (longest to smallest)
1338 * locked by &smk_net6addr_lock in smk_write_net6addr
1341 static void smk_net6addr_insert(struct smk_net6addr *new)
1343 struct smk_net6addr *m_next;
1344 struct smk_net6addr *m;
1346 if (list_empty(&smk_net6addr_list)) {
1347 list_add_rcu(&new->list, &smk_net6addr_list);
1351 m = list_entry_rcu(smk_net6addr_list.next,
1352 struct smk_net6addr, list);
1354 if (new->smk_masks > m->smk_masks) {
1355 list_add_rcu(&new->list, &smk_net6addr_list);
1359 list_for_each_entry_rcu(m, &smk_net6addr_list, list) {
1360 if (list_is_last(&m->list, &smk_net6addr_list)) {
1361 list_add_rcu(&new->list, &m->list);
1364 m_next = list_entry_rcu(m->list.next,
1365 struct smk_net6addr, list);
1366 if (new->smk_masks > m_next->smk_masks) {
1367 list_add_rcu(&new->list, &m->list);
1375 * smk_write_net6addr - write() for /smack/netlabel
1376 * @file: file pointer, not actually used
1377 * @buf: where to get the data from
1378 * @count: bytes sent
1379 * @ppos: where to start
1381 * Accepts only one net6addr per write call.
1382 * Returns number of bytes written or error code, as appropriate
1384 static ssize_t smk_write_net6addr(struct file *file, const char __user *buf,
1385 size_t count, loff_t *ppos)
1387 struct smk_net6addr *snp;
1388 struct in6_addr newname;
1389 struct in6_addr fullmask;
1390 struct smack_known *skp = NULL;
1396 unsigned int scanned[8];
1398 unsigned int mask = 128;
1401 * Must have privilege.
1402 * No partial writes.
1403 * Enough data must be present.
1404 * "<addr/mask, as a:b:c:d:e:f:g:h/e><space><label>"
1405 * "<addr, as a:b:c:d:e:f:g:h><space><label>"
1407 if (!smack_privileged(CAP_MAC_ADMIN))
1411 if (count < SMK_NETLBLADDRMIN)
1414 data = memdup_user_nul(buf, count);
1416 return PTR_ERR(data);
1418 smack = kzalloc(count + 1, GFP_KERNEL);
1419 if (smack == NULL) {
1424 i = sscanf(data, "%x:%x:%x:%x:%x:%x:%x:%x/%u %s",
1425 &scanned[0], &scanned[1], &scanned[2], &scanned[3],
1426 &scanned[4], &scanned[5], &scanned[6], &scanned[7],
1429 i = sscanf(data, "%x:%x:%x:%x:%x:%x:%x:%x %s",
1430 &scanned[0], &scanned[1], &scanned[2],
1431 &scanned[3], &scanned[4], &scanned[5],
1432 &scanned[6], &scanned[7], smack);
1442 for (i = 0; i < 8; i++) {
1443 if (scanned[i] > 0xffff) {
1447 newname.s6_addr16[i] = htons(scanned[i]);
1451 * If smack begins with '-', it is an option, don't import it
1453 if (smack[0] != '-') {
1454 skp = smk_import_entry(smack, 0);
1461 * Only -DELETE is supported for IPv6
1463 if (strcmp(smack, SMACK_DELETE_OPTION) != 0) {
1469 for (i = 0, m = mask; i < 8; i++) {
1471 fullmask.s6_addr16[i] = 0xffff;
1474 fullmask.s6_addr16[i] = (1 << m) - 1;
1477 fullmask.s6_addr16[i] = 0;
1478 newname.s6_addr16[i] &= fullmask.s6_addr16[i];
1482 * Only allow one writer at a time. Writes should be
1483 * quite rare and small in any case.
1485 mutex_lock(&smk_net6addr_lock);
1487 * Try to find the prefix in the list
1489 list_for_each_entry_rcu(snp, &smk_net6addr_list, list) {
1490 if (mask != snp->smk_masks)
1492 for (found = 1, i = 0; i < 8; i++) {
1493 if (newname.s6_addr16[i] !=
1494 snp->smk_host.s6_addr16[i]) {
1503 snp = kzalloc(sizeof(*snp), GFP_KERNEL);
1507 snp->smk_host = newname;
1508 snp->smk_mask = fullmask;
1509 snp->smk_masks = mask;
1510 snp->smk_label = skp;
1511 smk_net6addr_insert(snp);
1514 snp->smk_label = skp;
1520 mutex_unlock(&smk_net6addr_lock);
1530 static const struct file_operations smk_net6addr_ops = {
1531 .open = smk_open_net6addr,
1533 .llseek = seq_lseek,
1534 .write = smk_write_net6addr,
1535 .release = seq_release,
1537 #endif /* CONFIG_IPV6 */
1540 * smk_read_doi - read() for /smack/doi
1541 * @filp: file pointer, not actually used
1542 * @buf: where to put the result
1543 * @count: maximum to send along
1544 * @ppos: where to start
1546 * Returns number of bytes read or error code, as appropriate
1548 static ssize_t smk_read_doi(struct file *filp, char __user *buf,
1549 size_t count, loff_t *ppos)
1557 sprintf(temp, "%d", smk_cipso_doi_value);
1558 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
1564 * smk_write_doi - write() for /smack/doi
1565 * @file: file pointer, not actually used
1566 * @buf: where to get the data from
1567 * @count: bytes sent
1568 * @ppos: where to start
1570 * Returns number of bytes written or error code, as appropriate
1572 static ssize_t smk_write_doi(struct file *file, const char __user *buf,
1573 size_t count, loff_t *ppos)
1578 if (!smack_privileged(CAP_MAC_ADMIN))
1581 if (count >= sizeof(temp) || count == 0)
1584 if (copy_from_user(temp, buf, count) != 0)
1589 if (sscanf(temp, "%d", &i) != 1)
1592 smk_cipso_doi_value = i;
1599 static const struct file_operations smk_doi_ops = {
1600 .read = smk_read_doi,
1601 .write = smk_write_doi,
1602 .llseek = default_llseek,
1606 * smk_read_direct - read() for /smack/direct
1607 * @filp: file pointer, not actually used
1608 * @buf: where to put the result
1609 * @count: maximum to send along
1610 * @ppos: where to start
1612 * Returns number of bytes read or error code, as appropriate
1614 static ssize_t smk_read_direct(struct file *filp, char __user *buf,
1615 size_t count, loff_t *ppos)
1623 sprintf(temp, "%d", smack_cipso_direct);
1624 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
1630 * smk_write_direct - write() for /smack/direct
1631 * @file: file pointer, not actually used
1632 * @buf: where to get the data from
1633 * @count: bytes sent
1634 * @ppos: where to start
1636 * Returns number of bytes written or error code, as appropriate
1638 static ssize_t smk_write_direct(struct file *file, const char __user *buf,
1639 size_t count, loff_t *ppos)
1641 struct smack_known *skp;
1645 if (!smack_privileged(CAP_MAC_ADMIN))
1648 if (count >= sizeof(temp) || count == 0)
1651 if (copy_from_user(temp, buf, count) != 0)
1656 if (sscanf(temp, "%d", &i) != 1)
1660 * Don't do anything if the value hasn't actually changed.
1661 * If it is changing reset the level on entries that were
1662 * set up to be direct when they were created.
1664 if (smack_cipso_direct != i) {
1665 mutex_lock(&smack_known_lock);
1666 list_for_each_entry_rcu(skp, &smack_known_list, list)
1667 if (skp->smk_netlabel.attr.mls.lvl ==
1669 skp->smk_netlabel.attr.mls.lvl = i;
1670 smack_cipso_direct = i;
1671 mutex_unlock(&smack_known_lock);
1677 static const struct file_operations smk_direct_ops = {
1678 .read = smk_read_direct,
1679 .write = smk_write_direct,
1680 .llseek = default_llseek,
1684 * smk_read_mapped - read() for /smack/mapped
1685 * @filp: file pointer, not actually used
1686 * @buf: where to put the result
1687 * @count: maximum to send along
1688 * @ppos: where to start
1690 * Returns number of bytes read or error code, as appropriate
1692 static ssize_t smk_read_mapped(struct file *filp, char __user *buf,
1693 size_t count, loff_t *ppos)
1701 sprintf(temp, "%d", smack_cipso_mapped);
1702 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
1708 * smk_write_mapped - write() for /smack/mapped
1709 * @file: file pointer, not actually used
1710 * @buf: where to get the data from
1711 * @count: bytes sent
1712 * @ppos: where to start
1714 * Returns number of bytes written or error code, as appropriate
1716 static ssize_t smk_write_mapped(struct file *file, const char __user *buf,
1717 size_t count, loff_t *ppos)
1719 struct smack_known *skp;
1723 if (!smack_privileged(CAP_MAC_ADMIN))
1726 if (count >= sizeof(temp) || count == 0)
1729 if (copy_from_user(temp, buf, count) != 0)
1734 if (sscanf(temp, "%d", &i) != 1)
1738 * Don't do anything if the value hasn't actually changed.
1739 * If it is changing reset the level on entries that were
1740 * set up to be mapped when they were created.
1742 if (smack_cipso_mapped != i) {
1743 mutex_lock(&smack_known_lock);
1744 list_for_each_entry_rcu(skp, &smack_known_list, list)
1745 if (skp->smk_netlabel.attr.mls.lvl ==
1747 skp->smk_netlabel.attr.mls.lvl = i;
1748 smack_cipso_mapped = i;
1749 mutex_unlock(&smack_known_lock);
1755 static const struct file_operations smk_mapped_ops = {
1756 .read = smk_read_mapped,
1757 .write = smk_write_mapped,
1758 .llseek = default_llseek,
1762 * smk_read_ambient - read() for /smack/ambient
1763 * @filp: file pointer, not actually used
1764 * @buf: where to put the result
1765 * @cn: maximum to send along
1766 * @ppos: where to start
1768 * Returns number of bytes read or error code, as appropriate
1770 static ssize_t smk_read_ambient(struct file *filp, char __user *buf,
1771 size_t cn, loff_t *ppos)
1779 * Being careful to avoid a problem in the case where
1780 * smack_net_ambient gets changed in midstream.
1782 mutex_lock(&smack_ambient_lock);
1784 asize = strlen(smack_net_ambient->smk_known) + 1;
1787 rc = simple_read_from_buffer(buf, cn, ppos,
1788 smack_net_ambient->smk_known,
1793 mutex_unlock(&smack_ambient_lock);
1799 * smk_write_ambient - write() for /smack/ambient
1800 * @file: file pointer, not actually used
1801 * @buf: where to get the data from
1802 * @count: bytes sent
1803 * @ppos: where to start
1805 * Returns number of bytes written or error code, as appropriate
1807 static ssize_t smk_write_ambient(struct file *file, const char __user *buf,
1808 size_t count, loff_t *ppos)
1810 struct smack_known *skp;
1815 if (!smack_privileged(CAP_MAC_ADMIN))
1818 data = memdup_user_nul(buf, count);
1820 return PTR_ERR(data);
1822 skp = smk_import_entry(data, count);
1828 mutex_lock(&smack_ambient_lock);
1830 oldambient = smack_net_ambient->smk_known;
1831 smack_net_ambient = skp;
1832 smk_unlbl_ambient(oldambient);
1834 mutex_unlock(&smack_ambient_lock);
1841 static const struct file_operations smk_ambient_ops = {
1842 .read = smk_read_ambient,
1843 .write = smk_write_ambient,
1844 .llseek = default_llseek,
1848 * Seq_file operations for /smack/onlycap
1850 static void *onlycap_seq_start(struct seq_file *s, loff_t *pos)
1852 return smk_seq_start(s, pos, &smack_onlycap_list);
1855 static void *onlycap_seq_next(struct seq_file *s, void *v, loff_t *pos)
1857 return smk_seq_next(s, v, pos, &smack_onlycap_list);
1860 static int onlycap_seq_show(struct seq_file *s, void *v)
1862 struct list_head *list = v;
1863 struct smack_known_list_elem *sklep =
1864 list_entry_rcu(list, struct smack_known_list_elem, list);
1866 seq_puts(s, sklep->smk_label->smk_known);
1872 static const struct seq_operations onlycap_seq_ops = {
1873 .start = onlycap_seq_start,
1874 .next = onlycap_seq_next,
1875 .show = onlycap_seq_show,
1876 .stop = smk_seq_stop,
1879 static int smk_open_onlycap(struct inode *inode, struct file *file)
1881 return seq_open(file, &onlycap_seq_ops);
1885 * smk_list_swap_rcu - swap public list with a private one in RCU-safe way
1886 * The caller must hold appropriate mutex to prevent concurrent modifications
1887 * to the public list.
1888 * Private list is assumed to be not accessible to other threads yet.
1890 * @public: public list
1891 * @private: private list
1893 static void smk_list_swap_rcu(struct list_head *public,
1894 struct list_head *private)
1896 struct list_head *first, *last;
1898 if (list_empty(public)) {
1899 list_splice_init_rcu(private, public, synchronize_rcu);
1901 /* Remember public list before replacing it */
1902 first = public->next;
1903 last = public->prev;
1905 /* Publish private list in place of public in RCU-safe way */
1906 private->prev->next = public;
1907 private->next->prev = public;
1908 rcu_assign_pointer(public->next, private->next);
1909 public->prev = private->prev;
1913 /* When all readers are done with the old public list,
1914 * attach it in place of private */
1915 private->next = first;
1916 private->prev = last;
1917 first->prev = private;
1918 last->next = private;
1923 * smk_parse_label_list - parse list of Smack labels, separated by spaces
1925 * @data: the string to parse
1926 * @private: destination list
1928 * Returns zero on success or error code, as appropriate
1930 static int smk_parse_label_list(char *data, struct list_head *list)
1933 struct smack_known *skp;
1934 struct smack_known_list_elem *sklep;
1936 while ((tok = strsep(&data, " ")) != NULL) {
1940 skp = smk_import_entry(tok, 0);
1942 return PTR_ERR(skp);
1944 sklep = kzalloc(sizeof(*sklep), GFP_KERNEL);
1948 sklep->smk_label = skp;
1949 list_add(&sklep->list, list);
1956 * smk_destroy_label_list - destroy a list of smack_known_list_elem
1957 * @head: header pointer of the list to destroy
1959 void smk_destroy_label_list(struct list_head *list)
1961 struct smack_known_list_elem *sklep;
1962 struct smack_known_list_elem *sklep2;
1964 list_for_each_entry_safe(sklep, sklep2, list, list)
1967 INIT_LIST_HEAD(list);
1971 * smk_write_onlycap - write() for smackfs/onlycap
1972 * @file: file pointer, not actually used
1973 * @buf: where to get the data from
1974 * @count: bytes sent
1975 * @ppos: where to start
1977 * Returns number of bytes written or error code, as appropriate
1979 static ssize_t smk_write_onlycap(struct file *file, const char __user *buf,
1980 size_t count, loff_t *ppos)
1983 LIST_HEAD(list_tmp);
1986 if (!smack_privileged(CAP_MAC_ADMIN))
1989 data = memdup_user_nul(buf, count);
1991 return PTR_ERR(data);
1993 rc = smk_parse_label_list(data, &list_tmp);
1997 * Clear the smack_onlycap on invalid label errors. This means
1998 * that we can pass a null string to unset the onlycap value.
2000 * Importing will also reject a label beginning with '-',
2001 * so "-usecapabilities" will also work.
2003 * But do so only on invalid label, not on system errors.
2004 * The invalid label must be first to count as clearing attempt.
2006 if (!rc || (rc == -EINVAL && list_empty(&list_tmp))) {
2007 mutex_lock(&smack_onlycap_lock);
2008 smk_list_swap_rcu(&smack_onlycap_list, &list_tmp);
2009 mutex_unlock(&smack_onlycap_lock);
2013 smk_destroy_label_list(&list_tmp);
2018 static const struct file_operations smk_onlycap_ops = {
2019 .open = smk_open_onlycap,
2021 .write = smk_write_onlycap,
2022 .llseek = seq_lseek,
2023 .release = seq_release,
2026 #ifdef CONFIG_SECURITY_SMACK_BRINGUP
2028 * smk_read_unconfined - read() for smackfs/unconfined
2029 * @filp: file pointer, not actually used
2030 * @buf: where to put the result
2031 * @cn: maximum to send along
2032 * @ppos: where to start
2034 * Returns number of bytes read or error code, as appropriate
2036 static ssize_t smk_read_unconfined(struct file *filp, char __user *buf,
2037 size_t cn, loff_t *ppos)
2040 ssize_t rc = -EINVAL;
2046 if (smack_unconfined != NULL)
2047 smack = smack_unconfined->smk_known;
2049 asize = strlen(smack) + 1;
2052 rc = simple_read_from_buffer(buf, cn, ppos, smack, asize);
2058 * smk_write_unconfined - write() for smackfs/unconfined
2059 * @file: file pointer, not actually used
2060 * @buf: where to get the data from
2061 * @count: bytes sent
2062 * @ppos: where to start
2064 * Returns number of bytes written or error code, as appropriate
2066 static ssize_t smk_write_unconfined(struct file *file, const char __user *buf,
2067 size_t count, loff_t *ppos)
2070 struct smack_known *skp;
2073 if (!smack_privileged(CAP_MAC_ADMIN))
2076 data = memdup_user_nul(buf, count);
2078 return PTR_ERR(data);
2081 * Clear the smack_unconfined on invalid label errors. This means
2082 * that we can pass a null string to unset the unconfined value.
2084 * Importing will also reject a label beginning with '-',
2085 * so "-confine" will also work.
2087 * But do so only on invalid label, not on system errors.
2089 skp = smk_import_entry(data, count);
2090 if (PTR_ERR(skp) == -EINVAL)
2092 else if (IS_ERR(skp)) {
2097 smack_unconfined = skp;
2104 static const struct file_operations smk_unconfined_ops = {
2105 .read = smk_read_unconfined,
2106 .write = smk_write_unconfined,
2107 .llseek = default_llseek,
2109 #endif /* CONFIG_SECURITY_SMACK_BRINGUP */
2112 * smk_read_logging - read() for /smack/logging
2113 * @filp: file pointer, not actually used
2114 * @buf: where to put the result
2115 * @cn: maximum to send along
2116 * @ppos: where to start
2118 * Returns number of bytes read or error code, as appropriate
2120 static ssize_t smk_read_logging(struct file *filp, char __user *buf,
2121 size_t count, loff_t *ppos)
2129 sprintf(temp, "%d\n", log_policy);
2130 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
2135 * smk_write_logging - write() for /smack/logging
2136 * @file: file pointer, not actually used
2137 * @buf: where to get the data from
2138 * @count: bytes sent
2139 * @ppos: where to start
2141 * Returns number of bytes written or error code, as appropriate
2143 static ssize_t smk_write_logging(struct file *file, const char __user *buf,
2144 size_t count, loff_t *ppos)
2149 if (!smack_privileged(CAP_MAC_ADMIN))
2152 if (count >= sizeof(temp) || count == 0)
2155 if (copy_from_user(temp, buf, count) != 0)
2160 if (sscanf(temp, "%d", &i) != 1)
2170 static const struct file_operations smk_logging_ops = {
2171 .read = smk_read_logging,
2172 .write = smk_write_logging,
2173 .llseek = default_llseek,
2177 * Seq_file read operations for /smack/load-self
2180 static void *load_self_seq_start(struct seq_file *s, loff_t *pos)
2182 struct task_smack *tsp = smack_cred(current_cred());
2184 return smk_seq_start(s, pos, &tsp->smk_rules);
2187 static void *load_self_seq_next(struct seq_file *s, void *v, loff_t *pos)
2189 struct task_smack *tsp = smack_cred(current_cred());
2191 return smk_seq_next(s, v, pos, &tsp->smk_rules);
2194 static int load_self_seq_show(struct seq_file *s, void *v)
2196 struct list_head *list = v;
2197 struct smack_rule *srp =
2198 list_entry_rcu(list, struct smack_rule, list);
2200 smk_rule_show(s, srp, SMK_LABELLEN);
2205 static const struct seq_operations load_self_seq_ops = {
2206 .start = load_self_seq_start,
2207 .next = load_self_seq_next,
2208 .show = load_self_seq_show,
2209 .stop = smk_seq_stop,
2214 * smk_open_load_self - open() for /smack/load-self2
2215 * @inode: inode structure representing file
2216 * @file: "load" file pointer
2218 * For reading, use load_seq_* seq_file reading operations.
2220 static int smk_open_load_self(struct inode *inode, struct file *file)
2222 return seq_open(file, &load_self_seq_ops);
2226 * smk_write_load_self - write() for /smack/load-self
2227 * @file: file pointer, not actually used
2228 * @buf: where to get the data from
2229 * @count: bytes sent
2230 * @ppos: where to start - must be 0
2233 static ssize_t smk_write_load_self(struct file *file, const char __user *buf,
2234 size_t count, loff_t *ppos)
2236 struct task_smack *tsp = smack_cred(current_cred());
2238 return smk_write_rules_list(file, buf, count, ppos, &tsp->smk_rules,
2239 &tsp->smk_rules_lock, SMK_FIXED24_FMT);
2242 static const struct file_operations smk_load_self_ops = {
2243 .open = smk_open_load_self,
2245 .llseek = seq_lseek,
2246 .write = smk_write_load_self,
2247 .release = seq_release,
2251 * smk_user_access - handle access check transaction
2252 * @file: file pointer
2253 * @buf: data from user space
2254 * @count: bytes sent
2255 * @ppos: where to start - must be 0
2257 static ssize_t smk_user_access(struct file *file, const char __user *buf,
2258 size_t count, loff_t *ppos, int format)
2260 struct smack_parsed_rule rule;
2264 data = simple_transaction_get(file, buf, count);
2266 return PTR_ERR(data);
2268 if (format == SMK_FIXED24_FMT) {
2269 if (count < SMK_LOADLEN)
2271 res = smk_parse_rule(data, &rule, 0);
2274 * simple_transaction_get() returns null-terminated data
2276 res = smk_parse_long_rule(data, &rule, 0, 3);
2280 res = smk_access(rule.smk_subject, rule.smk_object,
2281 rule.smk_access1, NULL);
2282 else if (res != -ENOENT)
2286 * smk_access() can return a value > 0 in the "bringup" case.
2288 data[0] = res >= 0 ? '1' : '0';
2291 simple_transaction_set(file, 2);
2293 if (format == SMK_FIXED24_FMT)
2299 * smk_write_access - handle access check transaction
2300 * @file: file pointer
2301 * @buf: data from user space
2302 * @count: bytes sent
2303 * @ppos: where to start - must be 0
2305 static ssize_t smk_write_access(struct file *file, const char __user *buf,
2306 size_t count, loff_t *ppos)
2308 return smk_user_access(file, buf, count, ppos, SMK_FIXED24_FMT);
2311 static const struct file_operations smk_access_ops = {
2312 .write = smk_write_access,
2313 .read = simple_transaction_read,
2314 .release = simple_transaction_release,
2315 .llseek = generic_file_llseek,
2320 * Seq_file read operations for /smack/load2
2323 static int load2_seq_show(struct seq_file *s, void *v)
2325 struct list_head *list = v;
2326 struct smack_rule *srp;
2327 struct smack_known *skp =
2328 list_entry_rcu(list, struct smack_known, list);
2330 list_for_each_entry_rcu(srp, &skp->smk_rules, list)
2331 smk_rule_show(s, srp, SMK_LONGLABEL);
2336 static const struct seq_operations load2_seq_ops = {
2337 .start = load2_seq_start,
2338 .next = load2_seq_next,
2339 .show = load2_seq_show,
2340 .stop = smk_seq_stop,
2344 * smk_open_load2 - open() for /smack/load2
2345 * @inode: inode structure representing file
2346 * @file: "load2" file pointer
2348 * For reading, use load2_seq_* seq_file reading operations.
2350 static int smk_open_load2(struct inode *inode, struct file *file)
2352 return seq_open(file, &load2_seq_ops);
2356 * smk_write_load2 - write() for /smack/load2
2357 * @file: file pointer, not actually used
2358 * @buf: where to get the data from
2359 * @count: bytes sent
2360 * @ppos: where to start - must be 0
2363 static ssize_t smk_write_load2(struct file *file, const char __user *buf,
2364 size_t count, loff_t *ppos)
2367 * Must have privilege.
2369 if (!smack_privileged(CAP_MAC_ADMIN))
2372 return smk_write_rules_list(file, buf, count, ppos, NULL, NULL,
2376 static const struct file_operations smk_load2_ops = {
2377 .open = smk_open_load2,
2379 .llseek = seq_lseek,
2380 .write = smk_write_load2,
2381 .release = seq_release,
2385 * Seq_file read operations for /smack/load-self2
2388 static void *load_self2_seq_start(struct seq_file *s, loff_t *pos)
2390 struct task_smack *tsp = smack_cred(current_cred());
2392 return smk_seq_start(s, pos, &tsp->smk_rules);
2395 static void *load_self2_seq_next(struct seq_file *s, void *v, loff_t *pos)
2397 struct task_smack *tsp = smack_cred(current_cred());
2399 return smk_seq_next(s, v, pos, &tsp->smk_rules);
2402 static int load_self2_seq_show(struct seq_file *s, void *v)
2404 struct list_head *list = v;
2405 struct smack_rule *srp =
2406 list_entry_rcu(list, struct smack_rule, list);
2408 smk_rule_show(s, srp, SMK_LONGLABEL);
2413 static const struct seq_operations load_self2_seq_ops = {
2414 .start = load_self2_seq_start,
2415 .next = load_self2_seq_next,
2416 .show = load_self2_seq_show,
2417 .stop = smk_seq_stop,
2421 * smk_open_load_self2 - open() for /smack/load-self2
2422 * @inode: inode structure representing file
2423 * @file: "load" file pointer
2425 * For reading, use load_seq_* seq_file reading operations.
2427 static int smk_open_load_self2(struct inode *inode, struct file *file)
2429 return seq_open(file, &load_self2_seq_ops);
2433 * smk_write_load_self2 - write() for /smack/load-self2
2434 * @file: file pointer, not actually used
2435 * @buf: where to get the data from
2436 * @count: bytes sent
2437 * @ppos: where to start - must be 0
2440 static ssize_t smk_write_load_self2(struct file *file, const char __user *buf,
2441 size_t count, loff_t *ppos)
2443 struct task_smack *tsp = smack_cred(current_cred());
2445 return smk_write_rules_list(file, buf, count, ppos, &tsp->smk_rules,
2446 &tsp->smk_rules_lock, SMK_LONG_FMT);
2449 static const struct file_operations smk_load_self2_ops = {
2450 .open = smk_open_load_self2,
2452 .llseek = seq_lseek,
2453 .write = smk_write_load_self2,
2454 .release = seq_release,
2458 * smk_write_access2 - handle access check transaction
2459 * @file: file pointer
2460 * @buf: data from user space
2461 * @count: bytes sent
2462 * @ppos: where to start - must be 0
2464 static ssize_t smk_write_access2(struct file *file, const char __user *buf,
2465 size_t count, loff_t *ppos)
2467 return smk_user_access(file, buf, count, ppos, SMK_LONG_FMT);
2470 static const struct file_operations smk_access2_ops = {
2471 .write = smk_write_access2,
2472 .read = simple_transaction_read,
2473 .release = simple_transaction_release,
2474 .llseek = generic_file_llseek,
2478 * smk_write_revoke_subj - write() for /smack/revoke-subject
2479 * @file: file pointer
2480 * @buf: data from user space
2481 * @count: bytes sent
2482 * @ppos: where to start - must be 0
2484 static ssize_t smk_write_revoke_subj(struct file *file, const char __user *buf,
2485 size_t count, loff_t *ppos)
2489 struct smack_known *skp;
2490 struct smack_rule *sp;
2491 struct list_head *rule_list;
2492 struct mutex *rule_lock;
2498 if (!smack_privileged(CAP_MAC_ADMIN))
2501 if (count == 0 || count > SMK_LONGLABEL)
2504 data = memdup_user(buf, count);
2506 return PTR_ERR(data);
2508 cp = smk_parse_smack(data, count);
2514 skp = smk_find_entry(cp);
2518 rule_list = &skp->smk_rules;
2519 rule_lock = &skp->smk_rules_lock;
2521 mutex_lock(rule_lock);
2523 list_for_each_entry_rcu(sp, rule_list, list)
2526 mutex_unlock(rule_lock);
2536 static const struct file_operations smk_revoke_subj_ops = {
2537 .write = smk_write_revoke_subj,
2538 .read = simple_transaction_read,
2539 .release = simple_transaction_release,
2540 .llseek = generic_file_llseek,
2544 * smk_init_sysfs - initialize /sys/fs/smackfs
2547 static int smk_init_sysfs(void)
2549 return sysfs_create_mount_point(fs_kobj, "smackfs");
2553 * smk_write_change_rule - write() for /smack/change-rule
2554 * @file: file pointer
2555 * @buf: data from user space
2556 * @count: bytes sent
2557 * @ppos: where to start - must be 0
2559 static ssize_t smk_write_change_rule(struct file *file, const char __user *buf,
2560 size_t count, loff_t *ppos)
2563 * Must have privilege.
2565 if (!smack_privileged(CAP_MAC_ADMIN))
2568 return smk_write_rules_list(file, buf, count, ppos, NULL, NULL,
2572 static const struct file_operations smk_change_rule_ops = {
2573 .write = smk_write_change_rule,
2574 .read = simple_transaction_read,
2575 .release = simple_transaction_release,
2576 .llseek = generic_file_llseek,
2580 * smk_read_syslog - read() for smackfs/syslog
2581 * @filp: file pointer, not actually used
2582 * @buf: where to put the result
2583 * @cn: maximum to send along
2584 * @ppos: where to start
2586 * Returns number of bytes read or error code, as appropriate
2588 static ssize_t smk_read_syslog(struct file *filp, char __user *buf,
2589 size_t cn, loff_t *ppos)
2591 struct smack_known *skp;
2592 ssize_t rc = -EINVAL;
2598 if (smack_syslog_label == NULL)
2599 skp = &smack_known_star;
2601 skp = smack_syslog_label;
2603 asize = strlen(skp->smk_known) + 1;
2606 rc = simple_read_from_buffer(buf, cn, ppos, skp->smk_known,
2613 * smk_write_syslog - write() for smackfs/syslog
2614 * @file: file pointer, not actually used
2615 * @buf: where to get the data from
2616 * @count: bytes sent
2617 * @ppos: where to start
2619 * Returns number of bytes written or error code, as appropriate
2621 static ssize_t smk_write_syslog(struct file *file, const char __user *buf,
2622 size_t count, loff_t *ppos)
2625 struct smack_known *skp;
2628 if (!smack_privileged(CAP_MAC_ADMIN))
2631 data = memdup_user_nul(buf, count);
2633 return PTR_ERR(data);
2635 skp = smk_import_entry(data, count);
2639 smack_syslog_label = skp;
2645 static const struct file_operations smk_syslog_ops = {
2646 .read = smk_read_syslog,
2647 .write = smk_write_syslog,
2648 .llseek = default_llseek,
2652 * Seq_file read operations for /smack/relabel-self
2655 static void *relabel_self_seq_start(struct seq_file *s, loff_t *pos)
2657 struct task_smack *tsp = smack_cred(current_cred());
2659 return smk_seq_start(s, pos, &tsp->smk_relabel);
2662 static void *relabel_self_seq_next(struct seq_file *s, void *v, loff_t *pos)
2664 struct task_smack *tsp = smack_cred(current_cred());
2666 return smk_seq_next(s, v, pos, &tsp->smk_relabel);
2669 static int relabel_self_seq_show(struct seq_file *s, void *v)
2671 struct list_head *list = v;
2672 struct smack_known_list_elem *sklep =
2673 list_entry(list, struct smack_known_list_elem, list);
2675 seq_puts(s, sklep->smk_label->smk_known);
2681 static const struct seq_operations relabel_self_seq_ops = {
2682 .start = relabel_self_seq_start,
2683 .next = relabel_self_seq_next,
2684 .show = relabel_self_seq_show,
2685 .stop = smk_seq_stop,
2689 * smk_open_relabel_self - open() for /smack/relabel-self
2690 * @inode: inode structure representing file
2691 * @file: "relabel-self" file pointer
2693 * Connect our relabel_self_seq_* operations with /smack/relabel-self
2696 static int smk_open_relabel_self(struct inode *inode, struct file *file)
2698 return seq_open(file, &relabel_self_seq_ops);
2702 * smk_write_relabel_self - write() for /smack/relabel-self
2703 * @file: file pointer, not actually used
2704 * @buf: where to get the data from
2705 * @count: bytes sent
2706 * @ppos: where to start - must be 0
2709 static ssize_t smk_write_relabel_self(struct file *file, const char __user *buf,
2710 size_t count, loff_t *ppos)
2712 struct task_smack *tsp = smack_cred(current_cred());
2715 LIST_HEAD(list_tmp);
2718 * Must have privilege.
2720 if (!smack_privileged(CAP_MAC_ADMIN))
2724 * Enough data must be present.
2729 data = memdup_user_nul(buf, count);
2731 return PTR_ERR(data);
2733 rc = smk_parse_label_list(data, &list_tmp);
2736 if (!rc || (rc == -EINVAL && list_empty(&list_tmp))) {
2737 smk_destroy_label_list(&tsp->smk_relabel);
2738 list_splice(&list_tmp, &tsp->smk_relabel);
2742 smk_destroy_label_list(&list_tmp);
2746 static const struct file_operations smk_relabel_self_ops = {
2747 .open = smk_open_relabel_self,
2749 .llseek = seq_lseek,
2750 .write = smk_write_relabel_self,
2751 .release = seq_release,
2755 * smk_read_ptrace - read() for /smack/ptrace
2756 * @filp: file pointer, not actually used
2757 * @buf: where to put the result
2758 * @count: maximum to send along
2759 * @ppos: where to start
2761 * Returns number of bytes read or error code, as appropriate
2763 static ssize_t smk_read_ptrace(struct file *filp, char __user *buf,
2764 size_t count, loff_t *ppos)
2772 sprintf(temp, "%d\n", smack_ptrace_rule);
2773 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
2778 * smk_write_ptrace - write() for /smack/ptrace
2779 * @file: file pointer
2780 * @buf: data from user space
2781 * @count: bytes sent
2782 * @ppos: where to start - must be 0
2784 static ssize_t smk_write_ptrace(struct file *file, const char __user *buf,
2785 size_t count, loff_t *ppos)
2790 if (!smack_privileged(CAP_MAC_ADMIN))
2793 if (*ppos != 0 || count >= sizeof(temp) || count == 0)
2796 if (copy_from_user(temp, buf, count) != 0)
2801 if (sscanf(temp, "%d", &i) != 1)
2803 if (i < SMACK_PTRACE_DEFAULT || i > SMACK_PTRACE_MAX)
2805 smack_ptrace_rule = i;
2810 static const struct file_operations smk_ptrace_ops = {
2811 .write = smk_write_ptrace,
2812 .read = smk_read_ptrace,
2813 .llseek = default_llseek,
2817 * smk_fill_super - fill the smackfs superblock
2818 * @sb: the empty superblock
2822 * Fill in the well known entries for the smack filesystem
2824 * Returns 0 on success, an error code on failure
2826 static int smk_fill_super(struct super_block *sb, void *data, int silent)
2830 static const struct tree_descr smack_files[] = {
2832 "load", &smk_load_ops, S_IRUGO|S_IWUSR},
2834 "cipso", &smk_cipso_ops, S_IRUGO|S_IWUSR},
2836 "doi", &smk_doi_ops, S_IRUGO|S_IWUSR},
2838 "direct", &smk_direct_ops, S_IRUGO|S_IWUSR},
2840 "ambient", &smk_ambient_ops, S_IRUGO|S_IWUSR},
2842 "netlabel", &smk_net4addr_ops, S_IRUGO|S_IWUSR},
2844 "onlycap", &smk_onlycap_ops, S_IRUGO|S_IWUSR},
2846 "logging", &smk_logging_ops, S_IRUGO|S_IWUSR},
2848 "load-self", &smk_load_self_ops, S_IRUGO|S_IWUGO},
2850 "access", &smk_access_ops, S_IRUGO|S_IWUGO},
2852 "mapped", &smk_mapped_ops, S_IRUGO|S_IWUSR},
2854 "load2", &smk_load2_ops, S_IRUGO|S_IWUSR},
2855 [SMK_LOAD_SELF2] = {
2856 "load-self2", &smk_load_self2_ops, S_IRUGO|S_IWUGO},
2858 "access2", &smk_access2_ops, S_IRUGO|S_IWUGO},
2860 "cipso2", &smk_cipso2_ops, S_IRUGO|S_IWUSR},
2861 [SMK_REVOKE_SUBJ] = {
2862 "revoke-subject", &smk_revoke_subj_ops,
2864 [SMK_CHANGE_RULE] = {
2865 "change-rule", &smk_change_rule_ops, S_IRUGO|S_IWUSR},
2867 "syslog", &smk_syslog_ops, S_IRUGO|S_IWUSR},
2869 "ptrace", &smk_ptrace_ops, S_IRUGO|S_IWUSR},
2870 #ifdef CONFIG_SECURITY_SMACK_BRINGUP
2871 [SMK_UNCONFINED] = {
2872 "unconfined", &smk_unconfined_ops, S_IRUGO|S_IWUSR},
2874 #if IS_ENABLED(CONFIG_IPV6)
2876 "ipv6host", &smk_net6addr_ops, S_IRUGO|S_IWUSR},
2877 #endif /* CONFIG_IPV6 */
2878 [SMK_RELABEL_SELF] = {
2879 "relabel-self", &smk_relabel_self_ops,
2885 rc = simple_fill_super(sb, SMACK_MAGIC, smack_files);
2887 printk(KERN_ERR "%s failed %d while creating inodes\n",
2896 * smk_mount - get the smackfs superblock
2897 * @fs_type: passed along without comment
2898 * @flags: passed along without comment
2899 * @dev_name: passed along without comment
2900 * @data: passed along without comment
2902 * Just passes everything along.
2904 * Returns what the lower level code does.
2906 static struct dentry *smk_mount(struct file_system_type *fs_type,
2907 int flags, const char *dev_name, void *data)
2909 return mount_single(fs_type, flags, data, smk_fill_super);
2912 static struct file_system_type smk_fs_type = {
2915 .kill_sb = kill_litter_super,
2918 static struct vfsmount *smackfs_mount;
2920 static int __init smk_preset_netlabel(struct smack_known *skp)
2922 skp->smk_netlabel.domain = skp->smk_known;
2923 skp->smk_netlabel.flags =
2924 NETLBL_SECATTR_DOMAIN | NETLBL_SECATTR_MLS_LVL;
2925 return smk_netlbl_mls(smack_cipso_direct, skp->smk_known,
2926 &skp->smk_netlabel, strlen(skp->smk_known));
2930 * init_smk_fs - get the smackfs superblock
2932 * register the smackfs
2934 * Do not register smackfs if Smack wasn't enabled
2935 * on boot. We can not put this method normally under the
2936 * smack_init() code path since the security subsystem get
2937 * initialized before the vfs caches.
2939 * Returns true if we were not chosen on boot or if
2940 * we were chosen and filesystem registration succeeded.
2942 static int __init init_smk_fs(void)
2947 if (smack_enabled == 0)
2950 err = smk_init_sysfs();
2952 printk(KERN_ERR "smackfs: sysfs mountpoint problem.\n");
2954 err = register_filesystem(&smk_fs_type);
2956 smackfs_mount = kern_mount(&smk_fs_type);
2957 if (IS_ERR(smackfs_mount)) {
2958 printk(KERN_ERR "smackfs: could not mount!\n");
2959 err = PTR_ERR(smackfs_mount);
2960 smackfs_mount = NULL;
2965 smk_unlbl_ambient(NULL);
2967 rc = smk_preset_netlabel(&smack_known_floor);
2968 if (err == 0 && rc < 0)
2970 rc = smk_preset_netlabel(&smack_known_hat);
2971 if (err == 0 && rc < 0)
2973 rc = smk_preset_netlabel(&smack_known_huh);
2974 if (err == 0 && rc < 0)
2976 rc = smk_preset_netlabel(&smack_known_star);
2977 if (err == 0 && rc < 0)
2979 rc = smk_preset_netlabel(&smack_known_web);
2980 if (err == 0 && rc < 0)
2986 __initcall(init_smk_fs);