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);
1032 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_DENTRY);
1033 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
1035 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
1039 isp = dentry->d_inode->i_security;
1041 * Don't do anything special for these.
1042 * XATTR_NAME_SMACKIPIN
1043 * XATTR_NAME_SMACKIPOUT
1044 * XATTR_NAME_SMACKEXEC
1046 if (strcmp(name, XATTR_NAME_SMACK) == 0)
1047 isp->smk_task = NULL;
1048 else if (strcmp(name, XATTR_NAME_SMACKMMAP) == 0)
1049 isp->smk_mmap = NULL;
1050 else if (strcmp(name, XATTR_NAME_SMACKTRANSMUTE) == 0)
1051 isp->smk_flags &= ~SMK_INODE_TRANSMUTE;
1057 * smack_inode_getsecurity - get smack xattrs
1058 * @inode: the object
1059 * @name: attribute name
1060 * @buffer: where to put the result
1063 * Returns the size of the attribute or an error code
1065 static int smack_inode_getsecurity(const struct inode *inode,
1066 const char *name, void **buffer,
1069 struct socket_smack *ssp;
1070 struct socket *sock;
1071 struct super_block *sbp;
1072 struct inode *ip = (struct inode *)inode;
1077 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
1078 isp = smk_of_inode(inode);
1079 ilen = strlen(isp) + 1;
1085 * The rest of the Smack xattrs are only on sockets.
1088 if (sbp->s_magic != SOCKFS_MAGIC)
1091 sock = SOCKET_I(ip);
1092 if (sock == NULL || sock->sk == NULL)
1095 ssp = sock->sk->sk_security;
1097 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
1098 isp = ssp->smk_in->smk_known;
1099 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0)
1100 isp = ssp->smk_out->smk_known;
1104 ilen = strlen(isp) + 1;
1115 * smack_inode_listsecurity - list the Smack attributes
1116 * @inode: the object
1117 * @buffer: where they go
1118 * @buffer_size: size of buffer
1120 * Returns 0 on success, -EINVAL otherwise
1122 static int smack_inode_listsecurity(struct inode *inode, char *buffer,
1125 int len = strlen(XATTR_NAME_SMACK);
1127 if (buffer != NULL && len <= buffer_size) {
1128 memcpy(buffer, XATTR_NAME_SMACK, len);
1135 * smack_inode_getsecid - Extract inode's security id
1136 * @inode: inode to extract the info from
1137 * @secid: where result will be saved
1139 static void smack_inode_getsecid(const struct inode *inode, u32 *secid)
1141 struct inode_smack *isp = inode->i_security;
1143 *secid = smack_to_secid(isp->smk_inode);
1151 * smack_file_permission - Smack check on file operations
1157 * Should access checks be done on each read or write?
1158 * UNICOS and SELinux say yes.
1159 * Trusted Solaris, Trusted Irix, and just about everyone else says no.
1161 * I'll say no for now. Smack does not do the frequent
1162 * label changing that SELinux does.
1164 static int smack_file_permission(struct file *file, int mask)
1170 * smack_file_alloc_security - assign a file security blob
1173 * The security blob for a file is a pointer to the master
1174 * label list, so no allocation is done.
1178 static int smack_file_alloc_security(struct file *file)
1180 struct smack_known *skp = smk_of_current();
1182 file->f_security = skp->smk_known;
1187 * smack_file_free_security - clear a file security blob
1190 * The security blob for a file is a pointer to the master
1191 * label list, so no memory is freed.
1193 static void smack_file_free_security(struct file *file)
1195 file->f_security = NULL;
1199 * smack_file_ioctl - Smack check on ioctls
1204 * Relies heavily on the correct use of the ioctl command conventions.
1206 * Returns 0 if allowed, error code otherwise
1208 static int smack_file_ioctl(struct file *file, unsigned int cmd,
1212 struct smk_audit_info ad;
1214 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_PATH);
1215 smk_ad_setfield_u_fs_path(&ad, file->f_path);
1217 if (_IOC_DIR(cmd) & _IOC_WRITE)
1218 rc = smk_curacc(file->f_security, MAY_WRITE, &ad);
1220 if (rc == 0 && (_IOC_DIR(cmd) & _IOC_READ))
1221 rc = smk_curacc(file->f_security, MAY_READ, &ad);
1227 * smack_file_lock - Smack check on file locking
1231 * Returns 0 if current has lock access, error code otherwise
1233 static int smack_file_lock(struct file *file, unsigned int cmd)
1235 struct smk_audit_info ad;
1237 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_PATH);
1238 smk_ad_setfield_u_fs_path(&ad, file->f_path);
1239 return smk_curacc(file->f_security, MAY_LOCK, &ad);
1243 * smack_file_fcntl - Smack check on fcntl
1245 * @cmd: what action to check
1248 * Generally these operations are harmless.
1249 * File locking operations present an obvious mechanism
1250 * for passing information, so they require write access.
1252 * Returns 0 if current has access, error code otherwise
1254 static int smack_file_fcntl(struct file *file, unsigned int cmd,
1257 struct smk_audit_info ad;
1266 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_PATH);
1267 smk_ad_setfield_u_fs_path(&ad, file->f_path);
1268 rc = smk_curacc(file->f_security, MAY_LOCK, &ad);
1272 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_PATH);
1273 smk_ad_setfield_u_fs_path(&ad, file->f_path);
1274 rc = smk_curacc(file->f_security, MAY_WRITE, &ad);
1285 * Check permissions for a mmap operation. The @file may be NULL, e.g.
1286 * if mapping anonymous memory.
1287 * @file contains the file structure for file to map (may be NULL).
1288 * @reqprot contains the protection requested by the application.
1289 * @prot contains the protection that will be applied by the kernel.
1290 * @flags contains the operational flags.
1291 * Return 0 if permission is granted.
1293 static int smack_mmap_file(struct file *file,
1294 unsigned long reqprot, unsigned long prot,
1295 unsigned long flags)
1297 struct smack_known *skp;
1298 struct smack_known *mkp;
1299 struct smack_rule *srp;
1300 struct task_smack *tsp;
1302 struct inode_smack *isp;
1311 isp = file_inode(file)->i_security;
1312 if (isp->smk_mmap == NULL)
1314 mkp = isp->smk_mmap;
1316 tsp = current_security();
1317 skp = smk_of_current();
1322 * For each Smack rule associated with the subject
1323 * label verify that the SMACK64MMAP also has access
1324 * to that rule's object label.
1326 list_for_each_entry_rcu(srp, &skp->smk_rules, list) {
1327 osmack = srp->smk_object;
1329 * Matching labels always allows access.
1331 if (mkp->smk_known == osmack)
1334 * If there is a matching local rule take
1335 * that into account as well.
1337 may = smk_access_entry(srp->smk_subject->smk_known, osmack,
1340 may = srp->smk_access;
1342 may &= srp->smk_access;
1344 * If may is zero the SMACK64MMAP subject can't
1345 * possibly have less access.
1351 * Fetch the global list entry.
1352 * If there isn't one a SMACK64MMAP subject
1353 * can't have as much access as current.
1355 mmay = smk_access_entry(mkp->smk_known, osmack,
1357 if (mmay == -ENOENT) {
1362 * If there is a local entry it modifies the
1363 * potential access, too.
1365 tmay = smk_access_entry(mkp->smk_known, osmack,
1367 if (tmay != -ENOENT)
1371 * If there is any access available to current that is
1372 * not available to a SMACK64MMAP subject
1375 if ((may | mmay) != mmay) {
1387 * smack_file_set_fowner - set the file security blob value
1388 * @file: object in question
1391 * Further research may be required on this one.
1393 static int smack_file_set_fowner(struct file *file)
1395 struct smack_known *skp = smk_of_current();
1397 file->f_security = skp->smk_known;
1402 * smack_file_send_sigiotask - Smack on sigio
1403 * @tsk: The target task
1404 * @fown: the object the signal come from
1407 * Allow a privileged task to get signals even if it shouldn't
1409 * Returns 0 if a subject with the object's smack could
1410 * write to the task, an error code otherwise.
1412 static int smack_file_send_sigiotask(struct task_struct *tsk,
1413 struct fown_struct *fown, int signum)
1415 struct smack_known *skp;
1416 struct smack_known *tkp = smk_of_task(tsk->cred->security);
1419 struct smk_audit_info ad;
1422 * struct fown_struct is never outside the context of a struct file
1424 file = container_of(fown, struct file, f_owner);
1426 /* we don't log here as rc can be overriden */
1427 skp = smk_find_entry(file->f_security);
1428 rc = smk_access(skp, tkp->smk_known, MAY_WRITE, NULL);
1429 if (rc != 0 && has_capability(tsk, CAP_MAC_OVERRIDE))
1432 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1433 smk_ad_setfield_u_tsk(&ad, tsk);
1434 smack_log(file->f_security, tkp->smk_known, MAY_WRITE, rc, &ad);
1439 * smack_file_receive - Smack file receive check
1442 * Returns 0 if current has access, error code otherwise
1444 static int smack_file_receive(struct file *file)
1447 struct smk_audit_info ad;
1449 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_PATH);
1450 smk_ad_setfield_u_fs_path(&ad, file->f_path);
1452 * This code relies on bitmasks.
1454 if (file->f_mode & FMODE_READ)
1456 if (file->f_mode & FMODE_WRITE)
1459 return smk_curacc(file->f_security, may, &ad);
1463 * smack_file_open - Smack dentry open processing
1467 * Set the security blob in the file structure.
1471 static int smack_file_open(struct file *file, const struct cred *cred)
1473 struct inode_smack *isp = file_inode(file)->i_security;
1475 file->f_security = isp->smk_inode;
1485 * smack_cred_alloc_blank - "allocate" blank task-level security credentials
1486 * @new: the new credentials
1487 * @gfp: the atomicity of any memory allocations
1489 * Prepare a blank set of credentials for modification. This must allocate all
1490 * the memory the LSM module might require such that cred_transfer() can
1491 * complete without error.
1493 static int smack_cred_alloc_blank(struct cred *cred, gfp_t gfp)
1495 struct task_smack *tsp;
1497 tsp = new_task_smack(NULL, NULL, gfp);
1501 cred->security = tsp;
1508 * smack_cred_free - "free" task-level security credentials
1509 * @cred: the credentials in question
1512 static void smack_cred_free(struct cred *cred)
1514 struct task_smack *tsp = cred->security;
1515 struct smack_rule *rp;
1516 struct list_head *l;
1517 struct list_head *n;
1521 cred->security = NULL;
1523 list_for_each_safe(l, n, &tsp->smk_rules) {
1524 rp = list_entry(l, struct smack_rule, list);
1525 list_del(&rp->list);
1532 * smack_cred_prepare - prepare new set of credentials for modification
1533 * @new: the new credentials
1534 * @old: the original credentials
1535 * @gfp: the atomicity of any memory allocations
1537 * Prepare a new set of credentials for modification.
1539 static int smack_cred_prepare(struct cred *new, const struct cred *old,
1542 struct task_smack *old_tsp = old->security;
1543 struct task_smack *new_tsp;
1546 new_tsp = new_task_smack(old_tsp->smk_task, old_tsp->smk_task, gfp);
1547 if (new_tsp == NULL)
1550 rc = smk_copy_rules(&new_tsp->smk_rules, &old_tsp->smk_rules, gfp);
1554 new->security = new_tsp;
1559 * smack_cred_transfer - Transfer the old credentials to the new credentials
1560 * @new: the new credentials
1561 * @old: the original credentials
1563 * Fill in a set of blank credentials from another set of credentials.
1565 static void smack_cred_transfer(struct cred *new, const struct cred *old)
1567 struct task_smack *old_tsp = old->security;
1568 struct task_smack *new_tsp = new->security;
1570 new_tsp->smk_task = old_tsp->smk_task;
1571 new_tsp->smk_forked = old_tsp->smk_task;
1572 mutex_init(&new_tsp->smk_rules_lock);
1573 INIT_LIST_HEAD(&new_tsp->smk_rules);
1576 /* cbs copy rule list */
1580 * smack_kernel_act_as - Set the subjective context in a set of credentials
1581 * @new: points to the set of credentials to be modified.
1582 * @secid: specifies the security ID to be set
1584 * Set the security data for a kernel service.
1586 static int smack_kernel_act_as(struct cred *new, u32 secid)
1588 struct task_smack *new_tsp = new->security;
1589 struct smack_known *skp = smack_from_secid(secid);
1594 new_tsp->smk_task = skp;
1599 * smack_kernel_create_files_as - Set the file creation label in a set of creds
1600 * @new: points to the set of credentials to be modified
1601 * @inode: points to the inode to use as a reference
1603 * Set the file creation context in a set of credentials to the same
1604 * as the objective context of the specified inode
1606 static int smack_kernel_create_files_as(struct cred *new,
1607 struct inode *inode)
1609 struct inode_smack *isp = inode->i_security;
1610 struct task_smack *tsp = new->security;
1612 tsp->smk_forked = smk_find_entry(isp->smk_inode);
1613 tsp->smk_task = tsp->smk_forked;
1618 * smk_curacc_on_task - helper to log task related access
1619 * @p: the task object
1620 * @access: the access requested
1621 * @caller: name of the calling function for audit
1623 * Return 0 if access is permitted
1625 static int smk_curacc_on_task(struct task_struct *p, int access,
1628 struct smk_audit_info ad;
1629 struct smack_known *skp = smk_of_task(task_security(p));
1631 smk_ad_init(&ad, caller, LSM_AUDIT_DATA_TASK);
1632 smk_ad_setfield_u_tsk(&ad, p);
1633 return smk_curacc(skp->smk_known, access, &ad);
1637 * smack_task_setpgid - Smack check on setting pgid
1638 * @p: the task object
1641 * Return 0 if write access is permitted
1643 static int smack_task_setpgid(struct task_struct *p, pid_t pgid)
1645 return smk_curacc_on_task(p, MAY_WRITE, __func__);
1649 * smack_task_getpgid - Smack access check for getpgid
1650 * @p: the object task
1652 * Returns 0 if current can read the object task, error code otherwise
1654 static int smack_task_getpgid(struct task_struct *p)
1656 return smk_curacc_on_task(p, MAY_READ, __func__);
1660 * smack_task_getsid - Smack access check for getsid
1661 * @p: the object task
1663 * Returns 0 if current can read the object task, error code otherwise
1665 static int smack_task_getsid(struct task_struct *p)
1667 return smk_curacc_on_task(p, MAY_READ, __func__);
1671 * smack_task_getsecid - get the secid of the task
1672 * @p: the object task
1673 * @secid: where to put the result
1675 * Sets the secid to contain a u32 version of the smack label.
1677 static void smack_task_getsecid(struct task_struct *p, u32 *secid)
1679 struct smack_known *skp = smk_of_task(task_security(p));
1681 *secid = skp->smk_secid;
1685 * smack_task_setnice - Smack check on setting nice
1686 * @p: the task object
1689 * Return 0 if write access is permitted
1691 static int smack_task_setnice(struct task_struct *p, int nice)
1695 rc = cap_task_setnice(p, nice);
1697 rc = smk_curacc_on_task(p, MAY_WRITE, __func__);
1702 * smack_task_setioprio - Smack check on setting ioprio
1703 * @p: the task object
1706 * Return 0 if write access is permitted
1708 static int smack_task_setioprio(struct task_struct *p, int ioprio)
1712 rc = cap_task_setioprio(p, ioprio);
1714 rc = smk_curacc_on_task(p, MAY_WRITE, __func__);
1719 * smack_task_getioprio - Smack check on reading ioprio
1720 * @p: the task object
1722 * Return 0 if read access is permitted
1724 static int smack_task_getioprio(struct task_struct *p)
1726 return smk_curacc_on_task(p, MAY_READ, __func__);
1730 * smack_task_setscheduler - Smack check on setting scheduler
1731 * @p: the task object
1735 * Return 0 if read access is permitted
1737 static int smack_task_setscheduler(struct task_struct *p)
1741 rc = cap_task_setscheduler(p);
1743 rc = smk_curacc_on_task(p, MAY_WRITE, __func__);
1748 * smack_task_getscheduler - Smack check on reading scheduler
1749 * @p: the task object
1751 * Return 0 if read access is permitted
1753 static int smack_task_getscheduler(struct task_struct *p)
1755 return smk_curacc_on_task(p, MAY_READ, __func__);
1759 * smack_task_movememory - Smack check on moving memory
1760 * @p: the task object
1762 * Return 0 if write access is permitted
1764 static int smack_task_movememory(struct task_struct *p)
1766 return smk_curacc_on_task(p, MAY_WRITE, __func__);
1770 * smack_task_kill - Smack check on signal delivery
1771 * @p: the task object
1774 * @secid: identifies the smack to use in lieu of current's
1776 * Return 0 if write access is permitted
1778 * The secid behavior is an artifact of an SELinux hack
1779 * in the USB code. Someday it may go away.
1781 static int smack_task_kill(struct task_struct *p, struct siginfo *info,
1784 struct smk_audit_info ad;
1785 struct smack_known *skp;
1786 struct smack_known *tkp = smk_of_task(task_security(p));
1788 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1789 smk_ad_setfield_u_tsk(&ad, p);
1791 * Sending a signal requires that the sender
1792 * can write the receiver.
1795 return smk_curacc(tkp->smk_known, MAY_WRITE, &ad);
1797 * If the secid isn't 0 we're dealing with some USB IO
1798 * specific behavior. This is not clean. For one thing
1799 * we can't take privilege into account.
1801 skp = smack_from_secid(secid);
1802 return smk_access(skp, tkp->smk_known, MAY_WRITE, &ad);
1806 * smack_task_wait - Smack access check for waiting
1807 * @p: task to wait for
1811 static int smack_task_wait(struct task_struct *p)
1814 * Allow the operation to succeed.
1816 * In userless environments (e.g. phones) programs
1817 * get marked with SMACK64EXEC and even if the parent
1818 * and child shouldn't be talking the parent still
1819 * may expect to know when the child exits.
1825 * smack_task_to_inode - copy task smack into the inode blob
1826 * @p: task to copy from
1827 * @inode: inode to copy to
1829 * Sets the smack pointer in the inode security blob
1831 static void smack_task_to_inode(struct task_struct *p, struct inode *inode)
1833 struct inode_smack *isp = inode->i_security;
1834 struct smack_known *skp = smk_of_task(task_security(p));
1836 isp->smk_inode = skp->smk_known;
1844 * smack_sk_alloc_security - Allocate a socket blob
1847 * @gfp_flags: memory allocation flags
1849 * Assign Smack pointers to current
1851 * Returns 0 on success, -ENOMEM is there's no memory
1853 static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags)
1855 struct smack_known *skp = smk_of_current();
1856 struct socket_smack *ssp;
1858 ssp = kzalloc(sizeof(struct socket_smack), gfp_flags);
1864 ssp->smk_packet = NULL;
1866 sk->sk_security = ssp;
1872 * smack_sk_free_security - Free a socket blob
1875 * Clears the blob pointer
1877 static void smack_sk_free_security(struct sock *sk)
1879 kfree(sk->sk_security);
1883 * smack_host_label - check host based restrictions
1884 * @sip: the object end
1886 * looks for host based access restrictions
1888 * This version will only be appropriate for really small sets of single label
1889 * hosts. The caller is responsible for ensuring that the RCU read lock is
1890 * taken before calling this function.
1892 * Returns the label of the far end or NULL if it's not special.
1894 static char *smack_host_label(struct sockaddr_in *sip)
1896 struct smk_netlbladdr *snp;
1897 struct in_addr *siap = &sip->sin_addr;
1899 if (siap->s_addr == 0)
1902 list_for_each_entry_rcu(snp, &smk_netlbladdr_list, list)
1904 * we break after finding the first match because
1905 * the list is sorted from longest to shortest mask
1906 * so we have found the most specific match
1908 if ((&snp->smk_host.sin_addr)->s_addr ==
1909 (siap->s_addr & (&snp->smk_mask)->s_addr)) {
1910 /* we have found the special CIPSO option */
1911 if (snp->smk_label == smack_cipso_option)
1913 return snp->smk_label;
1920 * smack_netlabel - Set the secattr on a socket
1922 * @labeled: socket label scheme
1924 * Convert the outbound smack value (smk_out) to a
1925 * secattr and attach it to the socket.
1927 * Returns 0 on success or an error code
1929 static int smack_netlabel(struct sock *sk, int labeled)
1931 struct smack_known *skp;
1932 struct socket_smack *ssp = sk->sk_security;
1936 * Usually the netlabel code will handle changing the
1937 * packet labeling based on the label.
1938 * The case of a single label host is different, because
1939 * a single label host should never get a labeled packet
1940 * even though the label is usually associated with a packet
1944 bh_lock_sock_nested(sk);
1946 if (ssp->smk_out == smack_net_ambient ||
1947 labeled == SMACK_UNLABELED_SOCKET)
1948 netlbl_sock_delattr(sk);
1951 rc = netlbl_sock_setattr(sk, sk->sk_family, &skp->smk_netlabel);
1961 * smack_netlbel_send - Set the secattr on a socket and perform access checks
1963 * @sap: the destination address
1965 * Set the correct secattr for the given socket based on the destination
1966 * address and perform any outbound access checks needed.
1968 * Returns 0 on success or an error code.
1971 static int smack_netlabel_send(struct sock *sk, struct sockaddr_in *sap)
1973 struct smack_known *skp;
1977 struct socket_smack *ssp = sk->sk_security;
1978 struct smk_audit_info ad;
1981 hostsp = smack_host_label(sap);
1982 if (hostsp != NULL) {
1984 struct lsm_network_audit net;
1986 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
1987 ad.a.u.net->family = sap->sin_family;
1988 ad.a.u.net->dport = sap->sin_port;
1989 ad.a.u.net->v4info.daddr = sap->sin_addr.s_addr;
1991 sk_lbl = SMACK_UNLABELED_SOCKET;
1993 rc = smk_access(skp, hostsp, MAY_WRITE, &ad);
1995 sk_lbl = SMACK_CIPSO_SOCKET;
2002 return smack_netlabel(sk, sk_lbl);
2006 * smk_ipv6_port_label - Smack port access table management
2010 * Create or update the port list entry
2012 static void smk_ipv6_port_label(struct socket *sock, struct sockaddr *address)
2014 struct sock *sk = sock->sk;
2015 struct sockaddr_in6 *addr6;
2016 struct socket_smack *ssp = sock->sk->sk_security;
2017 struct smk_port_label *spp;
2018 unsigned short port = 0;
2020 if (address == NULL) {
2022 * This operation is changing the Smack information
2023 * on the bound socket. Take the changes to the port
2026 list_for_each_entry(spp, &smk_ipv6_port_list, list) {
2027 if (sk != spp->smk_sock)
2029 spp->smk_in = ssp->smk_in;
2030 spp->smk_out = ssp->smk_out;
2034 * A NULL address is only used for updating existing
2035 * bound entries. If there isn't one, it's OK.
2040 addr6 = (struct sockaddr_in6 *)address;
2041 port = ntohs(addr6->sin6_port);
2043 * This is a special case that is safely ignored.
2049 * Look for an existing port list entry.
2050 * This is an indication that a port is getting reused.
2052 list_for_each_entry(spp, &smk_ipv6_port_list, list) {
2053 if (spp->smk_port != port)
2055 spp->smk_port = port;
2057 spp->smk_in = ssp->smk_in;
2058 spp->smk_out = ssp->smk_out;
2063 * A new port entry is required.
2065 spp = kzalloc(sizeof(*spp), GFP_KERNEL);
2069 spp->smk_port = port;
2071 spp->smk_in = ssp->smk_in;
2072 spp->smk_out = ssp->smk_out;
2074 list_add(&spp->list, &smk_ipv6_port_list);
2079 * smk_ipv6_port_check - check Smack port access
2083 * Create or update the port list entry
2085 static int smk_ipv6_port_check(struct sock *sk, struct sockaddr_in6 *address,
2090 struct smk_port_label *spp;
2091 struct socket_smack *ssp = sk->sk_security;
2092 struct smack_known *skp;
2093 unsigned short port = 0;
2095 struct smk_audit_info ad;
2097 struct lsm_network_audit net;
2100 if (act == SMK_RECEIVING) {
2101 skp = smack_net_ambient;
2102 object = ssp->smk_in->smk_known;
2105 object = smack_net_ambient->smk_known;
2109 * Get the IP address and port from the address.
2111 port = ntohs(address->sin6_port);
2112 bep = (__be16 *)(&address->sin6_addr);
2113 be32p = (__be32 *)(&address->sin6_addr);
2116 * It's remote, so port lookup does no good.
2118 if (be32p[0] || be32p[1] || be32p[2] || bep[6] || ntohs(bep[7]) != 1)
2122 * It's local so the send check has to have passed.
2124 if (act == SMK_RECEIVING) {
2125 skp = &smack_known_web;
2129 list_for_each_entry(spp, &smk_ipv6_port_list, list) {
2130 if (spp->smk_port != port)
2132 object = spp->smk_in->smk_known;
2133 if (act == SMK_CONNECTING)
2134 ssp->smk_packet = spp->smk_out;
2141 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
2142 ad.a.u.net->family = sk->sk_family;
2143 ad.a.u.net->dport = port;
2144 if (act == SMK_RECEIVING)
2145 ad.a.u.net->v6info.saddr = address->sin6_addr;
2147 ad.a.u.net->v6info.daddr = address->sin6_addr;
2149 return smk_access(skp, object, MAY_WRITE, &ad);
2153 * smack_inode_setsecurity - set smack xattrs
2154 * @inode: the object
2155 * @name: attribute name
2156 * @value: attribute value
2157 * @size: size of the attribute
2160 * Sets the named attribute in the appropriate blob
2162 * Returns 0 on success, or an error code
2164 static int smack_inode_setsecurity(struct inode *inode, const char *name,
2165 const void *value, size_t size, int flags)
2167 struct smack_known *skp;
2168 struct inode_smack *nsp = inode->i_security;
2169 struct socket_smack *ssp;
2170 struct socket *sock;
2173 if (value == NULL || size > SMK_LONGLABEL || size == 0)
2176 skp = smk_import_entry(value, size);
2180 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
2181 nsp->smk_inode = skp->smk_known;
2182 nsp->smk_flags |= SMK_INODE_INSTANT;
2186 * The rest of the Smack xattrs are only on sockets.
2188 if (inode->i_sb->s_magic != SOCKFS_MAGIC)
2191 sock = SOCKET_I(inode);
2192 if (sock == NULL || sock->sk == NULL)
2195 ssp = sock->sk->sk_security;
2197 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
2199 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0) {
2201 if (sock->sk->sk_family == PF_INET) {
2202 rc = smack_netlabel(sock->sk, SMACK_CIPSO_SOCKET);
2205 "Smack: \"%s\" netlbl error %d.\n",
2211 if (sock->sk->sk_family == PF_INET6)
2212 smk_ipv6_port_label(sock, NULL);
2218 * smack_socket_post_create - finish socket setup
2220 * @family: protocol family
2225 * Sets the netlabel information on the socket
2227 * Returns 0 on success, and error code otherwise
2229 static int smack_socket_post_create(struct socket *sock, int family,
2230 int type, int protocol, int kern)
2232 if (family != PF_INET || sock->sk == NULL)
2235 * Set the outbound netlbl.
2237 return smack_netlabel(sock->sk, SMACK_CIPSO_SOCKET);
2241 * smack_socket_bind - record port binding information.
2243 * @address: the port address
2244 * @addrlen: size of the address
2246 * Records the label bound to a port.
2250 static int smack_socket_bind(struct socket *sock, struct sockaddr *address,
2253 if (sock->sk != NULL && sock->sk->sk_family == PF_INET6)
2254 smk_ipv6_port_label(sock, address);
2260 * smack_socket_connect - connect access check
2262 * @sap: the other end
2263 * @addrlen: size of sap
2265 * Verifies that a connection may be possible
2267 * Returns 0 on success, and error code otherwise
2269 static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
2274 if (sock->sk == NULL)
2277 switch (sock->sk->sk_family) {
2279 if (addrlen < sizeof(struct sockaddr_in))
2281 rc = smack_netlabel_send(sock->sk, (struct sockaddr_in *)sap);
2284 if (addrlen < sizeof(struct sockaddr_in6))
2286 rc = smk_ipv6_port_check(sock->sk, (struct sockaddr_in6 *)sap,
2294 * smack_flags_to_may - convert S_ to MAY_ values
2295 * @flags: the S_ value
2297 * Returns the equivalent MAY_ value
2299 static int smack_flags_to_may(int flags)
2303 if (flags & S_IRUGO)
2305 if (flags & S_IWUGO)
2307 if (flags & S_IXUGO)
2314 * smack_msg_msg_alloc_security - Set the security blob for msg_msg
2319 static int smack_msg_msg_alloc_security(struct msg_msg *msg)
2321 struct smack_known *skp = smk_of_current();
2323 msg->security = skp->smk_known;
2328 * smack_msg_msg_free_security - Clear the security blob for msg_msg
2331 * Clears the blob pointer
2333 static void smack_msg_msg_free_security(struct msg_msg *msg)
2335 msg->security = NULL;
2339 * smack_of_shm - the smack pointer for the shm
2342 * Returns a pointer to the smack value
2344 static char *smack_of_shm(struct shmid_kernel *shp)
2346 return (char *)shp->shm_perm.security;
2350 * smack_shm_alloc_security - Set the security blob for shm
2355 static int smack_shm_alloc_security(struct shmid_kernel *shp)
2357 struct kern_ipc_perm *isp = &shp->shm_perm;
2358 struct smack_known *skp = smk_of_current();
2360 isp->security = skp->smk_known;
2365 * smack_shm_free_security - Clear the security blob for shm
2368 * Clears the blob pointer
2370 static void smack_shm_free_security(struct shmid_kernel *shp)
2372 struct kern_ipc_perm *isp = &shp->shm_perm;
2374 isp->security = NULL;
2378 * smk_curacc_shm : check if current has access on shm
2380 * @access : access requested
2382 * Returns 0 if current has the requested access, error code otherwise
2384 static int smk_curacc_shm(struct shmid_kernel *shp, int access)
2386 char *ssp = smack_of_shm(shp);
2387 struct smk_audit_info ad;
2390 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2391 ad.a.u.ipc_id = shp->shm_perm.id;
2393 return smk_curacc(ssp, access, &ad);
2397 * smack_shm_associate - Smack access check for shm
2399 * @shmflg: access requested
2401 * Returns 0 if current has the requested access, error code otherwise
2403 static int smack_shm_associate(struct shmid_kernel *shp, int shmflg)
2407 may = smack_flags_to_may(shmflg);
2408 return smk_curacc_shm(shp, may);
2412 * smack_shm_shmctl - Smack access check for shm
2414 * @cmd: what it wants to do
2416 * Returns 0 if current has the requested access, error code otherwise
2418 static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd)
2431 may = MAY_READWRITE;
2436 * System level information.
2442 return smk_curacc_shm(shp, may);
2446 * smack_shm_shmat - Smack access for shmat
2449 * @shmflg: access requested
2451 * Returns 0 if current has the requested access, error code otherwise
2453 static int smack_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr,
2458 may = smack_flags_to_may(shmflg);
2459 return smk_curacc_shm(shp, may);
2463 * smack_of_sem - the smack pointer for the sem
2466 * Returns a pointer to the smack value
2468 static char *smack_of_sem(struct sem_array *sma)
2470 return (char *)sma->sem_perm.security;
2474 * smack_sem_alloc_security - Set the security blob for sem
2479 static int smack_sem_alloc_security(struct sem_array *sma)
2481 struct kern_ipc_perm *isp = &sma->sem_perm;
2482 struct smack_known *skp = smk_of_current();
2484 isp->security = skp->smk_known;
2489 * smack_sem_free_security - Clear the security blob for sem
2492 * Clears the blob pointer
2494 static void smack_sem_free_security(struct sem_array *sma)
2496 struct kern_ipc_perm *isp = &sma->sem_perm;
2498 isp->security = NULL;
2502 * smk_curacc_sem : check if current has access on sem
2504 * @access : access requested
2506 * Returns 0 if current has the requested access, error code otherwise
2508 static int smk_curacc_sem(struct sem_array *sma, int access)
2510 char *ssp = smack_of_sem(sma);
2511 struct smk_audit_info ad;
2514 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2515 ad.a.u.ipc_id = sma->sem_perm.id;
2517 return smk_curacc(ssp, access, &ad);
2521 * smack_sem_associate - Smack access check for sem
2523 * @semflg: access requested
2525 * Returns 0 if current has the requested access, error code otherwise
2527 static int smack_sem_associate(struct sem_array *sma, int semflg)
2531 may = smack_flags_to_may(semflg);
2532 return smk_curacc_sem(sma, may);
2536 * smack_sem_shmctl - Smack access check for sem
2538 * @cmd: what it wants to do
2540 * Returns 0 if current has the requested access, error code otherwise
2542 static int smack_sem_semctl(struct sem_array *sma, int cmd)
2560 may = MAY_READWRITE;
2565 * System level information
2572 return smk_curacc_sem(sma, may);
2576 * smack_sem_semop - Smack checks of semaphore operations
2582 * Treated as read and write in all cases.
2584 * Returns 0 if access is allowed, error code otherwise
2586 static int smack_sem_semop(struct sem_array *sma, struct sembuf *sops,
2587 unsigned nsops, int alter)
2589 return smk_curacc_sem(sma, MAY_READWRITE);
2593 * smack_msg_alloc_security - Set the security blob for msg
2598 static int smack_msg_queue_alloc_security(struct msg_queue *msq)
2600 struct kern_ipc_perm *kisp = &msq->q_perm;
2601 struct smack_known *skp = smk_of_current();
2603 kisp->security = skp->smk_known;
2608 * smack_msg_free_security - Clear the security blob for msg
2611 * Clears the blob pointer
2613 static void smack_msg_queue_free_security(struct msg_queue *msq)
2615 struct kern_ipc_perm *kisp = &msq->q_perm;
2617 kisp->security = NULL;
2621 * smack_of_msq - the smack pointer for the msq
2624 * Returns a pointer to the smack value
2626 static char *smack_of_msq(struct msg_queue *msq)
2628 return (char *)msq->q_perm.security;
2632 * smk_curacc_msq : helper to check if current has access on msq
2634 * @access : access requested
2636 * return 0 if current has access, error otherwise
2638 static int smk_curacc_msq(struct msg_queue *msq, int access)
2640 char *msp = smack_of_msq(msq);
2641 struct smk_audit_info ad;
2644 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2645 ad.a.u.ipc_id = msq->q_perm.id;
2647 return smk_curacc(msp, access, &ad);
2651 * smack_msg_queue_associate - Smack access check for msg_queue
2653 * @msqflg: access requested
2655 * Returns 0 if current has the requested access, error code otherwise
2657 static int smack_msg_queue_associate(struct msg_queue *msq, int msqflg)
2661 may = smack_flags_to_may(msqflg);
2662 return smk_curacc_msq(msq, may);
2666 * smack_msg_queue_msgctl - Smack access check for msg_queue
2668 * @cmd: what it wants to do
2670 * Returns 0 if current has the requested access, error code otherwise
2672 static int smack_msg_queue_msgctl(struct msg_queue *msq, int cmd)
2683 may = MAY_READWRITE;
2688 * System level information
2695 return smk_curacc_msq(msq, may);
2699 * smack_msg_queue_msgsnd - Smack access check for msg_queue
2702 * @msqflg: access requested
2704 * Returns 0 if current has the requested access, error code otherwise
2706 static int smack_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
2711 may = smack_flags_to_may(msqflg);
2712 return smk_curacc_msq(msq, may);
2716 * smack_msg_queue_msgsnd - Smack access check for msg_queue
2723 * Returns 0 if current has read and write access, error code otherwise
2725 static int smack_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
2726 struct task_struct *target, long type, int mode)
2728 return smk_curacc_msq(msq, MAY_READWRITE);
2732 * smack_ipc_permission - Smack access for ipc_permission()
2733 * @ipp: the object permissions
2734 * @flag: access requested
2736 * Returns 0 if current has read and write access, error code otherwise
2738 static int smack_ipc_permission(struct kern_ipc_perm *ipp, short flag)
2740 char *isp = ipp->security;
2741 int may = smack_flags_to_may(flag);
2742 struct smk_audit_info ad;
2745 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2746 ad.a.u.ipc_id = ipp->id;
2748 return smk_curacc(isp, may, &ad);
2752 * smack_ipc_getsecid - Extract smack security id
2753 * @ipp: the object permissions
2754 * @secid: where result will be saved
2756 static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, u32 *secid)
2758 char *smack = ipp->security;
2760 *secid = smack_to_secid(smack);
2764 * smack_d_instantiate - Make sure the blob is correct on an inode
2765 * @opt_dentry: dentry where inode will be attached
2766 * @inode: the object
2768 * Set the inode's security blob if it hasn't been done already.
2770 static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
2772 struct super_block *sbp;
2773 struct superblock_smack *sbsp;
2774 struct inode_smack *isp;
2775 struct smack_known *skp;
2776 struct smack_known *ckp = smk_of_current();
2778 char trattr[TRANS_TRUE_SIZE];
2786 isp = inode->i_security;
2788 mutex_lock(&isp->smk_lock);
2790 * If the inode is already instantiated
2791 * take the quick way out
2793 if (isp->smk_flags & SMK_INODE_INSTANT)
2797 sbsp = sbp->s_security;
2799 * We're going to use the superblock default label
2800 * if there's no label on the file.
2802 final = sbsp->smk_default;
2805 * If this is the root inode the superblock
2806 * may be in the process of initialization.
2807 * If that is the case use the root value out
2808 * of the superblock.
2810 if (opt_dentry->d_parent == opt_dentry) {
2811 isp->smk_inode = sbsp->smk_root;
2812 isp->smk_flags |= SMK_INODE_INSTANT;
2817 * This is pretty hackish.
2818 * Casey says that we shouldn't have to do
2819 * file system specific code, but it does help
2820 * with keeping it simple.
2822 switch (sbp->s_magic) {
2825 * Casey says that it's a little embarrassing
2826 * that the smack file system doesn't do
2827 * extended attributes.
2829 final = smack_known_star.smk_known;
2833 * Casey says pipes are easy (?)
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;
2847 * Socket access is controlled by the socket
2848 * structures associated with the task involved.
2850 final = smack_known_star.smk_known;
2852 case PROC_SUPER_MAGIC:
2854 * Casey says procfs appears not to care.
2855 * The superblock default suffices.
2860 * Device labels should come from the filesystem,
2861 * but watch out, because they're volitile,
2862 * getting recreated on every reboot.
2864 final = smack_known_star.smk_known;
2868 * If a smack value has been set we want to use it,
2869 * but since tmpfs isn't giving us the opportunity
2870 * to set mount options simulate setting the
2871 * superblock default.
2875 * This isn't an understood special case.
2876 * Get the value from the xattr.
2880 * UNIX domain sockets use lower level socket data.
2882 if (S_ISSOCK(inode->i_mode)) {
2883 final = smack_known_star.smk_known;
2887 * No xattr support means, alas, no SMACK label.
2888 * Use the aforeapplied default.
2889 * It would be curious if the label of the task
2890 * does not match that assigned.
2892 if (inode->i_op->getxattr == NULL)
2895 * Get the dentry for xattr.
2897 dp = dget(opt_dentry);
2898 skp = smk_fetch(XATTR_NAME_SMACK, inode, dp);
2900 final = skp->smk_known;
2903 * Transmuting directory
2905 if (S_ISDIR(inode->i_mode)) {
2907 * If this is a new directory and the label was
2908 * transmuted when the inode was initialized
2909 * set the transmute attribute on the directory
2910 * and mark the inode.
2912 * If there is a transmute attribute on the
2913 * directory mark the inode.
2915 if (isp->smk_flags & SMK_INODE_CHANGED) {
2916 isp->smk_flags &= ~SMK_INODE_CHANGED;
2917 rc = inode->i_op->setxattr(dp,
2918 XATTR_NAME_SMACKTRANSMUTE,
2919 TRANS_TRUE, TRANS_TRUE_SIZE,
2922 rc = inode->i_op->getxattr(dp,
2923 XATTR_NAME_SMACKTRANSMUTE, trattr,
2925 if (rc >= 0 && strncmp(trattr, TRANS_TRUE,
2926 TRANS_TRUE_SIZE) != 0)
2930 transflag = SMK_INODE_TRANSMUTE;
2933 * Don't let the exec or mmap label be "*" or "@".
2935 skp = smk_fetch(XATTR_NAME_SMACKEXEC, inode, dp);
2936 if (skp == &smack_known_star || skp == &smack_known_web)
2938 isp->smk_task = skp;
2939 skp = smk_fetch(XATTR_NAME_SMACKMMAP, inode, dp);
2940 if (skp == &smack_known_star || skp == &smack_known_web)
2942 isp->smk_mmap = skp;
2949 isp->smk_inode = ckp->smk_known;
2951 isp->smk_inode = final;
2953 isp->smk_flags |= (SMK_INODE_INSTANT | transflag);
2956 mutex_unlock(&isp->smk_lock);
2961 * smack_getprocattr - Smack process attribute access
2962 * @p: the object task
2963 * @name: the name of the attribute in /proc/.../attr
2964 * @value: where to put the result
2966 * Places a copy of the task Smack into value
2968 * Returns the length of the smack label or an error code
2970 static int smack_getprocattr(struct task_struct *p, char *name, char **value)
2972 struct smack_known *skp = smk_of_task(task_security(p));
2976 if (strcmp(name, "current") != 0)
2979 cp = kstrdup(skp->smk_known, GFP_KERNEL);
2989 * smack_setprocattr - Smack process attribute setting
2990 * @p: the object task
2991 * @name: the name of the attribute in /proc/.../attr
2992 * @value: the value to set
2993 * @size: the size of the value
2995 * Sets the Smack value of the task. Only setting self
2996 * is permitted and only with privilege
2998 * Returns the length of the smack label or an error code
3000 static int smack_setprocattr(struct task_struct *p, char *name,
3001 void *value, size_t size)
3003 struct task_smack *tsp;
3005 struct smack_known *skp;
3008 * Changing another process' Smack value is too dangerous
3009 * and supports no sane use case.
3014 if (!smack_privileged(CAP_MAC_ADMIN))
3017 if (value == NULL || size == 0 || size >= SMK_LONGLABEL)
3020 if (strcmp(name, "current") != 0)
3023 skp = smk_import_entry(value, size);
3028 * No process is ever allowed the web ("@") label.
3030 if (skp == &smack_known_web)
3033 new = prepare_creds();
3037 tsp = new->security;
3038 tsp->smk_task = skp;
3045 * smack_unix_stream_connect - Smack access on UDS
3047 * @other: the other sock
3050 * Return 0 if a subject with the smack of sock could access
3051 * an object with the smack of other, otherwise an error code
3053 static int smack_unix_stream_connect(struct sock *sock,
3054 struct sock *other, struct sock *newsk)
3056 struct smack_known *skp;
3057 struct smack_known *okp;
3058 struct socket_smack *ssp = sock->sk_security;
3059 struct socket_smack *osp = other->sk_security;
3060 struct socket_smack *nsp = newsk->sk_security;
3061 struct smk_audit_info ad;
3064 struct lsm_network_audit net;
3067 if (!smack_privileged(CAP_MAC_OVERRIDE)) {
3071 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
3072 smk_ad_setfield_u_net_sk(&ad, other);
3074 rc = smk_access(skp, okp->smk_known, MAY_WRITE, &ad);
3076 rc = smk_access(okp, okp->smk_known, MAY_WRITE, NULL);
3080 * Cross reference the peer labels for SO_PEERSEC.
3083 nsp->smk_packet = ssp->smk_out;
3084 ssp->smk_packet = osp->smk_out;
3091 * smack_unix_may_send - Smack access on UDS
3093 * @other: the other socket
3095 * Return 0 if a subject with the smack of sock could access
3096 * an object with the smack of other, otherwise an error code
3098 static int smack_unix_may_send(struct socket *sock, struct socket *other)
3100 struct socket_smack *ssp = sock->sk->sk_security;
3101 struct socket_smack *osp = other->sk->sk_security;
3102 struct smack_known *skp;
3103 struct smk_audit_info ad;
3106 struct lsm_network_audit net;
3108 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
3109 smk_ad_setfield_u_net_sk(&ad, other->sk);
3112 if (smack_privileged(CAP_MAC_OVERRIDE))
3116 return smk_access(skp, osp->smk_in->smk_known, MAY_WRITE, &ad);
3120 * smack_socket_sendmsg - Smack check based on destination host
3123 * @size: the size of the message
3125 * Return 0 if the current subject can write to the destination host.
3126 * For IPv4 this is only a question if the destination is a single label host.
3127 * For IPv6 this is a check against the label of the port.
3129 static int smack_socket_sendmsg(struct socket *sock, struct msghdr *msg,
3132 struct sockaddr_in *sip = (struct sockaddr_in *) msg->msg_name;
3133 struct sockaddr_in6 *sap = (struct sockaddr_in6 *) msg->msg_name;
3137 * Perfectly reasonable for this to be NULL
3142 switch (sip->sin_family) {
3144 rc = smack_netlabel_send(sock->sk, sip);
3147 rc = smk_ipv6_port_check(sock->sk, sap, SMK_SENDING);
3154 * smack_from_secattr - Convert a netlabel attr.mls.lvl/attr.mls.cat pair to smack
3155 * @sap: netlabel secattr
3156 * @ssp: socket security information
3158 * Returns a pointer to a Smack label entry found on the label list.
3160 static struct smack_known *smack_from_secattr(struct netlbl_lsm_secattr *sap,
3161 struct socket_smack *ssp)
3163 struct smack_known *skp;
3168 if ((sap->flags & NETLBL_SECATTR_MLS_LVL) != 0) {
3170 * Looks like a CIPSO packet.
3171 * If there are flags but no level netlabel isn't
3172 * behaving the way we expect it to.
3174 * Look it up in the label table
3175 * Without guidance regarding the smack value
3176 * for the packet fall back on the network
3180 list_for_each_entry(skp, &smack_known_list, list) {
3181 if (sap->attr.mls.lvl != skp->smk_netlabel.attr.mls.lvl)
3184 * Compare the catsets. Use the netlbl APIs.
3186 if ((sap->flags & NETLBL_SECATTR_MLS_CAT) == 0) {
3187 if ((skp->smk_netlabel.flags &
3188 NETLBL_SECATTR_MLS_CAT) == 0)
3192 for (acat = -1, kcat = -1; acat == kcat; ) {
3193 acat = netlbl_secattr_catmap_walk(
3194 sap->attr.mls.cat, acat + 1);
3195 kcat = netlbl_secattr_catmap_walk(
3196 skp->smk_netlabel.attr.mls.cat,
3198 if (acat < 0 || kcat < 0)
3211 if (ssp != NULL && ssp->smk_in == &smack_known_star)
3212 return &smack_known_web;
3213 return &smack_known_star;
3215 if ((sap->flags & NETLBL_SECATTR_SECID) != 0) {
3217 * Looks like a fallback, which gives us a secid.
3219 skp = smack_from_secid(sap->attr.secid);
3221 * This has got to be a bug because it is
3222 * impossible to specify a fallback without
3223 * specifying the label, which will ensure
3224 * it has a secid, and the only way to get a
3225 * secid is from a fallback.
3227 BUG_ON(skp == NULL);
3231 * Without guidance regarding the smack value
3232 * for the packet fall back on the network
3235 return smack_net_ambient;
3238 static int smk_skb_to_addr_ipv6(struct sk_buff *skb, struct sockaddr_in6 *sip)
3242 int proto = -EINVAL;
3243 struct ipv6hdr _ipv6h;
3244 struct ipv6hdr *ip6;
3246 struct tcphdr _tcph, *th;
3247 struct udphdr _udph, *uh;
3248 struct dccp_hdr _dccph, *dh;
3252 offset = skb_network_offset(skb);
3253 ip6 = skb_header_pointer(skb, offset, sizeof(_ipv6h), &_ipv6h);
3256 sip->sin6_addr = ip6->saddr;
3258 nexthdr = ip6->nexthdr;
3259 offset += sizeof(_ipv6h);
3260 offset = ipv6_skip_exthdr(skb, offset, &nexthdr, &frag_off);
3267 th = skb_header_pointer(skb, offset, sizeof(_tcph), &_tcph);
3269 sip->sin6_port = th->source;
3272 uh = skb_header_pointer(skb, offset, sizeof(_udph), &_udph);
3274 sip->sin6_port = uh->source;
3277 dh = skb_header_pointer(skb, offset, sizeof(_dccph), &_dccph);
3279 sip->sin6_port = dh->dccph_sport;
3286 * smack_socket_sock_rcv_skb - Smack packet delivery access check
3290 * Returns 0 if the packet should be delivered, an error code otherwise
3292 static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
3294 struct netlbl_lsm_secattr secattr;
3295 struct socket_smack *ssp = sk->sk_security;
3296 struct smack_known *skp;
3297 struct sockaddr_in6 sadd;
3299 struct smk_audit_info ad;
3301 struct lsm_network_audit net;
3303 switch (sk->sk_family) {
3306 * Translate what netlabel gave us.
3308 netlbl_secattr_init(&secattr);
3310 rc = netlbl_skbuff_getattr(skb, sk->sk_family, &secattr);
3312 skp = smack_from_secattr(&secattr, ssp);
3314 skp = smack_net_ambient;
3316 netlbl_secattr_destroy(&secattr);
3319 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
3320 ad.a.u.net->family = sk->sk_family;
3321 ad.a.u.net->netif = skb->skb_iif;
3322 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
3325 * Receiving a packet requires that the other end
3326 * be able to write here. Read access is not required.
3327 * This is the simplist possible security model
3330 rc = smk_access(skp, ssp->smk_in->smk_known, MAY_WRITE, &ad);
3332 netlbl_skbuff_err(skb, rc, 0);
3335 rc = smk_skb_to_addr_ipv6(skb, &sadd);
3336 if (rc == IPPROTO_UDP || rc == IPPROTO_TCP)
3337 rc = smk_ipv6_port_check(sk, &sadd, SMK_RECEIVING);
3346 * smack_socket_getpeersec_stream - pull in packet label
3348 * @optval: user's destination
3349 * @optlen: size thereof
3352 * returns zero on success, an error code otherwise
3354 static int smack_socket_getpeersec_stream(struct socket *sock,
3355 char __user *optval,
3356 int __user *optlen, unsigned len)
3358 struct socket_smack *ssp;
3363 ssp = sock->sk->sk_security;
3364 if (ssp->smk_packet != NULL) {
3365 rcp = ssp->smk_packet->smk_known;
3366 slen = strlen(rcp) + 1;
3371 else if (copy_to_user(optval, rcp, slen) != 0)
3374 if (put_user(slen, optlen) != 0)
3382 * smack_socket_getpeersec_dgram - pull in packet label
3383 * @sock: the peer socket
3385 * @secid: pointer to where to put the secid of the packet
3387 * Sets the netlabel socket state on sk from parent
3389 static int smack_socket_getpeersec_dgram(struct socket *sock,
3390 struct sk_buff *skb, u32 *secid)
3393 struct netlbl_lsm_secattr secattr;
3394 struct socket_smack *ssp = NULL;
3395 struct smack_known *skp;
3396 int family = PF_UNSPEC;
3397 u32 s = 0; /* 0 is the invalid secid */
3401 if (skb->protocol == htons(ETH_P_IP))
3403 else if (skb->protocol == htons(ETH_P_IPV6))
3406 if (family == PF_UNSPEC && sock != NULL)
3407 family = sock->sk->sk_family;
3409 if (family == PF_UNIX) {
3410 ssp = sock->sk->sk_security;
3411 s = ssp->smk_out->smk_secid;
3412 } else if (family == PF_INET || family == PF_INET6) {
3414 * Translate what netlabel gave us.
3416 if (sock != NULL && sock->sk != NULL)
3417 ssp = sock->sk->sk_security;
3418 netlbl_secattr_init(&secattr);
3419 rc = netlbl_skbuff_getattr(skb, family, &secattr);
3421 skp = smack_from_secattr(&secattr, ssp);
3424 netlbl_secattr_destroy(&secattr);
3433 * smack_sock_graft - Initialize a newly created socket with an existing sock
3435 * @parent: parent socket
3437 * Set the smk_{in,out} state of an existing sock based on the process that
3438 * is creating the new socket.
3440 static void smack_sock_graft(struct sock *sk, struct socket *parent)
3442 struct socket_smack *ssp;
3443 struct smack_known *skp = smk_of_current();
3446 (sk->sk_family != PF_INET && sk->sk_family != PF_INET6))
3449 ssp = sk->sk_security;
3452 /* cssp->smk_packet is already set in smack_inet_csk_clone() */
3456 * smack_inet_conn_request - Smack access check on connect
3457 * @sk: socket involved
3461 * Returns 0 if a task with the packet label could write to
3462 * the socket, otherwise an error code
3464 static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
3465 struct request_sock *req)
3467 u16 family = sk->sk_family;
3468 struct smack_known *skp;
3469 struct socket_smack *ssp = sk->sk_security;
3470 struct netlbl_lsm_secattr secattr;
3471 struct sockaddr_in addr;
3475 struct smk_audit_info ad;
3477 struct lsm_network_audit net;
3480 if (family == PF_INET6) {
3482 * Handle mapped IPv4 packets arriving
3483 * via IPv6 sockets. Don't set up netlabel
3484 * processing on IPv6.
3486 if (skb->protocol == htons(ETH_P_IP))
3492 netlbl_secattr_init(&secattr);
3493 rc = netlbl_skbuff_getattr(skb, family, &secattr);
3495 skp = smack_from_secattr(&secattr, ssp);
3497 skp = &smack_known_huh;
3498 netlbl_secattr_destroy(&secattr);
3501 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
3502 ad.a.u.net->family = family;
3503 ad.a.u.net->netif = skb->skb_iif;
3504 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
3507 * Receiving a packet requires that the other end be able to write
3508 * here. Read access is not required.
3510 rc = smk_access(skp, ssp->smk_in->smk_known, MAY_WRITE, &ad);
3515 * Save the peer's label in the request_sock so we can later setup
3516 * smk_packet in the child socket so that SO_PEERCRED can report it.
3518 req->peer_secid = skp->smk_secid;
3521 * We need to decide if we want to label the incoming connection here
3522 * if we do we only need to label the request_sock and the stack will
3523 * propagate the wire-label to the sock when it is created.
3526 addr.sin_addr.s_addr = hdr->saddr;
3528 hsp = smack_host_label(&addr);
3532 rc = netlbl_req_setattr(req, &skp->smk_netlabel);
3534 netlbl_req_delattr(req);
3540 * smack_inet_csk_clone - Copy the connection information to the new socket
3541 * @sk: the new socket
3542 * @req: the connection's request_sock
3544 * Transfer the connection's peer label to the newly created socket.
3546 static void smack_inet_csk_clone(struct sock *sk,
3547 const struct request_sock *req)
3549 struct socket_smack *ssp = sk->sk_security;
3550 struct smack_known *skp;
3552 if (req->peer_secid != 0) {
3553 skp = smack_from_secid(req->peer_secid);
3554 ssp->smk_packet = skp;
3556 ssp->smk_packet = NULL;
3560 * Key management security hooks
3562 * Casey has not tested key support very heavily.
3563 * The permission check is most likely too restrictive.
3564 * If you care about keys please have a look.
3569 * smack_key_alloc - Set the key security blob
3571 * @cred: the credentials to use
3574 * No allocation required
3578 static int smack_key_alloc(struct key *key, const struct cred *cred,
3579 unsigned long flags)
3581 struct smack_known *skp = smk_of_task(cred->security);
3583 key->security = skp->smk_known;
3588 * smack_key_free - Clear the key security blob
3591 * Clear the blob pointer
3593 static void smack_key_free(struct key *key)
3595 key->security = NULL;
3599 * smack_key_permission - Smack access on a key
3600 * @key_ref: gets to the object
3601 * @cred: the credentials to use
3604 * Return 0 if the task has read and write to the object,
3605 * an error code otherwise
3607 static int smack_key_permission(key_ref_t key_ref,
3608 const struct cred *cred, key_perm_t perm)
3611 struct smk_audit_info ad;
3612 struct smack_known *tkp = smk_of_task(cred->security);
3614 keyp = key_ref_to_ptr(key_ref);
3618 * If the key hasn't been initialized give it access so that
3621 if (keyp->security == NULL)
3624 * This should not occur
3629 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_KEY);
3630 ad.a.u.key_struct.key = keyp->serial;
3631 ad.a.u.key_struct.key_desc = keyp->description;
3633 return smk_access(tkp, keyp->security, MAY_READWRITE, &ad);
3635 #endif /* CONFIG_KEYS */
3640 * Audit requires a unique representation of each Smack specific
3641 * rule. This unique representation is used to distinguish the
3642 * object to be audited from remaining kernel objects and also
3643 * works as a glue between the audit hooks.
3645 * Since repository entries are added but never deleted, we'll use
3646 * the smack_known label address related to the given audit rule as
3647 * the needed unique representation. This also better fits the smack
3648 * model where nearly everything is a label.
3653 * smack_audit_rule_init - Initialize a smack audit rule
3654 * @field: audit rule fields given from user-space (audit.h)
3655 * @op: required testing operator (=, !=, >, <, ...)
3656 * @rulestr: smack label to be audited
3657 * @vrule: pointer to save our own audit rule representation
3659 * Prepare to audit cases where (@field @op @rulestr) is true.
3660 * The label to be audited is created if necessay.
3662 static int smack_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
3664 char **rule = (char **)vrule;
3667 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
3670 if (op != Audit_equal && op != Audit_not_equal)
3673 *rule = smk_import(rulestr, 0);
3679 * smack_audit_rule_known - Distinguish Smack audit rules
3680 * @krule: rule of interest, in Audit kernel representation format
3682 * This is used to filter Smack rules from remaining Audit ones.
3683 * If it's proved that this rule belongs to us, the
3684 * audit_rule_match hook will be called to do the final judgement.
3686 static int smack_audit_rule_known(struct audit_krule *krule)
3688 struct audit_field *f;
3691 for (i = 0; i < krule->field_count; i++) {
3692 f = &krule->fields[i];
3694 if (f->type == AUDIT_SUBJ_USER || f->type == AUDIT_OBJ_USER)
3702 * smack_audit_rule_match - Audit given object ?
3703 * @secid: security id for identifying the object to test
3704 * @field: audit rule flags given from user-space
3705 * @op: required testing operator
3706 * @vrule: smack internal rule presentation
3707 * @actx: audit context associated with the check
3709 * The core Audit hook. It's used to take the decision of
3710 * whether to audit or not to audit a given object.
3712 static int smack_audit_rule_match(u32 secid, u32 field, u32 op, void *vrule,
3713 struct audit_context *actx)
3715 struct smack_known *skp;
3719 audit_log(actx, GFP_ATOMIC, AUDIT_SELINUX_ERR,
3720 "Smack: missing rule\n");
3724 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
3727 skp = smack_from_secid(secid);
3730 * No need to do string comparisons. If a match occurs,
3731 * both pointers will point to the same smack_known
3734 if (op == Audit_equal)
3735 return (rule == skp->smk_known);
3736 if (op == Audit_not_equal)
3737 return (rule != skp->smk_known);
3743 * smack_audit_rule_free - free smack rule representation
3744 * @vrule: rule to be freed.
3746 * No memory was allocated.
3748 static void smack_audit_rule_free(void *vrule)
3753 #endif /* CONFIG_AUDIT */
3756 * smack_ismaclabel - check if xattr @name references a smack MAC label
3757 * @name: Full xattr name to check.
3759 static int smack_ismaclabel(const char *name)
3761 return (strcmp(name, XATTR_SMACK_SUFFIX) == 0);
3766 * smack_secid_to_secctx - return the smack label for a secid
3767 * @secid: incoming integer
3768 * @secdata: destination
3769 * @seclen: how long it is
3771 * Exists for networking code.
3773 static int smack_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
3775 struct smack_known *skp = smack_from_secid(secid);
3778 *secdata = skp->smk_known;
3779 *seclen = strlen(skp->smk_known);
3784 * smack_secctx_to_secid - return the secid for a smack label
3785 * @secdata: smack label
3786 * @seclen: how long result is
3787 * @secid: outgoing integer
3789 * Exists for audit and networking code.
3791 static int smack_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
3793 *secid = smack_to_secid(secdata);
3798 * smack_release_secctx - don't do anything.
3802 * Exists to make sure nothing gets done, and properly
3804 static void smack_release_secctx(char *secdata, u32 seclen)
3808 static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
3810 return smack_inode_setsecurity(inode, XATTR_SMACK_SUFFIX, ctx, ctxlen, 0);
3813 static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
3815 return __vfs_setxattr_noperm(dentry, XATTR_NAME_SMACK, ctx, ctxlen, 0);
3818 static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
3821 len = smack_inode_getsecurity(inode, XATTR_SMACK_SUFFIX, ctx, true);
3829 struct security_operations smack_ops = {
3832 .ptrace_access_check = smack_ptrace_access_check,
3833 .ptrace_traceme = smack_ptrace_traceme,
3834 .syslog = smack_syslog,
3836 .sb_alloc_security = smack_sb_alloc_security,
3837 .sb_free_security = smack_sb_free_security,
3838 .sb_copy_data = smack_sb_copy_data,
3839 .sb_kern_mount = smack_sb_kern_mount,
3840 .sb_statfs = smack_sb_statfs,
3842 .bprm_set_creds = smack_bprm_set_creds,
3843 .bprm_committing_creds = smack_bprm_committing_creds,
3844 .bprm_secureexec = smack_bprm_secureexec,
3846 .inode_alloc_security = smack_inode_alloc_security,
3847 .inode_free_security = smack_inode_free_security,
3848 .inode_init_security = smack_inode_init_security,
3849 .inode_link = smack_inode_link,
3850 .inode_unlink = smack_inode_unlink,
3851 .inode_rmdir = smack_inode_rmdir,
3852 .inode_rename = smack_inode_rename,
3853 .inode_permission = smack_inode_permission,
3854 .inode_setattr = smack_inode_setattr,
3855 .inode_getattr = smack_inode_getattr,
3856 .inode_setxattr = smack_inode_setxattr,
3857 .inode_post_setxattr = smack_inode_post_setxattr,
3858 .inode_getxattr = smack_inode_getxattr,
3859 .inode_removexattr = smack_inode_removexattr,
3860 .inode_getsecurity = smack_inode_getsecurity,
3861 .inode_setsecurity = smack_inode_setsecurity,
3862 .inode_listsecurity = smack_inode_listsecurity,
3863 .inode_getsecid = smack_inode_getsecid,
3865 .file_permission = smack_file_permission,
3866 .file_alloc_security = smack_file_alloc_security,
3867 .file_free_security = smack_file_free_security,
3868 .file_ioctl = smack_file_ioctl,
3869 .file_lock = smack_file_lock,
3870 .file_fcntl = smack_file_fcntl,
3871 .mmap_file = smack_mmap_file,
3872 .mmap_addr = cap_mmap_addr,
3873 .file_set_fowner = smack_file_set_fowner,
3874 .file_send_sigiotask = smack_file_send_sigiotask,
3875 .file_receive = smack_file_receive,
3877 .file_open = smack_file_open,
3879 .cred_alloc_blank = smack_cred_alloc_blank,
3880 .cred_free = smack_cred_free,
3881 .cred_prepare = smack_cred_prepare,
3882 .cred_transfer = smack_cred_transfer,
3883 .kernel_act_as = smack_kernel_act_as,
3884 .kernel_create_files_as = smack_kernel_create_files_as,
3885 .task_setpgid = smack_task_setpgid,
3886 .task_getpgid = smack_task_getpgid,
3887 .task_getsid = smack_task_getsid,
3888 .task_getsecid = smack_task_getsecid,
3889 .task_setnice = smack_task_setnice,
3890 .task_setioprio = smack_task_setioprio,
3891 .task_getioprio = smack_task_getioprio,
3892 .task_setscheduler = smack_task_setscheduler,
3893 .task_getscheduler = smack_task_getscheduler,
3894 .task_movememory = smack_task_movememory,
3895 .task_kill = smack_task_kill,
3896 .task_wait = smack_task_wait,
3897 .task_to_inode = smack_task_to_inode,
3899 .ipc_permission = smack_ipc_permission,
3900 .ipc_getsecid = smack_ipc_getsecid,
3902 .msg_msg_alloc_security = smack_msg_msg_alloc_security,
3903 .msg_msg_free_security = smack_msg_msg_free_security,
3905 .msg_queue_alloc_security = smack_msg_queue_alloc_security,
3906 .msg_queue_free_security = smack_msg_queue_free_security,
3907 .msg_queue_associate = smack_msg_queue_associate,
3908 .msg_queue_msgctl = smack_msg_queue_msgctl,
3909 .msg_queue_msgsnd = smack_msg_queue_msgsnd,
3910 .msg_queue_msgrcv = smack_msg_queue_msgrcv,
3912 .shm_alloc_security = smack_shm_alloc_security,
3913 .shm_free_security = smack_shm_free_security,
3914 .shm_associate = smack_shm_associate,
3915 .shm_shmctl = smack_shm_shmctl,
3916 .shm_shmat = smack_shm_shmat,
3918 .sem_alloc_security = smack_sem_alloc_security,
3919 .sem_free_security = smack_sem_free_security,
3920 .sem_associate = smack_sem_associate,
3921 .sem_semctl = smack_sem_semctl,
3922 .sem_semop = smack_sem_semop,
3924 .d_instantiate = smack_d_instantiate,
3926 .getprocattr = smack_getprocattr,
3927 .setprocattr = smack_setprocattr,
3929 .unix_stream_connect = smack_unix_stream_connect,
3930 .unix_may_send = smack_unix_may_send,
3932 .socket_post_create = smack_socket_post_create,
3933 .socket_bind = smack_socket_bind,
3934 .socket_connect = smack_socket_connect,
3935 .socket_sendmsg = smack_socket_sendmsg,
3936 .socket_sock_rcv_skb = smack_socket_sock_rcv_skb,
3937 .socket_getpeersec_stream = smack_socket_getpeersec_stream,
3938 .socket_getpeersec_dgram = smack_socket_getpeersec_dgram,
3939 .sk_alloc_security = smack_sk_alloc_security,
3940 .sk_free_security = smack_sk_free_security,
3941 .sock_graft = smack_sock_graft,
3942 .inet_conn_request = smack_inet_conn_request,
3943 .inet_csk_clone = smack_inet_csk_clone,
3945 /* key management security hooks */
3947 .key_alloc = smack_key_alloc,
3948 .key_free = smack_key_free,
3949 .key_permission = smack_key_permission,
3950 #endif /* CONFIG_KEYS */
3954 .audit_rule_init = smack_audit_rule_init,
3955 .audit_rule_known = smack_audit_rule_known,
3956 .audit_rule_match = smack_audit_rule_match,
3957 .audit_rule_free = smack_audit_rule_free,
3958 #endif /* CONFIG_AUDIT */
3960 .ismaclabel = smack_ismaclabel,
3961 .secid_to_secctx = smack_secid_to_secctx,
3962 .secctx_to_secid = smack_secctx_to_secid,
3963 .release_secctx = smack_release_secctx,
3964 .inode_notifysecctx = smack_inode_notifysecctx,
3965 .inode_setsecctx = smack_inode_setsecctx,
3966 .inode_getsecctx = smack_inode_getsecctx,
3970 static __init void init_smack_known_list(void)
3973 * Initialize rule list locks
3975 mutex_init(&smack_known_huh.smk_rules_lock);
3976 mutex_init(&smack_known_hat.smk_rules_lock);
3977 mutex_init(&smack_known_floor.smk_rules_lock);
3978 mutex_init(&smack_known_star.smk_rules_lock);
3979 mutex_init(&smack_known_invalid.smk_rules_lock);
3980 mutex_init(&smack_known_web.smk_rules_lock);
3982 * Initialize rule lists
3984 INIT_LIST_HEAD(&smack_known_huh.smk_rules);
3985 INIT_LIST_HEAD(&smack_known_hat.smk_rules);
3986 INIT_LIST_HEAD(&smack_known_star.smk_rules);
3987 INIT_LIST_HEAD(&smack_known_floor.smk_rules);
3988 INIT_LIST_HEAD(&smack_known_invalid.smk_rules);
3989 INIT_LIST_HEAD(&smack_known_web.smk_rules);
3991 * Create the known labels list
3993 smk_insert_entry(&smack_known_huh);
3994 smk_insert_entry(&smack_known_hat);
3995 smk_insert_entry(&smack_known_star);
3996 smk_insert_entry(&smack_known_floor);
3997 smk_insert_entry(&smack_known_invalid);
3998 smk_insert_entry(&smack_known_web);
4002 * smack_init - initialize the smack system
4006 static __init int smack_init(void)
4009 struct task_smack *tsp;
4011 if (!security_module_enable(&smack_ops))
4014 tsp = new_task_smack(&smack_known_floor, &smack_known_floor,
4019 printk(KERN_INFO "Smack: Initializing.\n");
4022 * Set the security state for the initial task.
4024 cred = (struct cred *) current->cred;
4025 cred->security = tsp;
4027 /* initialize the smack_known_list */
4028 init_smack_known_list();
4033 if (register_security(&smack_ops))
4034 panic("smack: Unable to register with kernel.\n");
4040 * Smack requires early initialization in order to label
4041 * all processes and objects when they are created.
4043 security_initcall(smack_init);