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
1465 * @cred: task credential
1467 * Set the security blob in the file structure.
1468 * Allow the open only if the task has read access. There are
1469 * many read operations (e.g. fstat) that you can do with an
1470 * fd even if you have the file open write-only.
1474 static int smack_file_open(struct file *file, const struct cred *cred)
1476 struct task_smack *tsp = cred->security;
1477 struct inode_smack *isp = file_inode(file)->i_security;
1478 struct smk_audit_info ad;
1481 if (smack_privileged(CAP_MAC_OVERRIDE))
1484 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_PATH);
1485 smk_ad_setfield_u_fs_path(&ad, file->f_path);
1486 rc = smk_access(tsp->smk_task, isp->smk_inode, MAY_READ, &ad);
1488 file->f_security = isp->smk_inode;
1498 * smack_cred_alloc_blank - "allocate" blank task-level security credentials
1499 * @new: the new credentials
1500 * @gfp: the atomicity of any memory allocations
1502 * Prepare a blank set of credentials for modification. This must allocate all
1503 * the memory the LSM module might require such that cred_transfer() can
1504 * complete without error.
1506 static int smack_cred_alloc_blank(struct cred *cred, gfp_t gfp)
1508 struct task_smack *tsp;
1510 tsp = new_task_smack(NULL, NULL, gfp);
1514 cred->security = tsp;
1521 * smack_cred_free - "free" task-level security credentials
1522 * @cred: the credentials in question
1525 static void smack_cred_free(struct cred *cred)
1527 struct task_smack *tsp = cred->security;
1528 struct smack_rule *rp;
1529 struct list_head *l;
1530 struct list_head *n;
1534 cred->security = NULL;
1536 list_for_each_safe(l, n, &tsp->smk_rules) {
1537 rp = list_entry(l, struct smack_rule, list);
1538 list_del(&rp->list);
1545 * smack_cred_prepare - prepare new set of credentials for modification
1546 * @new: the new credentials
1547 * @old: the original credentials
1548 * @gfp: the atomicity of any memory allocations
1550 * Prepare a new set of credentials for modification.
1552 static int smack_cred_prepare(struct cred *new, const struct cred *old,
1555 struct task_smack *old_tsp = old->security;
1556 struct task_smack *new_tsp;
1559 new_tsp = new_task_smack(old_tsp->smk_task, old_tsp->smk_task, gfp);
1560 if (new_tsp == NULL)
1563 rc = smk_copy_rules(&new_tsp->smk_rules, &old_tsp->smk_rules, gfp);
1567 new->security = new_tsp;
1572 * smack_cred_transfer - Transfer the old credentials to the new credentials
1573 * @new: the new credentials
1574 * @old: the original credentials
1576 * Fill in a set of blank credentials from another set of credentials.
1578 static void smack_cred_transfer(struct cred *new, const struct cred *old)
1580 struct task_smack *old_tsp = old->security;
1581 struct task_smack *new_tsp = new->security;
1583 new_tsp->smk_task = old_tsp->smk_task;
1584 new_tsp->smk_forked = old_tsp->smk_task;
1585 mutex_init(&new_tsp->smk_rules_lock);
1586 INIT_LIST_HEAD(&new_tsp->smk_rules);
1589 /* cbs copy rule list */
1593 * smack_kernel_act_as - Set the subjective context in a set of credentials
1594 * @new: points to the set of credentials to be modified.
1595 * @secid: specifies the security ID to be set
1597 * Set the security data for a kernel service.
1599 static int smack_kernel_act_as(struct cred *new, u32 secid)
1601 struct task_smack *new_tsp = new->security;
1602 struct smack_known *skp = smack_from_secid(secid);
1607 new_tsp->smk_task = skp;
1612 * smack_kernel_create_files_as - Set the file creation label in a set of creds
1613 * @new: points to the set of credentials to be modified
1614 * @inode: points to the inode to use as a reference
1616 * Set the file creation context in a set of credentials to the same
1617 * as the objective context of the specified inode
1619 static int smack_kernel_create_files_as(struct cred *new,
1620 struct inode *inode)
1622 struct inode_smack *isp = inode->i_security;
1623 struct task_smack *tsp = new->security;
1625 tsp->smk_forked = smk_find_entry(isp->smk_inode);
1626 tsp->smk_task = tsp->smk_forked;
1631 * smk_curacc_on_task - helper to log task related access
1632 * @p: the task object
1633 * @access: the access requested
1634 * @caller: name of the calling function for audit
1636 * Return 0 if access is permitted
1638 static int smk_curacc_on_task(struct task_struct *p, int access,
1641 struct smk_audit_info ad;
1642 struct smack_known *skp = smk_of_task(task_security(p));
1644 smk_ad_init(&ad, caller, LSM_AUDIT_DATA_TASK);
1645 smk_ad_setfield_u_tsk(&ad, p);
1646 return smk_curacc(skp->smk_known, access, &ad);
1650 * smack_task_setpgid - Smack check on setting pgid
1651 * @p: the task object
1654 * Return 0 if write access is permitted
1656 static int smack_task_setpgid(struct task_struct *p, pid_t pgid)
1658 return smk_curacc_on_task(p, MAY_WRITE, __func__);
1662 * smack_task_getpgid - Smack access check for getpgid
1663 * @p: the object task
1665 * Returns 0 if current can read the object task, error code otherwise
1667 static int smack_task_getpgid(struct task_struct *p)
1669 return smk_curacc_on_task(p, MAY_READ, __func__);
1673 * smack_task_getsid - Smack access check for getsid
1674 * @p: the object task
1676 * Returns 0 if current can read the object task, error code otherwise
1678 static int smack_task_getsid(struct task_struct *p)
1680 return smk_curacc_on_task(p, MAY_READ, __func__);
1684 * smack_task_getsecid - get the secid of the task
1685 * @p: the object task
1686 * @secid: where to put the result
1688 * Sets the secid to contain a u32 version of the smack label.
1690 static void smack_task_getsecid(struct task_struct *p, u32 *secid)
1692 struct smack_known *skp = smk_of_task(task_security(p));
1694 *secid = skp->smk_secid;
1698 * smack_task_setnice - Smack check on setting nice
1699 * @p: the task object
1702 * Return 0 if write access is permitted
1704 static int smack_task_setnice(struct task_struct *p, int nice)
1708 rc = cap_task_setnice(p, nice);
1710 rc = smk_curacc_on_task(p, MAY_WRITE, __func__);
1715 * smack_task_setioprio - Smack check on setting ioprio
1716 * @p: the task object
1719 * Return 0 if write access is permitted
1721 static int smack_task_setioprio(struct task_struct *p, int ioprio)
1725 rc = cap_task_setioprio(p, ioprio);
1727 rc = smk_curacc_on_task(p, MAY_WRITE, __func__);
1732 * smack_task_getioprio - Smack check on reading ioprio
1733 * @p: the task object
1735 * Return 0 if read access is permitted
1737 static int smack_task_getioprio(struct task_struct *p)
1739 return smk_curacc_on_task(p, MAY_READ, __func__);
1743 * smack_task_setscheduler - Smack check on setting scheduler
1744 * @p: the task object
1748 * Return 0 if read access is permitted
1750 static int smack_task_setscheduler(struct task_struct *p)
1754 rc = cap_task_setscheduler(p);
1756 rc = smk_curacc_on_task(p, MAY_WRITE, __func__);
1761 * smack_task_getscheduler - Smack check on reading scheduler
1762 * @p: the task object
1764 * Return 0 if read access is permitted
1766 static int smack_task_getscheduler(struct task_struct *p)
1768 return smk_curacc_on_task(p, MAY_READ, __func__);
1772 * smack_task_movememory - Smack check on moving memory
1773 * @p: the task object
1775 * Return 0 if write access is permitted
1777 static int smack_task_movememory(struct task_struct *p)
1779 return smk_curacc_on_task(p, MAY_WRITE, __func__);
1783 * smack_task_kill - Smack check on signal delivery
1784 * @p: the task object
1787 * @secid: identifies the smack to use in lieu of current's
1789 * Return 0 if write access is permitted
1791 * The secid behavior is an artifact of an SELinux hack
1792 * in the USB code. Someday it may go away.
1794 static int smack_task_kill(struct task_struct *p, struct siginfo *info,
1797 struct smk_audit_info ad;
1798 struct smack_known *skp;
1799 struct smack_known *tkp = smk_of_task(task_security(p));
1801 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1802 smk_ad_setfield_u_tsk(&ad, p);
1804 * Sending a signal requires that the sender
1805 * can write the receiver.
1808 return smk_curacc(tkp->smk_known, MAY_WRITE, &ad);
1810 * If the secid isn't 0 we're dealing with some USB IO
1811 * specific behavior. This is not clean. For one thing
1812 * we can't take privilege into account.
1814 skp = smack_from_secid(secid);
1815 return smk_access(skp, tkp->smk_known, MAY_WRITE, &ad);
1819 * smack_task_wait - Smack access check for waiting
1820 * @p: task to wait for
1824 static int smack_task_wait(struct task_struct *p)
1827 * Allow the operation to succeed.
1829 * In userless environments (e.g. phones) programs
1830 * get marked with SMACK64EXEC and even if the parent
1831 * and child shouldn't be talking the parent still
1832 * may expect to know when the child exits.
1838 * smack_task_to_inode - copy task smack into the inode blob
1839 * @p: task to copy from
1840 * @inode: inode to copy to
1842 * Sets the smack pointer in the inode security blob
1844 static void smack_task_to_inode(struct task_struct *p, struct inode *inode)
1846 struct inode_smack *isp = inode->i_security;
1847 struct smack_known *skp = smk_of_task(task_security(p));
1849 isp->smk_inode = skp->smk_known;
1857 * smack_sk_alloc_security - Allocate a socket blob
1860 * @gfp_flags: memory allocation flags
1862 * Assign Smack pointers to current
1864 * Returns 0 on success, -ENOMEM is there's no memory
1866 static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags)
1868 struct smack_known *skp = smk_of_current();
1869 struct socket_smack *ssp;
1871 ssp = kzalloc(sizeof(struct socket_smack), gfp_flags);
1877 ssp->smk_packet = NULL;
1879 sk->sk_security = ssp;
1885 * smack_sk_free_security - Free a socket blob
1888 * Clears the blob pointer
1890 static void smack_sk_free_security(struct sock *sk)
1892 kfree(sk->sk_security);
1896 * smack_host_label - check host based restrictions
1897 * @sip: the object end
1899 * looks for host based access restrictions
1901 * This version will only be appropriate for really small sets of single label
1902 * hosts. The caller is responsible for ensuring that the RCU read lock is
1903 * taken before calling this function.
1905 * Returns the label of the far end or NULL if it's not special.
1907 static char *smack_host_label(struct sockaddr_in *sip)
1909 struct smk_netlbladdr *snp;
1910 struct in_addr *siap = &sip->sin_addr;
1912 if (siap->s_addr == 0)
1915 list_for_each_entry_rcu(snp, &smk_netlbladdr_list, list)
1917 * we break after finding the first match because
1918 * the list is sorted from longest to shortest mask
1919 * so we have found the most specific match
1921 if ((&snp->smk_host.sin_addr)->s_addr ==
1922 (siap->s_addr & (&snp->smk_mask)->s_addr)) {
1923 /* we have found the special CIPSO option */
1924 if (snp->smk_label == smack_cipso_option)
1926 return snp->smk_label;
1933 * smack_netlabel - Set the secattr on a socket
1935 * @labeled: socket label scheme
1937 * Convert the outbound smack value (smk_out) to a
1938 * secattr and attach it to the socket.
1940 * Returns 0 on success or an error code
1942 static int smack_netlabel(struct sock *sk, int labeled)
1944 struct smack_known *skp;
1945 struct socket_smack *ssp = sk->sk_security;
1949 * Usually the netlabel code will handle changing the
1950 * packet labeling based on the label.
1951 * The case of a single label host is different, because
1952 * a single label host should never get a labeled packet
1953 * even though the label is usually associated with a packet
1957 bh_lock_sock_nested(sk);
1959 if (ssp->smk_out == smack_net_ambient ||
1960 labeled == SMACK_UNLABELED_SOCKET)
1961 netlbl_sock_delattr(sk);
1964 rc = netlbl_sock_setattr(sk, sk->sk_family, &skp->smk_netlabel);
1974 * smack_netlbel_send - Set the secattr on a socket and perform access checks
1976 * @sap: the destination address
1978 * Set the correct secattr for the given socket based on the destination
1979 * address and perform any outbound access checks needed.
1981 * Returns 0 on success or an error code.
1984 static int smack_netlabel_send(struct sock *sk, struct sockaddr_in *sap)
1986 struct smack_known *skp;
1990 struct socket_smack *ssp = sk->sk_security;
1991 struct smk_audit_info ad;
1994 hostsp = smack_host_label(sap);
1995 if (hostsp != NULL) {
1997 struct lsm_network_audit net;
1999 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
2000 ad.a.u.net->family = sap->sin_family;
2001 ad.a.u.net->dport = sap->sin_port;
2002 ad.a.u.net->v4info.daddr = sap->sin_addr.s_addr;
2004 sk_lbl = SMACK_UNLABELED_SOCKET;
2006 rc = smk_access(skp, hostsp, MAY_WRITE, &ad);
2008 sk_lbl = SMACK_CIPSO_SOCKET;
2015 return smack_netlabel(sk, sk_lbl);
2019 * smk_ipv6_port_label - Smack port access table management
2023 * Create or update the port list entry
2025 static void smk_ipv6_port_label(struct socket *sock, struct sockaddr *address)
2027 struct sock *sk = sock->sk;
2028 struct sockaddr_in6 *addr6;
2029 struct socket_smack *ssp = sock->sk->sk_security;
2030 struct smk_port_label *spp;
2031 unsigned short port = 0;
2033 if (address == NULL) {
2035 * This operation is changing the Smack information
2036 * on the bound socket. Take the changes to the port
2039 list_for_each_entry(spp, &smk_ipv6_port_list, list) {
2040 if (sk != spp->smk_sock)
2042 spp->smk_in = ssp->smk_in;
2043 spp->smk_out = ssp->smk_out;
2047 * A NULL address is only used for updating existing
2048 * bound entries. If there isn't one, it's OK.
2053 addr6 = (struct sockaddr_in6 *)address;
2054 port = ntohs(addr6->sin6_port);
2056 * This is a special case that is safely ignored.
2062 * Look for an existing port list entry.
2063 * This is an indication that a port is getting reused.
2065 list_for_each_entry(spp, &smk_ipv6_port_list, list) {
2066 if (spp->smk_port != port)
2068 spp->smk_port = port;
2070 spp->smk_in = ssp->smk_in;
2071 spp->smk_out = ssp->smk_out;
2076 * A new port entry is required.
2078 spp = kzalloc(sizeof(*spp), GFP_KERNEL);
2082 spp->smk_port = port;
2084 spp->smk_in = ssp->smk_in;
2085 spp->smk_out = ssp->smk_out;
2087 list_add(&spp->list, &smk_ipv6_port_list);
2092 * smk_ipv6_port_check - check Smack port access
2096 * Create or update the port list entry
2098 static int smk_ipv6_port_check(struct sock *sk, struct sockaddr_in6 *address,
2103 struct smk_port_label *spp;
2104 struct socket_smack *ssp = sk->sk_security;
2105 struct smack_known *skp;
2106 unsigned short port = 0;
2108 struct smk_audit_info ad;
2110 struct lsm_network_audit net;
2113 if (act == SMK_RECEIVING) {
2114 skp = smack_net_ambient;
2115 object = ssp->smk_in->smk_known;
2118 object = smack_net_ambient->smk_known;
2122 * Get the IP address and port from the address.
2124 port = ntohs(address->sin6_port);
2125 bep = (__be16 *)(&address->sin6_addr);
2126 be32p = (__be32 *)(&address->sin6_addr);
2129 * It's remote, so port lookup does no good.
2131 if (be32p[0] || be32p[1] || be32p[2] || bep[6] || ntohs(bep[7]) != 1)
2135 * It's local so the send check has to have passed.
2137 if (act == SMK_RECEIVING) {
2138 skp = &smack_known_web;
2142 list_for_each_entry(spp, &smk_ipv6_port_list, list) {
2143 if (spp->smk_port != port)
2145 object = spp->smk_in->smk_known;
2146 if (act == SMK_CONNECTING)
2147 ssp->smk_packet = spp->smk_out;
2154 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
2155 ad.a.u.net->family = sk->sk_family;
2156 ad.a.u.net->dport = port;
2157 if (act == SMK_RECEIVING)
2158 ad.a.u.net->v6info.saddr = address->sin6_addr;
2160 ad.a.u.net->v6info.daddr = address->sin6_addr;
2162 return smk_access(skp, object, MAY_WRITE, &ad);
2166 * smack_inode_setsecurity - set smack xattrs
2167 * @inode: the object
2168 * @name: attribute name
2169 * @value: attribute value
2170 * @size: size of the attribute
2173 * Sets the named attribute in the appropriate blob
2175 * Returns 0 on success, or an error code
2177 static int smack_inode_setsecurity(struct inode *inode, const char *name,
2178 const void *value, size_t size, int flags)
2180 struct smack_known *skp;
2181 struct inode_smack *nsp = inode->i_security;
2182 struct socket_smack *ssp;
2183 struct socket *sock;
2186 if (value == NULL || size > SMK_LONGLABEL || size == 0)
2189 skp = smk_import_entry(value, size);
2193 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
2194 nsp->smk_inode = skp->smk_known;
2195 nsp->smk_flags |= SMK_INODE_INSTANT;
2199 * The rest of the Smack xattrs are only on sockets.
2201 if (inode->i_sb->s_magic != SOCKFS_MAGIC)
2204 sock = SOCKET_I(inode);
2205 if (sock == NULL || sock->sk == NULL)
2208 ssp = sock->sk->sk_security;
2210 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
2212 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0) {
2214 if (sock->sk->sk_family == PF_INET) {
2215 rc = smack_netlabel(sock->sk, SMACK_CIPSO_SOCKET);
2218 "Smack: \"%s\" netlbl error %d.\n",
2224 if (sock->sk->sk_family == PF_INET6)
2225 smk_ipv6_port_label(sock, NULL);
2231 * smack_socket_post_create - finish socket setup
2233 * @family: protocol family
2238 * Sets the netlabel information on the socket
2240 * Returns 0 on success, and error code otherwise
2242 static int smack_socket_post_create(struct socket *sock, int family,
2243 int type, int protocol, int kern)
2245 if (family != PF_INET || sock->sk == NULL)
2248 * Set the outbound netlbl.
2250 return smack_netlabel(sock->sk, SMACK_CIPSO_SOCKET);
2254 * smack_socket_bind - record port binding information.
2256 * @address: the port address
2257 * @addrlen: size of the address
2259 * Records the label bound to a port.
2263 static int smack_socket_bind(struct socket *sock, struct sockaddr *address,
2266 if (sock->sk != NULL && sock->sk->sk_family == PF_INET6)
2267 smk_ipv6_port_label(sock, address);
2273 * smack_socket_connect - connect access check
2275 * @sap: the other end
2276 * @addrlen: size of sap
2278 * Verifies that a connection may be possible
2280 * Returns 0 on success, and error code otherwise
2282 static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
2287 if (sock->sk == NULL)
2290 switch (sock->sk->sk_family) {
2292 if (addrlen < sizeof(struct sockaddr_in))
2294 rc = smack_netlabel_send(sock->sk, (struct sockaddr_in *)sap);
2297 if (addrlen < sizeof(struct sockaddr_in6))
2299 rc = smk_ipv6_port_check(sock->sk, (struct sockaddr_in6 *)sap,
2307 * smack_flags_to_may - convert S_ to MAY_ values
2308 * @flags: the S_ value
2310 * Returns the equivalent MAY_ value
2312 static int smack_flags_to_may(int flags)
2316 if (flags & S_IRUGO)
2318 if (flags & S_IWUGO)
2320 if (flags & S_IXUGO)
2327 * smack_msg_msg_alloc_security - Set the security blob for msg_msg
2332 static int smack_msg_msg_alloc_security(struct msg_msg *msg)
2334 struct smack_known *skp = smk_of_current();
2336 msg->security = skp->smk_known;
2341 * smack_msg_msg_free_security - Clear the security blob for msg_msg
2344 * Clears the blob pointer
2346 static void smack_msg_msg_free_security(struct msg_msg *msg)
2348 msg->security = NULL;
2352 * smack_of_shm - the smack pointer for the shm
2355 * Returns a pointer to the smack value
2357 static char *smack_of_shm(struct shmid_kernel *shp)
2359 return (char *)shp->shm_perm.security;
2363 * smack_shm_alloc_security - Set the security blob for shm
2368 static int smack_shm_alloc_security(struct shmid_kernel *shp)
2370 struct kern_ipc_perm *isp = &shp->shm_perm;
2371 struct smack_known *skp = smk_of_current();
2373 isp->security = skp->smk_known;
2378 * smack_shm_free_security - Clear the security blob for shm
2381 * Clears the blob pointer
2383 static void smack_shm_free_security(struct shmid_kernel *shp)
2385 struct kern_ipc_perm *isp = &shp->shm_perm;
2387 isp->security = NULL;
2391 * smk_curacc_shm : check if current has access on shm
2393 * @access : access requested
2395 * Returns 0 if current has the requested access, error code otherwise
2397 static int smk_curacc_shm(struct shmid_kernel *shp, int access)
2399 char *ssp = smack_of_shm(shp);
2400 struct smk_audit_info ad;
2403 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2404 ad.a.u.ipc_id = shp->shm_perm.id;
2406 return smk_curacc(ssp, access, &ad);
2410 * smack_shm_associate - Smack access check for shm
2412 * @shmflg: access requested
2414 * Returns 0 if current has the requested access, error code otherwise
2416 static int smack_shm_associate(struct shmid_kernel *shp, int shmflg)
2420 may = smack_flags_to_may(shmflg);
2421 return smk_curacc_shm(shp, may);
2425 * smack_shm_shmctl - Smack access check for shm
2427 * @cmd: what it wants to do
2429 * Returns 0 if current has the requested access, error code otherwise
2431 static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd)
2444 may = MAY_READWRITE;
2449 * System level information.
2455 return smk_curacc_shm(shp, may);
2459 * smack_shm_shmat - Smack access for shmat
2462 * @shmflg: access requested
2464 * Returns 0 if current has the requested access, error code otherwise
2466 static int smack_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr,
2471 may = smack_flags_to_may(shmflg);
2472 return smk_curacc_shm(shp, may);
2476 * smack_of_sem - the smack pointer for the sem
2479 * Returns a pointer to the smack value
2481 static char *smack_of_sem(struct sem_array *sma)
2483 return (char *)sma->sem_perm.security;
2487 * smack_sem_alloc_security - Set the security blob for sem
2492 static int smack_sem_alloc_security(struct sem_array *sma)
2494 struct kern_ipc_perm *isp = &sma->sem_perm;
2495 struct smack_known *skp = smk_of_current();
2497 isp->security = skp->smk_known;
2502 * smack_sem_free_security - Clear the security blob for sem
2505 * Clears the blob pointer
2507 static void smack_sem_free_security(struct sem_array *sma)
2509 struct kern_ipc_perm *isp = &sma->sem_perm;
2511 isp->security = NULL;
2515 * smk_curacc_sem : check if current has access on sem
2517 * @access : access requested
2519 * Returns 0 if current has the requested access, error code otherwise
2521 static int smk_curacc_sem(struct sem_array *sma, int access)
2523 char *ssp = smack_of_sem(sma);
2524 struct smk_audit_info ad;
2527 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2528 ad.a.u.ipc_id = sma->sem_perm.id;
2530 return smk_curacc(ssp, access, &ad);
2534 * smack_sem_associate - Smack access check for sem
2536 * @semflg: access requested
2538 * Returns 0 if current has the requested access, error code otherwise
2540 static int smack_sem_associate(struct sem_array *sma, int semflg)
2544 may = smack_flags_to_may(semflg);
2545 return smk_curacc_sem(sma, may);
2549 * smack_sem_shmctl - Smack access check for sem
2551 * @cmd: what it wants to do
2553 * Returns 0 if current has the requested access, error code otherwise
2555 static int smack_sem_semctl(struct sem_array *sma, int cmd)
2573 may = MAY_READWRITE;
2578 * System level information
2585 return smk_curacc_sem(sma, may);
2589 * smack_sem_semop - Smack checks of semaphore operations
2595 * Treated as read and write in all cases.
2597 * Returns 0 if access is allowed, error code otherwise
2599 static int smack_sem_semop(struct sem_array *sma, struct sembuf *sops,
2600 unsigned nsops, int alter)
2602 return smk_curacc_sem(sma, MAY_READWRITE);
2606 * smack_msg_alloc_security - Set the security blob for msg
2611 static int smack_msg_queue_alloc_security(struct msg_queue *msq)
2613 struct kern_ipc_perm *kisp = &msq->q_perm;
2614 struct smack_known *skp = smk_of_current();
2616 kisp->security = skp->smk_known;
2621 * smack_msg_free_security - Clear the security blob for msg
2624 * Clears the blob pointer
2626 static void smack_msg_queue_free_security(struct msg_queue *msq)
2628 struct kern_ipc_perm *kisp = &msq->q_perm;
2630 kisp->security = NULL;
2634 * smack_of_msq - the smack pointer for the msq
2637 * Returns a pointer to the smack value
2639 static char *smack_of_msq(struct msg_queue *msq)
2641 return (char *)msq->q_perm.security;
2645 * smk_curacc_msq : helper to check if current has access on msq
2647 * @access : access requested
2649 * return 0 if current has access, error otherwise
2651 static int smk_curacc_msq(struct msg_queue *msq, int access)
2653 char *msp = smack_of_msq(msq);
2654 struct smk_audit_info ad;
2657 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2658 ad.a.u.ipc_id = msq->q_perm.id;
2660 return smk_curacc(msp, access, &ad);
2664 * smack_msg_queue_associate - Smack access check for msg_queue
2666 * @msqflg: access requested
2668 * Returns 0 if current has the requested access, error code otherwise
2670 static int smack_msg_queue_associate(struct msg_queue *msq, int msqflg)
2674 may = smack_flags_to_may(msqflg);
2675 return smk_curacc_msq(msq, may);
2679 * smack_msg_queue_msgctl - Smack access check for msg_queue
2681 * @cmd: what it wants to do
2683 * Returns 0 if current has the requested access, error code otherwise
2685 static int smack_msg_queue_msgctl(struct msg_queue *msq, int cmd)
2696 may = MAY_READWRITE;
2701 * System level information
2708 return smk_curacc_msq(msq, may);
2712 * smack_msg_queue_msgsnd - Smack access check for msg_queue
2715 * @msqflg: access requested
2717 * Returns 0 if current has the requested access, error code otherwise
2719 static int smack_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
2724 may = smack_flags_to_may(msqflg);
2725 return smk_curacc_msq(msq, may);
2729 * smack_msg_queue_msgsnd - Smack access check for msg_queue
2736 * Returns 0 if current has read and write access, error code otherwise
2738 static int smack_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
2739 struct task_struct *target, long type, int mode)
2741 return smk_curacc_msq(msq, MAY_READWRITE);
2745 * smack_ipc_permission - Smack access for ipc_permission()
2746 * @ipp: the object permissions
2747 * @flag: access requested
2749 * Returns 0 if current has read and write access, error code otherwise
2751 static int smack_ipc_permission(struct kern_ipc_perm *ipp, short flag)
2753 char *isp = ipp->security;
2754 int may = smack_flags_to_may(flag);
2755 struct smk_audit_info ad;
2758 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2759 ad.a.u.ipc_id = ipp->id;
2761 return smk_curacc(isp, may, &ad);
2765 * smack_ipc_getsecid - Extract smack security id
2766 * @ipp: the object permissions
2767 * @secid: where result will be saved
2769 static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, u32 *secid)
2771 char *smack = ipp->security;
2773 *secid = smack_to_secid(smack);
2777 * smack_d_instantiate - Make sure the blob is correct on an inode
2778 * @opt_dentry: dentry where inode will be attached
2779 * @inode: the object
2781 * Set the inode's security blob if it hasn't been done already.
2783 static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
2785 struct super_block *sbp;
2786 struct superblock_smack *sbsp;
2787 struct inode_smack *isp;
2788 struct smack_known *skp;
2789 struct smack_known *ckp = smk_of_current();
2791 char trattr[TRANS_TRUE_SIZE];
2799 isp = inode->i_security;
2801 mutex_lock(&isp->smk_lock);
2803 * If the inode is already instantiated
2804 * take the quick way out
2806 if (isp->smk_flags & SMK_INODE_INSTANT)
2810 sbsp = sbp->s_security;
2812 * We're going to use the superblock default label
2813 * if there's no label on the file.
2815 final = sbsp->smk_default;
2818 * If this is the root inode the superblock
2819 * may be in the process of initialization.
2820 * If that is the case use the root value out
2821 * of the superblock.
2823 if (opt_dentry->d_parent == opt_dentry) {
2824 isp->smk_inode = sbsp->smk_root;
2825 isp->smk_flags |= SMK_INODE_INSTANT;
2830 * This is pretty hackish.
2831 * Casey says that we shouldn't have to do
2832 * file system specific code, but it does help
2833 * with keeping it simple.
2835 switch (sbp->s_magic) {
2838 * Casey says that it's a little embarrassing
2839 * that the smack file system doesn't do
2840 * extended attributes.
2842 final = smack_known_star.smk_known;
2846 * Casey says pipes are easy (?)
2848 final = smack_known_star.smk_known;
2850 case DEVPTS_SUPER_MAGIC:
2852 * devpts seems content with the label of the task.
2853 * Programs that change smack have to treat the
2856 final = ckp->smk_known;
2860 * Socket access is controlled by the socket
2861 * structures associated with the task involved.
2863 final = smack_known_star.smk_known;
2865 case PROC_SUPER_MAGIC:
2867 * Casey says procfs appears not to care.
2868 * The superblock default suffices.
2873 * Device labels should come from the filesystem,
2874 * but watch out, because they're volitile,
2875 * getting recreated on every reboot.
2877 final = smack_known_star.smk_known;
2881 * If a smack value has been set we want to use it,
2882 * but since tmpfs isn't giving us the opportunity
2883 * to set mount options simulate setting the
2884 * superblock default.
2888 * This isn't an understood special case.
2889 * Get the value from the xattr.
2893 * UNIX domain sockets use lower level socket data.
2895 if (S_ISSOCK(inode->i_mode)) {
2896 final = smack_known_star.smk_known;
2900 * No xattr support means, alas, no SMACK label.
2901 * Use the aforeapplied default.
2902 * It would be curious if the label of the task
2903 * does not match that assigned.
2905 if (inode->i_op->getxattr == NULL)
2908 * Get the dentry for xattr.
2910 dp = dget(opt_dentry);
2911 skp = smk_fetch(XATTR_NAME_SMACK, inode, dp);
2913 final = skp->smk_known;
2916 * Transmuting directory
2918 if (S_ISDIR(inode->i_mode)) {
2920 * If this is a new directory and the label was
2921 * transmuted when the inode was initialized
2922 * set the transmute attribute on the directory
2923 * and mark the inode.
2925 * If there is a transmute attribute on the
2926 * directory mark the inode.
2928 if (isp->smk_flags & SMK_INODE_CHANGED) {
2929 isp->smk_flags &= ~SMK_INODE_CHANGED;
2930 rc = inode->i_op->setxattr(dp,
2931 XATTR_NAME_SMACKTRANSMUTE,
2932 TRANS_TRUE, TRANS_TRUE_SIZE,
2935 rc = inode->i_op->getxattr(dp,
2936 XATTR_NAME_SMACKTRANSMUTE, trattr,
2938 if (rc >= 0 && strncmp(trattr, TRANS_TRUE,
2939 TRANS_TRUE_SIZE) != 0)
2943 transflag = SMK_INODE_TRANSMUTE;
2946 * Don't let the exec or mmap label be "*" or "@".
2948 skp = smk_fetch(XATTR_NAME_SMACKEXEC, inode, dp);
2949 if (skp == &smack_known_star || skp == &smack_known_web)
2951 isp->smk_task = skp;
2952 skp = smk_fetch(XATTR_NAME_SMACKMMAP, inode, dp);
2953 if (skp == &smack_known_star || skp == &smack_known_web)
2955 isp->smk_mmap = skp;
2962 isp->smk_inode = ckp->smk_known;
2964 isp->smk_inode = final;
2966 isp->smk_flags |= (SMK_INODE_INSTANT | transflag);
2969 mutex_unlock(&isp->smk_lock);
2974 * smack_getprocattr - Smack process attribute access
2975 * @p: the object task
2976 * @name: the name of the attribute in /proc/.../attr
2977 * @value: where to put the result
2979 * Places a copy of the task Smack into value
2981 * Returns the length of the smack label or an error code
2983 static int smack_getprocattr(struct task_struct *p, char *name, char **value)
2985 struct smack_known *skp = smk_of_task(task_security(p));
2989 if (strcmp(name, "current") != 0)
2992 cp = kstrdup(skp->smk_known, GFP_KERNEL);
3002 * smack_setprocattr - Smack process attribute setting
3003 * @p: the object task
3004 * @name: the name of the attribute in /proc/.../attr
3005 * @value: the value to set
3006 * @size: the size of the value
3008 * Sets the Smack value of the task. Only setting self
3009 * is permitted and only with privilege
3011 * Returns the length of the smack label or an error code
3013 static int smack_setprocattr(struct task_struct *p, char *name,
3014 void *value, size_t size)
3016 struct task_smack *tsp;
3018 struct smack_known *skp;
3021 * Changing another process' Smack value is too dangerous
3022 * and supports no sane use case.
3027 if (!smack_privileged(CAP_MAC_ADMIN))
3030 if (value == NULL || size == 0 || size >= SMK_LONGLABEL)
3033 if (strcmp(name, "current") != 0)
3036 skp = smk_import_entry(value, size);
3041 * No process is ever allowed the web ("@") label.
3043 if (skp == &smack_known_web)
3046 new = prepare_creds();
3050 tsp = new->security;
3051 tsp->smk_task = skp;
3058 * smack_unix_stream_connect - Smack access on UDS
3060 * @other: the other sock
3063 * Return 0 if a subject with the smack of sock could access
3064 * an object with the smack of other, otherwise an error code
3066 static int smack_unix_stream_connect(struct sock *sock,
3067 struct sock *other, struct sock *newsk)
3069 struct smack_known *skp;
3070 struct smack_known *okp;
3071 struct socket_smack *ssp = sock->sk_security;
3072 struct socket_smack *osp = other->sk_security;
3073 struct socket_smack *nsp = newsk->sk_security;
3074 struct smk_audit_info ad;
3077 struct lsm_network_audit net;
3080 if (!smack_privileged(CAP_MAC_OVERRIDE)) {
3084 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
3085 smk_ad_setfield_u_net_sk(&ad, other);
3087 rc = smk_access(skp, okp->smk_known, MAY_WRITE, &ad);
3089 rc = smk_access(okp, okp->smk_known, MAY_WRITE, NULL);
3093 * Cross reference the peer labels for SO_PEERSEC.
3096 nsp->smk_packet = ssp->smk_out;
3097 ssp->smk_packet = osp->smk_out;
3104 * smack_unix_may_send - Smack access on UDS
3106 * @other: the other socket
3108 * Return 0 if a subject with the smack of sock could access
3109 * an object with the smack of other, otherwise an error code
3111 static int smack_unix_may_send(struct socket *sock, struct socket *other)
3113 struct socket_smack *ssp = sock->sk->sk_security;
3114 struct socket_smack *osp = other->sk->sk_security;
3115 struct smack_known *skp;
3116 struct smk_audit_info ad;
3119 struct lsm_network_audit net;
3121 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
3122 smk_ad_setfield_u_net_sk(&ad, other->sk);
3125 if (smack_privileged(CAP_MAC_OVERRIDE))
3129 return smk_access(skp, osp->smk_in->smk_known, MAY_WRITE, &ad);
3133 * smack_socket_sendmsg - Smack check based on destination host
3136 * @size: the size of the message
3138 * Return 0 if the current subject can write to the destination host.
3139 * For IPv4 this is only a question if the destination is a single label host.
3140 * For IPv6 this is a check against the label of the port.
3142 static int smack_socket_sendmsg(struct socket *sock, struct msghdr *msg,
3145 struct sockaddr_in *sip = (struct sockaddr_in *) msg->msg_name;
3146 struct sockaddr_in6 *sap = (struct sockaddr_in6 *) msg->msg_name;
3150 * Perfectly reasonable for this to be NULL
3155 switch (sip->sin_family) {
3157 rc = smack_netlabel_send(sock->sk, sip);
3160 rc = smk_ipv6_port_check(sock->sk, sap, SMK_SENDING);
3167 * smack_from_secattr - Convert a netlabel attr.mls.lvl/attr.mls.cat pair to smack
3168 * @sap: netlabel secattr
3169 * @ssp: socket security information
3171 * Returns a pointer to a Smack label entry found on the label list.
3173 static struct smack_known *smack_from_secattr(struct netlbl_lsm_secattr *sap,
3174 struct socket_smack *ssp)
3176 struct smack_known *skp;
3181 if ((sap->flags & NETLBL_SECATTR_MLS_LVL) != 0) {
3183 * Looks like a CIPSO packet.
3184 * If there are flags but no level netlabel isn't
3185 * behaving the way we expect it to.
3187 * Look it up in the label table
3188 * Without guidance regarding the smack value
3189 * for the packet fall back on the network
3193 list_for_each_entry(skp, &smack_known_list, list) {
3194 if (sap->attr.mls.lvl != skp->smk_netlabel.attr.mls.lvl)
3197 * Compare the catsets. Use the netlbl APIs.
3199 if ((sap->flags & NETLBL_SECATTR_MLS_CAT) == 0) {
3200 if ((skp->smk_netlabel.flags &
3201 NETLBL_SECATTR_MLS_CAT) == 0)
3205 for (acat = -1, kcat = -1; acat == kcat; ) {
3206 acat = netlbl_secattr_catmap_walk(
3207 sap->attr.mls.cat, acat + 1);
3208 kcat = netlbl_secattr_catmap_walk(
3209 skp->smk_netlabel.attr.mls.cat,
3211 if (acat < 0 || kcat < 0)
3224 if (ssp != NULL && ssp->smk_in == &smack_known_star)
3225 return &smack_known_web;
3226 return &smack_known_star;
3228 if ((sap->flags & NETLBL_SECATTR_SECID) != 0) {
3230 * Looks like a fallback, which gives us a secid.
3232 skp = smack_from_secid(sap->attr.secid);
3234 * This has got to be a bug because it is
3235 * impossible to specify a fallback without
3236 * specifying the label, which will ensure
3237 * it has a secid, and the only way to get a
3238 * secid is from a fallback.
3240 BUG_ON(skp == NULL);
3244 * Without guidance regarding the smack value
3245 * for the packet fall back on the network
3248 return smack_net_ambient;
3251 static int smk_skb_to_addr_ipv6(struct sk_buff *skb, struct sockaddr_in6 *sip)
3255 int proto = -EINVAL;
3256 struct ipv6hdr _ipv6h;
3257 struct ipv6hdr *ip6;
3259 struct tcphdr _tcph, *th;
3260 struct udphdr _udph, *uh;
3261 struct dccp_hdr _dccph, *dh;
3265 offset = skb_network_offset(skb);
3266 ip6 = skb_header_pointer(skb, offset, sizeof(_ipv6h), &_ipv6h);
3269 sip->sin6_addr = ip6->saddr;
3271 nexthdr = ip6->nexthdr;
3272 offset += sizeof(_ipv6h);
3273 offset = ipv6_skip_exthdr(skb, offset, &nexthdr, &frag_off);
3280 th = skb_header_pointer(skb, offset, sizeof(_tcph), &_tcph);
3282 sip->sin6_port = th->source;
3285 uh = skb_header_pointer(skb, offset, sizeof(_udph), &_udph);
3287 sip->sin6_port = uh->source;
3290 dh = skb_header_pointer(skb, offset, sizeof(_dccph), &_dccph);
3292 sip->sin6_port = dh->dccph_sport;
3299 * smack_socket_sock_rcv_skb - Smack packet delivery access check
3303 * Returns 0 if the packet should be delivered, an error code otherwise
3305 static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
3307 struct netlbl_lsm_secattr secattr;
3308 struct socket_smack *ssp = sk->sk_security;
3309 struct smack_known *skp;
3310 struct sockaddr_in6 sadd;
3312 struct smk_audit_info ad;
3314 struct lsm_network_audit net;
3316 switch (sk->sk_family) {
3319 * Translate what netlabel gave us.
3321 netlbl_secattr_init(&secattr);
3323 rc = netlbl_skbuff_getattr(skb, sk->sk_family, &secattr);
3325 skp = smack_from_secattr(&secattr, ssp);
3327 skp = smack_net_ambient;
3329 netlbl_secattr_destroy(&secattr);
3332 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
3333 ad.a.u.net->family = sk->sk_family;
3334 ad.a.u.net->netif = skb->skb_iif;
3335 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
3338 * Receiving a packet requires that the other end
3339 * be able to write here. Read access is not required.
3340 * This is the simplist possible security model
3343 rc = smk_access(skp, ssp->smk_in->smk_known, MAY_WRITE, &ad);
3345 netlbl_skbuff_err(skb, rc, 0);
3348 rc = smk_skb_to_addr_ipv6(skb, &sadd);
3349 if (rc == IPPROTO_UDP || rc == IPPROTO_TCP)
3350 rc = smk_ipv6_port_check(sk, &sadd, SMK_RECEIVING);
3359 * smack_socket_getpeersec_stream - pull in packet label
3361 * @optval: user's destination
3362 * @optlen: size thereof
3365 * returns zero on success, an error code otherwise
3367 static int smack_socket_getpeersec_stream(struct socket *sock,
3368 char __user *optval,
3369 int __user *optlen, unsigned len)
3371 struct socket_smack *ssp;
3376 ssp = sock->sk->sk_security;
3377 if (ssp->smk_packet != NULL) {
3378 rcp = ssp->smk_packet->smk_known;
3379 slen = strlen(rcp) + 1;
3384 else if (copy_to_user(optval, rcp, slen) != 0)
3387 if (put_user(slen, optlen) != 0)
3395 * smack_socket_getpeersec_dgram - pull in packet label
3396 * @sock: the peer socket
3398 * @secid: pointer to where to put the secid of the packet
3400 * Sets the netlabel socket state on sk from parent
3402 static int smack_socket_getpeersec_dgram(struct socket *sock,
3403 struct sk_buff *skb, u32 *secid)
3406 struct netlbl_lsm_secattr secattr;
3407 struct socket_smack *ssp = NULL;
3408 struct smack_known *skp;
3409 int family = PF_UNSPEC;
3410 u32 s = 0; /* 0 is the invalid secid */
3414 if (skb->protocol == htons(ETH_P_IP))
3416 else if (skb->protocol == htons(ETH_P_IPV6))
3419 if (family == PF_UNSPEC && sock != NULL)
3420 family = sock->sk->sk_family;
3422 if (family == PF_UNIX) {
3423 ssp = sock->sk->sk_security;
3424 s = ssp->smk_out->smk_secid;
3425 } else if (family == PF_INET || family == PF_INET6) {
3427 * Translate what netlabel gave us.
3429 if (sock != NULL && sock->sk != NULL)
3430 ssp = sock->sk->sk_security;
3431 netlbl_secattr_init(&secattr);
3432 rc = netlbl_skbuff_getattr(skb, family, &secattr);
3434 skp = smack_from_secattr(&secattr, ssp);
3437 netlbl_secattr_destroy(&secattr);
3446 * smack_sock_graft - Initialize a newly created socket with an existing sock
3448 * @parent: parent socket
3450 * Set the smk_{in,out} state of an existing sock based on the process that
3451 * is creating the new socket.
3453 static void smack_sock_graft(struct sock *sk, struct socket *parent)
3455 struct socket_smack *ssp;
3456 struct smack_known *skp = smk_of_current();
3459 (sk->sk_family != PF_INET && sk->sk_family != PF_INET6))
3462 ssp = sk->sk_security;
3465 /* cssp->smk_packet is already set in smack_inet_csk_clone() */
3469 * smack_inet_conn_request - Smack access check on connect
3470 * @sk: socket involved
3474 * Returns 0 if a task with the packet label could write to
3475 * the socket, otherwise an error code
3477 static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
3478 struct request_sock *req)
3480 u16 family = sk->sk_family;
3481 struct smack_known *skp;
3482 struct socket_smack *ssp = sk->sk_security;
3483 struct netlbl_lsm_secattr secattr;
3484 struct sockaddr_in addr;
3488 struct smk_audit_info ad;
3490 struct lsm_network_audit net;
3493 if (family == PF_INET6) {
3495 * Handle mapped IPv4 packets arriving
3496 * via IPv6 sockets. Don't set up netlabel
3497 * processing on IPv6.
3499 if (skb->protocol == htons(ETH_P_IP))
3505 netlbl_secattr_init(&secattr);
3506 rc = netlbl_skbuff_getattr(skb, family, &secattr);
3508 skp = smack_from_secattr(&secattr, ssp);
3510 skp = &smack_known_huh;
3511 netlbl_secattr_destroy(&secattr);
3514 smk_ad_init_net(&ad, __func__, LSM_AUDIT_DATA_NET, &net);
3515 ad.a.u.net->family = family;
3516 ad.a.u.net->netif = skb->skb_iif;
3517 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
3520 * Receiving a packet requires that the other end be able to write
3521 * here. Read access is not required.
3523 rc = smk_access(skp, ssp->smk_in->smk_known, MAY_WRITE, &ad);
3528 * Save the peer's label in the request_sock so we can later setup
3529 * smk_packet in the child socket so that SO_PEERCRED can report it.
3531 req->peer_secid = skp->smk_secid;
3534 * We need to decide if we want to label the incoming connection here
3535 * if we do we only need to label the request_sock and the stack will
3536 * propagate the wire-label to the sock when it is created.
3539 addr.sin_addr.s_addr = hdr->saddr;
3541 hsp = smack_host_label(&addr);
3545 rc = netlbl_req_setattr(req, &skp->smk_netlabel);
3547 netlbl_req_delattr(req);
3553 * smack_inet_csk_clone - Copy the connection information to the new socket
3554 * @sk: the new socket
3555 * @req: the connection's request_sock
3557 * Transfer the connection's peer label to the newly created socket.
3559 static void smack_inet_csk_clone(struct sock *sk,
3560 const struct request_sock *req)
3562 struct socket_smack *ssp = sk->sk_security;
3563 struct smack_known *skp;
3565 if (req->peer_secid != 0) {
3566 skp = smack_from_secid(req->peer_secid);
3567 ssp->smk_packet = skp;
3569 ssp->smk_packet = NULL;
3573 * Key management security hooks
3575 * Casey has not tested key support very heavily.
3576 * The permission check is most likely too restrictive.
3577 * If you care about keys please have a look.
3582 * smack_key_alloc - Set the key security blob
3584 * @cred: the credentials to use
3587 * No allocation required
3591 static int smack_key_alloc(struct key *key, const struct cred *cred,
3592 unsigned long flags)
3594 struct smack_known *skp = smk_of_task(cred->security);
3596 key->security = skp->smk_known;
3601 * smack_key_free - Clear the key security blob
3604 * Clear the blob pointer
3606 static void smack_key_free(struct key *key)
3608 key->security = NULL;
3612 * smack_key_permission - Smack access on a key
3613 * @key_ref: gets to the object
3614 * @cred: the credentials to use
3617 * Return 0 if the task has read and write to the object,
3618 * an error code otherwise
3620 static int smack_key_permission(key_ref_t key_ref,
3621 const struct cred *cred, key_perm_t perm)
3624 struct smk_audit_info ad;
3625 struct smack_known *tkp = smk_of_task(cred->security);
3627 keyp = key_ref_to_ptr(key_ref);
3631 * If the key hasn't been initialized give it access so that
3634 if (keyp->security == NULL)
3637 * This should not occur
3642 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_KEY);
3643 ad.a.u.key_struct.key = keyp->serial;
3644 ad.a.u.key_struct.key_desc = keyp->description;
3646 return smk_access(tkp, keyp->security, MAY_READWRITE, &ad);
3648 #endif /* CONFIG_KEYS */
3653 * Audit requires a unique representation of each Smack specific
3654 * rule. This unique representation is used to distinguish the
3655 * object to be audited from remaining kernel objects and also
3656 * works as a glue between the audit hooks.
3658 * Since repository entries are added but never deleted, we'll use
3659 * the smack_known label address related to the given audit rule as
3660 * the needed unique representation. This also better fits the smack
3661 * model where nearly everything is a label.
3666 * smack_audit_rule_init - Initialize a smack audit rule
3667 * @field: audit rule fields given from user-space (audit.h)
3668 * @op: required testing operator (=, !=, >, <, ...)
3669 * @rulestr: smack label to be audited
3670 * @vrule: pointer to save our own audit rule representation
3672 * Prepare to audit cases where (@field @op @rulestr) is true.
3673 * The label to be audited is created if necessay.
3675 static int smack_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
3677 char **rule = (char **)vrule;
3680 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
3683 if (op != Audit_equal && op != Audit_not_equal)
3686 *rule = smk_import(rulestr, 0);
3692 * smack_audit_rule_known - Distinguish Smack audit rules
3693 * @krule: rule of interest, in Audit kernel representation format
3695 * This is used to filter Smack rules from remaining Audit ones.
3696 * If it's proved that this rule belongs to us, the
3697 * audit_rule_match hook will be called to do the final judgement.
3699 static int smack_audit_rule_known(struct audit_krule *krule)
3701 struct audit_field *f;
3704 for (i = 0; i < krule->field_count; i++) {
3705 f = &krule->fields[i];
3707 if (f->type == AUDIT_SUBJ_USER || f->type == AUDIT_OBJ_USER)
3715 * smack_audit_rule_match - Audit given object ?
3716 * @secid: security id for identifying the object to test
3717 * @field: audit rule flags given from user-space
3718 * @op: required testing operator
3719 * @vrule: smack internal rule presentation
3720 * @actx: audit context associated with the check
3722 * The core Audit hook. It's used to take the decision of
3723 * whether to audit or not to audit a given object.
3725 static int smack_audit_rule_match(u32 secid, u32 field, u32 op, void *vrule,
3726 struct audit_context *actx)
3728 struct smack_known *skp;
3732 audit_log(actx, GFP_ATOMIC, AUDIT_SELINUX_ERR,
3733 "Smack: missing rule\n");
3737 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
3740 skp = smack_from_secid(secid);
3743 * No need to do string comparisons. If a match occurs,
3744 * both pointers will point to the same smack_known
3747 if (op == Audit_equal)
3748 return (rule == skp->smk_known);
3749 if (op == Audit_not_equal)
3750 return (rule != skp->smk_known);
3756 * smack_audit_rule_free - free smack rule representation
3757 * @vrule: rule to be freed.
3759 * No memory was allocated.
3761 static void smack_audit_rule_free(void *vrule)
3766 #endif /* CONFIG_AUDIT */
3769 * smack_ismaclabel - check if xattr @name references a smack MAC label
3770 * @name: Full xattr name to check.
3772 static int smack_ismaclabel(const char *name)
3774 return (strcmp(name, XATTR_SMACK_SUFFIX) == 0);
3779 * smack_secid_to_secctx - return the smack label for a secid
3780 * @secid: incoming integer
3781 * @secdata: destination
3782 * @seclen: how long it is
3784 * Exists for networking code.
3786 static int smack_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
3788 struct smack_known *skp = smack_from_secid(secid);
3791 *secdata = skp->smk_known;
3792 *seclen = strlen(skp->smk_known);
3797 * smack_secctx_to_secid - return the secid for a smack label
3798 * @secdata: smack label
3799 * @seclen: how long result is
3800 * @secid: outgoing integer
3802 * Exists for audit and networking code.
3804 static int smack_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
3806 *secid = smack_to_secid(secdata);
3811 * smack_release_secctx - don't do anything.
3815 * Exists to make sure nothing gets done, and properly
3817 static void smack_release_secctx(char *secdata, u32 seclen)
3821 static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
3823 return smack_inode_setsecurity(inode, XATTR_SMACK_SUFFIX, ctx, ctxlen, 0);
3826 static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
3828 return __vfs_setxattr_noperm(dentry, XATTR_NAME_SMACK, ctx, ctxlen, 0);
3831 static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
3834 len = smack_inode_getsecurity(inode, XATTR_SMACK_SUFFIX, ctx, true);
3842 struct security_operations smack_ops = {
3845 .ptrace_access_check = smack_ptrace_access_check,
3846 .ptrace_traceme = smack_ptrace_traceme,
3847 .syslog = smack_syslog,
3849 .sb_alloc_security = smack_sb_alloc_security,
3850 .sb_free_security = smack_sb_free_security,
3851 .sb_copy_data = smack_sb_copy_data,
3852 .sb_kern_mount = smack_sb_kern_mount,
3853 .sb_statfs = smack_sb_statfs,
3855 .bprm_set_creds = smack_bprm_set_creds,
3856 .bprm_committing_creds = smack_bprm_committing_creds,
3857 .bprm_secureexec = smack_bprm_secureexec,
3859 .inode_alloc_security = smack_inode_alloc_security,
3860 .inode_free_security = smack_inode_free_security,
3861 .inode_init_security = smack_inode_init_security,
3862 .inode_link = smack_inode_link,
3863 .inode_unlink = smack_inode_unlink,
3864 .inode_rmdir = smack_inode_rmdir,
3865 .inode_rename = smack_inode_rename,
3866 .inode_permission = smack_inode_permission,
3867 .inode_setattr = smack_inode_setattr,
3868 .inode_getattr = smack_inode_getattr,
3869 .inode_setxattr = smack_inode_setxattr,
3870 .inode_post_setxattr = smack_inode_post_setxattr,
3871 .inode_getxattr = smack_inode_getxattr,
3872 .inode_removexattr = smack_inode_removexattr,
3873 .inode_getsecurity = smack_inode_getsecurity,
3874 .inode_setsecurity = smack_inode_setsecurity,
3875 .inode_listsecurity = smack_inode_listsecurity,
3876 .inode_getsecid = smack_inode_getsecid,
3878 .file_permission = smack_file_permission,
3879 .file_alloc_security = smack_file_alloc_security,
3880 .file_free_security = smack_file_free_security,
3881 .file_ioctl = smack_file_ioctl,
3882 .file_lock = smack_file_lock,
3883 .file_fcntl = smack_file_fcntl,
3884 .mmap_file = smack_mmap_file,
3885 .mmap_addr = cap_mmap_addr,
3886 .file_set_fowner = smack_file_set_fowner,
3887 .file_send_sigiotask = smack_file_send_sigiotask,
3888 .file_receive = smack_file_receive,
3890 .file_open = smack_file_open,
3892 .cred_alloc_blank = smack_cred_alloc_blank,
3893 .cred_free = smack_cred_free,
3894 .cred_prepare = smack_cred_prepare,
3895 .cred_transfer = smack_cred_transfer,
3896 .kernel_act_as = smack_kernel_act_as,
3897 .kernel_create_files_as = smack_kernel_create_files_as,
3898 .task_setpgid = smack_task_setpgid,
3899 .task_getpgid = smack_task_getpgid,
3900 .task_getsid = smack_task_getsid,
3901 .task_getsecid = smack_task_getsecid,
3902 .task_setnice = smack_task_setnice,
3903 .task_setioprio = smack_task_setioprio,
3904 .task_getioprio = smack_task_getioprio,
3905 .task_setscheduler = smack_task_setscheduler,
3906 .task_getscheduler = smack_task_getscheduler,
3907 .task_movememory = smack_task_movememory,
3908 .task_kill = smack_task_kill,
3909 .task_wait = smack_task_wait,
3910 .task_to_inode = smack_task_to_inode,
3912 .ipc_permission = smack_ipc_permission,
3913 .ipc_getsecid = smack_ipc_getsecid,
3915 .msg_msg_alloc_security = smack_msg_msg_alloc_security,
3916 .msg_msg_free_security = smack_msg_msg_free_security,
3918 .msg_queue_alloc_security = smack_msg_queue_alloc_security,
3919 .msg_queue_free_security = smack_msg_queue_free_security,
3920 .msg_queue_associate = smack_msg_queue_associate,
3921 .msg_queue_msgctl = smack_msg_queue_msgctl,
3922 .msg_queue_msgsnd = smack_msg_queue_msgsnd,
3923 .msg_queue_msgrcv = smack_msg_queue_msgrcv,
3925 .shm_alloc_security = smack_shm_alloc_security,
3926 .shm_free_security = smack_shm_free_security,
3927 .shm_associate = smack_shm_associate,
3928 .shm_shmctl = smack_shm_shmctl,
3929 .shm_shmat = smack_shm_shmat,
3931 .sem_alloc_security = smack_sem_alloc_security,
3932 .sem_free_security = smack_sem_free_security,
3933 .sem_associate = smack_sem_associate,
3934 .sem_semctl = smack_sem_semctl,
3935 .sem_semop = smack_sem_semop,
3937 .d_instantiate = smack_d_instantiate,
3939 .getprocattr = smack_getprocattr,
3940 .setprocattr = smack_setprocattr,
3942 .unix_stream_connect = smack_unix_stream_connect,
3943 .unix_may_send = smack_unix_may_send,
3945 .socket_post_create = smack_socket_post_create,
3946 .socket_bind = smack_socket_bind,
3947 .socket_connect = smack_socket_connect,
3948 .socket_sendmsg = smack_socket_sendmsg,
3949 .socket_sock_rcv_skb = smack_socket_sock_rcv_skb,
3950 .socket_getpeersec_stream = smack_socket_getpeersec_stream,
3951 .socket_getpeersec_dgram = smack_socket_getpeersec_dgram,
3952 .sk_alloc_security = smack_sk_alloc_security,
3953 .sk_free_security = smack_sk_free_security,
3954 .sock_graft = smack_sock_graft,
3955 .inet_conn_request = smack_inet_conn_request,
3956 .inet_csk_clone = smack_inet_csk_clone,
3958 /* key management security hooks */
3960 .key_alloc = smack_key_alloc,
3961 .key_free = smack_key_free,
3962 .key_permission = smack_key_permission,
3963 #endif /* CONFIG_KEYS */
3967 .audit_rule_init = smack_audit_rule_init,
3968 .audit_rule_known = smack_audit_rule_known,
3969 .audit_rule_match = smack_audit_rule_match,
3970 .audit_rule_free = smack_audit_rule_free,
3971 #endif /* CONFIG_AUDIT */
3973 .ismaclabel = smack_ismaclabel,
3974 .secid_to_secctx = smack_secid_to_secctx,
3975 .secctx_to_secid = smack_secctx_to_secid,
3976 .release_secctx = smack_release_secctx,
3977 .inode_notifysecctx = smack_inode_notifysecctx,
3978 .inode_setsecctx = smack_inode_setsecctx,
3979 .inode_getsecctx = smack_inode_getsecctx,
3983 static __init void init_smack_known_list(void)
3986 * Initialize rule list locks
3988 mutex_init(&smack_known_huh.smk_rules_lock);
3989 mutex_init(&smack_known_hat.smk_rules_lock);
3990 mutex_init(&smack_known_floor.smk_rules_lock);
3991 mutex_init(&smack_known_star.smk_rules_lock);
3992 mutex_init(&smack_known_invalid.smk_rules_lock);
3993 mutex_init(&smack_known_web.smk_rules_lock);
3995 * Initialize rule lists
3997 INIT_LIST_HEAD(&smack_known_huh.smk_rules);
3998 INIT_LIST_HEAD(&smack_known_hat.smk_rules);
3999 INIT_LIST_HEAD(&smack_known_star.smk_rules);
4000 INIT_LIST_HEAD(&smack_known_floor.smk_rules);
4001 INIT_LIST_HEAD(&smack_known_invalid.smk_rules);
4002 INIT_LIST_HEAD(&smack_known_web.smk_rules);
4004 * Create the known labels list
4006 smk_insert_entry(&smack_known_huh);
4007 smk_insert_entry(&smack_known_hat);
4008 smk_insert_entry(&smack_known_star);
4009 smk_insert_entry(&smack_known_floor);
4010 smk_insert_entry(&smack_known_invalid);
4011 smk_insert_entry(&smack_known_web);
4015 * smack_init - initialize the smack system
4019 static __init int smack_init(void)
4022 struct task_smack *tsp;
4024 if (!security_module_enable(&smack_ops))
4027 tsp = new_task_smack(&smack_known_floor, &smack_known_floor,
4032 printk(KERN_INFO "Smack: Initializing.\n");
4035 * Set the security state for the initial task.
4037 cred = (struct cred *) current->cred;
4038 cred->security = tsp;
4040 /* initialize the smack_known_list */
4041 init_smack_known_list();
4046 if (register_security(&smack_ops))
4047 panic("smack: Unable to register with kernel.\n");
4053 * Smack requires early initialization in order to label
4054 * all processes and objects when they are created.
4056 security_initcall(smack_init);