2 * Simplified MAC Kernel (smack) security module
4 * This file contains the smack hook function implementations.
7 * Casey Schaufler <casey@schaufler-ca.com>
8 * Jarkko Sakkinen <jarkko.sakkinen@intel.com>
10 * Copyright (C) 2007 Casey Schaufler <casey@schaufler-ca.com>
11 * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
12 * Paul Moore <paul@paul-moore.com>
13 * Copyright (C) 2010 Nokia Corporation
14 * Copyright (C) 2011 Intel Corporation.
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2,
18 * as published by the Free Software Foundation.
21 #include <linux/xattr.h>
22 #include <linux/pagemap.h>
23 #include <linux/mount.h>
24 #include <linux/stat.h>
26 #include <asm/ioctls.h>
28 #include <linux/tcp.h>
29 #include <linux/udp.h>
30 #include <linux/dccp.h>
31 #include <linux/slab.h>
32 #include <linux/mutex.h>
33 #include <linux/pipe_fs_i.h>
34 #include <net/cipso_ipv4.h>
37 #include <linux/audit.h>
38 #include <linux/magic.h>
39 #include <linux/dcache.h>
40 #include <linux/personality.h>
41 #include <linux/msg.h>
42 #include <linux/shm.h>
43 #include <linux/binfmts.h>
46 #define task_security(task) (task_cred_xxx((task), security))
48 #define TRANS_TRUE "TRUE"
49 #define TRANS_TRUE_SIZE 4
51 #define SMK_CONNECTING 0
52 #define SMK_RECEIVING 1
55 LIST_HEAD(smk_ipv6_port_list);
58 * smk_fetch - Fetch the smack label from a file.
59 * @ip: a pointer to the inode
60 * @dp: a pointer to the dentry
62 * Returns a pointer to the master list entry for the Smack label
63 * or NULL if there was no label to fetch.
65 static struct smack_known *smk_fetch(const char *name, struct inode *ip,
70 struct smack_known *skp = NULL;
72 if (ip->i_op->getxattr == NULL)
75 buffer = kzalloc(SMK_LONGLABEL, GFP_KERNEL);
79 rc = ip->i_op->getxattr(dp, name, buffer, SMK_LONGLABEL);
81 skp = smk_import_entry(buffer, rc);
89 * new_inode_smack - allocate an inode security blob
90 * @smack: a pointer to the Smack label to use in the blob
92 * Returns the new blob or NULL if there's no memory available
94 struct inode_smack *new_inode_smack(char *smack)
96 struct inode_smack *isp;
98 isp = kzalloc(sizeof(struct inode_smack), GFP_NOFS);
102 isp->smk_inode = smack;
104 mutex_init(&isp->smk_lock);
110 * new_task_smack - allocate a task security blob
111 * @smack: a pointer to the Smack label to use in the blob
113 * Returns the new blob or NULL if there's no memory available
115 static struct task_smack *new_task_smack(struct smack_known *task,
116 struct smack_known *forked, gfp_t gfp)
118 struct task_smack *tsp;
120 tsp = kzalloc(sizeof(struct task_smack), gfp);
124 tsp->smk_task = task;
125 tsp->smk_forked = forked;
126 INIT_LIST_HEAD(&tsp->smk_rules);
127 mutex_init(&tsp->smk_rules_lock);
133 * smk_copy_rules - copy a rule set
134 * @nhead - new rules header pointer
135 * @ohead - old rules header pointer
137 * Returns 0 on success, -ENOMEM on error
139 static int smk_copy_rules(struct list_head *nhead, struct list_head *ohead,
142 struct smack_rule *nrp;
143 struct smack_rule *orp;
146 INIT_LIST_HEAD(nhead);
148 list_for_each_entry_rcu(orp, ohead, list) {
149 nrp = kzalloc(sizeof(struct smack_rule), gfp);
155 list_add_rcu(&nrp->list, nhead);
161 * smk_ptrace_mode - helper function for converting PTRACE_MODE_* into MAY_*
162 * @mode - input mode in form of PTRACE_MODE_*
164 * Returns a converted MAY_* mode usable by smack rules
166 static inline unsigned int smk_ptrace_mode(unsigned int mode)
169 case PTRACE_MODE_READ:
171 case PTRACE_MODE_ATTACH:
172 return MAY_READWRITE;
179 * smk_ptrace_rule_check - helper for ptrace access
180 * @tracer: tracer process
181 * @tracee_label: label of the process that's about to be traced,
182 * the pointer must originate from smack structures
183 * @mode: ptrace attachment mode (PTRACE_MODE_*)
184 * @func: name of the function that called us, used for audit
186 * Returns 0 on access granted, -error on error
188 static int smk_ptrace_rule_check(struct task_struct *tracer, char *tracee_label,
189 unsigned int mode, const char *func)
192 struct smk_audit_info ad, *saip = NULL;
193 struct task_smack *tsp;
194 struct smack_known *skp;
196 if ((mode & PTRACE_MODE_NOAUDIT) == 0) {
197 smk_ad_init(&ad, func, LSM_AUDIT_DATA_TASK);
198 smk_ad_setfield_u_tsk(&ad, tracer);
202 tsp = task_security(tracer);
203 skp = smk_of_task(tsp);
205 if ((mode & PTRACE_MODE_ATTACH) &&
206 (smack_ptrace_rule == SMACK_PTRACE_EXACT ||
207 smack_ptrace_rule == SMACK_PTRACE_DRACONIAN)) {
208 if (skp->smk_known == tracee_label)
210 else if (smack_ptrace_rule == SMACK_PTRACE_DRACONIAN)
212 else if (capable(CAP_SYS_PTRACE))
218 smack_log(skp->smk_known, tracee_label, 0, rc, saip);
223 /* In case of rule==SMACK_PTRACE_DEFAULT or mode==PTRACE_MODE_READ */
224 rc = smk_tskacc(tsp, tracee_label, smk_ptrace_mode(mode), saip);
230 * We he, that is fun!
234 * smack_ptrace_access_check - Smack approval on PTRACE_ATTACH
235 * @ctp: child task pointer
236 * @mode: ptrace attachment mode (PTRACE_MODE_*)
238 * Returns 0 if access is OK, an error code otherwise
240 * Do the capability checks.
242 static int smack_ptrace_access_check(struct task_struct *ctp, unsigned int mode)
245 struct smack_known *skp;
247 rc = cap_ptrace_access_check(ctp, mode);
251 skp = smk_of_task(task_security(ctp));
253 rc = smk_ptrace_rule_check(current, skp->smk_known, mode, __func__);
258 * smack_ptrace_traceme - Smack approval on PTRACE_TRACEME
259 * @ptp: parent task pointer
261 * Returns 0 if access is OK, an error code otherwise
263 * Do the capability checks, and require PTRACE_MODE_ATTACH.
265 static int smack_ptrace_traceme(struct task_struct *ptp)
268 struct smack_known *skp;
270 rc = cap_ptrace_traceme(ptp);
274 skp = smk_of_task(current_security());
276 rc = smk_ptrace_rule_check(ptp, skp->smk_known,
277 PTRACE_MODE_ATTACH, __func__);
282 * smack_syslog - Smack approval on syslog
283 * @type: message type
285 * Returns 0 on success, error code otherwise.
287 static int smack_syslog(int typefrom_file)
290 struct smack_known *skp = smk_of_current();
292 if (smack_privileged(CAP_MAC_OVERRIDE))
295 if (smack_syslog_label != NULL && smack_syslog_label != skp)
307 * smack_sb_alloc_security - allocate a superblock blob
308 * @sb: the superblock getting the blob
310 * Returns 0 on success or -ENOMEM on error.
312 static int smack_sb_alloc_security(struct super_block *sb)
314 struct superblock_smack *sbsp;
316 sbsp = kzalloc(sizeof(struct superblock_smack), GFP_KERNEL);
321 sbsp->smk_root = smack_known_floor.smk_known;
322 sbsp->smk_default = smack_known_floor.smk_known;
323 sbsp->smk_floor = smack_known_floor.smk_known;
324 sbsp->smk_hat = smack_known_hat.smk_known;
326 * smk_initialized will be zero from kzalloc.
328 sb->s_security = sbsp;
334 * smack_sb_free_security - free a superblock blob
335 * @sb: the superblock getting the blob
338 static void smack_sb_free_security(struct super_block *sb)
340 kfree(sb->s_security);
341 sb->s_security = NULL;
345 * smack_sb_copy_data - copy mount options data for processing
346 * @orig: where to start
347 * @smackopts: mount options string
349 * Returns 0 on success or -ENOMEM on error.
351 * Copy the Smack specific mount options out of the mount
354 static int smack_sb_copy_data(char *orig, char *smackopts)
356 char *cp, *commap, *otheropts, *dp;
358 otheropts = (char *)get_zeroed_page(GFP_KERNEL);
359 if (otheropts == NULL)
362 for (cp = orig, commap = orig; commap != NULL; cp = commap + 1) {
363 if (strstr(cp, SMK_FSDEFAULT) == cp)
365 else if (strstr(cp, SMK_FSFLOOR) == cp)
367 else if (strstr(cp, SMK_FSHAT) == cp)
369 else if (strstr(cp, SMK_FSROOT) == cp)
371 else if (strstr(cp, SMK_FSTRANS) == cp)
376 commap = strchr(cp, ',');
385 strcpy(orig, otheropts);
386 free_page((unsigned long)otheropts);
392 * smack_sb_kern_mount - Smack specific mount processing
393 * @sb: the file system superblock
394 * @flags: the mount flags
395 * @data: the smack mount options
397 * Returns 0 on success, an error code on failure
399 static int smack_sb_kern_mount(struct super_block *sb, int flags, void *data)
401 struct dentry *root = sb->s_root;
402 struct inode *inode = root->d_inode;
403 struct superblock_smack *sp = sb->s_security;
404 struct inode_smack *isp;
405 struct smack_known *skp;
412 if (sp->smk_initialized)
415 sp->smk_initialized = 1;
417 for (op = data; op != NULL; op = commap) {
418 commap = strchr(op, ',');
422 if (strncmp(op, SMK_FSHAT, strlen(SMK_FSHAT)) == 0) {
423 op += strlen(SMK_FSHAT);
424 nsp = smk_import(op, 0);
429 } else if (strncmp(op, SMK_FSFLOOR, strlen(SMK_FSFLOOR)) == 0) {
430 op += strlen(SMK_FSFLOOR);
431 nsp = smk_import(op, 0);
436 } else if (strncmp(op, SMK_FSDEFAULT,
437 strlen(SMK_FSDEFAULT)) == 0) {
438 op += strlen(SMK_FSDEFAULT);
439 nsp = smk_import(op, 0);
441 sp->smk_default = nsp;
444 } else if (strncmp(op, SMK_FSROOT, strlen(SMK_FSROOT)) == 0) {
445 op += strlen(SMK_FSROOT);
446 nsp = smk_import(op, 0);
451 } else if (strncmp(op, SMK_FSTRANS, strlen(SMK_FSTRANS)) == 0) {
452 op += strlen(SMK_FSTRANS);
453 nsp = smk_import(op, 0);
462 if (!smack_privileged(CAP_MAC_ADMIN)) {
464 * Unprivileged mounts don't get to specify Smack values.
469 * Unprivileged mounts get root and default from the caller.
471 skp = smk_of_current();
472 sp->smk_root = skp->smk_known;
473 sp->smk_default = skp->smk_known;
476 * Initialize the root inode.
478 isp = inode->i_security;
480 isp = new_inode_smack(sp->smk_root);
483 inode->i_security = isp;
485 isp->smk_inode = sp->smk_root;
488 isp->smk_flags |= SMK_INODE_TRANSMUTE;
494 * smack_sb_statfs - Smack check on statfs
495 * @dentry: identifies the file system in question
497 * Returns 0 if current can read the floor of the filesystem,
498 * and error code otherwise
500 static int smack_sb_statfs(struct dentry *dentry)
502 struct superblock_smack *sbp = dentry->d_sb->s_security;
504 struct smk_audit_info ad;
506 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_DENTRY);
507 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
509 rc = smk_curacc(sbp->smk_floor, MAY_READ, &ad);
518 * smack_bprm_set_creds - set creds for exec
519 * @bprm: the exec information
521 * Returns 0 if it gets a blob, -EPERM if exec forbidden and -ENOMEM otherwise
523 static int smack_bprm_set_creds(struct linux_binprm *bprm)
525 struct inode *inode = file_inode(bprm->file);
526 struct task_smack *bsp = bprm->cred->security;
527 struct inode_smack *isp;
530 rc = cap_bprm_set_creds(bprm);
534 if (bprm->cred_prepared)
537 isp = inode->i_security;
538 if (isp->smk_task == NULL || isp->smk_task == bsp->smk_task)
541 if (bprm->unsafe & (LSM_UNSAFE_PTRACE | LSM_UNSAFE_PTRACE_CAP)) {
542 struct task_struct *tracer;
546 tracer = ptrace_parent(current);
547 if (likely(tracer != NULL))
548 rc = smk_ptrace_rule_check(tracer,
549 isp->smk_task->smk_known,
556 } else if (bprm->unsafe)
559 bsp->smk_task = isp->smk_task;
560 bprm->per_clear |= PER_CLEAR_ON_SETID;
566 * smack_bprm_committing_creds - Prepare to install the new credentials
569 * @bprm: binprm for exec
571 static void smack_bprm_committing_creds(struct linux_binprm *bprm)
573 struct task_smack *bsp = bprm->cred->security;
575 if (bsp->smk_task != bsp->smk_forked)
576 current->pdeath_signal = 0;
580 * smack_bprm_secureexec - Return the decision to use secureexec.
581 * @bprm: binprm for exec
583 * Returns 0 on success.
585 static int smack_bprm_secureexec(struct linux_binprm *bprm)
587 struct task_smack *tsp = current_security();
588 int ret = cap_bprm_secureexec(bprm);
590 if (!ret && (tsp->smk_task != tsp->smk_forked))
601 * smack_inode_alloc_security - allocate an inode blob
602 * @inode: the inode in need of a blob
604 * Returns 0 if it gets a blob, -ENOMEM otherwise
606 static int smack_inode_alloc_security(struct inode *inode)
608 struct smack_known *skp = smk_of_current();
610 inode->i_security = new_inode_smack(skp->smk_known);
611 if (inode->i_security == NULL)
617 * smack_inode_free_security - free an inode blob
618 * @inode: the inode with a blob
620 * Clears the blob pointer in inode
622 static void smack_inode_free_security(struct inode *inode)
624 kfree(inode->i_security);
625 inode->i_security = NULL;
629 * smack_inode_init_security - copy out the smack from an inode
633 * @name: where to put the attribute name
634 * @value: where to put the attribute value
635 * @len: where to put the length of the attribute
637 * Returns 0 if it all works out, -ENOMEM if there's no memory
639 static int smack_inode_init_security(struct inode *inode, struct inode *dir,
640 const struct qstr *qstr, const char **name,
641 void **value, size_t *len)
643 struct inode_smack *issp = inode->i_security;
644 struct smack_known *skp = smk_of_current();
645 char *isp = smk_of_inode(inode);
646 char *dsp = smk_of_inode(dir);
650 *name = XATTR_SMACK_SUFFIX;
654 may = smk_access_entry(skp->smk_known, dsp, &skp->smk_rules);
658 * If the access rule allows transmutation and
659 * the directory requests transmutation then
660 * by all means transmute.
661 * Mark the inode as changed.
663 if (may > 0 && ((may & MAY_TRANSMUTE) != 0) &&
664 smk_inode_transmutable(dir)) {
666 issp->smk_flags |= SMK_INODE_CHANGED;
669 *value = kstrdup(isp, GFP_NOFS);
675 *len = strlen(isp) + 1;
681 * smack_inode_link - Smack check on link
682 * @old_dentry: the existing object
684 * @new_dentry: the new object
686 * Returns 0 if access is permitted, an error code otherwise
688 static int smack_inode_link(struct dentry *old_dentry, struct inode *dir,
689 struct dentry *new_dentry)
692 struct smk_audit_info ad;
695 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_DENTRY);
696 smk_ad_setfield_u_fs_path_dentry(&ad, old_dentry);
698 isp = smk_of_inode(old_dentry->d_inode);
699 rc = smk_curacc(isp, MAY_WRITE, &ad);
701 if (rc == 0 && new_dentry->d_inode != NULL) {
702 isp = smk_of_inode(new_dentry->d_inode);
703 smk_ad_setfield_u_fs_path_dentry(&ad, new_dentry);
704 rc = smk_curacc(isp, MAY_WRITE, &ad);
711 * smack_inode_unlink - Smack check on inode deletion
712 * @dir: containing directory object
713 * @dentry: file to unlink
715 * Returns 0 if current can write the containing directory
716 * and the object, error code otherwise
718 static int smack_inode_unlink(struct inode *dir, struct dentry *dentry)
720 struct inode *ip = dentry->d_inode;
721 struct smk_audit_info ad;
724 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_DENTRY);
725 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
728 * You need write access to the thing you're unlinking
730 rc = smk_curacc(smk_of_inode(ip), MAY_WRITE, &ad);
733 * You also need write access to the containing directory
735 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_INODE);
736 smk_ad_setfield_u_fs_inode(&ad, dir);
737 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE, &ad);
743 * smack_inode_rmdir - Smack check on directory deletion
744 * @dir: containing directory object
745 * @dentry: directory to unlink
747 * Returns 0 if current can write the containing directory
748 * and the directory, error code otherwise
750 static int smack_inode_rmdir(struct inode *dir, struct dentry *dentry)
752 struct smk_audit_info ad;
755 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_DENTRY);
756 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
759 * You need write access to the thing you're removing
761 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
764 * You also need write access to the containing directory
766 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_INODE);
767 smk_ad_setfield_u_fs_inode(&ad, dir);
768 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE, &ad);
775 * smack_inode_rename - Smack check on rename
776 * @old_inode: the old directory
777 * @old_dentry: unused
778 * @new_inode: the new directory
779 * @new_dentry: unused
781 * Read and write access is required on both the old and
784 * Returns 0 if access is permitted, an error code otherwise
786 static int smack_inode_rename(struct inode *old_inode,
787 struct dentry *old_dentry,
788 struct inode *new_inode,
789 struct dentry *new_dentry)
793 struct smk_audit_info ad;
795 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_DENTRY);
796 smk_ad_setfield_u_fs_path_dentry(&ad, old_dentry);
798 isp = smk_of_inode(old_dentry->d_inode);
799 rc = smk_curacc(isp, MAY_READWRITE, &ad);
801 if (rc == 0 && new_dentry->d_inode != NULL) {
802 isp = smk_of_inode(new_dentry->d_inode);
803 smk_ad_setfield_u_fs_path_dentry(&ad, new_dentry);
804 rc = smk_curacc(isp, MAY_READWRITE, &ad);
810 * smack_inode_permission - Smack version of permission()
811 * @inode: the inode in question
812 * @mask: the access requested
814 * This is the important Smack hook.
816 * Returns 0 if access is permitted, -EACCES otherwise
818 static int smack_inode_permission(struct inode *inode, int mask)
820 struct smk_audit_info ad;
821 int no_block = mask & MAY_NOT_BLOCK;
823 mask &= (MAY_READ|MAY_WRITE|MAY_EXEC|MAY_APPEND);
825 * No permission to check. Existence test. Yup, it's there.
830 /* May be droppable after audit */
833 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_INODE);
834 smk_ad_setfield_u_fs_inode(&ad, inode);
835 return smk_curacc(smk_of_inode(inode), mask, &ad);
839 * smack_inode_setattr - Smack check for setting attributes
840 * @dentry: the object
841 * @iattr: for the force flag
843 * Returns 0 if access is permitted, an error code otherwise
845 static int smack_inode_setattr(struct dentry *dentry, struct iattr *iattr)
847 struct smk_audit_info ad;
849 * Need to allow for clearing the setuid bit.
851 if (iattr->ia_valid & ATTR_FORCE)
853 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_DENTRY);
854 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
856 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
860 * smack_inode_getattr - Smack check for getting attributes
862 * @dentry: the object
864 * Returns 0 if access is permitted, an error code otherwise
866 static int smack_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
868 struct smk_audit_info ad;
871 path.dentry = dentry;
874 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_PATH);
875 smk_ad_setfield_u_fs_path(&ad, path);
876 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ, &ad);
880 * smack_inode_setxattr - Smack check for setting xattrs
881 * @dentry: the object
882 * @name: name of the attribute
887 * This protects the Smack attribute explicitly.
889 * Returns 0 if access is permitted, an error code otherwise
891 static int smack_inode_setxattr(struct dentry *dentry, const char *name,
892 const void *value, size_t size, int flags)
894 struct smk_audit_info ad;
895 struct smack_known *skp;
897 int check_import = 0;
902 * Check label validity here so import won't fail in post_setxattr
904 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
905 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
906 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0) {
909 } else if (strcmp(name, XATTR_NAME_SMACKEXEC) == 0 ||
910 strcmp(name, XATTR_NAME_SMACKMMAP) == 0) {
914 } else if (strcmp(name, XATTR_NAME_SMACKTRANSMUTE) == 0) {
916 if (size != TRANS_TRUE_SIZE ||
917 strncmp(value, TRANS_TRUE, TRANS_TRUE_SIZE) != 0)
920 rc = cap_inode_setxattr(dentry, name, value, size, flags);
922 if (check_priv && !smack_privileged(CAP_MAC_ADMIN))
925 if (rc == 0 && check_import) {
926 skp = smk_import_entry(value, size);
927 if (skp == NULL || (check_star &&
928 (skp == &smack_known_star || skp == &smack_known_web)))
932 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_DENTRY);
933 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
936 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
942 * smack_inode_post_setxattr - Apply the Smack update approved above
944 * @name: attribute name
945 * @value: attribute value
946 * @size: attribute size
949 * Set the pointer in the inode blob to the entry found
950 * in the master label list.
952 static void smack_inode_post_setxattr(struct dentry *dentry, const char *name,
953 const void *value, size_t size, int flags)
955 struct smack_known *skp;
956 struct inode_smack *isp = dentry->d_inode->i_security;
958 if (strcmp(name, XATTR_NAME_SMACKTRANSMUTE) == 0) {
959 isp->smk_flags |= SMK_INODE_TRANSMUTE;
963 if (strcmp(name, XATTR_NAME_SMACK) == 0) {
964 skp = smk_import_entry(value, size);
966 isp->smk_inode = skp->smk_known;
968 isp->smk_inode = smack_known_invalid.smk_known;
969 } else if (strcmp(name, XATTR_NAME_SMACKEXEC) == 0) {
970 skp = smk_import_entry(value, size);
974 isp->smk_task = &smack_known_invalid;
975 } else if (strcmp(name, XATTR_NAME_SMACKMMAP) == 0) {
976 skp = smk_import_entry(value, size);
980 isp->smk_mmap = &smack_known_invalid;
987 * smack_inode_getxattr - Smack check on getxattr
988 * @dentry: the object
991 * Returns 0 if access is permitted, an error code otherwise
993 static int smack_inode_getxattr(struct dentry *dentry, const char *name)
995 struct smk_audit_info ad;
997 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_DENTRY);
998 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
1000 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ, &ad);
1004 * smack_inode_removexattr - Smack check on removexattr
1005 * @dentry: the object
1006 * @name: name of the attribute
1008 * Removing the Smack attribute requires CAP_MAC_ADMIN
1010 * Returns 0 if access is permitted, an error code otherwise
1012 static int smack_inode_removexattr(struct dentry *dentry, const char *name)
1014 struct inode_smack *isp;
1015 struct smk_audit_info ad;
1018 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
1019 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
1020 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0 ||
1021 strcmp(name, XATTR_NAME_SMACKEXEC) == 0 ||
1022 strcmp(name, XATTR_NAME_SMACKTRANSMUTE) == 0 ||
1023 strcmp(name, XATTR_NAME_SMACKMMAP) == 0) {
1024 if (!smack_privileged(CAP_MAC_ADMIN))
1027 rc = cap_inode_removexattr(dentry, name);
1029 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_DENTRY);
1030 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
1032 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
1035 isp = dentry->d_inode->i_security;
1036 isp->smk_task = NULL;
1037 isp->smk_mmap = NULL;
1044 * smack_inode_getsecurity - get smack xattrs
1045 * @inode: the object
1046 * @name: attribute name
1047 * @buffer: where to put the result
1050 * Returns the size of the attribute or an error code
1052 static int smack_inode_getsecurity(const struct inode *inode,
1053 const char *name, void **buffer,
1056 struct socket_smack *ssp;
1057 struct socket *sock;
1058 struct super_block *sbp;
1059 struct inode *ip = (struct inode *)inode;
1064 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
1065 isp = smk_of_inode(inode);
1066 ilen = strlen(isp) + 1;
1072 * The rest of the Smack xattrs are only on sockets.
1075 if (sbp->s_magic != SOCKFS_MAGIC)
1078 sock = SOCKET_I(ip);
1079 if (sock == NULL || sock->sk == NULL)
1082 ssp = sock->sk->sk_security;
1084 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
1086 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0)
1087 isp = ssp->smk_out->smk_known;
1091 ilen = strlen(isp) + 1;
1102 * smack_inode_listsecurity - list the Smack attributes
1103 * @inode: the object
1104 * @buffer: where they go
1105 * @buffer_size: size of buffer
1107 * Returns 0 on success, -EINVAL otherwise
1109 static int smack_inode_listsecurity(struct inode *inode, char *buffer,
1112 int len = strlen(XATTR_NAME_SMACK);
1114 if (buffer != NULL && len <= buffer_size) {
1115 memcpy(buffer, XATTR_NAME_SMACK, len);
1122 * smack_inode_getsecid - Extract inode's security id
1123 * @inode: inode to extract the info from
1124 * @secid: where result will be saved
1126 static void smack_inode_getsecid(const struct inode *inode, u32 *secid)
1128 struct inode_smack *isp = inode->i_security;
1130 *secid = smack_to_secid(isp->smk_inode);
1138 * smack_file_permission - Smack check on file operations
1144 * Should access checks be done on each read or write?
1145 * UNICOS and SELinux say yes.
1146 * Trusted Solaris, Trusted Irix, and just about everyone else says no.
1148 * I'll say no for now. Smack does not do the frequent
1149 * label changing that SELinux does.
1151 static int smack_file_permission(struct file *file, int mask)
1157 * smack_file_alloc_security - assign a file security blob
1160 * The security blob for a file is a pointer to the master
1161 * label list, so no allocation is done.
1165 static int smack_file_alloc_security(struct file *file)
1167 struct smack_known *skp = smk_of_current();
1169 file->f_security = skp->smk_known;
1174 * smack_file_free_security - clear a file security blob
1177 * The security blob for a file is a pointer to the master
1178 * label list, so no memory is freed.
1180 static void smack_file_free_security(struct file *file)
1182 file->f_security = NULL;
1186 * smack_file_ioctl - Smack check on ioctls
1191 * Relies heavily on the correct use of the ioctl command conventions.
1193 * Returns 0 if allowed, error code otherwise
1195 static int smack_file_ioctl(struct file *file, unsigned int cmd,
1199 struct smk_audit_info ad;
1201 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_PATH);
1202 smk_ad_setfield_u_fs_path(&ad, file->f_path);
1204 if (_IOC_DIR(cmd) & _IOC_WRITE)
1205 rc = smk_curacc(file->f_security, MAY_WRITE, &ad);
1207 if (rc == 0 && (_IOC_DIR(cmd) & _IOC_READ))
1208 rc = smk_curacc(file->f_security, MAY_READ, &ad);
1214 * smack_file_lock - Smack check on file locking
1218 * Returns 0 if current has lock access, error code otherwise
1220 static int smack_file_lock(struct file *file, unsigned int cmd)
1222 struct smk_audit_info ad;
1224 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_PATH);
1225 smk_ad_setfield_u_fs_path(&ad, file->f_path);
1226 return smk_curacc(file->f_security, MAY_LOCK, &ad);
1230 * smack_file_fcntl - Smack check on fcntl
1232 * @cmd: what action to check
1235 * Generally these operations are harmless.
1236 * File locking operations present an obvious mechanism
1237 * for passing information, so they require write access.
1239 * Returns 0 if current has access, error code otherwise
1241 static int smack_file_fcntl(struct file *file, unsigned int cmd,
1244 struct smk_audit_info ad;
1253 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_PATH);
1254 smk_ad_setfield_u_fs_path(&ad, file->f_path);
1255 rc = smk_curacc(file->f_security, MAY_LOCK, &ad);
1259 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_PATH);
1260 smk_ad_setfield_u_fs_path(&ad, file->f_path);
1261 rc = smk_curacc(file->f_security, MAY_WRITE, &ad);
1272 * Check permissions for a mmap operation. The @file may be NULL, e.g.
1273 * if mapping anonymous memory.
1274 * @file contains the file structure for file to map (may be NULL).
1275 * @reqprot contains the protection requested by the application.
1276 * @prot contains the protection that will be applied by the kernel.
1277 * @flags contains the operational flags.
1278 * Return 0 if permission is granted.
1280 static int smack_mmap_file(struct file *file,
1281 unsigned long reqprot, unsigned long prot,
1282 unsigned long flags)
1284 struct smack_known *skp;
1285 struct smack_known *mkp;
1286 struct smack_rule *srp;
1287 struct task_smack *tsp;
1289 struct inode_smack *isp;
1298 isp = file_inode(file)->i_security;
1299 if (isp->smk_mmap == NULL)
1301 mkp = isp->smk_mmap;
1303 tsp = current_security();
1304 skp = smk_of_current();
1309 * For each Smack rule associated with the subject
1310 * label verify that the SMACK64MMAP also has access
1311 * to that rule's object label.
1313 list_for_each_entry_rcu(srp, &skp->smk_rules, list) {
1314 osmack = srp->smk_object;
1316 * Matching labels always allows access.
1318 if (mkp->smk_known == osmack)
1321 * If there is a matching local rule take
1322 * that into account as well.
1324 may = smk_access_entry(srp->smk_subject->smk_known, osmack,
1327 may = srp->smk_access;
1329 may &= srp->smk_access;
1331 * If may is zero the SMACK64MMAP subject can't
1332 * possibly have less access.
1338 * Fetch the global list entry.
1339 * If there isn't one a SMACK64MMAP subject
1340 * can't have as much access as current.
1342 mmay = smk_access_entry(mkp->smk_known, osmack,
1344 if (mmay == -ENOENT) {
1349 * If there is a local entry it modifies the
1350 * potential access, too.
1352 tmay = smk_access_entry(mkp->smk_known, osmack,
1354 if (tmay != -ENOENT)
1358 * If there is any access available to current that is
1359 * not available to a SMACK64MMAP subject
1362 if ((may | mmay) != mmay) {
1374 * smack_file_set_fowner - set the file security blob value
1375 * @file: object in question
1378 * Further research may be required on this one.
1380 static int smack_file_set_fowner(struct file *file)
1382 struct smack_known *skp = smk_of_current();
1384 file->f_security = skp->smk_known;
1389 * smack_file_send_sigiotask - Smack on sigio
1390 * @tsk: The target task
1391 * @fown: the object the signal come from
1394 * Allow a privileged task to get signals even if it shouldn't
1396 * Returns 0 if a subject with the object's smack could
1397 * write to the task, an error code otherwise.
1399 static int smack_file_send_sigiotask(struct task_struct *tsk,
1400 struct fown_struct *fown, int signum)
1402 struct smack_known *skp;
1403 struct smack_known *tkp = smk_of_task(tsk->cred->security);
1406 struct smk_audit_info ad;
1409 * struct fown_struct is never outside the context of a struct file
1411 file = container_of(fown, struct file, f_owner);
1413 /* we don't log here as rc can be overriden */
1414 skp = smk_find_entry(file->f_security);
1415 rc = smk_access(skp, tkp->smk_known, MAY_WRITE, NULL);
1416 if (rc != 0 && has_capability(tsk, CAP_MAC_OVERRIDE))
1419 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1420 smk_ad_setfield_u_tsk(&ad, tsk);
1421 smack_log(file->f_security, tkp->smk_known, MAY_WRITE, rc, &ad);
1426 * smack_file_receive - Smack file receive check
1429 * Returns 0 if current has access, error code otherwise
1431 static int smack_file_receive(struct file *file)
1434 struct smk_audit_info ad;
1436 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_PATH);
1437 smk_ad_setfield_u_fs_path(&ad, file->f_path);
1439 * This code relies on bitmasks.
1441 if (file->f_mode & FMODE_READ)
1443 if (file->f_mode & FMODE_WRITE)
1446 return smk_curacc(file->f_security, may, &ad);
1450 * smack_file_open - Smack dentry open processing
1454 * Set the security blob in the file structure.
1458 static int smack_file_open(struct file *file, const struct cred *cred)
1460 struct inode_smack *isp = file_inode(file)->i_security;
1462 file->f_security = isp->smk_inode;
1472 * smack_cred_alloc_blank - "allocate" blank task-level security credentials
1473 * @new: the new credentials
1474 * @gfp: the atomicity of any memory allocations
1476 * Prepare a blank set of credentials for modification. This must allocate all
1477 * the memory the LSM module might require such that cred_transfer() can
1478 * complete without error.
1480 static int smack_cred_alloc_blank(struct cred *cred, gfp_t gfp)
1482 struct task_smack *tsp;
1484 tsp = new_task_smack(NULL, NULL, gfp);
1488 cred->security = tsp;
1495 * smack_cred_free - "free" task-level security credentials
1496 * @cred: the credentials in question
1499 static void smack_cred_free(struct cred *cred)
1501 struct task_smack *tsp = cred->security;
1502 struct smack_rule *rp;
1503 struct list_head *l;
1504 struct list_head *n;
1508 cred->security = NULL;
1510 list_for_each_safe(l, n, &tsp->smk_rules) {
1511 rp = list_entry(l, struct smack_rule, list);
1512 list_del(&rp->list);
1519 * smack_cred_prepare - prepare new set of credentials for modification
1520 * @new: the new credentials
1521 * @old: the original credentials
1522 * @gfp: the atomicity of any memory allocations
1524 * Prepare a new set of credentials for modification.
1526 static int smack_cred_prepare(struct cred *new, const struct cred *old,
1529 struct task_smack *old_tsp = old->security;
1530 struct task_smack *new_tsp;
1533 new_tsp = new_task_smack(old_tsp->smk_task, old_tsp->smk_task, gfp);
1534 if (new_tsp == NULL)
1537 rc = smk_copy_rules(&new_tsp->smk_rules, &old_tsp->smk_rules, gfp);
1541 new->security = new_tsp;
1546 * smack_cred_transfer - Transfer the old credentials to the new credentials
1547 * @new: the new credentials
1548 * @old: the original credentials
1550 * Fill in a set of blank credentials from another set of credentials.
1552 static void smack_cred_transfer(struct cred *new, const struct cred *old)
1554 struct task_smack *old_tsp = old->security;
1555 struct task_smack *new_tsp = new->security;
1557 new_tsp->smk_task = old_tsp->smk_task;
1558 new_tsp->smk_forked = old_tsp->smk_task;
1559 mutex_init(&new_tsp->smk_rules_lock);
1560 INIT_LIST_HEAD(&new_tsp->smk_rules);
1563 /* cbs copy rule list */
1567 * smack_kernel_act_as - Set the subjective context in a set of credentials
1568 * @new: points to the set of credentials to be modified.
1569 * @secid: specifies the security ID to be set
1571 * Set the security data for a kernel service.
1573 static int smack_kernel_act_as(struct cred *new, u32 secid)
1575 struct task_smack *new_tsp = new->security;
1576 struct smack_known *skp = smack_from_secid(secid);
1581 new_tsp->smk_task = skp;
1586 * smack_kernel_create_files_as - Set the file creation label in a set of creds
1587 * @new: points to the set of credentials to be modified
1588 * @inode: points to the inode to use as a reference
1590 * Set the file creation context in a set of credentials to the same
1591 * as the objective context of the specified inode
1593 static int smack_kernel_create_files_as(struct cred *new,
1594 struct inode *inode)
1596 struct inode_smack *isp = inode->i_security;
1597 struct task_smack *tsp = new->security;
1599 tsp->smk_forked = smk_find_entry(isp->smk_inode);
1600 tsp->smk_task = tsp->smk_forked;
1605 * smk_curacc_on_task - helper to log task related access
1606 * @p: the task object
1607 * @access: the access requested
1608 * @caller: name of the calling function for audit
1610 * Return 0 if access is permitted
1612 static int smk_curacc_on_task(struct task_struct *p, int access,
1615 struct smk_audit_info ad;
1616 struct smack_known *skp = smk_of_task(task_security(p));
1618 smk_ad_init(&ad, caller, LSM_AUDIT_DATA_TASK);
1619 smk_ad_setfield_u_tsk(&ad, p);
1620 return smk_curacc(skp->smk_known, access, &ad);
1624 * smack_task_setpgid - Smack check on setting pgid
1625 * @p: the task object
1628 * Return 0 if write access is permitted
1630 static int smack_task_setpgid(struct task_struct *p, pid_t pgid)
1632 return smk_curacc_on_task(p, MAY_WRITE, __func__);
1636 * smack_task_getpgid - Smack access check for getpgid
1637 * @p: the object task
1639 * Returns 0 if current can read the object task, error code otherwise
1641 static int smack_task_getpgid(struct task_struct *p)
1643 return smk_curacc_on_task(p, MAY_READ, __func__);
1647 * smack_task_getsid - Smack access check for getsid
1648 * @p: the object task
1650 * Returns 0 if current can read the object task, error code otherwise
1652 static int smack_task_getsid(struct task_struct *p)
1654 return smk_curacc_on_task(p, MAY_READ, __func__);
1658 * smack_task_getsecid - get the secid of the task
1659 * @p: the object task
1660 * @secid: where to put the result
1662 * Sets the secid to contain a u32 version of the smack label.
1664 static void smack_task_getsecid(struct task_struct *p, u32 *secid)
1666 struct smack_known *skp = smk_of_task(task_security(p));
1668 *secid = skp->smk_secid;
1672 * smack_task_setnice - Smack check on setting nice
1673 * @p: the task object
1676 * Return 0 if write access is permitted
1678 static int smack_task_setnice(struct task_struct *p, int nice)
1682 rc = cap_task_setnice(p, nice);
1684 rc = smk_curacc_on_task(p, MAY_WRITE, __func__);
1689 * smack_task_setioprio - Smack check on setting ioprio
1690 * @p: the task object
1693 * Return 0 if write access is permitted
1695 static int smack_task_setioprio(struct task_struct *p, int ioprio)
1699 rc = cap_task_setioprio(p, ioprio);
1701 rc = smk_curacc_on_task(p, MAY_WRITE, __func__);
1706 * smack_task_getioprio - Smack check on reading ioprio
1707 * @p: the task object
1709 * Return 0 if read access is permitted
1711 static int smack_task_getioprio(struct task_struct *p)
1713 return smk_curacc_on_task(p, MAY_READ, __func__);
1717 * smack_task_setscheduler - Smack check on setting scheduler
1718 * @p: the task object
1722 * Return 0 if read access is permitted
1724 static int smack_task_setscheduler(struct task_struct *p)
1728 rc = cap_task_setscheduler(p);
1730 rc = smk_curacc_on_task(p, MAY_WRITE, __func__);
1735 * smack_task_getscheduler - Smack check on reading scheduler
1736 * @p: the task object
1738 * Return 0 if read access is permitted
1740 static int smack_task_getscheduler(struct task_struct *p)
1742 return smk_curacc_on_task(p, MAY_READ, __func__);
1746 * smack_task_movememory - Smack check on moving memory
1747 * @p: the task object
1749 * Return 0 if write access is permitted
1751 static int smack_task_movememory(struct task_struct *p)
1753 return smk_curacc_on_task(p, MAY_WRITE, __func__);
1757 * smack_task_kill - Smack check on signal delivery
1758 * @p: the task object
1761 * @secid: identifies the smack to use in lieu of current's
1763 * Return 0 if write access is permitted
1765 * The secid behavior is an artifact of an SELinux hack
1766 * in the USB code. Someday it may go away.
1768 static int smack_task_kill(struct task_struct *p, struct siginfo *info,
1771 struct smk_audit_info ad;
1772 struct smack_known *skp;
1773 struct smack_known *tkp = smk_of_task(task_security(p));
1775 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1776 smk_ad_setfield_u_tsk(&ad, p);
1778 * Sending a signal requires that the sender
1779 * can write the receiver.
1782 return smk_curacc(tkp->smk_known, MAY_WRITE, &ad);
1784 * If the secid isn't 0 we're dealing with some USB IO
1785 * specific behavior. This is not clean. For one thing
1786 * we can't take privilege into account.
1788 skp = smack_from_secid(secid);
1789 return smk_access(skp, tkp->smk_known, MAY_WRITE, &ad);
1793 * smack_task_wait - Smack access check for waiting
1794 * @p: task to wait for
1798 static int smack_task_wait(struct task_struct *p)
1801 * Allow the operation to succeed.
1803 * In userless environments (e.g. phones) programs
1804 * get marked with SMACK64EXEC and even if the parent
1805 * and child shouldn't be talking the parent still
1806 * may expect to know when the child exits.
1812 * smack_task_to_inode - copy task smack into the inode blob
1813 * @p: task to copy from
1814 * @inode: inode to copy to
1816 * Sets the smack pointer in the inode security blob
1818 static void smack_task_to_inode(struct task_struct *p, struct inode *inode)
1820 struct inode_smack *isp = inode->i_security;
1821 struct smack_known *skp = smk_of_task(task_security(p));
1823 isp->smk_inode = skp->smk_known;
1831 * smack_sk_alloc_security - Allocate a socket blob
1834 * @gfp_flags: memory allocation flags
1836 * Assign Smack pointers to current
1838 * Returns 0 on success, -ENOMEM is there's no memory
1840 static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags)
1842 struct smack_known *skp = smk_of_current();
1843 struct socket_smack *ssp;
1845 ssp = kzalloc(sizeof(struct socket_smack), gfp_flags);
1849 ssp->smk_in = skp->smk_known;
1851 ssp->smk_packet = NULL;
1853 sk->sk_security = ssp;
1859 * smack_sk_free_security - Free a socket blob
1862 * Clears the blob pointer
1864 static void smack_sk_free_security(struct sock *sk)
1866 kfree(sk->sk_security);
1870 * smack_host_label - check host based restrictions
1871 * @sip: the object end
1873 * looks for host based access restrictions
1875 * This version will only be appropriate for really small sets of single label
1876 * hosts. The caller is responsible for ensuring that the RCU read lock is
1877 * taken before calling this function.
1879 * Returns the label of the far end or NULL if it's not special.
1881 static char *smack_host_label(struct sockaddr_in *sip)
1883 struct smk_netlbladdr *snp;
1884 struct in_addr *siap = &sip->sin_addr;
1886 if (siap->s_addr == 0)
1889 list_for_each_entry_rcu(snp, &smk_netlbladdr_list, list)
1891 * we break after finding the first match because
1892 * the list is sorted from longest to shortest mask
1893 * so we have found the most specific match
1895 if ((&snp->smk_host.sin_addr)->s_addr ==
1896 (siap->s_addr & (&snp->smk_mask)->s_addr)) {
1897 /* we have found the special CIPSO option */
1898 if (snp->smk_label == smack_cipso_option)
1900 return snp->smk_label;
1907 * smack_netlabel - Set the secattr on a socket
1909 * @labeled: socket label scheme
1911 * Convert the outbound smack value (smk_out) to a
1912 * secattr and attach it to the socket.
1914 * Returns 0 on success or an error code
1916 static int smack_netlabel(struct sock *sk, int labeled)
1918 struct smack_known *skp;
1919 struct socket_smack *ssp = sk->sk_security;
1923 * Usually the netlabel code will handle changing the
1924 * packet labeling based on the label.
1925 * The case of a single label host is different, because
1926 * a single label host should never get a labeled packet
1927 * even though the label is usually associated with a packet
1931 bh_lock_sock_nested(sk);
1933 if (ssp->smk_out == smack_net_ambient ||
1934 labeled == SMACK_UNLABELED_SOCKET)
1935 netlbl_sock_delattr(sk);
1938 rc = netlbl_sock_setattr(sk, sk->sk_family, &skp->smk_netlabel);
1948 * smack_netlbel_send - Set the secattr on a socket and perform access checks
1950 * @sap: the destination address
1952 * Set the correct secattr for the given socket based on the destination
1953 * address and perform any outbound access checks needed.
1955 * Returns 0 on success or an error code.
1958 static int smack_netlabel_send(struct sock *sk, struct sockaddr_in *sap)
1960 struct smack_known *skp;
1964 struct socket_smack *ssp = sk->sk_security;
1965 struct smk_audit_info ad;
1968 hostsp = smack_host_label(sap);
1969 if (hostsp != NULL) {
1971 struct lsm_network_audit net;
1973 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
1974 ad.a.u.net->family = sap->sin_family;
1975 ad.a.u.net->dport = sap->sin_port;
1976 ad.a.u.net->v4info.daddr = sap->sin_addr.s_addr;
1978 sk_lbl = SMACK_UNLABELED_SOCKET;
1980 rc = smk_access(skp, hostsp, MAY_WRITE, &ad);
1982 sk_lbl = SMACK_CIPSO_SOCKET;
1989 return smack_netlabel(sk, sk_lbl);
1993 * smk_ipv6_port_label - Smack port access table management
1997 * Create or update the port list entry
1999 static void smk_ipv6_port_label(struct socket *sock, struct sockaddr *address)
2001 struct sock *sk = sock->sk;
2002 struct sockaddr_in6 *addr6;
2003 struct socket_smack *ssp = sock->sk->sk_security;
2004 struct smk_port_label *spp;
2005 unsigned short port = 0;
2007 if (address == NULL) {
2009 * This operation is changing the Smack information
2010 * on the bound socket. Take the changes to the port
2013 list_for_each_entry(spp, &smk_ipv6_port_list, list) {
2014 if (sk != spp->smk_sock)
2016 spp->smk_in = ssp->smk_in;
2017 spp->smk_out = ssp->smk_out;
2021 * A NULL address is only used for updating existing
2022 * bound entries. If there isn't one, it's OK.
2027 addr6 = (struct sockaddr_in6 *)address;
2028 port = ntohs(addr6->sin6_port);
2030 * This is a special case that is safely ignored.
2036 * Look for an existing port list entry.
2037 * This is an indication that a port is getting reused.
2039 list_for_each_entry(spp, &smk_ipv6_port_list, list) {
2040 if (spp->smk_port != port)
2042 spp->smk_port = port;
2044 spp->smk_in = ssp->smk_in;
2045 spp->smk_out = ssp->smk_out;
2050 * A new port entry is required.
2052 spp = kzalloc(sizeof(*spp), GFP_KERNEL);
2056 spp->smk_port = port;
2058 spp->smk_in = ssp->smk_in;
2059 spp->smk_out = ssp->smk_out;
2061 list_add(&spp->list, &smk_ipv6_port_list);
2066 * smk_ipv6_port_check - check Smack port access
2070 * Create or update the port list entry
2072 static int smk_ipv6_port_check(struct sock *sk, struct sockaddr_in6 *address,
2077 struct smk_port_label *spp;
2078 struct socket_smack *ssp = sk->sk_security;
2079 struct smack_known *skp;
2080 unsigned short port = 0;
2082 struct smk_audit_info ad;
2084 struct lsm_network_audit net;
2087 if (act == SMK_RECEIVING) {
2088 skp = smack_net_ambient;
2089 object = ssp->smk_in;
2092 object = smack_net_ambient->smk_known;
2096 * Get the IP address and port from the address.
2098 port = ntohs(address->sin6_port);
2099 bep = (__be16 *)(&address->sin6_addr);
2100 be32p = (__be32 *)(&address->sin6_addr);
2103 * It's remote, so port lookup does no good.
2105 if (be32p[0] || be32p[1] || be32p[2] || bep[6] || ntohs(bep[7]) != 1)
2109 * It's local so the send check has to have passed.
2111 if (act == SMK_RECEIVING) {
2112 skp = &smack_known_web;
2116 list_for_each_entry(spp, &smk_ipv6_port_list, list) {
2117 if (spp->smk_port != port)
2119 object = spp->smk_in;
2120 if (act == SMK_CONNECTING)
2121 ssp->smk_packet = spp->smk_out->smk_known;
2128 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
2129 ad.a.u.net->family = sk->sk_family;
2130 ad.a.u.net->dport = port;
2131 if (act == SMK_RECEIVING)
2132 ad.a.u.net->v6info.saddr = address->sin6_addr;
2134 ad.a.u.net->v6info.daddr = address->sin6_addr;
2136 return smk_access(skp, object, MAY_WRITE, &ad);
2140 * smack_inode_setsecurity - set smack xattrs
2141 * @inode: the object
2142 * @name: attribute name
2143 * @value: attribute value
2144 * @size: size of the attribute
2147 * Sets the named attribute in the appropriate blob
2149 * Returns 0 on success, or an error code
2151 static int smack_inode_setsecurity(struct inode *inode, const char *name,
2152 const void *value, size_t size, int flags)
2154 struct smack_known *skp;
2155 struct inode_smack *nsp = inode->i_security;
2156 struct socket_smack *ssp;
2157 struct socket *sock;
2160 if (value == NULL || size > SMK_LONGLABEL || size == 0)
2163 skp = smk_import_entry(value, size);
2167 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
2168 nsp->smk_inode = skp->smk_known;
2169 nsp->smk_flags |= SMK_INODE_INSTANT;
2173 * The rest of the Smack xattrs are only on sockets.
2175 if (inode->i_sb->s_magic != SOCKFS_MAGIC)
2178 sock = SOCKET_I(inode);
2179 if (sock == NULL || sock->sk == NULL)
2182 ssp = sock->sk->sk_security;
2184 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
2185 ssp->smk_in = skp->smk_known;
2186 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0) {
2188 if (sock->sk->sk_family == PF_INET) {
2189 rc = smack_netlabel(sock->sk, SMACK_CIPSO_SOCKET);
2192 "Smack: \"%s\" netlbl error %d.\n",
2198 if (sock->sk->sk_family == PF_INET6)
2199 smk_ipv6_port_label(sock, NULL);
2205 * smack_socket_post_create - finish socket setup
2207 * @family: protocol family
2212 * Sets the netlabel information on the socket
2214 * Returns 0 on success, and error code otherwise
2216 static int smack_socket_post_create(struct socket *sock, int family,
2217 int type, int protocol, int kern)
2219 if (family != PF_INET || sock->sk == NULL)
2222 * Set the outbound netlbl.
2224 return smack_netlabel(sock->sk, SMACK_CIPSO_SOCKET);
2228 * smack_socket_bind - record port binding information.
2230 * @address: the port address
2231 * @addrlen: size of the address
2233 * Records the label bound to a port.
2237 static int smack_socket_bind(struct socket *sock, struct sockaddr *address,
2240 if (sock->sk != NULL && sock->sk->sk_family == PF_INET6)
2241 smk_ipv6_port_label(sock, address);
2247 * smack_socket_connect - connect access check
2249 * @sap: the other end
2250 * @addrlen: size of sap
2252 * Verifies that a connection may be possible
2254 * Returns 0 on success, and error code otherwise
2256 static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
2261 if (sock->sk == NULL)
2264 switch (sock->sk->sk_family) {
2266 if (addrlen < sizeof(struct sockaddr_in))
2268 rc = smack_netlabel_send(sock->sk, (struct sockaddr_in *)sap);
2271 if (addrlen < sizeof(struct sockaddr_in6))
2273 rc = smk_ipv6_port_check(sock->sk, (struct sockaddr_in6 *)sap,
2281 * smack_flags_to_may - convert S_ to MAY_ values
2282 * @flags: the S_ value
2284 * Returns the equivalent MAY_ value
2286 static int smack_flags_to_may(int flags)
2290 if (flags & S_IRUGO)
2292 if (flags & S_IWUGO)
2294 if (flags & S_IXUGO)
2301 * smack_msg_msg_alloc_security - Set the security blob for msg_msg
2306 static int smack_msg_msg_alloc_security(struct msg_msg *msg)
2308 struct smack_known *skp = smk_of_current();
2310 msg->security = skp->smk_known;
2315 * smack_msg_msg_free_security - Clear the security blob for msg_msg
2318 * Clears the blob pointer
2320 static void smack_msg_msg_free_security(struct msg_msg *msg)
2322 msg->security = NULL;
2326 * smack_of_shm - the smack pointer for the shm
2329 * Returns a pointer to the smack value
2331 static char *smack_of_shm(struct shmid_kernel *shp)
2333 return (char *)shp->shm_perm.security;
2337 * smack_shm_alloc_security - Set the security blob for shm
2342 static int smack_shm_alloc_security(struct shmid_kernel *shp)
2344 struct kern_ipc_perm *isp = &shp->shm_perm;
2345 struct smack_known *skp = smk_of_current();
2347 isp->security = skp->smk_known;
2352 * smack_shm_free_security - Clear the security blob for shm
2355 * Clears the blob pointer
2357 static void smack_shm_free_security(struct shmid_kernel *shp)
2359 struct kern_ipc_perm *isp = &shp->shm_perm;
2361 isp->security = NULL;
2365 * smk_curacc_shm : check if current has access on shm
2367 * @access : access requested
2369 * Returns 0 if current has the requested access, error code otherwise
2371 static int smk_curacc_shm(struct shmid_kernel *shp, int access)
2373 char *ssp = smack_of_shm(shp);
2374 struct smk_audit_info ad;
2377 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2378 ad.a.u.ipc_id = shp->shm_perm.id;
2380 return smk_curacc(ssp, access, &ad);
2384 * smack_shm_associate - Smack access check for shm
2386 * @shmflg: access requested
2388 * Returns 0 if current has the requested access, error code otherwise
2390 static int smack_shm_associate(struct shmid_kernel *shp, int shmflg)
2394 may = smack_flags_to_may(shmflg);
2395 return smk_curacc_shm(shp, may);
2399 * smack_shm_shmctl - Smack access check for shm
2401 * @cmd: what it wants to do
2403 * Returns 0 if current has the requested access, error code otherwise
2405 static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd)
2418 may = MAY_READWRITE;
2423 * System level information.
2429 return smk_curacc_shm(shp, may);
2433 * smack_shm_shmat - Smack access for shmat
2436 * @shmflg: access requested
2438 * Returns 0 if current has the requested access, error code otherwise
2440 static int smack_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr,
2445 may = smack_flags_to_may(shmflg);
2446 return smk_curacc_shm(shp, may);
2450 * smack_of_sem - the smack pointer for the sem
2453 * Returns a pointer to the smack value
2455 static char *smack_of_sem(struct sem_array *sma)
2457 return (char *)sma->sem_perm.security;
2461 * smack_sem_alloc_security - Set the security blob for sem
2466 static int smack_sem_alloc_security(struct sem_array *sma)
2468 struct kern_ipc_perm *isp = &sma->sem_perm;
2469 struct smack_known *skp = smk_of_current();
2471 isp->security = skp->smk_known;
2476 * smack_sem_free_security - Clear the security blob for sem
2479 * Clears the blob pointer
2481 static void smack_sem_free_security(struct sem_array *sma)
2483 struct kern_ipc_perm *isp = &sma->sem_perm;
2485 isp->security = NULL;
2489 * smk_curacc_sem : check if current has access on sem
2491 * @access : access requested
2493 * Returns 0 if current has the requested access, error code otherwise
2495 static int smk_curacc_sem(struct sem_array *sma, int access)
2497 char *ssp = smack_of_sem(sma);
2498 struct smk_audit_info ad;
2501 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2502 ad.a.u.ipc_id = sma->sem_perm.id;
2504 return smk_curacc(ssp, access, &ad);
2508 * smack_sem_associate - Smack access check for sem
2510 * @semflg: access requested
2512 * Returns 0 if current has the requested access, error code otherwise
2514 static int smack_sem_associate(struct sem_array *sma, int semflg)
2518 may = smack_flags_to_may(semflg);
2519 return smk_curacc_sem(sma, may);
2523 * smack_sem_shmctl - Smack access check for sem
2525 * @cmd: what it wants to do
2527 * Returns 0 if current has the requested access, error code otherwise
2529 static int smack_sem_semctl(struct sem_array *sma, int cmd)
2547 may = MAY_READWRITE;
2552 * System level information
2559 return smk_curacc_sem(sma, may);
2563 * smack_sem_semop - Smack checks of semaphore operations
2569 * Treated as read and write in all cases.
2571 * Returns 0 if access is allowed, error code otherwise
2573 static int smack_sem_semop(struct sem_array *sma, struct sembuf *sops,
2574 unsigned nsops, int alter)
2576 return smk_curacc_sem(sma, MAY_READWRITE);
2580 * smack_msg_alloc_security - Set the security blob for msg
2585 static int smack_msg_queue_alloc_security(struct msg_queue *msq)
2587 struct kern_ipc_perm *kisp = &msq->q_perm;
2588 struct smack_known *skp = smk_of_current();
2590 kisp->security = skp->smk_known;
2595 * smack_msg_free_security - Clear the security blob for msg
2598 * Clears the blob pointer
2600 static void smack_msg_queue_free_security(struct msg_queue *msq)
2602 struct kern_ipc_perm *kisp = &msq->q_perm;
2604 kisp->security = NULL;
2608 * smack_of_msq - the smack pointer for the msq
2611 * Returns a pointer to the smack value
2613 static char *smack_of_msq(struct msg_queue *msq)
2615 return (char *)msq->q_perm.security;
2619 * smk_curacc_msq : helper to check if current has access on msq
2621 * @access : access requested
2623 * return 0 if current has access, error otherwise
2625 static int smk_curacc_msq(struct msg_queue *msq, int access)
2627 char *msp = smack_of_msq(msq);
2628 struct smk_audit_info ad;
2631 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2632 ad.a.u.ipc_id = msq->q_perm.id;
2634 return smk_curacc(msp, access, &ad);
2638 * smack_msg_queue_associate - Smack access check for msg_queue
2640 * @msqflg: access requested
2642 * Returns 0 if current has the requested access, error code otherwise
2644 static int smack_msg_queue_associate(struct msg_queue *msq, int msqflg)
2648 may = smack_flags_to_may(msqflg);
2649 return smk_curacc_msq(msq, may);
2653 * smack_msg_queue_msgctl - Smack access check for msg_queue
2655 * @cmd: what it wants to do
2657 * Returns 0 if current has the requested access, error code otherwise
2659 static int smack_msg_queue_msgctl(struct msg_queue *msq, int cmd)
2670 may = MAY_READWRITE;
2675 * System level information
2682 return smk_curacc_msq(msq, may);
2686 * smack_msg_queue_msgsnd - Smack access check for msg_queue
2689 * @msqflg: access requested
2691 * Returns 0 if current has the requested access, error code otherwise
2693 static int smack_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
2698 may = smack_flags_to_may(msqflg);
2699 return smk_curacc_msq(msq, may);
2703 * smack_msg_queue_msgsnd - Smack access check for msg_queue
2710 * Returns 0 if current has read and write access, error code otherwise
2712 static int smack_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
2713 struct task_struct *target, long type, int mode)
2715 return smk_curacc_msq(msq, MAY_READWRITE);
2719 * smack_ipc_permission - Smack access for ipc_permission()
2720 * @ipp: the object permissions
2721 * @flag: access requested
2723 * Returns 0 if current has read and write access, error code otherwise
2725 static int smack_ipc_permission(struct kern_ipc_perm *ipp, short flag)
2727 char *isp = ipp->security;
2728 int may = smack_flags_to_may(flag);
2729 struct smk_audit_info ad;
2732 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2733 ad.a.u.ipc_id = ipp->id;
2735 return smk_curacc(isp, may, &ad);
2739 * smack_ipc_getsecid - Extract smack security id
2740 * @ipp: the object permissions
2741 * @secid: where result will be saved
2743 static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, u32 *secid)
2745 char *smack = ipp->security;
2747 *secid = smack_to_secid(smack);
2751 * smack_d_instantiate - Make sure the blob is correct on an inode
2752 * @opt_dentry: dentry where inode will be attached
2753 * @inode: the object
2755 * Set the inode's security blob if it hasn't been done already.
2757 static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
2759 struct super_block *sbp;
2760 struct superblock_smack *sbsp;
2761 struct inode_smack *isp;
2762 struct smack_known *skp;
2763 struct smack_known *ckp = smk_of_current();
2765 char trattr[TRANS_TRUE_SIZE];
2773 isp = inode->i_security;
2775 mutex_lock(&isp->smk_lock);
2777 * If the inode is already instantiated
2778 * take the quick way out
2780 if (isp->smk_flags & SMK_INODE_INSTANT)
2784 sbsp = sbp->s_security;
2786 * We're going to use the superblock default label
2787 * if there's no label on the file.
2789 final = sbsp->smk_default;
2792 * If this is the root inode the superblock
2793 * may be in the process of initialization.
2794 * If that is the case use the root value out
2795 * of the superblock.
2797 if (opt_dentry->d_parent == opt_dentry) {
2798 if (sbp->s_magic == CGROUP_SUPER_MAGIC) {
2800 * The cgroup filesystem is never mounted,
2801 * so there's no opportunity to set the mount
2804 sbsp->smk_root = smack_known_star.smk_known;
2805 sbsp->smk_default = smack_known_star.smk_known;
2807 isp->smk_inode = sbsp->smk_root;
2808 isp->smk_flags |= SMK_INODE_INSTANT;
2813 * This is pretty hackish.
2814 * Casey says that we shouldn't have to do
2815 * file system specific code, but it does help
2816 * with keeping it simple.
2818 switch (sbp->s_magic) {
2822 case CGROUP_SUPER_MAGIC:
2824 * Casey says that it's a little embarrassing
2825 * that the smack file system doesn't do
2826 * extended attributes.
2828 * Casey says pipes are easy (?)
2830 * Socket access is controlled by the socket
2831 * structures associated with the task involved.
2833 * Cgroupfs is special
2835 final = smack_known_star.smk_known;
2837 case DEVPTS_SUPER_MAGIC:
2839 * devpts seems content with the label of the task.
2840 * Programs that change smack have to treat the
2843 final = ckp->smk_known;
2845 case PROC_SUPER_MAGIC:
2847 * Casey says procfs appears not to care.
2848 * The superblock default suffices.
2853 * Device labels should come from the filesystem,
2854 * but watch out, because they're volitile,
2855 * getting recreated on every reboot.
2857 final = smack_known_star.smk_known;
2861 * If a smack value has been set we want to use it,
2862 * but since tmpfs isn't giving us the opportunity
2863 * to set mount options simulate setting the
2864 * superblock default.
2868 * This isn't an understood special case.
2869 * Get the value from the xattr.
2873 * UNIX domain sockets use lower level socket data.
2875 if (S_ISSOCK(inode->i_mode)) {
2876 final = smack_known_star.smk_known;
2880 * No xattr support means, alas, no SMACK label.
2881 * Use the aforeapplied default.
2882 * It would be curious if the label of the task
2883 * does not match that assigned.
2885 if (inode->i_op->getxattr == NULL)
2888 * Get the dentry for xattr.
2890 dp = dget(opt_dentry);
2891 skp = smk_fetch(XATTR_NAME_SMACK, inode, dp);
2893 final = skp->smk_known;
2896 * Transmuting directory
2898 if (S_ISDIR(inode->i_mode)) {
2900 * If this is a new directory and the label was
2901 * transmuted when the inode was initialized
2902 * set the transmute attribute on the directory
2903 * and mark the inode.
2905 * If there is a transmute attribute on the
2906 * directory mark the inode.
2908 if (isp->smk_flags & SMK_INODE_CHANGED) {
2909 isp->smk_flags &= ~SMK_INODE_CHANGED;
2910 rc = inode->i_op->setxattr(dp,
2911 XATTR_NAME_SMACKTRANSMUTE,
2912 TRANS_TRUE, TRANS_TRUE_SIZE,
2915 rc = inode->i_op->getxattr(dp,
2916 XATTR_NAME_SMACKTRANSMUTE, trattr,
2918 if (rc >= 0 && strncmp(trattr, TRANS_TRUE,
2919 TRANS_TRUE_SIZE) != 0)
2923 transflag = SMK_INODE_TRANSMUTE;
2926 * Don't let the exec or mmap label be "*" or "@".
2928 skp = smk_fetch(XATTR_NAME_SMACKEXEC, inode, dp);
2929 if (skp == &smack_known_star || skp == &smack_known_web)
2931 isp->smk_task = skp;
2932 skp = smk_fetch(XATTR_NAME_SMACKMMAP, inode, dp);
2933 if (skp == &smack_known_star || skp == &smack_known_web)
2935 isp->smk_mmap = skp;
2942 isp->smk_inode = ckp->smk_known;
2944 isp->smk_inode = final;
2946 isp->smk_flags |= (SMK_INODE_INSTANT | transflag);
2949 mutex_unlock(&isp->smk_lock);
2954 * smack_getprocattr - Smack process attribute access
2955 * @p: the object task
2956 * @name: the name of the attribute in /proc/.../attr
2957 * @value: where to put the result
2959 * Places a copy of the task Smack into value
2961 * Returns the length of the smack label or an error code
2963 static int smack_getprocattr(struct task_struct *p, char *name, char **value)
2965 struct smack_known *skp = smk_of_task(task_security(p));
2969 if (strcmp(name, "current") != 0)
2972 cp = kstrdup(skp->smk_known, GFP_KERNEL);
2982 * smack_setprocattr - Smack process attribute setting
2983 * @p: the object task
2984 * @name: the name of the attribute in /proc/.../attr
2985 * @value: the value to set
2986 * @size: the size of the value
2988 * Sets the Smack value of the task. Only setting self
2989 * is permitted and only with privilege
2991 * Returns the length of the smack label or an error code
2993 static int smack_setprocattr(struct task_struct *p, char *name,
2994 void *value, size_t size)
2996 struct task_smack *tsp;
2998 struct smack_known *skp;
3001 * Changing another process' Smack value is too dangerous
3002 * and supports no sane use case.
3007 if (!smack_privileged(CAP_MAC_ADMIN))
3010 if (value == NULL || size == 0 || size >= SMK_LONGLABEL)
3013 if (strcmp(name, "current") != 0)
3016 skp = smk_import_entry(value, size);
3021 * No process is ever allowed the web ("@") label.
3023 if (skp == &smack_known_web)
3026 new = prepare_creds();
3030 tsp = new->security;
3031 tsp->smk_task = skp;
3038 * smack_unix_stream_connect - Smack access on UDS
3040 * @other: the other sock
3043 * Return 0 if a subject with the smack of sock could access
3044 * an object with the smack of other, otherwise an error code
3046 static int smack_unix_stream_connect(struct sock *sock,
3047 struct sock *other, struct sock *newsk)
3049 struct smack_known *skp;
3050 struct socket_smack *ssp = sock->sk_security;
3051 struct socket_smack *osp = other->sk_security;
3052 struct socket_smack *nsp = newsk->sk_security;
3053 struct smk_audit_info ad;
3057 struct lsm_network_audit net;
3059 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
3060 smk_ad_setfield_u_net_sk(&ad, other);
3063 if (!smack_privileged(CAP_MAC_OVERRIDE)) {
3065 rc = smk_access(skp, osp->smk_in, MAY_WRITE, &ad);
3069 * Cross reference the peer labels for SO_PEERSEC.
3072 nsp->smk_packet = ssp->smk_out->smk_known;
3073 ssp->smk_packet = osp->smk_out->smk_known;
3080 * smack_unix_may_send - Smack access on UDS
3082 * @other: the other socket
3084 * Return 0 if a subject with the smack of sock could access
3085 * an object with the smack of other, otherwise an error code
3087 static int smack_unix_may_send(struct socket *sock, struct socket *other)
3089 struct socket_smack *ssp = sock->sk->sk_security;
3090 struct socket_smack *osp = other->sk->sk_security;
3091 struct smack_known *skp;
3092 struct smk_audit_info ad;
3095 struct lsm_network_audit net;
3097 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
3098 smk_ad_setfield_u_net_sk(&ad, other->sk);
3101 if (smack_privileged(CAP_MAC_OVERRIDE))
3105 return smk_access(skp, osp->smk_in, MAY_WRITE, &ad);
3109 * smack_socket_sendmsg - Smack check based on destination host
3112 * @size: the size of the message
3114 * Return 0 if the current subject can write to the destination host.
3115 * For IPv4 this is only a question if the destination is a single label host.
3116 * For IPv6 this is a check against the label of the port.
3118 static int smack_socket_sendmsg(struct socket *sock, struct msghdr *msg,
3121 struct sockaddr_in *sip = (struct sockaddr_in *) msg->msg_name;
3122 struct sockaddr_in6 *sap = (struct sockaddr_in6 *) msg->msg_name;
3126 * Perfectly reasonable for this to be NULL
3131 switch (sip->sin_family) {
3133 rc = smack_netlabel_send(sock->sk, sip);
3136 rc = smk_ipv6_port_check(sock->sk, sap, SMK_SENDING);
3143 * smack_from_secattr - Convert a netlabel attr.mls.lvl/attr.mls.cat pair to smack
3144 * @sap: netlabel secattr
3145 * @ssp: socket security information
3147 * Returns a pointer to a Smack label entry found on the label list.
3149 static struct smack_known *smack_from_secattr(struct netlbl_lsm_secattr *sap,
3150 struct socket_smack *ssp)
3152 struct smack_known *skp;
3157 if ((sap->flags & NETLBL_SECATTR_MLS_LVL) != 0) {
3159 * Looks like a CIPSO packet.
3160 * If there are flags but no level netlabel isn't
3161 * behaving the way we expect it to.
3163 * Look it up in the label table
3164 * Without guidance regarding the smack value
3165 * for the packet fall back on the network
3169 list_for_each_entry(skp, &smack_known_list, list) {
3170 if (sap->attr.mls.lvl != skp->smk_netlabel.attr.mls.lvl)
3173 * Compare the catsets. Use the netlbl APIs.
3175 if ((sap->flags & NETLBL_SECATTR_MLS_CAT) == 0) {
3176 if ((skp->smk_netlabel.flags &
3177 NETLBL_SECATTR_MLS_CAT) == 0)
3181 for (acat = -1, kcat = -1; acat == kcat; ) {
3182 acat = netlbl_secattr_catmap_walk(
3183 sap->attr.mls.cat, acat + 1);
3184 kcat = netlbl_secattr_catmap_walk(
3185 skp->smk_netlabel.attr.mls.cat,
3187 if (acat < 0 || kcat < 0)
3200 if (ssp != NULL && ssp->smk_in == smack_known_star.smk_known)
3201 return &smack_known_web;
3202 return &smack_known_star;
3204 if ((sap->flags & NETLBL_SECATTR_SECID) != 0) {
3206 * Looks like a fallback, which gives us a secid.
3208 skp = smack_from_secid(sap->attr.secid);
3210 * This has got to be a bug because it is
3211 * impossible to specify a fallback without
3212 * specifying the label, which will ensure
3213 * it has a secid, and the only way to get a
3214 * secid is from a fallback.
3216 BUG_ON(skp == NULL);
3220 * Without guidance regarding the smack value
3221 * for the packet fall back on the network
3224 return smack_net_ambient;
3227 static int smk_skb_to_addr_ipv6(struct sk_buff *skb, struct sockaddr_in6 *sip)
3231 int proto = -EINVAL;
3232 struct ipv6hdr _ipv6h;
3233 struct ipv6hdr *ip6;
3235 struct tcphdr _tcph, *th;
3236 struct udphdr _udph, *uh;
3237 struct dccp_hdr _dccph, *dh;
3241 offset = skb_network_offset(skb);
3242 ip6 = skb_header_pointer(skb, offset, sizeof(_ipv6h), &_ipv6h);
3245 sip->sin6_addr = ip6->saddr;
3247 nexthdr = ip6->nexthdr;
3248 offset += sizeof(_ipv6h);
3249 offset = ipv6_skip_exthdr(skb, offset, &nexthdr, &frag_off);
3256 th = skb_header_pointer(skb, offset, sizeof(_tcph), &_tcph);
3258 sip->sin6_port = th->source;
3261 uh = skb_header_pointer(skb, offset, sizeof(_udph), &_udph);
3263 sip->sin6_port = uh->source;
3266 dh = skb_header_pointer(skb, offset, sizeof(_dccph), &_dccph);
3268 sip->sin6_port = dh->dccph_sport;
3275 * smack_socket_sock_rcv_skb - Smack packet delivery access check
3279 * Returns 0 if the packet should be delivered, an error code otherwise
3281 static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
3283 struct netlbl_lsm_secattr secattr;
3284 struct socket_smack *ssp = sk->sk_security;
3285 struct smack_known *skp;
3286 struct sockaddr_in6 sadd;
3288 struct smk_audit_info ad;
3290 struct lsm_network_audit net;
3292 switch (sk->sk_family) {
3295 * Translate what netlabel gave us.
3297 netlbl_secattr_init(&secattr);
3299 rc = netlbl_skbuff_getattr(skb, sk->sk_family, &secattr);
3301 skp = smack_from_secattr(&secattr, ssp);
3303 skp = smack_net_ambient;
3305 netlbl_secattr_destroy(&secattr);
3308 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
3309 ad.a.u.net->family = sk->sk_family;
3310 ad.a.u.net->netif = skb->skb_iif;
3311 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
3314 * Receiving a packet requires that the other end
3315 * be able to write here. Read access is not required.
3316 * This is the simplist possible security model
3319 rc = smk_access(skp, ssp->smk_in, MAY_WRITE, &ad);
3321 netlbl_skbuff_err(skb, rc, 0);
3324 rc = smk_skb_to_addr_ipv6(skb, &sadd);
3325 if (rc == IPPROTO_UDP || rc == IPPROTO_TCP)
3326 rc = smk_ipv6_port_check(sk, &sadd, SMK_RECEIVING);
3335 * smack_socket_getpeersec_stream - pull in packet label
3337 * @optval: user's destination
3338 * @optlen: size thereof
3341 * returns zero on success, an error code otherwise
3343 static int smack_socket_getpeersec_stream(struct socket *sock,
3344 char __user *optval,
3345 int __user *optlen, unsigned len)
3347 struct socket_smack *ssp;
3352 ssp = sock->sk->sk_security;
3353 if (ssp->smk_packet != NULL) {
3354 rcp = ssp->smk_packet;
3355 slen = strlen(rcp) + 1;
3360 else if (copy_to_user(optval, rcp, slen) != 0)
3363 if (put_user(slen, optlen) != 0)
3371 * smack_socket_getpeersec_dgram - pull in packet label
3372 * @sock: the peer socket
3374 * @secid: pointer to where to put the secid of the packet
3376 * Sets the netlabel socket state on sk from parent
3378 static int smack_socket_getpeersec_dgram(struct socket *sock,
3379 struct sk_buff *skb, u32 *secid)
3382 struct netlbl_lsm_secattr secattr;
3383 struct socket_smack *ssp = NULL;
3384 struct smack_known *skp;
3385 int family = PF_UNSPEC;
3386 u32 s = 0; /* 0 is the invalid secid */
3390 if (skb->protocol == htons(ETH_P_IP))
3392 else if (skb->protocol == htons(ETH_P_IPV6))
3395 if (family == PF_UNSPEC && sock != NULL)
3396 family = sock->sk->sk_family;
3398 if (family == PF_UNIX) {
3399 ssp = sock->sk->sk_security;
3400 s = ssp->smk_out->smk_secid;
3401 } else if (family == PF_INET || family == PF_INET6) {
3403 * Translate what netlabel gave us.
3405 if (sock != NULL && sock->sk != NULL)
3406 ssp = sock->sk->sk_security;
3407 netlbl_secattr_init(&secattr);
3408 rc = netlbl_skbuff_getattr(skb, family, &secattr);
3410 skp = smack_from_secattr(&secattr, ssp);
3413 netlbl_secattr_destroy(&secattr);
3422 * smack_sock_graft - Initialize a newly created socket with an existing sock
3424 * @parent: parent socket
3426 * Set the smk_{in,out} state of an existing sock based on the process that
3427 * is creating the new socket.
3429 static void smack_sock_graft(struct sock *sk, struct socket *parent)
3431 struct socket_smack *ssp;
3432 struct smack_known *skp = smk_of_current();
3435 (sk->sk_family != PF_INET && sk->sk_family != PF_INET6))
3438 ssp = sk->sk_security;
3439 ssp->smk_in = skp->smk_known;
3441 /* cssp->smk_packet is already set in smack_inet_csk_clone() */
3445 * smack_inet_conn_request - Smack access check on connect
3446 * @sk: socket involved
3450 * Returns 0 if a task with the packet label could write to
3451 * the socket, otherwise an error code
3453 static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
3454 struct request_sock *req)
3456 u16 family = sk->sk_family;
3457 struct smack_known *skp;
3458 struct socket_smack *ssp = sk->sk_security;
3459 struct netlbl_lsm_secattr secattr;
3460 struct sockaddr_in addr;
3464 struct smk_audit_info ad;
3466 struct lsm_network_audit net;
3469 if (family == PF_INET6) {
3471 * Handle mapped IPv4 packets arriving
3472 * via IPv6 sockets. Don't set up netlabel
3473 * processing on IPv6.
3475 if (skb->protocol == htons(ETH_P_IP))
3481 netlbl_secattr_init(&secattr);
3482 rc = netlbl_skbuff_getattr(skb, family, &secattr);
3484 skp = smack_from_secattr(&secattr, ssp);
3486 skp = &smack_known_huh;
3487 netlbl_secattr_destroy(&secattr);
3490 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
3491 ad.a.u.net->family = family;
3492 ad.a.u.net->netif = skb->skb_iif;
3493 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
3496 * Receiving a packet requires that the other end be able to write
3497 * here. Read access is not required.
3499 rc = smk_access(skp, ssp->smk_in, MAY_WRITE, &ad);
3504 * Save the peer's label in the request_sock so we can later setup
3505 * smk_packet in the child socket so that SO_PEERCRED can report it.
3507 req->peer_secid = skp->smk_secid;
3510 * We need to decide if we want to label the incoming connection here
3511 * if we do we only need to label the request_sock and the stack will
3512 * propagate the wire-label to the sock when it is created.
3515 addr.sin_addr.s_addr = hdr->saddr;
3517 hsp = smack_host_label(&addr);
3521 rc = netlbl_req_setattr(req, &skp->smk_netlabel);
3523 netlbl_req_delattr(req);
3529 * smack_inet_csk_clone - Copy the connection information to the new socket
3530 * @sk: the new socket
3531 * @req: the connection's request_sock
3533 * Transfer the connection's peer label to the newly created socket.
3535 static void smack_inet_csk_clone(struct sock *sk,
3536 const struct request_sock *req)
3538 struct socket_smack *ssp = sk->sk_security;
3539 struct smack_known *skp;
3541 if (req->peer_secid != 0) {
3542 skp = smack_from_secid(req->peer_secid);
3543 ssp->smk_packet = skp->smk_known;
3545 ssp->smk_packet = NULL;
3549 * Key management security hooks
3551 * Casey has not tested key support very heavily.
3552 * The permission check is most likely too restrictive.
3553 * If you care about keys please have a look.
3558 * smack_key_alloc - Set the key security blob
3560 * @cred: the credentials to use
3563 * No allocation required
3567 static int smack_key_alloc(struct key *key, const struct cred *cred,
3568 unsigned long flags)
3570 struct smack_known *skp = smk_of_task(cred->security);
3572 key->security = skp->smk_known;
3577 * smack_key_free - Clear the key security blob
3580 * Clear the blob pointer
3582 static void smack_key_free(struct key *key)
3584 key->security = NULL;
3588 * smack_key_permission - Smack access on a key
3589 * @key_ref: gets to the object
3590 * @cred: the credentials to use
3593 * Return 0 if the task has read and write to the object,
3594 * an error code otherwise
3596 static int smack_key_permission(key_ref_t key_ref,
3597 const struct cred *cred, unsigned perm)
3600 struct smk_audit_info ad;
3601 struct smack_known *tkp = smk_of_task(cred->security);
3604 keyp = key_ref_to_ptr(key_ref);
3608 * If the key hasn't been initialized give it access so that
3611 if (keyp->security == NULL)
3614 * This should not occur
3619 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_KEY);
3620 ad.a.u.key_struct.key = keyp->serial;
3621 ad.a.u.key_struct.key_desc = keyp->description;
3623 if (perm & KEY_NEED_READ)
3625 if (perm & (KEY_NEED_WRITE | KEY_NEED_LINK | KEY_NEED_SETATTR))
3626 request = MAY_WRITE;
3627 return smk_access(tkp, keyp->security, request, &ad);
3629 #endif /* CONFIG_KEYS */
3634 * Audit requires a unique representation of each Smack specific
3635 * rule. This unique representation is used to distinguish the
3636 * object to be audited from remaining kernel objects and also
3637 * works as a glue between the audit hooks.
3639 * Since repository entries are added but never deleted, we'll use
3640 * the smack_known label address related to the given audit rule as
3641 * the needed unique representation. This also better fits the smack
3642 * model where nearly everything is a label.
3647 * smack_audit_rule_init - Initialize a smack audit rule
3648 * @field: audit rule fields given from user-space (audit.h)
3649 * @op: required testing operator (=, !=, >, <, ...)
3650 * @rulestr: smack label to be audited
3651 * @vrule: pointer to save our own audit rule representation
3653 * Prepare to audit cases where (@field @op @rulestr) is true.
3654 * The label to be audited is created if necessay.
3656 static int smack_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
3658 char **rule = (char **)vrule;
3661 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
3664 if (op != Audit_equal && op != Audit_not_equal)
3667 *rule = smk_import(rulestr, 0);
3673 * smack_audit_rule_known - Distinguish Smack audit rules
3674 * @krule: rule of interest, in Audit kernel representation format
3676 * This is used to filter Smack rules from remaining Audit ones.
3677 * If it's proved that this rule belongs to us, the
3678 * audit_rule_match hook will be called to do the final judgement.
3680 static int smack_audit_rule_known(struct audit_krule *krule)
3682 struct audit_field *f;
3685 for (i = 0; i < krule->field_count; i++) {
3686 f = &krule->fields[i];
3688 if (f->type == AUDIT_SUBJ_USER || f->type == AUDIT_OBJ_USER)
3696 * smack_audit_rule_match - Audit given object ?
3697 * @secid: security id for identifying the object to test
3698 * @field: audit rule flags given from user-space
3699 * @op: required testing operator
3700 * @vrule: smack internal rule presentation
3701 * @actx: audit context associated with the check
3703 * The core Audit hook. It's used to take the decision of
3704 * whether to audit or not to audit a given object.
3706 static int smack_audit_rule_match(u32 secid, u32 field, u32 op, void *vrule,
3707 struct audit_context *actx)
3709 struct smack_known *skp;
3712 if (unlikely(!rule)) {
3713 WARN_ONCE(1, "Smack: missing rule\n");
3717 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
3720 skp = smack_from_secid(secid);
3723 * No need to do string comparisons. If a match occurs,
3724 * both pointers will point to the same smack_known
3727 if (op == Audit_equal)
3728 return (rule == skp->smk_known);
3729 if (op == Audit_not_equal)
3730 return (rule != skp->smk_known);
3736 * smack_audit_rule_free - free smack rule representation
3737 * @vrule: rule to be freed.
3739 * No memory was allocated.
3741 static void smack_audit_rule_free(void *vrule)
3746 #endif /* CONFIG_AUDIT */
3749 * smack_ismaclabel - check if xattr @name references a smack MAC label
3750 * @name: Full xattr name to check.
3752 static int smack_ismaclabel(const char *name)
3754 return (strcmp(name, XATTR_SMACK_SUFFIX) == 0);
3759 * smack_secid_to_secctx - return the smack label for a secid
3760 * @secid: incoming integer
3761 * @secdata: destination
3762 * @seclen: how long it is
3764 * Exists for networking code.
3766 static int smack_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
3768 struct smack_known *skp = smack_from_secid(secid);
3771 *secdata = skp->smk_known;
3772 *seclen = strlen(skp->smk_known);
3777 * smack_secctx_to_secid - return the secid for a smack label
3778 * @secdata: smack label
3779 * @seclen: how long result is
3780 * @secid: outgoing integer
3782 * Exists for audit and networking code.
3784 static int smack_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
3786 *secid = smack_to_secid(secdata);
3791 * smack_release_secctx - don't do anything.
3795 * Exists to make sure nothing gets done, and properly
3797 static void smack_release_secctx(char *secdata, u32 seclen)
3801 static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
3803 return smack_inode_setsecurity(inode, XATTR_SMACK_SUFFIX, ctx, ctxlen, 0);
3806 static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
3808 return __vfs_setxattr_noperm(dentry, XATTR_NAME_SMACK, ctx, ctxlen, 0);
3811 static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
3814 len = smack_inode_getsecurity(inode, XATTR_SMACK_SUFFIX, ctx, true);
3822 struct security_operations smack_ops = {
3825 .ptrace_access_check = smack_ptrace_access_check,
3826 .ptrace_traceme = smack_ptrace_traceme,
3827 .syslog = smack_syslog,
3829 .sb_alloc_security = smack_sb_alloc_security,
3830 .sb_free_security = smack_sb_free_security,
3831 .sb_copy_data = smack_sb_copy_data,
3832 .sb_kern_mount = smack_sb_kern_mount,
3833 .sb_statfs = smack_sb_statfs,
3835 .bprm_set_creds = smack_bprm_set_creds,
3836 .bprm_committing_creds = smack_bprm_committing_creds,
3837 .bprm_secureexec = smack_bprm_secureexec,
3839 .inode_alloc_security = smack_inode_alloc_security,
3840 .inode_free_security = smack_inode_free_security,
3841 .inode_init_security = smack_inode_init_security,
3842 .inode_link = smack_inode_link,
3843 .inode_unlink = smack_inode_unlink,
3844 .inode_rmdir = smack_inode_rmdir,
3845 .inode_rename = smack_inode_rename,
3846 .inode_permission = smack_inode_permission,
3847 .inode_setattr = smack_inode_setattr,
3848 .inode_getattr = smack_inode_getattr,
3849 .inode_setxattr = smack_inode_setxattr,
3850 .inode_post_setxattr = smack_inode_post_setxattr,
3851 .inode_getxattr = smack_inode_getxattr,
3852 .inode_removexattr = smack_inode_removexattr,
3853 .inode_getsecurity = smack_inode_getsecurity,
3854 .inode_setsecurity = smack_inode_setsecurity,
3855 .inode_listsecurity = smack_inode_listsecurity,
3856 .inode_getsecid = smack_inode_getsecid,
3858 .file_permission = smack_file_permission,
3859 .file_alloc_security = smack_file_alloc_security,
3860 .file_free_security = smack_file_free_security,
3861 .file_ioctl = smack_file_ioctl,
3862 .file_lock = smack_file_lock,
3863 .file_fcntl = smack_file_fcntl,
3864 .mmap_file = smack_mmap_file,
3865 .mmap_addr = cap_mmap_addr,
3866 .file_set_fowner = smack_file_set_fowner,
3867 .file_send_sigiotask = smack_file_send_sigiotask,
3868 .file_receive = smack_file_receive,
3870 .file_open = smack_file_open,
3872 .cred_alloc_blank = smack_cred_alloc_blank,
3873 .cred_free = smack_cred_free,
3874 .cred_prepare = smack_cred_prepare,
3875 .cred_transfer = smack_cred_transfer,
3876 .kernel_act_as = smack_kernel_act_as,
3877 .kernel_create_files_as = smack_kernel_create_files_as,
3878 .task_setpgid = smack_task_setpgid,
3879 .task_getpgid = smack_task_getpgid,
3880 .task_getsid = smack_task_getsid,
3881 .task_getsecid = smack_task_getsecid,
3882 .task_setnice = smack_task_setnice,
3883 .task_setioprio = smack_task_setioprio,
3884 .task_getioprio = smack_task_getioprio,
3885 .task_setscheduler = smack_task_setscheduler,
3886 .task_getscheduler = smack_task_getscheduler,
3887 .task_movememory = smack_task_movememory,
3888 .task_kill = smack_task_kill,
3889 .task_wait = smack_task_wait,
3890 .task_to_inode = smack_task_to_inode,
3892 .ipc_permission = smack_ipc_permission,
3893 .ipc_getsecid = smack_ipc_getsecid,
3895 .msg_msg_alloc_security = smack_msg_msg_alloc_security,
3896 .msg_msg_free_security = smack_msg_msg_free_security,
3898 .msg_queue_alloc_security = smack_msg_queue_alloc_security,
3899 .msg_queue_free_security = smack_msg_queue_free_security,
3900 .msg_queue_associate = smack_msg_queue_associate,
3901 .msg_queue_msgctl = smack_msg_queue_msgctl,
3902 .msg_queue_msgsnd = smack_msg_queue_msgsnd,
3903 .msg_queue_msgrcv = smack_msg_queue_msgrcv,
3905 .shm_alloc_security = smack_shm_alloc_security,
3906 .shm_free_security = smack_shm_free_security,
3907 .shm_associate = smack_shm_associate,
3908 .shm_shmctl = smack_shm_shmctl,
3909 .shm_shmat = smack_shm_shmat,
3911 .sem_alloc_security = smack_sem_alloc_security,
3912 .sem_free_security = smack_sem_free_security,
3913 .sem_associate = smack_sem_associate,
3914 .sem_semctl = smack_sem_semctl,
3915 .sem_semop = smack_sem_semop,
3917 .d_instantiate = smack_d_instantiate,
3919 .getprocattr = smack_getprocattr,
3920 .setprocattr = smack_setprocattr,
3922 .unix_stream_connect = smack_unix_stream_connect,
3923 .unix_may_send = smack_unix_may_send,
3925 .socket_post_create = smack_socket_post_create,
3926 .socket_bind = smack_socket_bind,
3927 .socket_connect = smack_socket_connect,
3928 .socket_sendmsg = smack_socket_sendmsg,
3929 .socket_sock_rcv_skb = smack_socket_sock_rcv_skb,
3930 .socket_getpeersec_stream = smack_socket_getpeersec_stream,
3931 .socket_getpeersec_dgram = smack_socket_getpeersec_dgram,
3932 .sk_alloc_security = smack_sk_alloc_security,
3933 .sk_free_security = smack_sk_free_security,
3934 .sock_graft = smack_sock_graft,
3935 .inet_conn_request = smack_inet_conn_request,
3936 .inet_csk_clone = smack_inet_csk_clone,
3938 /* key management security hooks */
3940 .key_alloc = smack_key_alloc,
3941 .key_free = smack_key_free,
3942 .key_permission = smack_key_permission,
3943 #endif /* CONFIG_KEYS */
3947 .audit_rule_init = smack_audit_rule_init,
3948 .audit_rule_known = smack_audit_rule_known,
3949 .audit_rule_match = smack_audit_rule_match,
3950 .audit_rule_free = smack_audit_rule_free,
3951 #endif /* CONFIG_AUDIT */
3953 .ismaclabel = smack_ismaclabel,
3954 .secid_to_secctx = smack_secid_to_secctx,
3955 .secctx_to_secid = smack_secctx_to_secid,
3956 .release_secctx = smack_release_secctx,
3957 .inode_notifysecctx = smack_inode_notifysecctx,
3958 .inode_setsecctx = smack_inode_setsecctx,
3959 .inode_getsecctx = smack_inode_getsecctx,
3963 static __init void init_smack_known_list(void)
3966 * Initialize rule list locks
3968 mutex_init(&smack_known_huh.smk_rules_lock);
3969 mutex_init(&smack_known_hat.smk_rules_lock);
3970 mutex_init(&smack_known_floor.smk_rules_lock);
3971 mutex_init(&smack_known_star.smk_rules_lock);
3972 mutex_init(&smack_known_invalid.smk_rules_lock);
3973 mutex_init(&smack_known_web.smk_rules_lock);
3975 * Initialize rule lists
3977 INIT_LIST_HEAD(&smack_known_huh.smk_rules);
3978 INIT_LIST_HEAD(&smack_known_hat.smk_rules);
3979 INIT_LIST_HEAD(&smack_known_star.smk_rules);
3980 INIT_LIST_HEAD(&smack_known_floor.smk_rules);
3981 INIT_LIST_HEAD(&smack_known_invalid.smk_rules);
3982 INIT_LIST_HEAD(&smack_known_web.smk_rules);
3984 * Create the known labels list
3986 smk_insert_entry(&smack_known_huh);
3987 smk_insert_entry(&smack_known_hat);
3988 smk_insert_entry(&smack_known_star);
3989 smk_insert_entry(&smack_known_floor);
3990 smk_insert_entry(&smack_known_invalid);
3991 smk_insert_entry(&smack_known_web);
3995 * smack_init - initialize the smack system
3999 static __init int smack_init(void)
4002 struct task_smack *tsp;
4004 if (!security_module_enable(&smack_ops))
4007 tsp = new_task_smack(&smack_known_floor, &smack_known_floor,
4012 printk(KERN_INFO "Smack: Initializing.\n");
4015 * Set the security state for the initial task.
4017 cred = (struct cred *) current->cred;
4018 cred->security = tsp;
4020 /* initialize the smack_known_list */
4021 init_smack_known_list();
4026 if (register_security(&smack_ops))
4027 panic("smack: Unable to register with kernel.\n");
4033 * Smack requires early initialization in order to label
4034 * all processes and objects when they are created.
4036 security_initcall(smack_init);