2 * Copyright (C) 2007 Casey Schaufler <casey@schaufler-ca.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, version 2.
9 * Casey Schaufler <casey@schaufler-ca.com>
10 * Ahmed S. Darwish <darwish.07@gmail.com>
12 * Special thanks to the authors of selinuxfs.
14 * Karl MacMillan <kmacmillan@tresys.com>
15 * James Morris <jmorris@redhat.com>
19 #include <linux/kernel.h>
20 #include <linux/vmalloc.h>
21 #include <linux/security.h>
22 #include <linux/mutex.h>
23 #include <linux/slab.h>
24 #include <net/net_namespace.h>
25 #include <net/cipso_ipv4.h>
26 #include <linux/seq_file.h>
27 #include <linux/ctype.h>
28 #include <linux/audit.h>
29 #include <linux/magic.h>
30 #include <linux/fs_context.h>
33 #define BEBITS (sizeof(__be32) * 8)
35 * smackfs pseudo filesystem.
40 SMK_LOAD = 3, /* load policy */
41 SMK_CIPSO = 4, /* load label -> CIPSO mapping */
42 SMK_DOI = 5, /* CIPSO DOI */
43 SMK_DIRECT = 6, /* CIPSO level indicating direct label */
44 SMK_AMBIENT = 7, /* internet ambient label */
45 SMK_NET4ADDR = 8, /* single label hosts */
46 SMK_ONLYCAP = 9, /* the only "capable" label */
47 SMK_LOGGING = 10, /* logging */
48 SMK_LOAD_SELF = 11, /* task specific rules */
49 SMK_ACCESSES = 12, /* access policy */
50 SMK_MAPPED = 13, /* CIPSO level indicating mapped label */
51 SMK_LOAD2 = 14, /* load policy with long labels */
52 SMK_LOAD_SELF2 = 15, /* load task specific rules with long labels */
53 SMK_ACCESS2 = 16, /* make an access check with long labels */
54 SMK_CIPSO2 = 17, /* load long label -> CIPSO mapping */
55 SMK_REVOKE_SUBJ = 18, /* set rules with subject label to '-' */
56 SMK_CHANGE_RULE = 19, /* change or add rules (long labels) */
57 SMK_SYSLOG = 20, /* change syslog label) */
58 SMK_PTRACE = 21, /* set ptrace rule */
59 #ifdef CONFIG_SECURITY_SMACK_BRINGUP
60 SMK_UNCONFINED = 22, /* define an unconfined label */
62 #if IS_ENABLED(CONFIG_IPV6)
63 SMK_NET6ADDR = 23, /* single label IPv6 hosts */
64 #endif /* CONFIG_IPV6 */
65 SMK_RELABEL_SELF = 24, /* relabel possible without CAP_MAC_ADMIN */
71 static DEFINE_MUTEX(smack_cipso_lock);
72 static DEFINE_MUTEX(smack_ambient_lock);
73 static DEFINE_MUTEX(smk_net4addr_lock);
74 #if IS_ENABLED(CONFIG_IPV6)
75 static DEFINE_MUTEX(smk_net6addr_lock);
76 #endif /* CONFIG_IPV6 */
79 * This is the "ambient" label for network traffic.
80 * If it isn't somehow marked, use this.
81 * It can be reset via smackfs/ambient
83 struct smack_known *smack_net_ambient;
86 * This is the level in a CIPSO header that indicates a
87 * smack label is contained directly in the category set.
88 * It can be reset via smackfs/direct
90 int smack_cipso_direct = SMACK_CIPSO_DIRECT_DEFAULT;
93 * This is the level in a CIPSO header that indicates a
94 * secid is contained directly in the category set.
95 * It can be reset via smackfs/mapped
97 int smack_cipso_mapped = SMACK_CIPSO_MAPPED_DEFAULT;
99 #ifdef CONFIG_SECURITY_SMACK_BRINGUP
101 * Allow one label to be unconfined. This is for
102 * debugging and application bring-up purposes only.
103 * It is bad and wrong, but everyone seems to expect
106 struct smack_known *smack_unconfined;
110 * If this value is set restrict syslog use to the label specified.
111 * It can be reset via smackfs/syslog
113 struct smack_known *smack_syslog_label;
116 * Ptrace current rule
117 * SMACK_PTRACE_DEFAULT regular smack ptrace rules (/proc based)
118 * SMACK_PTRACE_EXACT labels must match, but can be overriden with
120 * SMACK_PTRACE_DRACONIAN lables must match, CAP_SYS_PTRACE has no effect
122 int smack_ptrace_rule = SMACK_PTRACE_DEFAULT;
125 * Certain IP addresses may be designated as single label hosts.
126 * Packets are sent there unlabeled, but only from tasks that
127 * can write to the specified label.
130 LIST_HEAD(smk_net4addr_list);
131 #if IS_ENABLED(CONFIG_IPV6)
132 LIST_HEAD(smk_net6addr_list);
133 #endif /* CONFIG_IPV6 */
136 * Rule lists are maintained for each label.
138 struct smack_parsed_rule {
139 struct smack_known *smk_subject;
140 struct smack_known *smk_object;
145 static int smk_cipso_doi_value = SMACK_CIPSO_DOI_DEFAULT;
148 * Values for parsing cipso rules
149 * SMK_DIGITLEN: Length of a digit field in a rule.
150 * SMK_CIPSOMIN: Minimum possible cipso rule length.
151 * SMK_CIPSOMAX: Maximum possible cipso rule length.
153 #define SMK_DIGITLEN 4
154 #define SMK_CIPSOMIN (SMK_LABELLEN + 2 * SMK_DIGITLEN)
155 #define SMK_CIPSOMAX (SMK_CIPSOMIN + SMACK_CIPSO_MAXCATNUM * SMK_DIGITLEN)
158 * Values for parsing MAC rules
159 * SMK_ACCESS: Maximum possible combination of access permissions
160 * SMK_ACCESSLEN: Maximum length for a rule access field
161 * SMK_LOADLEN: Smack rule length
163 #define SMK_OACCESS "rwxa"
164 #define SMK_ACCESS "rwxatl"
165 #define SMK_OACCESSLEN (sizeof(SMK_OACCESS) - 1)
166 #define SMK_ACCESSLEN (sizeof(SMK_ACCESS) - 1)
167 #define SMK_OLOADLEN (SMK_LABELLEN + SMK_LABELLEN + SMK_OACCESSLEN)
168 #define SMK_LOADLEN (SMK_LABELLEN + SMK_LABELLEN + SMK_ACCESSLEN)
171 * Stricly for CIPSO level manipulation.
172 * Set the category bit number in a smack label sized buffer.
174 static inline void smack_catset_bit(unsigned int cat, char *catsetp)
176 if (cat == 0 || cat > (SMK_CIPSOLEN * 8))
179 catsetp[(cat - 1) / 8] |= 0x80 >> ((cat - 1) % 8);
183 * smk_netlabel_audit_set - fill a netlbl_audit struct
184 * @nap: structure to fill
186 static void smk_netlabel_audit_set(struct netlbl_audit *nap)
188 struct smack_known *skp = smk_of_current();
190 nap->loginuid = audit_get_loginuid(current);
191 nap->sessionid = audit_get_sessionid(current);
192 nap->secid = skp->smk_secid;
196 * Value for parsing single label host rules
199 #define SMK_NETLBLADDRMIN 9
202 * smk_set_access - add a rule to the rule list or replace an old rule
203 * @srp: the rule to add or replace
204 * @rule_list: the list of rules
205 * @rule_lock: the rule list lock
207 * Looks through the current subject/object/access list for
208 * the subject/object pair and replaces the access that was
209 * there. If the pair isn't found add it with the specified
212 * Returns 0 if nothing goes wrong or -ENOMEM if it fails
213 * during the allocation of the new pair to add.
215 static int smk_set_access(struct smack_parsed_rule *srp,
216 struct list_head *rule_list,
217 struct mutex *rule_lock)
219 struct smack_rule *sp;
223 mutex_lock(rule_lock);
226 * Because the object label is less likely to match
227 * than the subject label check it first
229 list_for_each_entry_rcu(sp, rule_list, list) {
230 if (sp->smk_object == srp->smk_object &&
231 sp->smk_subject == srp->smk_subject) {
233 sp->smk_access |= srp->smk_access1;
234 sp->smk_access &= ~srp->smk_access2;
240 sp = kmem_cache_zalloc(smack_rule_cache, GFP_KERNEL);
246 sp->smk_subject = srp->smk_subject;
247 sp->smk_object = srp->smk_object;
248 sp->smk_access = srp->smk_access1 & ~srp->smk_access2;
250 list_add_rcu(&sp->list, rule_list);
254 mutex_unlock(rule_lock);
259 * smk_perm_from_str - parse smack accesses from a text string
260 * @string: a text string that contains a Smack accesses code
262 * Returns an integer with respective bits set for specified accesses.
264 static int smk_perm_from_str(const char *string)
269 for (cp = string; ; cp++)
291 perm |= MAY_TRANSMUTE;
307 * smk_fill_rule - Fill Smack rule from strings
308 * @subject: subject label string
309 * @object: object label string
310 * @access1: access string
311 * @access2: string with permissions to be removed
313 * @import: if non-zero, import labels
314 * @len: label length limit
316 * Returns 0 on success, appropriate error code on failure.
318 static int smk_fill_rule(const char *subject, const char *object,
319 const char *access1, const char *access2,
320 struct smack_parsed_rule *rule, int import,
324 struct smack_known *skp;
327 rule->smk_subject = smk_import_entry(subject, len);
328 if (IS_ERR(rule->smk_subject))
329 return PTR_ERR(rule->smk_subject);
331 rule->smk_object = smk_import_entry(object, len);
332 if (IS_ERR(rule->smk_object))
333 return PTR_ERR(rule->smk_object);
335 cp = smk_parse_smack(subject, len);
338 skp = smk_find_entry(cp);
342 rule->smk_subject = skp;
344 cp = smk_parse_smack(object, len);
347 skp = smk_find_entry(cp);
351 rule->smk_object = skp;
354 rule->smk_access1 = smk_perm_from_str(access1);
356 rule->smk_access2 = smk_perm_from_str(access2);
358 rule->smk_access2 = ~rule->smk_access1;
364 * smk_parse_rule - parse Smack rule from load string
365 * @data: string to be parsed whose size is SMK_LOADLEN
367 * @import: if non-zero, import labels
369 * Returns 0 on success, -1 on errors.
371 static int smk_parse_rule(const char *data, struct smack_parsed_rule *rule,
376 rc = smk_fill_rule(data, data + SMK_LABELLEN,
377 data + SMK_LABELLEN + SMK_LABELLEN, NULL, rule,
378 import, SMK_LABELLEN);
383 * smk_parse_long_rule - parse Smack rule from rule string
384 * @data: string to be parsed, null terminated
385 * @rule: Will be filled with Smack parsed rule
386 * @import: if non-zero, import labels
387 * @tokens: numer of substrings expected in data
389 * Returns number of processed bytes on success, -ERRNO on failure.
391 static ssize_t smk_parse_long_rule(char *data, struct smack_parsed_rule *rule,
392 int import, int tokens)
400 * Parsing the rule in-place, filling all white-spaces with '\0'
402 for (i = 0; i < tokens; ++i) {
403 while (isspace(data[cnt]))
406 if (data[cnt] == '\0')
407 /* Unexpected end of data */
412 while (data[cnt] && !isspace(data[cnt]))
415 while (isspace(data[cnt]))
421 rc = smk_fill_rule(tok[0], tok[1], tok[2], tok[3], rule, import, 0);
422 return rc == 0 ? cnt : rc;
425 #define SMK_FIXED24_FMT 0 /* Fixed 24byte label format */
426 #define SMK_LONG_FMT 1 /* Variable long label format */
427 #define SMK_CHANGE_FMT 2 /* Rule modification format */
429 * smk_write_rules_list - write() for any /smack rule file
430 * @file: file pointer, not actually used
431 * @buf: where to get the data from
433 * @ppos: where to start - must be 0
434 * @rule_list: the list of rules to write to
435 * @rule_lock: lock for the rule list
436 * @format: /smack/load or /smack/load2 or /smack/change-rule format.
438 * Get one smack access rule from above.
439 * The format for SMK_LONG_FMT is:
440 * "subject<whitespace>object<whitespace>access[<whitespace>...]"
441 * The format for SMK_FIXED24_FMT is exactly:
442 * "subject object rwxat"
443 * The format for SMK_CHANGE_FMT is:
444 * "subject<whitespace>object<whitespace>
445 * acc_enable<whitespace>acc_disable[<whitespace>...]"
447 static ssize_t smk_write_rules_list(struct file *file, const char __user *buf,
448 size_t count, loff_t *ppos,
449 struct list_head *rule_list,
450 struct mutex *rule_lock, int format)
452 struct smack_parsed_rule rule;
461 * Enough data must be present.
466 if (format == SMK_FIXED24_FMT) {
468 * Minor hack for backward compatibility
470 if (count < SMK_OLOADLEN || count > SMK_LOADLEN)
473 if (count >= PAGE_SIZE) {
474 count = PAGE_SIZE - 1;
479 data = memdup_user_nul(buf, count);
481 return PTR_ERR(data);
484 * In case of parsing only part of user buf,
485 * avoid having partial rule at the data buffer
488 while (count > 0 && (data[count - 1] != '\n'))
497 tokens = (format == SMK_CHANGE_FMT ? 4 : 3);
498 while (cnt < count) {
499 if (format == SMK_FIXED24_FMT) {
500 rc = smk_parse_rule(data, &rule, 1);
505 rc = smk_parse_long_rule(data + cnt, &rule, 1, tokens);
515 if (rule_list == NULL)
516 rc = smk_set_access(&rule, &rule.smk_subject->smk_rules,
517 &rule.smk_subject->smk_rules_lock);
519 rc = smk_set_access(&rule, rule_list, rule_lock);
532 * Core logic for smackfs seq list operations.
535 static void *smk_seq_start(struct seq_file *s, loff_t *pos,
536 struct list_head *head)
538 struct list_head *list;
542 for (list = rcu_dereference(list_next_rcu(head));
544 list = rcu_dereference(list_next_rcu(list))) {
552 static void *smk_seq_next(struct seq_file *s, void *v, loff_t *pos,
553 struct list_head *head)
555 struct list_head *list = v;
558 list = rcu_dereference(list_next_rcu(list));
560 return (list == head) ? NULL : list;
563 static void smk_seq_stop(struct seq_file *s, void *v)
568 static void smk_rule_show(struct seq_file *s, struct smack_rule *srp, int max)
571 * Don't show any rules with label names too long for
572 * interface file (/smack/load or /smack/load2)
573 * because you should expect to be able to write
574 * anything you read back.
576 if (strlen(srp->smk_subject->smk_known) >= max ||
577 strlen(srp->smk_object->smk_known) >= max)
580 if (srp->smk_access == 0)
583 seq_printf(s, "%s %s",
584 srp->smk_subject->smk_known,
585 srp->smk_object->smk_known);
589 if (srp->smk_access & MAY_READ)
591 if (srp->smk_access & MAY_WRITE)
593 if (srp->smk_access & MAY_EXEC)
595 if (srp->smk_access & MAY_APPEND)
597 if (srp->smk_access & MAY_TRANSMUTE)
599 if (srp->smk_access & MAY_LOCK)
601 if (srp->smk_access & MAY_BRINGUP)
608 * Seq_file read operations for /smack/load
611 static void *load2_seq_start(struct seq_file *s, loff_t *pos)
613 return smk_seq_start(s, pos, &smack_known_list);
616 static void *load2_seq_next(struct seq_file *s, void *v, loff_t *pos)
618 return smk_seq_next(s, v, pos, &smack_known_list);
621 static int load_seq_show(struct seq_file *s, void *v)
623 struct list_head *list = v;
624 struct smack_rule *srp;
625 struct smack_known *skp =
626 list_entry_rcu(list, struct smack_known, list);
628 list_for_each_entry_rcu(srp, &skp->smk_rules, list)
629 smk_rule_show(s, srp, SMK_LABELLEN);
634 static const struct seq_operations load_seq_ops = {
635 .start = load2_seq_start,
636 .next = load2_seq_next,
637 .show = load_seq_show,
638 .stop = smk_seq_stop,
642 * smk_open_load - open() for /smack/load
643 * @inode: inode structure representing file
644 * @file: "load" file pointer
646 * For reading, use load_seq_* seq_file reading operations.
648 static int smk_open_load(struct inode *inode, struct file *file)
650 return seq_open(file, &load_seq_ops);
654 * smk_write_load - write() for /smack/load
655 * @file: file pointer, not actually used
656 * @buf: where to get the data from
658 * @ppos: where to start - must be 0
661 static ssize_t smk_write_load(struct file *file, const char __user *buf,
662 size_t count, loff_t *ppos)
665 * Must have privilege.
667 * Enough data must be present.
669 if (!smack_privileged(CAP_MAC_ADMIN))
672 return smk_write_rules_list(file, buf, count, ppos, NULL, NULL,
676 static const struct file_operations smk_load_ops = {
677 .open = smk_open_load,
680 .write = smk_write_load,
681 .release = seq_release,
685 * smk_cipso_doi - initialize the CIPSO domain
687 static void smk_cipso_doi(void)
690 struct cipso_v4_doi *doip;
691 struct netlbl_audit nai;
693 smk_netlabel_audit_set(&nai);
695 rc = netlbl_cfg_map_del(NULL, PF_INET, NULL, NULL, &nai);
697 printk(KERN_WARNING "%s:%d remove rc = %d\n",
698 __func__, __LINE__, rc);
700 doip = kmalloc(sizeof(struct cipso_v4_doi), GFP_KERNEL);
702 panic("smack: Failed to initialize cipso DOI.\n");
703 doip->map.std = NULL;
704 doip->doi = smk_cipso_doi_value;
705 doip->type = CIPSO_V4_MAP_PASS;
706 doip->tags[0] = CIPSO_V4_TAG_RBITMAP;
707 for (rc = 1; rc < CIPSO_V4_TAG_MAXCNT; rc++)
708 doip->tags[rc] = CIPSO_V4_TAG_INVALID;
710 rc = netlbl_cfg_cipsov4_add(doip, &nai);
712 printk(KERN_WARNING "%s:%d cipso add rc = %d\n",
713 __func__, __LINE__, rc);
717 rc = netlbl_cfg_cipsov4_map_add(doip->doi, NULL, NULL, NULL, &nai);
719 printk(KERN_WARNING "%s:%d map add rc = %d\n",
720 __func__, __LINE__, rc);
727 * smk_unlbl_ambient - initialize the unlabeled domain
728 * @oldambient: previous domain string
730 static void smk_unlbl_ambient(char *oldambient)
733 struct netlbl_audit nai;
735 smk_netlabel_audit_set(&nai);
737 if (oldambient != NULL) {
738 rc = netlbl_cfg_map_del(oldambient, PF_INET, NULL, NULL, &nai);
740 printk(KERN_WARNING "%s:%d remove rc = %d\n",
741 __func__, __LINE__, rc);
743 if (smack_net_ambient == NULL)
744 smack_net_ambient = &smack_known_floor;
746 rc = netlbl_cfg_unlbl_map_add(smack_net_ambient->smk_known, PF_INET,
749 printk(KERN_WARNING "%s:%d add rc = %d\n",
750 __func__, __LINE__, rc);
754 * Seq_file read operations for /smack/cipso
757 static void *cipso_seq_start(struct seq_file *s, loff_t *pos)
759 return smk_seq_start(s, pos, &smack_known_list);
762 static void *cipso_seq_next(struct seq_file *s, void *v, loff_t *pos)
764 return smk_seq_next(s, v, pos, &smack_known_list);
768 * Print cipso labels in format:
769 * label level[/cat[,cat]]
771 static int cipso_seq_show(struct seq_file *s, void *v)
773 struct list_head *list = v;
774 struct smack_known *skp =
775 list_entry_rcu(list, struct smack_known, list);
776 struct netlbl_lsm_catmap *cmp = skp->smk_netlabel.attr.mls.cat;
781 * Don't show a label that could not have been set using
782 * /smack/cipso. This is in support of the notion that
783 * anything read from /smack/cipso ought to be writeable
786 * /smack/cipso2 should be used instead.
788 if (strlen(skp->smk_known) >= SMK_LABELLEN)
791 seq_printf(s, "%s %3d", skp->smk_known, skp->smk_netlabel.attr.mls.lvl);
793 for (i = netlbl_catmap_walk(cmp, 0); i >= 0;
794 i = netlbl_catmap_walk(cmp, i + 1)) {
795 seq_printf(s, "%c%d", sep, i);
804 static const struct seq_operations cipso_seq_ops = {
805 .start = cipso_seq_start,
806 .next = cipso_seq_next,
807 .show = cipso_seq_show,
808 .stop = smk_seq_stop,
812 * smk_open_cipso - open() for /smack/cipso
813 * @inode: inode structure representing file
814 * @file: "cipso" file pointer
816 * Connect our cipso_seq_* operations with /smack/cipso
819 static int smk_open_cipso(struct inode *inode, struct file *file)
821 return seq_open(file, &cipso_seq_ops);
825 * smk_set_cipso - do the work for write() for cipso and cipso2
826 * @file: file pointer, not actually used
827 * @buf: where to get the data from
829 * @ppos: where to start
830 * @format: /smack/cipso or /smack/cipso2
832 * Accepts only one cipso rule per write call.
833 * Returns number of bytes written or error code, as appropriate
835 static ssize_t smk_set_cipso(struct file *file, const char __user *buf,
836 size_t count, loff_t *ppos, int format)
838 struct smack_known *skp;
839 struct netlbl_lsm_secattr ncats;
840 char mapcatset[SMK_CIPSOLEN];
844 ssize_t rc = -EINVAL;
851 * Must have privilege.
853 * Enough data must be present.
855 if (!smack_privileged(CAP_MAC_ADMIN))
859 if (format == SMK_FIXED24_FMT &&
860 (count < SMK_CIPSOMIN || count > SMK_CIPSOMAX))
863 data = memdup_user_nul(buf, count);
865 return PTR_ERR(data);
869 * Only allow one writer at a time. Writes should be
870 * quite rare and small in any case.
872 mutex_lock(&smack_cipso_lock);
874 skp = smk_import_entry(rule, 0);
880 if (format == SMK_FIXED24_FMT)
881 rule += SMK_LABELLEN;
883 rule += strlen(skp->smk_known) + 1;
885 ret = sscanf(rule, "%d", &maplevel);
886 if (ret != 1 || maplevel > SMACK_CIPSO_MAXLEVEL)
889 rule += SMK_DIGITLEN;
890 ret = sscanf(rule, "%d", &catlen);
891 if (ret != 1 || catlen > SMACK_CIPSO_MAXCATNUM)
894 if (format == SMK_FIXED24_FMT &&
895 count != (SMK_CIPSOMIN + catlen * SMK_DIGITLEN))
898 memset(mapcatset, 0, sizeof(mapcatset));
900 for (i = 0; i < catlen; i++) {
901 rule += SMK_DIGITLEN;
902 ret = sscanf(rule, "%u", &cat);
903 if (ret != 1 || cat > SMACK_CIPSO_MAXCATNUM)
906 smack_catset_bit(cat, mapcatset);
909 rc = smk_netlbl_mls(maplevel, mapcatset, &ncats, SMK_CIPSOLEN);
911 netlbl_catmap_free(skp->smk_netlabel.attr.mls.cat);
912 skp->smk_netlabel.attr.mls.cat = ncats.attr.mls.cat;
913 skp->smk_netlabel.attr.mls.lvl = ncats.attr.mls.lvl;
918 mutex_unlock(&smack_cipso_lock);
924 * smk_write_cipso - write() for /smack/cipso
925 * @file: file pointer, not actually used
926 * @buf: where to get the data from
928 * @ppos: where to start
930 * Accepts only one cipso rule per write call.
931 * Returns number of bytes written or error code, as appropriate
933 static ssize_t smk_write_cipso(struct file *file, const char __user *buf,
934 size_t count, loff_t *ppos)
936 return smk_set_cipso(file, buf, count, ppos, SMK_FIXED24_FMT);
939 static const struct file_operations smk_cipso_ops = {
940 .open = smk_open_cipso,
943 .write = smk_write_cipso,
944 .release = seq_release,
948 * Seq_file read operations for /smack/cipso2
952 * Print cipso labels in format:
953 * label level[/cat[,cat]]
955 static int cipso2_seq_show(struct seq_file *s, void *v)
957 struct list_head *list = v;
958 struct smack_known *skp =
959 list_entry_rcu(list, struct smack_known, list);
960 struct netlbl_lsm_catmap *cmp = skp->smk_netlabel.attr.mls.cat;
964 seq_printf(s, "%s %3d", skp->smk_known, skp->smk_netlabel.attr.mls.lvl);
966 for (i = netlbl_catmap_walk(cmp, 0); i >= 0;
967 i = netlbl_catmap_walk(cmp, i + 1)) {
968 seq_printf(s, "%c%d", sep, i);
977 static const struct seq_operations cipso2_seq_ops = {
978 .start = cipso_seq_start,
979 .next = cipso_seq_next,
980 .show = cipso2_seq_show,
981 .stop = smk_seq_stop,
985 * smk_open_cipso2 - open() for /smack/cipso2
986 * @inode: inode structure representing file
987 * @file: "cipso2" file pointer
989 * Connect our cipso_seq_* operations with /smack/cipso2
992 static int smk_open_cipso2(struct inode *inode, struct file *file)
994 return seq_open(file, &cipso2_seq_ops);
998 * smk_write_cipso2 - write() for /smack/cipso2
999 * @file: file pointer, not actually used
1000 * @buf: where to get the data from
1001 * @count: bytes sent
1002 * @ppos: where to start
1004 * Accepts only one cipso rule per write call.
1005 * Returns number of bytes written or error code, as appropriate
1007 static ssize_t smk_write_cipso2(struct file *file, const char __user *buf,
1008 size_t count, loff_t *ppos)
1010 return smk_set_cipso(file, buf, count, ppos, SMK_LONG_FMT);
1013 static const struct file_operations smk_cipso2_ops = {
1014 .open = smk_open_cipso2,
1016 .llseek = seq_lseek,
1017 .write = smk_write_cipso2,
1018 .release = seq_release,
1022 * Seq_file read operations for /smack/netlabel
1025 static void *net4addr_seq_start(struct seq_file *s, loff_t *pos)
1027 return smk_seq_start(s, pos, &smk_net4addr_list);
1030 static void *net4addr_seq_next(struct seq_file *s, void *v, loff_t *pos)
1032 return smk_seq_next(s, v, pos, &smk_net4addr_list);
1036 * Print host/label pairs
1038 static int net4addr_seq_show(struct seq_file *s, void *v)
1040 struct list_head *list = v;
1041 struct smk_net4addr *skp =
1042 list_entry_rcu(list, struct smk_net4addr, list);
1043 char *kp = SMACK_CIPSO_OPTION;
1045 if (skp->smk_label != NULL)
1046 kp = skp->smk_label->smk_known;
1047 seq_printf(s, "%pI4/%d %s\n", &skp->smk_host.s_addr,
1048 skp->smk_masks, kp);
1053 static const struct seq_operations net4addr_seq_ops = {
1054 .start = net4addr_seq_start,
1055 .next = net4addr_seq_next,
1056 .show = net4addr_seq_show,
1057 .stop = smk_seq_stop,
1061 * smk_open_net4addr - open() for /smack/netlabel
1062 * @inode: inode structure representing file
1063 * @file: "netlabel" file pointer
1065 * Connect our net4addr_seq_* operations with /smack/netlabel
1068 static int smk_open_net4addr(struct inode *inode, struct file *file)
1070 return seq_open(file, &net4addr_seq_ops);
1074 * smk_net4addr_insert
1075 * @new : netlabel to insert
1077 * This helper insert netlabel in the smack_net4addrs list
1078 * sorted by netmask length (longest to smallest)
1079 * locked by &smk_net4addr_lock in smk_write_net4addr
1082 static void smk_net4addr_insert(struct smk_net4addr *new)
1084 struct smk_net4addr *m;
1085 struct smk_net4addr *m_next;
1087 if (list_empty(&smk_net4addr_list)) {
1088 list_add_rcu(&new->list, &smk_net4addr_list);
1092 m = list_entry_rcu(smk_net4addr_list.next,
1093 struct smk_net4addr, list);
1095 /* the comparison '>' is a bit hacky, but works */
1096 if (new->smk_masks > m->smk_masks) {
1097 list_add_rcu(&new->list, &smk_net4addr_list);
1101 list_for_each_entry_rcu(m, &smk_net4addr_list, list) {
1102 if (list_is_last(&m->list, &smk_net4addr_list)) {
1103 list_add_rcu(&new->list, &m->list);
1106 m_next = list_entry_rcu(m->list.next,
1107 struct smk_net4addr, list);
1108 if (new->smk_masks > m_next->smk_masks) {
1109 list_add_rcu(&new->list, &m->list);
1117 * smk_write_net4addr - write() for /smack/netlabel
1118 * @file: file pointer, not actually used
1119 * @buf: where to get the data from
1120 * @count: bytes sent
1121 * @ppos: where to start
1123 * Accepts only one net4addr per write call.
1124 * Returns number of bytes written or error code, as appropriate
1126 static ssize_t smk_write_net4addr(struct file *file, const char __user *buf,
1127 size_t count, loff_t *ppos)
1129 struct smk_net4addr *snp;
1130 struct sockaddr_in newname;
1132 struct smack_known *skp = NULL;
1134 char *host = (char *)&newname.sin_addr.s_addr;
1136 struct netlbl_audit audit_info;
1137 struct in_addr mask;
1141 u32 mask_bits = (1<<31);
1146 * Must have privilege.
1147 * No partial writes.
1148 * Enough data must be present.
1149 * "<addr/mask, as a.b.c.d/e><space><label>"
1150 * "<addr, as a.b.c.d><space><label>"
1152 if (!smack_privileged(CAP_MAC_ADMIN))
1156 if (count < SMK_NETLBLADDRMIN)
1159 data = memdup_user_nul(buf, count);
1161 return PTR_ERR(data);
1163 smack = kzalloc(count + 1, GFP_KERNEL);
1164 if (smack == NULL) {
1169 rc = sscanf(data, "%hhd.%hhd.%hhd.%hhd/%u %s",
1170 &host[0], &host[1], &host[2], &host[3], &masks, smack);
1172 rc = sscanf(data, "%hhd.%hhd.%hhd.%hhd %s",
1173 &host[0], &host[1], &host[2], &host[3], smack);
1181 if (masks > BEBITS) {
1187 * If smack begins with '-', it is an option, don't import it
1189 if (smack[0] != '-') {
1190 skp = smk_import_entry(smack, 0);
1197 * Only the -CIPSO option is supported for IPv4
1199 if (strcmp(smack, SMACK_CIPSO_OPTION) != 0) {
1205 for (m = masks, temp_mask = 0; m > 0; m--) {
1206 temp_mask |= mask_bits;
1209 mask.s_addr = cpu_to_be32(temp_mask);
1211 newname.sin_addr.s_addr &= mask.s_addr;
1213 * Only allow one writer at a time. Writes should be
1214 * quite rare and small in any case.
1216 mutex_lock(&smk_net4addr_lock);
1218 nsa = newname.sin_addr.s_addr;
1219 /* try to find if the prefix is already in the list */
1221 list_for_each_entry_rcu(snp, &smk_net4addr_list, list) {
1222 if (snp->smk_host.s_addr == nsa && snp->smk_masks == masks) {
1227 smk_netlabel_audit_set(&audit_info);
1230 snp = kzalloc(sizeof(*snp), GFP_KERNEL);
1235 snp->smk_host.s_addr = newname.sin_addr.s_addr;
1236 snp->smk_mask.s_addr = mask.s_addr;
1237 snp->smk_label = skp;
1238 snp->smk_masks = masks;
1239 smk_net4addr_insert(snp);
1243 * Delete the unlabeled entry, only if the previous label
1244 * wasn't the special CIPSO option
1246 if (snp->smk_label != NULL)
1247 rc = netlbl_cfg_unlbl_static_del(&init_net, NULL,
1248 &snp->smk_host, &snp->smk_mask,
1249 PF_INET, &audit_info);
1252 snp->smk_label = skp;
1256 * Now tell netlabel about the single label nature of
1257 * this host so that incoming packets get labeled.
1258 * but only if we didn't get the special CIPSO option
1260 if (rc == 0 && skp != NULL)
1261 rc = netlbl_cfg_unlbl_static_add(&init_net, NULL,
1262 &snp->smk_host, &snp->smk_mask, PF_INET,
1263 snp->smk_label->smk_secid, &audit_info);
1268 mutex_unlock(&smk_net4addr_lock);
1278 static const struct file_operations smk_net4addr_ops = {
1279 .open = smk_open_net4addr,
1281 .llseek = seq_lseek,
1282 .write = smk_write_net4addr,
1283 .release = seq_release,
1286 #if IS_ENABLED(CONFIG_IPV6)
1288 * Seq_file read operations for /smack/netlabel6
1291 static void *net6addr_seq_start(struct seq_file *s, loff_t *pos)
1293 return smk_seq_start(s, pos, &smk_net6addr_list);
1296 static void *net6addr_seq_next(struct seq_file *s, void *v, loff_t *pos)
1298 return smk_seq_next(s, v, pos, &smk_net6addr_list);
1302 * Print host/label pairs
1304 static int net6addr_seq_show(struct seq_file *s, void *v)
1306 struct list_head *list = v;
1307 struct smk_net6addr *skp =
1308 list_entry(list, struct smk_net6addr, list);
1310 if (skp->smk_label != NULL)
1311 seq_printf(s, "%pI6/%d %s\n", &skp->smk_host, skp->smk_masks,
1312 skp->smk_label->smk_known);
1317 static const struct seq_operations net6addr_seq_ops = {
1318 .start = net6addr_seq_start,
1319 .next = net6addr_seq_next,
1320 .show = net6addr_seq_show,
1321 .stop = smk_seq_stop,
1325 * smk_open_net6addr - open() for /smack/netlabel
1326 * @inode: inode structure representing file
1327 * @file: "netlabel" file pointer
1329 * Connect our net6addr_seq_* operations with /smack/netlabel
1332 static int smk_open_net6addr(struct inode *inode, struct file *file)
1334 return seq_open(file, &net6addr_seq_ops);
1338 * smk_net6addr_insert
1339 * @new : entry to insert
1341 * This inserts an entry in the smack_net6addrs list
1342 * sorted by netmask length (longest to smallest)
1343 * locked by &smk_net6addr_lock in smk_write_net6addr
1346 static void smk_net6addr_insert(struct smk_net6addr *new)
1348 struct smk_net6addr *m_next;
1349 struct smk_net6addr *m;
1351 if (list_empty(&smk_net6addr_list)) {
1352 list_add_rcu(&new->list, &smk_net6addr_list);
1356 m = list_entry_rcu(smk_net6addr_list.next,
1357 struct smk_net6addr, list);
1359 if (new->smk_masks > m->smk_masks) {
1360 list_add_rcu(&new->list, &smk_net6addr_list);
1364 list_for_each_entry_rcu(m, &smk_net6addr_list, list) {
1365 if (list_is_last(&m->list, &smk_net6addr_list)) {
1366 list_add_rcu(&new->list, &m->list);
1369 m_next = list_entry_rcu(m->list.next,
1370 struct smk_net6addr, list);
1371 if (new->smk_masks > m_next->smk_masks) {
1372 list_add_rcu(&new->list, &m->list);
1380 * smk_write_net6addr - write() for /smack/netlabel
1381 * @file: file pointer, not actually used
1382 * @buf: where to get the data from
1383 * @count: bytes sent
1384 * @ppos: where to start
1386 * Accepts only one net6addr per write call.
1387 * Returns number of bytes written or error code, as appropriate
1389 static ssize_t smk_write_net6addr(struct file *file, const char __user *buf,
1390 size_t count, loff_t *ppos)
1392 struct smk_net6addr *snp;
1393 struct in6_addr newname;
1394 struct in6_addr fullmask;
1395 struct smack_known *skp = NULL;
1401 unsigned int scanned[8];
1403 unsigned int mask = 128;
1406 * Must have privilege.
1407 * No partial writes.
1408 * Enough data must be present.
1409 * "<addr/mask, as a:b:c:d:e:f:g:h/e><space><label>"
1410 * "<addr, as a:b:c:d:e:f:g:h><space><label>"
1412 if (!smack_privileged(CAP_MAC_ADMIN))
1416 if (count < SMK_NETLBLADDRMIN)
1419 data = memdup_user_nul(buf, count);
1421 return PTR_ERR(data);
1423 smack = kzalloc(count + 1, GFP_KERNEL);
1424 if (smack == NULL) {
1429 i = sscanf(data, "%x:%x:%x:%x:%x:%x:%x:%x/%u %s",
1430 &scanned[0], &scanned[1], &scanned[2], &scanned[3],
1431 &scanned[4], &scanned[5], &scanned[6], &scanned[7],
1434 i = sscanf(data, "%x:%x:%x:%x:%x:%x:%x:%x %s",
1435 &scanned[0], &scanned[1], &scanned[2],
1436 &scanned[3], &scanned[4], &scanned[5],
1437 &scanned[6], &scanned[7], smack);
1447 for (i = 0; i < 8; i++) {
1448 if (scanned[i] > 0xffff) {
1452 newname.s6_addr16[i] = htons(scanned[i]);
1456 * If smack begins with '-', it is an option, don't import it
1458 if (smack[0] != '-') {
1459 skp = smk_import_entry(smack, 0);
1466 * Only -DELETE is supported for IPv6
1468 if (strcmp(smack, SMACK_DELETE_OPTION) != 0) {
1474 for (i = 0, m = mask; i < 8; i++) {
1476 fullmask.s6_addr16[i] = 0xffff;
1479 fullmask.s6_addr16[i] = (1 << m) - 1;
1482 fullmask.s6_addr16[i] = 0;
1483 newname.s6_addr16[i] &= fullmask.s6_addr16[i];
1487 * Only allow one writer at a time. Writes should be
1488 * quite rare and small in any case.
1490 mutex_lock(&smk_net6addr_lock);
1492 * Try to find the prefix in the list
1494 list_for_each_entry_rcu(snp, &smk_net6addr_list, list) {
1495 if (mask != snp->smk_masks)
1497 for (found = 1, i = 0; i < 8; i++) {
1498 if (newname.s6_addr16[i] !=
1499 snp->smk_host.s6_addr16[i]) {
1508 snp = kzalloc(sizeof(*snp), GFP_KERNEL);
1512 snp->smk_host = newname;
1513 snp->smk_mask = fullmask;
1514 snp->smk_masks = mask;
1515 snp->smk_label = skp;
1516 smk_net6addr_insert(snp);
1519 snp->smk_label = skp;
1525 mutex_unlock(&smk_net6addr_lock);
1535 static const struct file_operations smk_net6addr_ops = {
1536 .open = smk_open_net6addr,
1538 .llseek = seq_lseek,
1539 .write = smk_write_net6addr,
1540 .release = seq_release,
1542 #endif /* CONFIG_IPV6 */
1545 * smk_read_doi - read() for /smack/doi
1546 * @filp: file pointer, not actually used
1547 * @buf: where to put the result
1548 * @count: maximum to send along
1549 * @ppos: where to start
1551 * Returns number of bytes read or error code, as appropriate
1553 static ssize_t smk_read_doi(struct file *filp, char __user *buf,
1554 size_t count, loff_t *ppos)
1562 sprintf(temp, "%d", smk_cipso_doi_value);
1563 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
1569 * smk_write_doi - write() for /smack/doi
1570 * @file: file pointer, not actually used
1571 * @buf: where to get the data from
1572 * @count: bytes sent
1573 * @ppos: where to start
1575 * Returns number of bytes written or error code, as appropriate
1577 static ssize_t smk_write_doi(struct file *file, const char __user *buf,
1578 size_t count, loff_t *ppos)
1583 if (!smack_privileged(CAP_MAC_ADMIN))
1586 if (count >= sizeof(temp) || count == 0)
1589 if (copy_from_user(temp, buf, count) != 0)
1594 if (sscanf(temp, "%d", &i) != 1)
1597 smk_cipso_doi_value = i;
1604 static const struct file_operations smk_doi_ops = {
1605 .read = smk_read_doi,
1606 .write = smk_write_doi,
1607 .llseek = default_llseek,
1611 * smk_read_direct - read() for /smack/direct
1612 * @filp: file pointer, not actually used
1613 * @buf: where to put the result
1614 * @count: maximum to send along
1615 * @ppos: where to start
1617 * Returns number of bytes read or error code, as appropriate
1619 static ssize_t smk_read_direct(struct file *filp, char __user *buf,
1620 size_t count, loff_t *ppos)
1628 sprintf(temp, "%d", smack_cipso_direct);
1629 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
1635 * smk_write_direct - write() for /smack/direct
1636 * @file: file pointer, not actually used
1637 * @buf: where to get the data from
1638 * @count: bytes sent
1639 * @ppos: where to start
1641 * Returns number of bytes written or error code, as appropriate
1643 static ssize_t smk_write_direct(struct file *file, const char __user *buf,
1644 size_t count, loff_t *ppos)
1646 struct smack_known *skp;
1650 if (!smack_privileged(CAP_MAC_ADMIN))
1653 if (count >= sizeof(temp) || count == 0)
1656 if (copy_from_user(temp, buf, count) != 0)
1661 if (sscanf(temp, "%d", &i) != 1)
1665 * Don't do anything if the value hasn't actually changed.
1666 * If it is changing reset the level on entries that were
1667 * set up to be direct when they were created.
1669 if (smack_cipso_direct != i) {
1670 mutex_lock(&smack_known_lock);
1671 list_for_each_entry_rcu(skp, &smack_known_list, list)
1672 if (skp->smk_netlabel.attr.mls.lvl ==
1674 skp->smk_netlabel.attr.mls.lvl = i;
1675 smack_cipso_direct = i;
1676 mutex_unlock(&smack_known_lock);
1682 static const struct file_operations smk_direct_ops = {
1683 .read = smk_read_direct,
1684 .write = smk_write_direct,
1685 .llseek = default_llseek,
1689 * smk_read_mapped - read() for /smack/mapped
1690 * @filp: file pointer, not actually used
1691 * @buf: where to put the result
1692 * @count: maximum to send along
1693 * @ppos: where to start
1695 * Returns number of bytes read or error code, as appropriate
1697 static ssize_t smk_read_mapped(struct file *filp, char __user *buf,
1698 size_t count, loff_t *ppos)
1706 sprintf(temp, "%d", smack_cipso_mapped);
1707 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
1713 * smk_write_mapped - write() for /smack/mapped
1714 * @file: file pointer, not actually used
1715 * @buf: where to get the data from
1716 * @count: bytes sent
1717 * @ppos: where to start
1719 * Returns number of bytes written or error code, as appropriate
1721 static ssize_t smk_write_mapped(struct file *file, const char __user *buf,
1722 size_t count, loff_t *ppos)
1724 struct smack_known *skp;
1728 if (!smack_privileged(CAP_MAC_ADMIN))
1731 if (count >= sizeof(temp) || count == 0)
1734 if (copy_from_user(temp, buf, count) != 0)
1739 if (sscanf(temp, "%d", &i) != 1)
1743 * Don't do anything if the value hasn't actually changed.
1744 * If it is changing reset the level on entries that were
1745 * set up to be mapped when they were created.
1747 if (smack_cipso_mapped != i) {
1748 mutex_lock(&smack_known_lock);
1749 list_for_each_entry_rcu(skp, &smack_known_list, list)
1750 if (skp->smk_netlabel.attr.mls.lvl ==
1752 skp->smk_netlabel.attr.mls.lvl = i;
1753 smack_cipso_mapped = i;
1754 mutex_unlock(&smack_known_lock);
1760 static const struct file_operations smk_mapped_ops = {
1761 .read = smk_read_mapped,
1762 .write = smk_write_mapped,
1763 .llseek = default_llseek,
1767 * smk_read_ambient - read() for /smack/ambient
1768 * @filp: file pointer, not actually used
1769 * @buf: where to put the result
1770 * @cn: maximum to send along
1771 * @ppos: where to start
1773 * Returns number of bytes read or error code, as appropriate
1775 static ssize_t smk_read_ambient(struct file *filp, char __user *buf,
1776 size_t cn, loff_t *ppos)
1784 * Being careful to avoid a problem in the case where
1785 * smack_net_ambient gets changed in midstream.
1787 mutex_lock(&smack_ambient_lock);
1789 asize = strlen(smack_net_ambient->smk_known) + 1;
1792 rc = simple_read_from_buffer(buf, cn, ppos,
1793 smack_net_ambient->smk_known,
1798 mutex_unlock(&smack_ambient_lock);
1804 * smk_write_ambient - write() for /smack/ambient
1805 * @file: file pointer, not actually used
1806 * @buf: where to get the data from
1807 * @count: bytes sent
1808 * @ppos: where to start
1810 * Returns number of bytes written or error code, as appropriate
1812 static ssize_t smk_write_ambient(struct file *file, const char __user *buf,
1813 size_t count, loff_t *ppos)
1815 struct smack_known *skp;
1820 if (!smack_privileged(CAP_MAC_ADMIN))
1823 data = memdup_user_nul(buf, count);
1825 return PTR_ERR(data);
1827 skp = smk_import_entry(data, count);
1833 mutex_lock(&smack_ambient_lock);
1835 oldambient = smack_net_ambient->smk_known;
1836 smack_net_ambient = skp;
1837 smk_unlbl_ambient(oldambient);
1839 mutex_unlock(&smack_ambient_lock);
1846 static const struct file_operations smk_ambient_ops = {
1847 .read = smk_read_ambient,
1848 .write = smk_write_ambient,
1849 .llseek = default_llseek,
1853 * Seq_file operations for /smack/onlycap
1855 static void *onlycap_seq_start(struct seq_file *s, loff_t *pos)
1857 return smk_seq_start(s, pos, &smack_onlycap_list);
1860 static void *onlycap_seq_next(struct seq_file *s, void *v, loff_t *pos)
1862 return smk_seq_next(s, v, pos, &smack_onlycap_list);
1865 static int onlycap_seq_show(struct seq_file *s, void *v)
1867 struct list_head *list = v;
1868 struct smack_known_list_elem *sklep =
1869 list_entry_rcu(list, struct smack_known_list_elem, list);
1871 seq_puts(s, sklep->smk_label->smk_known);
1877 static const struct seq_operations onlycap_seq_ops = {
1878 .start = onlycap_seq_start,
1879 .next = onlycap_seq_next,
1880 .show = onlycap_seq_show,
1881 .stop = smk_seq_stop,
1884 static int smk_open_onlycap(struct inode *inode, struct file *file)
1886 return seq_open(file, &onlycap_seq_ops);
1890 * smk_list_swap_rcu - swap public list with a private one in RCU-safe way
1891 * The caller must hold appropriate mutex to prevent concurrent modifications
1892 * to the public list.
1893 * Private list is assumed to be not accessible to other threads yet.
1895 * @public: public list
1896 * @private: private list
1898 static void smk_list_swap_rcu(struct list_head *public,
1899 struct list_head *private)
1901 struct list_head *first, *last;
1903 if (list_empty(public)) {
1904 list_splice_init_rcu(private, public, synchronize_rcu);
1906 /* Remember public list before replacing it */
1907 first = public->next;
1908 last = public->prev;
1910 /* Publish private list in place of public in RCU-safe way */
1911 private->prev->next = public;
1912 private->next->prev = public;
1913 rcu_assign_pointer(public->next, private->next);
1914 public->prev = private->prev;
1918 /* When all readers are done with the old public list,
1919 * attach it in place of private */
1920 private->next = first;
1921 private->prev = last;
1922 first->prev = private;
1923 last->next = private;
1928 * smk_parse_label_list - parse list of Smack labels, separated by spaces
1930 * @data: the string to parse
1931 * @private: destination list
1933 * Returns zero on success or error code, as appropriate
1935 static int smk_parse_label_list(char *data, struct list_head *list)
1938 struct smack_known *skp;
1939 struct smack_known_list_elem *sklep;
1941 while ((tok = strsep(&data, " ")) != NULL) {
1945 skp = smk_import_entry(tok, 0);
1947 return PTR_ERR(skp);
1949 sklep = kzalloc(sizeof(*sklep), GFP_KERNEL);
1953 sklep->smk_label = skp;
1954 list_add(&sklep->list, list);
1961 * smk_destroy_label_list - destroy a list of smack_known_list_elem
1962 * @head: header pointer of the list to destroy
1964 void smk_destroy_label_list(struct list_head *list)
1966 struct smack_known_list_elem *sklep;
1967 struct smack_known_list_elem *sklep2;
1969 list_for_each_entry_safe(sklep, sklep2, list, list)
1972 INIT_LIST_HEAD(list);
1976 * smk_write_onlycap - write() for smackfs/onlycap
1977 * @file: file pointer, not actually used
1978 * @buf: where to get the data from
1979 * @count: bytes sent
1980 * @ppos: where to start
1982 * Returns number of bytes written or error code, as appropriate
1984 static ssize_t smk_write_onlycap(struct file *file, const char __user *buf,
1985 size_t count, loff_t *ppos)
1988 LIST_HEAD(list_tmp);
1991 if (!smack_privileged(CAP_MAC_ADMIN))
1994 data = memdup_user_nul(buf, count);
1996 return PTR_ERR(data);
1998 rc = smk_parse_label_list(data, &list_tmp);
2002 * Clear the smack_onlycap on invalid label errors. This means
2003 * that we can pass a null string to unset the onlycap value.
2005 * Importing will also reject a label beginning with '-',
2006 * so "-usecapabilities" will also work.
2008 * But do so only on invalid label, not on system errors.
2009 * The invalid label must be first to count as clearing attempt.
2011 if (!rc || (rc == -EINVAL && list_empty(&list_tmp))) {
2012 mutex_lock(&smack_onlycap_lock);
2013 smk_list_swap_rcu(&smack_onlycap_list, &list_tmp);
2014 mutex_unlock(&smack_onlycap_lock);
2018 smk_destroy_label_list(&list_tmp);
2023 static const struct file_operations smk_onlycap_ops = {
2024 .open = smk_open_onlycap,
2026 .write = smk_write_onlycap,
2027 .llseek = seq_lseek,
2028 .release = seq_release,
2031 #ifdef CONFIG_SECURITY_SMACK_BRINGUP
2033 * smk_read_unconfined - read() for smackfs/unconfined
2034 * @filp: file pointer, not actually used
2035 * @buf: where to put the result
2036 * @cn: maximum to send along
2037 * @ppos: where to start
2039 * Returns number of bytes read or error code, as appropriate
2041 static ssize_t smk_read_unconfined(struct file *filp, char __user *buf,
2042 size_t cn, loff_t *ppos)
2045 ssize_t rc = -EINVAL;
2051 if (smack_unconfined != NULL)
2052 smack = smack_unconfined->smk_known;
2054 asize = strlen(smack) + 1;
2057 rc = simple_read_from_buffer(buf, cn, ppos, smack, asize);
2063 * smk_write_unconfined - write() for smackfs/unconfined
2064 * @file: file pointer, not actually used
2065 * @buf: where to get the data from
2066 * @count: bytes sent
2067 * @ppos: where to start
2069 * Returns number of bytes written or error code, as appropriate
2071 static ssize_t smk_write_unconfined(struct file *file, const char __user *buf,
2072 size_t count, loff_t *ppos)
2075 struct smack_known *skp;
2078 if (!smack_privileged(CAP_MAC_ADMIN))
2081 data = memdup_user_nul(buf, count);
2083 return PTR_ERR(data);
2086 * Clear the smack_unconfined on invalid label errors. This means
2087 * that we can pass a null string to unset the unconfined value.
2089 * Importing will also reject a label beginning with '-',
2090 * so "-confine" will also work.
2092 * But do so only on invalid label, not on system errors.
2094 skp = smk_import_entry(data, count);
2095 if (PTR_ERR(skp) == -EINVAL)
2097 else if (IS_ERR(skp)) {
2102 smack_unconfined = skp;
2109 static const struct file_operations smk_unconfined_ops = {
2110 .read = smk_read_unconfined,
2111 .write = smk_write_unconfined,
2112 .llseek = default_llseek,
2114 #endif /* CONFIG_SECURITY_SMACK_BRINGUP */
2117 * smk_read_logging - read() for /smack/logging
2118 * @filp: file pointer, not actually used
2119 * @buf: where to put the result
2120 * @cn: maximum to send along
2121 * @ppos: where to start
2123 * Returns number of bytes read or error code, as appropriate
2125 static ssize_t smk_read_logging(struct file *filp, char __user *buf,
2126 size_t count, loff_t *ppos)
2134 sprintf(temp, "%d\n", log_policy);
2135 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
2140 * smk_write_logging - write() for /smack/logging
2141 * @file: file pointer, not actually used
2142 * @buf: where to get the data from
2143 * @count: bytes sent
2144 * @ppos: where to start
2146 * Returns number of bytes written or error code, as appropriate
2148 static ssize_t smk_write_logging(struct file *file, const char __user *buf,
2149 size_t count, loff_t *ppos)
2154 if (!smack_privileged(CAP_MAC_ADMIN))
2157 if (count >= sizeof(temp) || count == 0)
2160 if (copy_from_user(temp, buf, count) != 0)
2165 if (sscanf(temp, "%d", &i) != 1)
2175 static const struct file_operations smk_logging_ops = {
2176 .read = smk_read_logging,
2177 .write = smk_write_logging,
2178 .llseek = default_llseek,
2182 * Seq_file read operations for /smack/load-self
2185 static void *load_self_seq_start(struct seq_file *s, loff_t *pos)
2187 struct task_smack *tsp = smack_cred(current_cred());
2189 return smk_seq_start(s, pos, &tsp->smk_rules);
2192 static void *load_self_seq_next(struct seq_file *s, void *v, loff_t *pos)
2194 struct task_smack *tsp = smack_cred(current_cred());
2196 return smk_seq_next(s, v, pos, &tsp->smk_rules);
2199 static int load_self_seq_show(struct seq_file *s, void *v)
2201 struct list_head *list = v;
2202 struct smack_rule *srp =
2203 list_entry_rcu(list, struct smack_rule, list);
2205 smk_rule_show(s, srp, SMK_LABELLEN);
2210 static const struct seq_operations load_self_seq_ops = {
2211 .start = load_self_seq_start,
2212 .next = load_self_seq_next,
2213 .show = load_self_seq_show,
2214 .stop = smk_seq_stop,
2219 * smk_open_load_self - open() for /smack/load-self2
2220 * @inode: inode structure representing file
2221 * @file: "load" file pointer
2223 * For reading, use load_seq_* seq_file reading operations.
2225 static int smk_open_load_self(struct inode *inode, struct file *file)
2227 return seq_open(file, &load_self_seq_ops);
2231 * smk_write_load_self - write() for /smack/load-self
2232 * @file: file pointer, not actually used
2233 * @buf: where to get the data from
2234 * @count: bytes sent
2235 * @ppos: where to start - must be 0
2238 static ssize_t smk_write_load_self(struct file *file, const char __user *buf,
2239 size_t count, loff_t *ppos)
2241 struct task_smack *tsp = smack_cred(current_cred());
2243 return smk_write_rules_list(file, buf, count, ppos, &tsp->smk_rules,
2244 &tsp->smk_rules_lock, SMK_FIXED24_FMT);
2247 static const struct file_operations smk_load_self_ops = {
2248 .open = smk_open_load_self,
2250 .llseek = seq_lseek,
2251 .write = smk_write_load_self,
2252 .release = seq_release,
2256 * smk_user_access - handle access check transaction
2257 * @file: file pointer
2258 * @buf: data from user space
2259 * @count: bytes sent
2260 * @ppos: where to start - must be 0
2262 static ssize_t smk_user_access(struct file *file, const char __user *buf,
2263 size_t count, loff_t *ppos, int format)
2265 struct smack_parsed_rule rule;
2269 data = simple_transaction_get(file, buf, count);
2271 return PTR_ERR(data);
2273 if (format == SMK_FIXED24_FMT) {
2274 if (count < SMK_LOADLEN)
2276 res = smk_parse_rule(data, &rule, 0);
2279 * simple_transaction_get() returns null-terminated data
2281 res = smk_parse_long_rule(data, &rule, 0, 3);
2285 res = smk_access(rule.smk_subject, rule.smk_object,
2286 rule.smk_access1, NULL);
2287 else if (res != -ENOENT)
2291 * smk_access() can return a value > 0 in the "bringup" case.
2293 data[0] = res >= 0 ? '1' : '0';
2296 simple_transaction_set(file, 2);
2298 if (format == SMK_FIXED24_FMT)
2304 * smk_write_access - handle access check transaction
2305 * @file: file pointer
2306 * @buf: data from user space
2307 * @count: bytes sent
2308 * @ppos: where to start - must be 0
2310 static ssize_t smk_write_access(struct file *file, const char __user *buf,
2311 size_t count, loff_t *ppos)
2313 return smk_user_access(file, buf, count, ppos, SMK_FIXED24_FMT);
2316 static const struct file_operations smk_access_ops = {
2317 .write = smk_write_access,
2318 .read = simple_transaction_read,
2319 .release = simple_transaction_release,
2320 .llseek = generic_file_llseek,
2325 * Seq_file read operations for /smack/load2
2328 static int load2_seq_show(struct seq_file *s, void *v)
2330 struct list_head *list = v;
2331 struct smack_rule *srp;
2332 struct smack_known *skp =
2333 list_entry_rcu(list, struct smack_known, list);
2335 list_for_each_entry_rcu(srp, &skp->smk_rules, list)
2336 smk_rule_show(s, srp, SMK_LONGLABEL);
2341 static const struct seq_operations load2_seq_ops = {
2342 .start = load2_seq_start,
2343 .next = load2_seq_next,
2344 .show = load2_seq_show,
2345 .stop = smk_seq_stop,
2349 * smk_open_load2 - open() for /smack/load2
2350 * @inode: inode structure representing file
2351 * @file: "load2" file pointer
2353 * For reading, use load2_seq_* seq_file reading operations.
2355 static int smk_open_load2(struct inode *inode, struct file *file)
2357 return seq_open(file, &load2_seq_ops);
2361 * smk_write_load2 - write() for /smack/load2
2362 * @file: file pointer, not actually used
2363 * @buf: where to get the data from
2364 * @count: bytes sent
2365 * @ppos: where to start - must be 0
2368 static ssize_t smk_write_load2(struct file *file, const char __user *buf,
2369 size_t count, loff_t *ppos)
2372 * Must have privilege.
2374 if (!smack_privileged(CAP_MAC_ADMIN))
2377 return smk_write_rules_list(file, buf, count, ppos, NULL, NULL,
2381 static const struct file_operations smk_load2_ops = {
2382 .open = smk_open_load2,
2384 .llseek = seq_lseek,
2385 .write = smk_write_load2,
2386 .release = seq_release,
2390 * Seq_file read operations for /smack/load-self2
2393 static void *load_self2_seq_start(struct seq_file *s, loff_t *pos)
2395 struct task_smack *tsp = smack_cred(current_cred());
2397 return smk_seq_start(s, pos, &tsp->smk_rules);
2400 static void *load_self2_seq_next(struct seq_file *s, void *v, loff_t *pos)
2402 struct task_smack *tsp = smack_cred(current_cred());
2404 return smk_seq_next(s, v, pos, &tsp->smk_rules);
2407 static int load_self2_seq_show(struct seq_file *s, void *v)
2409 struct list_head *list = v;
2410 struct smack_rule *srp =
2411 list_entry_rcu(list, struct smack_rule, list);
2413 smk_rule_show(s, srp, SMK_LONGLABEL);
2418 static const struct seq_operations load_self2_seq_ops = {
2419 .start = load_self2_seq_start,
2420 .next = load_self2_seq_next,
2421 .show = load_self2_seq_show,
2422 .stop = smk_seq_stop,
2426 * smk_open_load_self2 - open() for /smack/load-self2
2427 * @inode: inode structure representing file
2428 * @file: "load" file pointer
2430 * For reading, use load_seq_* seq_file reading operations.
2432 static int smk_open_load_self2(struct inode *inode, struct file *file)
2434 return seq_open(file, &load_self2_seq_ops);
2438 * smk_write_load_self2 - write() for /smack/load-self2
2439 * @file: file pointer, not actually used
2440 * @buf: where to get the data from
2441 * @count: bytes sent
2442 * @ppos: where to start - must be 0
2445 static ssize_t smk_write_load_self2(struct file *file, const char __user *buf,
2446 size_t count, loff_t *ppos)
2448 struct task_smack *tsp = smack_cred(current_cred());
2450 return smk_write_rules_list(file, buf, count, ppos, &tsp->smk_rules,
2451 &tsp->smk_rules_lock, SMK_LONG_FMT);
2454 static const struct file_operations smk_load_self2_ops = {
2455 .open = smk_open_load_self2,
2457 .llseek = seq_lseek,
2458 .write = smk_write_load_self2,
2459 .release = seq_release,
2463 * smk_write_access2 - handle access check transaction
2464 * @file: file pointer
2465 * @buf: data from user space
2466 * @count: bytes sent
2467 * @ppos: where to start - must be 0
2469 static ssize_t smk_write_access2(struct file *file, const char __user *buf,
2470 size_t count, loff_t *ppos)
2472 return smk_user_access(file, buf, count, ppos, SMK_LONG_FMT);
2475 static const struct file_operations smk_access2_ops = {
2476 .write = smk_write_access2,
2477 .read = simple_transaction_read,
2478 .release = simple_transaction_release,
2479 .llseek = generic_file_llseek,
2483 * smk_write_revoke_subj - write() for /smack/revoke-subject
2484 * @file: file pointer
2485 * @buf: data from user space
2486 * @count: bytes sent
2487 * @ppos: where to start - must be 0
2489 static ssize_t smk_write_revoke_subj(struct file *file, const char __user *buf,
2490 size_t count, loff_t *ppos)
2494 struct smack_known *skp;
2495 struct smack_rule *sp;
2496 struct list_head *rule_list;
2497 struct mutex *rule_lock;
2503 if (!smack_privileged(CAP_MAC_ADMIN))
2506 if (count == 0 || count > SMK_LONGLABEL)
2509 data = memdup_user(buf, count);
2511 return PTR_ERR(data);
2513 cp = smk_parse_smack(data, count);
2519 skp = smk_find_entry(cp);
2523 rule_list = &skp->smk_rules;
2524 rule_lock = &skp->smk_rules_lock;
2526 mutex_lock(rule_lock);
2528 list_for_each_entry_rcu(sp, rule_list, list)
2531 mutex_unlock(rule_lock);
2541 static const struct file_operations smk_revoke_subj_ops = {
2542 .write = smk_write_revoke_subj,
2543 .read = simple_transaction_read,
2544 .release = simple_transaction_release,
2545 .llseek = generic_file_llseek,
2549 * smk_init_sysfs - initialize /sys/fs/smackfs
2552 static int smk_init_sysfs(void)
2554 return sysfs_create_mount_point(fs_kobj, "smackfs");
2558 * smk_write_change_rule - write() for /smack/change-rule
2559 * @file: file pointer
2560 * @buf: data from user space
2561 * @count: bytes sent
2562 * @ppos: where to start - must be 0
2564 static ssize_t smk_write_change_rule(struct file *file, const char __user *buf,
2565 size_t count, loff_t *ppos)
2568 * Must have privilege.
2570 if (!smack_privileged(CAP_MAC_ADMIN))
2573 return smk_write_rules_list(file, buf, count, ppos, NULL, NULL,
2577 static const struct file_operations smk_change_rule_ops = {
2578 .write = smk_write_change_rule,
2579 .read = simple_transaction_read,
2580 .release = simple_transaction_release,
2581 .llseek = generic_file_llseek,
2585 * smk_read_syslog - read() for smackfs/syslog
2586 * @filp: file pointer, not actually used
2587 * @buf: where to put the result
2588 * @cn: maximum to send along
2589 * @ppos: where to start
2591 * Returns number of bytes read or error code, as appropriate
2593 static ssize_t smk_read_syslog(struct file *filp, char __user *buf,
2594 size_t cn, loff_t *ppos)
2596 struct smack_known *skp;
2597 ssize_t rc = -EINVAL;
2603 if (smack_syslog_label == NULL)
2604 skp = &smack_known_star;
2606 skp = smack_syslog_label;
2608 asize = strlen(skp->smk_known) + 1;
2611 rc = simple_read_from_buffer(buf, cn, ppos, skp->smk_known,
2618 * smk_write_syslog - write() for smackfs/syslog
2619 * @file: file pointer, not actually used
2620 * @buf: where to get the data from
2621 * @count: bytes sent
2622 * @ppos: where to start
2624 * Returns number of bytes written or error code, as appropriate
2626 static ssize_t smk_write_syslog(struct file *file, const char __user *buf,
2627 size_t count, loff_t *ppos)
2630 struct smack_known *skp;
2633 if (!smack_privileged(CAP_MAC_ADMIN))
2636 data = memdup_user_nul(buf, count);
2638 return PTR_ERR(data);
2640 skp = smk_import_entry(data, count);
2644 smack_syslog_label = skp;
2650 static const struct file_operations smk_syslog_ops = {
2651 .read = smk_read_syslog,
2652 .write = smk_write_syslog,
2653 .llseek = default_llseek,
2657 * Seq_file read operations for /smack/relabel-self
2660 static void *relabel_self_seq_start(struct seq_file *s, loff_t *pos)
2662 struct task_smack *tsp = smack_cred(current_cred());
2664 return smk_seq_start(s, pos, &tsp->smk_relabel);
2667 static void *relabel_self_seq_next(struct seq_file *s, void *v, loff_t *pos)
2669 struct task_smack *tsp = smack_cred(current_cred());
2671 return smk_seq_next(s, v, pos, &tsp->smk_relabel);
2674 static int relabel_self_seq_show(struct seq_file *s, void *v)
2676 struct list_head *list = v;
2677 struct smack_known_list_elem *sklep =
2678 list_entry(list, struct smack_known_list_elem, list);
2680 seq_puts(s, sklep->smk_label->smk_known);
2686 static const struct seq_operations relabel_self_seq_ops = {
2687 .start = relabel_self_seq_start,
2688 .next = relabel_self_seq_next,
2689 .show = relabel_self_seq_show,
2690 .stop = smk_seq_stop,
2694 * smk_open_relabel_self - open() for /smack/relabel-self
2695 * @inode: inode structure representing file
2696 * @file: "relabel-self" file pointer
2698 * Connect our relabel_self_seq_* operations with /smack/relabel-self
2701 static int smk_open_relabel_self(struct inode *inode, struct file *file)
2703 return seq_open(file, &relabel_self_seq_ops);
2707 * smk_write_relabel_self - write() for /smack/relabel-self
2708 * @file: file pointer, not actually used
2709 * @buf: where to get the data from
2710 * @count: bytes sent
2711 * @ppos: where to start - must be 0
2714 static ssize_t smk_write_relabel_self(struct file *file, const char __user *buf,
2715 size_t count, loff_t *ppos)
2717 struct task_smack *tsp = smack_cred(current_cred());
2720 LIST_HEAD(list_tmp);
2723 * Must have privilege.
2725 if (!smack_privileged(CAP_MAC_ADMIN))
2729 * Enough data must be present.
2734 data = memdup_user_nul(buf, count);
2736 return PTR_ERR(data);
2738 rc = smk_parse_label_list(data, &list_tmp);
2741 if (!rc || (rc == -EINVAL && list_empty(&list_tmp))) {
2742 smk_destroy_label_list(&tsp->smk_relabel);
2743 list_splice(&list_tmp, &tsp->smk_relabel);
2747 smk_destroy_label_list(&list_tmp);
2751 static const struct file_operations smk_relabel_self_ops = {
2752 .open = smk_open_relabel_self,
2754 .llseek = seq_lseek,
2755 .write = smk_write_relabel_self,
2756 .release = seq_release,
2760 * smk_read_ptrace - read() for /smack/ptrace
2761 * @filp: file pointer, not actually used
2762 * @buf: where to put the result
2763 * @count: maximum to send along
2764 * @ppos: where to start
2766 * Returns number of bytes read or error code, as appropriate
2768 static ssize_t smk_read_ptrace(struct file *filp, char __user *buf,
2769 size_t count, loff_t *ppos)
2777 sprintf(temp, "%d\n", smack_ptrace_rule);
2778 rc = simple_read_from_buffer(buf, count, ppos, temp, strlen(temp));
2783 * smk_write_ptrace - write() for /smack/ptrace
2784 * @file: file pointer
2785 * @buf: data from user space
2786 * @count: bytes sent
2787 * @ppos: where to start - must be 0
2789 static ssize_t smk_write_ptrace(struct file *file, const char __user *buf,
2790 size_t count, loff_t *ppos)
2795 if (!smack_privileged(CAP_MAC_ADMIN))
2798 if (*ppos != 0 || count >= sizeof(temp) || count == 0)
2801 if (copy_from_user(temp, buf, count) != 0)
2806 if (sscanf(temp, "%d", &i) != 1)
2808 if (i < SMACK_PTRACE_DEFAULT || i > SMACK_PTRACE_MAX)
2810 smack_ptrace_rule = i;
2815 static const struct file_operations smk_ptrace_ops = {
2816 .write = smk_write_ptrace,
2817 .read = smk_read_ptrace,
2818 .llseek = default_llseek,
2822 * smk_fill_super - fill the smackfs superblock
2823 * @sb: the empty superblock
2826 * Fill in the well known entries for the smack filesystem
2828 * Returns 0 on success, an error code on failure
2830 static int smk_fill_super(struct super_block *sb, struct fs_context *fc)
2834 static const struct tree_descr smack_files[] = {
2836 "load", &smk_load_ops, S_IRUGO|S_IWUSR},
2838 "cipso", &smk_cipso_ops, S_IRUGO|S_IWUSR},
2840 "doi", &smk_doi_ops, S_IRUGO|S_IWUSR},
2842 "direct", &smk_direct_ops, S_IRUGO|S_IWUSR},
2844 "ambient", &smk_ambient_ops, S_IRUGO|S_IWUSR},
2846 "netlabel", &smk_net4addr_ops, S_IRUGO|S_IWUSR},
2848 "onlycap", &smk_onlycap_ops, S_IRUGO|S_IWUSR},
2850 "logging", &smk_logging_ops, S_IRUGO|S_IWUSR},
2852 "load-self", &smk_load_self_ops, S_IRUGO|S_IWUGO},
2854 "access", &smk_access_ops, S_IRUGO|S_IWUGO},
2856 "mapped", &smk_mapped_ops, S_IRUGO|S_IWUSR},
2858 "load2", &smk_load2_ops, S_IRUGO|S_IWUSR},
2859 [SMK_LOAD_SELF2] = {
2860 "load-self2", &smk_load_self2_ops, S_IRUGO|S_IWUGO},
2862 "access2", &smk_access2_ops, S_IRUGO|S_IWUGO},
2864 "cipso2", &smk_cipso2_ops, S_IRUGO|S_IWUSR},
2865 [SMK_REVOKE_SUBJ] = {
2866 "revoke-subject", &smk_revoke_subj_ops,
2868 [SMK_CHANGE_RULE] = {
2869 "change-rule", &smk_change_rule_ops, S_IRUGO|S_IWUSR},
2871 "syslog", &smk_syslog_ops, S_IRUGO|S_IWUSR},
2873 "ptrace", &smk_ptrace_ops, S_IRUGO|S_IWUSR},
2874 #ifdef CONFIG_SECURITY_SMACK_BRINGUP
2875 [SMK_UNCONFINED] = {
2876 "unconfined", &smk_unconfined_ops, S_IRUGO|S_IWUSR},
2878 #if IS_ENABLED(CONFIG_IPV6)
2880 "ipv6host", &smk_net6addr_ops, S_IRUGO|S_IWUSR},
2881 #endif /* CONFIG_IPV6 */
2882 [SMK_RELABEL_SELF] = {
2883 "relabel-self", &smk_relabel_self_ops,
2889 rc = simple_fill_super(sb, SMACK_MAGIC, smack_files);
2891 printk(KERN_ERR "%s failed %d while creating inodes\n",
2900 * smk_get_tree - get the smackfs superblock
2901 * @fc: The mount context, including any options
2903 * Just passes everything along.
2905 * Returns what the lower level code does.
2907 static int smk_get_tree(struct fs_context *fc)
2909 return get_tree_single(fc, smk_fill_super);
2912 static const struct fs_context_operations smk_context_ops = {
2913 .get_tree = smk_get_tree,
2917 * smk_init_fs_context - Initialise a filesystem context for smackfs
2918 * @fc: The blank mount context
2920 static int smk_init_fs_context(struct fs_context *fc)
2922 fc->ops = &smk_context_ops;
2926 static struct file_system_type smk_fs_type = {
2928 .init_fs_context = smk_init_fs_context,
2929 .kill_sb = kill_litter_super,
2932 static struct vfsmount *smackfs_mount;
2934 static int __init smk_preset_netlabel(struct smack_known *skp)
2936 skp->smk_netlabel.domain = skp->smk_known;
2937 skp->smk_netlabel.flags =
2938 NETLBL_SECATTR_DOMAIN | NETLBL_SECATTR_MLS_LVL;
2939 return smk_netlbl_mls(smack_cipso_direct, skp->smk_known,
2940 &skp->smk_netlabel, strlen(skp->smk_known));
2944 * init_smk_fs - get the smackfs superblock
2946 * register the smackfs
2948 * Do not register smackfs if Smack wasn't enabled
2949 * on boot. We can not put this method normally under the
2950 * smack_init() code path since the security subsystem get
2951 * initialized before the vfs caches.
2953 * Returns true if we were not chosen on boot or if
2954 * we were chosen and filesystem registration succeeded.
2956 static int __init init_smk_fs(void)
2961 if (smack_enabled == 0)
2964 err = smk_init_sysfs();
2966 printk(KERN_ERR "smackfs: sysfs mountpoint problem.\n");
2968 err = register_filesystem(&smk_fs_type);
2970 smackfs_mount = kern_mount(&smk_fs_type);
2971 if (IS_ERR(smackfs_mount)) {
2972 printk(KERN_ERR "smackfs: could not mount!\n");
2973 err = PTR_ERR(smackfs_mount);
2974 smackfs_mount = NULL;
2979 smk_unlbl_ambient(NULL);
2981 rc = smk_preset_netlabel(&smack_known_floor);
2982 if (err == 0 && rc < 0)
2984 rc = smk_preset_netlabel(&smack_known_hat);
2985 if (err == 0 && rc < 0)
2987 rc = smk_preset_netlabel(&smack_known_huh);
2988 if (err == 0 && rc < 0)
2990 rc = smk_preset_netlabel(&smack_known_star);
2991 if (err == 0 && rc < 0)
2993 rc = smk_preset_netlabel(&smack_known_web);
2994 if (err == 0 && rc < 0)
3000 __initcall(init_smk_fs);