2 * Simplified MAC Kernel (smack) security module
4 * This file contains the smack hook function implementations.
7 * Casey Schaufler <casey@schaufler-ca.com>
9 * Copyright (C) 2007 Casey Schaufler <casey@schaufler-ca.com>
10 * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
11 * Paul Moore <paul.moore@hp.com>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2,
15 * as published by the Free Software Foundation.
18 #include <linux/xattr.h>
19 #include <linux/pagemap.h>
20 #include <linux/mount.h>
21 #include <linux/stat.h>
23 #include <asm/ioctls.h>
25 #include <linux/tcp.h>
26 #include <linux/udp.h>
27 #include <linux/slab.h>
28 #include <linux/mutex.h>
29 #include <linux/pipe_fs_i.h>
30 #include <net/netlabel.h>
31 #include <net/cipso_ipv4.h>
32 #include <linux/audit.h>
33 #include <linux/magic.h>
36 #define task_security(task) (task_cred_xxx((task), security))
39 * smk_fetch - Fetch the smack label from a file.
40 * @ip: a pointer to the inode
41 * @dp: a pointer to the dentry
43 * Returns a pointer to the master list entry for the Smack label
44 * or NULL if there was no label to fetch.
46 static char *smk_fetch(struct inode *ip, struct dentry *dp)
49 char in[SMK_LABELLEN];
51 if (ip->i_op->getxattr == NULL)
54 rc = ip->i_op->getxattr(dp, XATTR_NAME_SMACK, in, SMK_LABELLEN);
58 return smk_import(in, rc);
62 * new_inode_smack - allocate an inode security blob
63 * @smack: a pointer to the Smack label to use in the blob
65 * Returns the new blob or NULL if there's no memory available
67 struct inode_smack *new_inode_smack(char *smack)
69 struct inode_smack *isp;
71 isp = kzalloc(sizeof(struct inode_smack), GFP_KERNEL);
75 isp->smk_inode = smack;
77 mutex_init(&isp->smk_lock);
88 * smack_ptrace_access_check - Smack approval on PTRACE_ATTACH
89 * @ctp: child task pointer
90 * @mode: ptrace attachment mode
92 * Returns 0 if access is OK, an error code otherwise
94 * Do the capability checks, and require read and write.
96 static int smack_ptrace_access_check(struct task_struct *ctp, unsigned int mode)
99 struct smk_audit_info ad;
102 rc = cap_ptrace_access_check(ctp, mode);
106 sp = current_security();
107 tsp = task_security(ctp);
108 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
109 smk_ad_setfield_u_tsk(&ad, ctp);
111 /* we won't log here, because rc can be overriden */
112 rc = smk_access(sp, tsp, MAY_READWRITE, NULL);
113 if (rc != 0 && capable(CAP_MAC_OVERRIDE))
116 smack_log(sp, tsp, MAY_READWRITE, rc, &ad);
121 * smack_ptrace_traceme - Smack approval on PTRACE_TRACEME
122 * @ptp: parent task pointer
124 * Returns 0 if access is OK, an error code otherwise
126 * Do the capability checks, and require read and write.
128 static int smack_ptrace_traceme(struct task_struct *ptp)
131 struct smk_audit_info ad;
134 rc = cap_ptrace_traceme(ptp);
138 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
139 smk_ad_setfield_u_tsk(&ad, ptp);
141 sp = current_security();
142 tsp = task_security(ptp);
143 /* we won't log here, because rc can be overriden */
144 rc = smk_access(tsp, sp, MAY_READWRITE, NULL);
145 if (rc != 0 && has_capability(ptp, CAP_MAC_OVERRIDE))
148 smack_log(tsp, sp, MAY_READWRITE, rc, &ad);
153 * smack_syslog - Smack approval on syslog
154 * @type: message type
156 * Require that the task has the floor label
158 * Returns 0 on success, error code otherwise.
160 static int smack_syslog(int typefrom_file)
163 char *sp = current_security();
165 if (capable(CAP_MAC_OVERRIDE))
168 if (sp != smack_known_floor.smk_known)
180 * smack_sb_alloc_security - allocate a superblock blob
181 * @sb: the superblock getting the blob
183 * Returns 0 on success or -ENOMEM on error.
185 static int smack_sb_alloc_security(struct super_block *sb)
187 struct superblock_smack *sbsp;
189 sbsp = kzalloc(sizeof(struct superblock_smack), GFP_KERNEL);
194 sbsp->smk_root = smack_known_floor.smk_known;
195 sbsp->smk_default = smack_known_floor.smk_known;
196 sbsp->smk_floor = smack_known_floor.smk_known;
197 sbsp->smk_hat = smack_known_hat.smk_known;
198 sbsp->smk_initialized = 0;
199 spin_lock_init(&sbsp->smk_sblock);
201 sb->s_security = sbsp;
207 * smack_sb_free_security - free a superblock blob
208 * @sb: the superblock getting the blob
211 static void smack_sb_free_security(struct super_block *sb)
213 kfree(sb->s_security);
214 sb->s_security = NULL;
218 * smack_sb_copy_data - copy mount options data for processing
219 * @orig: where to start
220 * @smackopts: mount options string
222 * Returns 0 on success or -ENOMEM on error.
224 * Copy the Smack specific mount options out of the mount
227 static int smack_sb_copy_data(char *orig, char *smackopts)
229 char *cp, *commap, *otheropts, *dp;
231 otheropts = (char *)get_zeroed_page(GFP_KERNEL);
232 if (otheropts == NULL)
235 for (cp = orig, commap = orig; commap != NULL; cp = commap + 1) {
236 if (strstr(cp, SMK_FSDEFAULT) == cp)
238 else if (strstr(cp, SMK_FSFLOOR) == cp)
240 else if (strstr(cp, SMK_FSHAT) == cp)
242 else if (strstr(cp, SMK_FSROOT) == cp)
247 commap = strchr(cp, ',');
256 strcpy(orig, otheropts);
257 free_page((unsigned long)otheropts);
263 * smack_sb_kern_mount - Smack specific mount processing
264 * @sb: the file system superblock
265 * @flags: the mount flags
266 * @data: the smack mount options
268 * Returns 0 on success, an error code on failure
270 static int smack_sb_kern_mount(struct super_block *sb, int flags, void *data)
272 struct dentry *root = sb->s_root;
273 struct inode *inode = root->d_inode;
274 struct superblock_smack *sp = sb->s_security;
275 struct inode_smack *isp;
280 spin_lock(&sp->smk_sblock);
281 if (sp->smk_initialized != 0) {
282 spin_unlock(&sp->smk_sblock);
285 sp->smk_initialized = 1;
286 spin_unlock(&sp->smk_sblock);
288 for (op = data; op != NULL; op = commap) {
289 commap = strchr(op, ',');
293 if (strncmp(op, SMK_FSHAT, strlen(SMK_FSHAT)) == 0) {
294 op += strlen(SMK_FSHAT);
295 nsp = smk_import(op, 0);
298 } else if (strncmp(op, SMK_FSFLOOR, strlen(SMK_FSFLOOR)) == 0) {
299 op += strlen(SMK_FSFLOOR);
300 nsp = smk_import(op, 0);
303 } else if (strncmp(op, SMK_FSDEFAULT,
304 strlen(SMK_FSDEFAULT)) == 0) {
305 op += strlen(SMK_FSDEFAULT);
306 nsp = smk_import(op, 0);
308 sp->smk_default = nsp;
309 } else if (strncmp(op, SMK_FSROOT, strlen(SMK_FSROOT)) == 0) {
310 op += strlen(SMK_FSROOT);
311 nsp = smk_import(op, 0);
318 * Initialize the root inode.
320 isp = inode->i_security;
322 inode->i_security = new_inode_smack(sp->smk_root);
324 isp->smk_inode = sp->smk_root;
330 * smack_sb_statfs - Smack check on statfs
331 * @dentry: identifies the file system in question
333 * Returns 0 if current can read the floor of the filesystem,
334 * and error code otherwise
336 static int smack_sb_statfs(struct dentry *dentry)
338 struct superblock_smack *sbp = dentry->d_sb->s_security;
340 struct smk_audit_info ad;
342 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
343 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
345 rc = smk_curacc(sbp->smk_floor, MAY_READ, &ad);
350 * smack_sb_mount - Smack check for mounting
357 * Returns 0 if current can write the floor of the filesystem
358 * being mounted on, an error code otherwise.
360 static int smack_sb_mount(char *dev_name, struct path *path,
361 char *type, unsigned long flags, void *data)
363 struct superblock_smack *sbp = path->mnt->mnt_sb->s_security;
364 struct smk_audit_info ad;
366 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
367 smk_ad_setfield_u_fs_path(&ad, *path);
369 return smk_curacc(sbp->smk_floor, MAY_WRITE, &ad);
373 * smack_sb_umount - Smack check for unmounting
374 * @mnt: file system to unmount
377 * Returns 0 if current can write the floor of the filesystem
378 * being unmounted, an error code otherwise.
380 static int smack_sb_umount(struct vfsmount *mnt, int flags)
382 struct superblock_smack *sbp;
383 struct smk_audit_info ad;
385 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
386 smk_ad_setfield_u_fs_path_dentry(&ad, mnt->mnt_root);
387 smk_ad_setfield_u_fs_path_mnt(&ad, mnt);
389 sbp = mnt->mnt_sb->s_security;
390 return smk_curacc(sbp->smk_floor, MAY_WRITE, &ad);
398 * smack_inode_alloc_security - allocate an inode blob
399 * @inode: the inode in need of a blob
401 * Returns 0 if it gets a blob, -ENOMEM otherwise
403 static int smack_inode_alloc_security(struct inode *inode)
405 inode->i_security = new_inode_smack(current_security());
406 if (inode->i_security == NULL)
412 * smack_inode_free_security - free an inode blob
413 * @inode: the inode with a blob
415 * Clears the blob pointer in inode
417 static void smack_inode_free_security(struct inode *inode)
419 kfree(inode->i_security);
420 inode->i_security = NULL;
424 * smack_inode_init_security - copy out the smack from an inode
427 * @name: where to put the attribute name
428 * @value: where to put the attribute value
429 * @len: where to put the length of the attribute
431 * Returns 0 if it all works out, -ENOMEM if there's no memory
433 static int smack_inode_init_security(struct inode *inode, struct inode *dir,
434 char **name, void **value, size_t *len)
436 char *isp = smk_of_inode(inode);
439 *name = kstrdup(XATTR_SMACK_SUFFIX, GFP_KERNEL);
445 *value = kstrdup(isp, GFP_KERNEL);
451 *len = strlen(isp) + 1;
457 * smack_inode_link - Smack check on link
458 * @old_dentry: the existing object
460 * @new_dentry: the new object
462 * Returns 0 if access is permitted, an error code otherwise
464 static int smack_inode_link(struct dentry *old_dentry, struct inode *dir,
465 struct dentry *new_dentry)
468 struct smk_audit_info ad;
471 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
472 smk_ad_setfield_u_fs_path_dentry(&ad, old_dentry);
474 isp = smk_of_inode(old_dentry->d_inode);
475 rc = smk_curacc(isp, MAY_WRITE, &ad);
477 if (rc == 0 && new_dentry->d_inode != NULL) {
478 isp = smk_of_inode(new_dentry->d_inode);
479 smk_ad_setfield_u_fs_path_dentry(&ad, new_dentry);
480 rc = smk_curacc(isp, MAY_WRITE, &ad);
487 * smack_inode_unlink - Smack check on inode deletion
488 * @dir: containing directory object
489 * @dentry: file to unlink
491 * Returns 0 if current can write the containing directory
492 * and the object, error code otherwise
494 static int smack_inode_unlink(struct inode *dir, struct dentry *dentry)
496 struct inode *ip = dentry->d_inode;
497 struct smk_audit_info ad;
500 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
501 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
504 * You need write access to the thing you're unlinking
506 rc = smk_curacc(smk_of_inode(ip), MAY_WRITE, &ad);
509 * You also need write access to the containing directory
511 smk_ad_setfield_u_fs_path_dentry(&ad, NULL);
512 smk_ad_setfield_u_fs_inode(&ad, dir);
513 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE, &ad);
519 * smack_inode_rmdir - Smack check on directory deletion
520 * @dir: containing directory object
521 * @dentry: directory to unlink
523 * Returns 0 if current can write the containing directory
524 * and the directory, error code otherwise
526 static int smack_inode_rmdir(struct inode *dir, struct dentry *dentry)
528 struct smk_audit_info ad;
531 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
532 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
535 * You need write access to the thing you're removing
537 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
540 * You also need write access to the containing directory
542 smk_ad_setfield_u_fs_path_dentry(&ad, NULL);
543 smk_ad_setfield_u_fs_inode(&ad, dir);
544 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE, &ad);
551 * smack_inode_rename - Smack check on rename
552 * @old_inode: the old directory
553 * @old_dentry: unused
554 * @new_inode: the new directory
555 * @new_dentry: unused
557 * Read and write access is required on both the old and
560 * Returns 0 if access is permitted, an error code otherwise
562 static int smack_inode_rename(struct inode *old_inode,
563 struct dentry *old_dentry,
564 struct inode *new_inode,
565 struct dentry *new_dentry)
569 struct smk_audit_info ad;
571 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
572 smk_ad_setfield_u_fs_path_dentry(&ad, old_dentry);
574 isp = smk_of_inode(old_dentry->d_inode);
575 rc = smk_curacc(isp, MAY_READWRITE, &ad);
577 if (rc == 0 && new_dentry->d_inode != NULL) {
578 isp = smk_of_inode(new_dentry->d_inode);
579 smk_ad_setfield_u_fs_path_dentry(&ad, new_dentry);
580 rc = smk_curacc(isp, MAY_READWRITE, &ad);
586 * smack_inode_permission - Smack version of permission()
587 * @inode: the inode in question
588 * @mask: the access requested
590 * This is the important Smack hook.
592 * Returns 0 if access is permitted, -EACCES otherwise
594 static int smack_inode_permission(struct inode *inode, int mask)
596 struct smk_audit_info ad;
598 mask &= (MAY_READ|MAY_WRITE|MAY_EXEC|MAY_APPEND);
600 * No permission to check. Existence test. Yup, it's there.
604 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
605 smk_ad_setfield_u_fs_inode(&ad, inode);
606 return smk_curacc(smk_of_inode(inode), mask, &ad);
610 * smack_inode_setattr - Smack check for setting attributes
611 * @dentry: the object
612 * @iattr: for the force flag
614 * Returns 0 if access is permitted, an error code otherwise
616 static int smack_inode_setattr(struct dentry *dentry, struct iattr *iattr)
618 struct smk_audit_info ad;
620 * Need to allow for clearing the setuid bit.
622 if (iattr->ia_valid & ATTR_FORCE)
624 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
625 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
627 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
631 * smack_inode_getattr - Smack check for getting attributes
633 * @dentry: the object
635 * Returns 0 if access is permitted, an error code otherwise
637 static int smack_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
639 struct smk_audit_info ad;
641 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
642 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
643 smk_ad_setfield_u_fs_path_mnt(&ad, mnt);
644 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ, &ad);
648 * smack_inode_setxattr - Smack check for setting xattrs
649 * @dentry: the object
650 * @name: name of the attribute
655 * This protects the Smack attribute explicitly.
657 * Returns 0 if access is permitted, an error code otherwise
659 static int smack_inode_setxattr(struct dentry *dentry, const char *name,
660 const void *value, size_t size, int flags)
662 struct smk_audit_info ad;
665 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
666 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
667 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0) {
668 if (!capable(CAP_MAC_ADMIN))
671 * check label validity here so import wont fail on
674 if (size == 0 || size >= SMK_LABELLEN ||
675 smk_import(value, size) == NULL)
678 rc = cap_inode_setxattr(dentry, name, value, size, flags);
680 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
681 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
684 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
690 * smack_inode_post_setxattr - Apply the Smack update approved above
692 * @name: attribute name
693 * @value: attribute value
694 * @size: attribute size
697 * Set the pointer in the inode blob to the entry found
698 * in the master label list.
700 static void smack_inode_post_setxattr(struct dentry *dentry, const char *name,
701 const void *value, size_t size, int flags)
703 struct inode_smack *isp;
709 if (strcmp(name, XATTR_NAME_SMACK))
712 isp = dentry->d_inode->i_security;
715 * No locking is done here. This is a pointer
718 nsp = smk_import(value, size);
720 isp->smk_inode = nsp;
722 isp->smk_inode = smack_known_invalid.smk_known;
728 * smack_inode_getxattr - Smack check on getxattr
729 * @dentry: the object
732 * Returns 0 if access is permitted, an error code otherwise
734 static int smack_inode_getxattr(struct dentry *dentry, const char *name)
736 struct smk_audit_info ad;
738 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
739 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
741 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ, &ad);
745 * smack_inode_removexattr - Smack check on removexattr
746 * @dentry: the object
747 * @name: name of the attribute
749 * Removing the Smack attribute requires CAP_MAC_ADMIN
751 * Returns 0 if access is permitted, an error code otherwise
753 static int smack_inode_removexattr(struct dentry *dentry, const char *name)
755 struct smk_audit_info ad;
758 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
759 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
760 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0) {
761 if (!capable(CAP_MAC_ADMIN))
764 rc = cap_inode_removexattr(dentry, name);
766 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
767 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
769 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
775 * smack_inode_getsecurity - get smack xattrs
777 * @name: attribute name
778 * @buffer: where to put the result
781 * Returns the size of the attribute or an error code
783 static int smack_inode_getsecurity(const struct inode *inode,
784 const char *name, void **buffer,
787 struct socket_smack *ssp;
789 struct super_block *sbp;
790 struct inode *ip = (struct inode *)inode;
795 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
796 isp = smk_of_inode(inode);
797 ilen = strlen(isp) + 1;
803 * The rest of the Smack xattrs are only on sockets.
806 if (sbp->s_magic != SOCKFS_MAGIC)
810 if (sock == NULL || sock->sk == NULL)
813 ssp = sock->sk->sk_security;
815 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
817 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0)
822 ilen = strlen(isp) + 1;
833 * smack_inode_listsecurity - list the Smack attributes
835 * @buffer: where they go
836 * @buffer_size: size of buffer
838 * Returns 0 on success, -EINVAL otherwise
840 static int smack_inode_listsecurity(struct inode *inode, char *buffer,
843 int len = strlen(XATTR_NAME_SMACK);
845 if (buffer != NULL && len <= buffer_size) {
846 memcpy(buffer, XATTR_NAME_SMACK, len);
853 * smack_inode_getsecid - Extract inode's security id
854 * @inode: inode to extract the info from
855 * @secid: where result will be saved
857 static void smack_inode_getsecid(const struct inode *inode, u32 *secid)
859 struct inode_smack *isp = inode->i_security;
861 *secid = smack_to_secid(isp->smk_inode);
869 * smack_file_permission - Smack check on file operations
875 * Should access checks be done on each read or write?
876 * UNICOS and SELinux say yes.
877 * Trusted Solaris, Trusted Irix, and just about everyone else says no.
879 * I'll say no for now. Smack does not do the frequent
880 * label changing that SELinux does.
882 static int smack_file_permission(struct file *file, int mask)
888 * smack_file_alloc_security - assign a file security blob
891 * The security blob for a file is a pointer to the master
892 * label list, so no allocation is done.
896 static int smack_file_alloc_security(struct file *file)
898 file->f_security = current_security();
903 * smack_file_free_security - clear a file security blob
906 * The security blob for a file is a pointer to the master
907 * label list, so no memory is freed.
909 static void smack_file_free_security(struct file *file)
911 file->f_security = NULL;
915 * smack_file_ioctl - Smack check on ioctls
920 * Relies heavily on the correct use of the ioctl command conventions.
922 * Returns 0 if allowed, error code otherwise
924 static int smack_file_ioctl(struct file *file, unsigned int cmd,
928 struct smk_audit_info ad;
930 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
931 smk_ad_setfield_u_fs_path(&ad, file->f_path);
933 if (_IOC_DIR(cmd) & _IOC_WRITE)
934 rc = smk_curacc(file->f_security, MAY_WRITE, &ad);
936 if (rc == 0 && (_IOC_DIR(cmd) & _IOC_READ))
937 rc = smk_curacc(file->f_security, MAY_READ, &ad);
943 * smack_file_lock - Smack check on file locking
947 * Returns 0 if current has write access, error code otherwise
949 static int smack_file_lock(struct file *file, unsigned int cmd)
951 struct smk_audit_info ad;
953 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
954 smk_ad_setfield_u_fs_path_dentry(&ad, file->f_path.dentry);
955 return smk_curacc(file->f_security, MAY_WRITE, &ad);
959 * smack_file_fcntl - Smack check on fcntl
961 * @cmd: what action to check
964 * Returns 0 if current has access, error code otherwise
966 static int smack_file_fcntl(struct file *file, unsigned int cmd,
969 struct smk_audit_info ad;
972 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
973 smk_ad_setfield_u_fs_path(&ad, file->f_path);
982 rc = smk_curacc(file->f_security, MAY_READ, &ad);
990 rc = smk_curacc(file->f_security, MAY_WRITE, &ad);
993 rc = smk_curacc(file->f_security, MAY_READWRITE, &ad);
1000 * smack_file_set_fowner - set the file security blob value
1001 * @file: object in question
1004 * Further research may be required on this one.
1006 static int smack_file_set_fowner(struct file *file)
1008 file->f_security = current_security();
1013 * smack_file_send_sigiotask - Smack on sigio
1014 * @tsk: The target task
1015 * @fown: the object the signal come from
1018 * Allow a privileged task to get signals even if it shouldn't
1020 * Returns 0 if a subject with the object's smack could
1021 * write to the task, an error code otherwise.
1023 static int smack_file_send_sigiotask(struct task_struct *tsk,
1024 struct fown_struct *fown, int signum)
1028 char *tsp = tsk->cred->security;
1029 struct smk_audit_info ad;
1032 * struct fown_struct is never outside the context of a struct file
1034 file = container_of(fown, struct file, f_owner);
1035 /* we don't log here as rc can be overriden */
1036 rc = smk_access(file->f_security, tsp, MAY_WRITE, NULL);
1037 if (rc != 0 && has_capability(tsk, CAP_MAC_OVERRIDE))
1040 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1041 smk_ad_setfield_u_tsk(&ad, tsk);
1042 smack_log(file->f_security, tsp, MAY_WRITE, rc, &ad);
1047 * smack_file_receive - Smack file receive check
1050 * Returns 0 if current has access, error code otherwise
1052 static int smack_file_receive(struct file *file)
1055 struct smk_audit_info ad;
1057 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1058 smk_ad_setfield_u_fs_path(&ad, file->f_path);
1060 * This code relies on bitmasks.
1062 if (file->f_mode & FMODE_READ)
1064 if (file->f_mode & FMODE_WRITE)
1067 return smk_curacc(file->f_security, may, &ad);
1075 * smack_cred_alloc_blank - "allocate" blank task-level security credentials
1076 * @new: the new credentials
1077 * @gfp: the atomicity of any memory allocations
1079 * Prepare a blank set of credentials for modification. This must allocate all
1080 * the memory the LSM module might require such that cred_transfer() can
1081 * complete without error.
1083 static int smack_cred_alloc_blank(struct cred *cred, gfp_t gfp)
1085 cred->security = NULL;
1091 * smack_cred_free - "free" task-level security credentials
1092 * @cred: the credentials in question
1094 * Smack isn't using copies of blobs. Everyone
1095 * points to an immutable list. The blobs never go away.
1096 * There is no leak here.
1098 static void smack_cred_free(struct cred *cred)
1100 cred->security = NULL;
1104 * smack_cred_prepare - prepare new set of credentials for modification
1105 * @new: the new credentials
1106 * @old: the original credentials
1107 * @gfp: the atomicity of any memory allocations
1109 * Prepare a new set of credentials for modification.
1111 static int smack_cred_prepare(struct cred *new, const struct cred *old,
1114 new->security = old->security;
1119 * smack_cred_transfer - Transfer the old credentials to the new credentials
1120 * @new: the new credentials
1121 * @old: the original credentials
1123 * Fill in a set of blank credentials from another set of credentials.
1125 static void smack_cred_transfer(struct cred *new, const struct cred *old)
1127 new->security = old->security;
1131 * smack_kernel_act_as - Set the subjective context in a set of credentials
1132 * @new: points to the set of credentials to be modified.
1133 * @secid: specifies the security ID to be set
1135 * Set the security data for a kernel service.
1137 static int smack_kernel_act_as(struct cred *new, u32 secid)
1139 char *smack = smack_from_secid(secid);
1144 new->security = smack;
1149 * smack_kernel_create_files_as - Set the file creation label in a set of creds
1150 * @new: points to the set of credentials to be modified
1151 * @inode: points to the inode to use as a reference
1153 * Set the file creation context in a set of credentials to the same
1154 * as the objective context of the specified inode
1156 static int smack_kernel_create_files_as(struct cred *new,
1157 struct inode *inode)
1159 struct inode_smack *isp = inode->i_security;
1161 new->security = isp->smk_inode;
1166 * smk_curacc_on_task - helper to log task related access
1167 * @p: the task object
1168 * @access : the access requested
1170 * Return 0 if access is permitted
1172 static int smk_curacc_on_task(struct task_struct *p, int access)
1174 struct smk_audit_info ad;
1176 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1177 smk_ad_setfield_u_tsk(&ad, p);
1178 return smk_curacc(task_security(p), access, &ad);
1182 * smack_task_setpgid - Smack check on setting pgid
1183 * @p: the task object
1186 * Return 0 if write access is permitted
1188 static int smack_task_setpgid(struct task_struct *p, pid_t pgid)
1190 return smk_curacc_on_task(p, MAY_WRITE);
1194 * smack_task_getpgid - Smack access check for getpgid
1195 * @p: the object task
1197 * Returns 0 if current can read the object task, error code otherwise
1199 static int smack_task_getpgid(struct task_struct *p)
1201 return smk_curacc_on_task(p, MAY_READ);
1205 * smack_task_getsid - Smack access check for getsid
1206 * @p: the object task
1208 * Returns 0 if current can read the object task, error code otherwise
1210 static int smack_task_getsid(struct task_struct *p)
1212 return smk_curacc_on_task(p, MAY_READ);
1216 * smack_task_getsecid - get the secid of the task
1217 * @p: the object task
1218 * @secid: where to put the result
1220 * Sets the secid to contain a u32 version of the smack label.
1222 static void smack_task_getsecid(struct task_struct *p, u32 *secid)
1224 *secid = smack_to_secid(task_security(p));
1228 * smack_task_setnice - Smack check on setting nice
1229 * @p: the task object
1232 * Return 0 if write access is permitted
1234 static int smack_task_setnice(struct task_struct *p, int nice)
1238 rc = cap_task_setnice(p, nice);
1240 rc = smk_curacc_on_task(p, MAY_WRITE);
1245 * smack_task_setioprio - Smack check on setting ioprio
1246 * @p: the task object
1249 * Return 0 if write access is permitted
1251 static int smack_task_setioprio(struct task_struct *p, int ioprio)
1255 rc = cap_task_setioprio(p, ioprio);
1257 rc = smk_curacc_on_task(p, MAY_WRITE);
1262 * smack_task_getioprio - Smack check on reading ioprio
1263 * @p: the task object
1265 * Return 0 if read access is permitted
1267 static int smack_task_getioprio(struct task_struct *p)
1269 return smk_curacc_on_task(p, MAY_READ);
1273 * smack_task_setscheduler - Smack check on setting scheduler
1274 * @p: the task object
1278 * Return 0 if read access is permitted
1280 static int smack_task_setscheduler(struct task_struct *p)
1284 rc = cap_task_setscheduler(p);
1286 rc = smk_curacc_on_task(p, MAY_WRITE);
1291 * smack_task_getscheduler - Smack check on reading scheduler
1292 * @p: the task object
1294 * Return 0 if read access is permitted
1296 static int smack_task_getscheduler(struct task_struct *p)
1298 return smk_curacc_on_task(p, MAY_READ);
1302 * smack_task_movememory - Smack check on moving memory
1303 * @p: the task object
1305 * Return 0 if write access is permitted
1307 static int smack_task_movememory(struct task_struct *p)
1309 return smk_curacc_on_task(p, MAY_WRITE);
1313 * smack_task_kill - Smack check on signal delivery
1314 * @p: the task object
1317 * @secid: identifies the smack to use in lieu of current's
1319 * Return 0 if write access is permitted
1321 * The secid behavior is an artifact of an SELinux hack
1322 * in the USB code. Someday it may go away.
1324 static int smack_task_kill(struct task_struct *p, struct siginfo *info,
1327 struct smk_audit_info ad;
1329 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1330 smk_ad_setfield_u_tsk(&ad, p);
1332 * Sending a signal requires that the sender
1333 * can write the receiver.
1336 return smk_curacc(task_security(p), MAY_WRITE, &ad);
1338 * If the secid isn't 0 we're dealing with some USB IO
1339 * specific behavior. This is not clean. For one thing
1340 * we can't take privilege into account.
1342 return smk_access(smack_from_secid(secid), task_security(p),
1347 * smack_task_wait - Smack access check for waiting
1348 * @p: task to wait for
1350 * Returns 0 if current can wait for p, error code otherwise
1352 static int smack_task_wait(struct task_struct *p)
1354 struct smk_audit_info ad;
1355 char *sp = current_security();
1356 char *tsp = task_security(p);
1359 /* we don't log here, we can be overriden */
1360 rc = smk_access(sp, tsp, MAY_WRITE, NULL);
1365 * Allow the operation to succeed if either task
1366 * has privilege to perform operations that might
1367 * account for the smack labels having gotten to
1368 * be different in the first place.
1370 * This breaks the strict subject/object access
1371 * control ideal, taking the object's privilege
1372 * state into account in the decision as well as
1375 if (capable(CAP_MAC_OVERRIDE) || has_capability(p, CAP_MAC_OVERRIDE))
1377 /* we log only if we didn't get overriden */
1379 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1380 smk_ad_setfield_u_tsk(&ad, p);
1381 smack_log(sp, tsp, MAY_WRITE, rc, &ad);
1386 * smack_task_to_inode - copy task smack into the inode blob
1387 * @p: task to copy from
1388 * @inode: inode to copy to
1390 * Sets the smack pointer in the inode security blob
1392 static void smack_task_to_inode(struct task_struct *p, struct inode *inode)
1394 struct inode_smack *isp = inode->i_security;
1395 isp->smk_inode = task_security(p);
1403 * smack_sk_alloc_security - Allocate a socket blob
1406 * @gfp_flags: memory allocation flags
1408 * Assign Smack pointers to current
1410 * Returns 0 on success, -ENOMEM is there's no memory
1412 static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags)
1414 char *csp = current_security();
1415 struct socket_smack *ssp;
1417 ssp = kzalloc(sizeof(struct socket_smack), gfp_flags);
1423 ssp->smk_packet[0] = '\0';
1425 sk->sk_security = ssp;
1431 * smack_sk_free_security - Free a socket blob
1434 * Clears the blob pointer
1436 static void smack_sk_free_security(struct sock *sk)
1438 kfree(sk->sk_security);
1442 * smack_host_label - check host based restrictions
1443 * @sip: the object end
1445 * looks for host based access restrictions
1447 * This version will only be appropriate for really small sets of single label
1448 * hosts. The caller is responsible for ensuring that the RCU read lock is
1449 * taken before calling this function.
1451 * Returns the label of the far end or NULL if it's not special.
1453 static char *smack_host_label(struct sockaddr_in *sip)
1455 struct smk_netlbladdr *snp;
1456 struct in_addr *siap = &sip->sin_addr;
1458 if (siap->s_addr == 0)
1461 list_for_each_entry_rcu(snp, &smk_netlbladdr_list, list)
1463 * we break after finding the first match because
1464 * the list is sorted from longest to shortest mask
1465 * so we have found the most specific match
1467 if ((&snp->smk_host.sin_addr)->s_addr ==
1468 (siap->s_addr & (&snp->smk_mask)->s_addr)) {
1469 /* we have found the special CIPSO option */
1470 if (snp->smk_label == smack_cipso_option)
1472 return snp->smk_label;
1479 * smack_set_catset - convert a capset to netlabel mls categories
1480 * @catset: the Smack categories
1481 * @sap: where to put the netlabel categories
1483 * Allocates and fills attr.mls.cat
1485 static void smack_set_catset(char *catset, struct netlbl_lsm_secattr *sap)
1496 sap->flags |= NETLBL_SECATTR_MLS_CAT;
1497 sap->attr.mls.cat = netlbl_secattr_catmap_alloc(GFP_ATOMIC);
1498 sap->attr.mls.cat->startbit = 0;
1500 for (cat = 1, cp = catset, byte = 0; byte < SMK_LABELLEN; cp++, byte++)
1501 for (m = 0x80; m != 0; m >>= 1, cat++) {
1504 rc = netlbl_secattr_catmap_setbit(sap->attr.mls.cat,
1510 * smack_to_secattr - fill a secattr from a smack value
1511 * @smack: the smack value
1512 * @nlsp: where the result goes
1514 * Casey says that CIPSO is good enough for now.
1515 * It can be used to effect.
1516 * It can also be abused to effect when necessary.
1517 * Appologies to the TSIG group in general and GW in particular.
1519 static void smack_to_secattr(char *smack, struct netlbl_lsm_secattr *nlsp)
1521 struct smack_cipso cipso;
1524 nlsp->domain = smack;
1525 nlsp->flags = NETLBL_SECATTR_DOMAIN | NETLBL_SECATTR_MLS_LVL;
1527 rc = smack_to_cipso(smack, &cipso);
1529 nlsp->attr.mls.lvl = cipso.smk_level;
1530 smack_set_catset(cipso.smk_catset, nlsp);
1532 nlsp->attr.mls.lvl = smack_cipso_direct;
1533 smack_set_catset(smack, nlsp);
1538 * smack_netlabel - Set the secattr on a socket
1540 * @labeled: socket label scheme
1542 * Convert the outbound smack value (smk_out) to a
1543 * secattr and attach it to the socket.
1545 * Returns 0 on success or an error code
1547 static int smack_netlabel(struct sock *sk, int labeled)
1549 struct socket_smack *ssp = sk->sk_security;
1550 struct netlbl_lsm_secattr secattr;
1554 * Usually the netlabel code will handle changing the
1555 * packet labeling based on the label.
1556 * The case of a single label host is different, because
1557 * a single label host should never get a labeled packet
1558 * even though the label is usually associated with a packet
1562 bh_lock_sock_nested(sk);
1564 if (ssp->smk_out == smack_net_ambient ||
1565 labeled == SMACK_UNLABELED_SOCKET)
1566 netlbl_sock_delattr(sk);
1568 netlbl_secattr_init(&secattr);
1569 smack_to_secattr(ssp->smk_out, &secattr);
1570 rc = netlbl_sock_setattr(sk, sk->sk_family, &secattr);
1571 netlbl_secattr_destroy(&secattr);
1581 * smack_netlbel_send - Set the secattr on a socket and perform access checks
1583 * @sap: the destination address
1585 * Set the correct secattr for the given socket based on the destination
1586 * address and perform any outbound access checks needed.
1588 * Returns 0 on success or an error code.
1591 static int smack_netlabel_send(struct sock *sk, struct sockaddr_in *sap)
1596 struct socket_smack *ssp = sk->sk_security;
1597 struct smk_audit_info ad;
1600 hostsp = smack_host_label(sap);
1601 if (hostsp != NULL) {
1602 sk_lbl = SMACK_UNLABELED_SOCKET;
1604 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
1605 ad.a.u.net.family = sap->sin_family;
1606 ad.a.u.net.dport = sap->sin_port;
1607 ad.a.u.net.v4info.daddr = sap->sin_addr.s_addr;
1609 rc = smk_access(ssp->smk_out, hostsp, MAY_WRITE, &ad);
1611 sk_lbl = SMACK_CIPSO_SOCKET;
1618 return smack_netlabel(sk, sk_lbl);
1622 * smack_inode_setsecurity - set smack xattrs
1623 * @inode: the object
1624 * @name: attribute name
1625 * @value: attribute value
1626 * @size: size of the attribute
1629 * Sets the named attribute in the appropriate blob
1631 * Returns 0 on success, or an error code
1633 static int smack_inode_setsecurity(struct inode *inode, const char *name,
1634 const void *value, size_t size, int flags)
1637 struct inode_smack *nsp = inode->i_security;
1638 struct socket_smack *ssp;
1639 struct socket *sock;
1642 if (value == NULL || size > SMK_LABELLEN || size == 0)
1645 sp = smk_import(value, size);
1649 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
1650 nsp->smk_inode = sp;
1651 nsp->smk_flags |= SMK_INODE_INSTANT;
1655 * The rest of the Smack xattrs are only on sockets.
1657 if (inode->i_sb->s_magic != SOCKFS_MAGIC)
1660 sock = SOCKET_I(inode);
1661 if (sock == NULL || sock->sk == NULL)
1664 ssp = sock->sk->sk_security;
1666 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
1668 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0) {
1670 if (sock->sk->sk_family != PF_UNIX) {
1671 rc = smack_netlabel(sock->sk, SMACK_CIPSO_SOCKET);
1674 "Smack: \"%s\" netlbl error %d.\n",
1684 * smack_socket_post_create - finish socket setup
1686 * @family: protocol family
1691 * Sets the netlabel information on the socket
1693 * Returns 0 on success, and error code otherwise
1695 static int smack_socket_post_create(struct socket *sock, int family,
1696 int type, int protocol, int kern)
1698 if (family != PF_INET || sock->sk == NULL)
1701 * Set the outbound netlbl.
1703 return smack_netlabel(sock->sk, SMACK_CIPSO_SOCKET);
1707 * smack_socket_connect - connect access check
1709 * @sap: the other end
1710 * @addrlen: size of sap
1712 * Verifies that a connection may be possible
1714 * Returns 0 on success, and error code otherwise
1716 static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
1719 if (sock->sk == NULL || sock->sk->sk_family != PF_INET)
1721 if (addrlen < sizeof(struct sockaddr_in))
1724 return smack_netlabel_send(sock->sk, (struct sockaddr_in *)sap);
1728 * smack_flags_to_may - convert S_ to MAY_ values
1729 * @flags: the S_ value
1731 * Returns the equivalent MAY_ value
1733 static int smack_flags_to_may(int flags)
1737 if (flags & S_IRUGO)
1739 if (flags & S_IWUGO)
1741 if (flags & S_IXUGO)
1748 * smack_msg_msg_alloc_security - Set the security blob for msg_msg
1753 static int smack_msg_msg_alloc_security(struct msg_msg *msg)
1755 msg->security = current_security();
1760 * smack_msg_msg_free_security - Clear the security blob for msg_msg
1763 * Clears the blob pointer
1765 static void smack_msg_msg_free_security(struct msg_msg *msg)
1767 msg->security = NULL;
1771 * smack_of_shm - the smack pointer for the shm
1774 * Returns a pointer to the smack value
1776 static char *smack_of_shm(struct shmid_kernel *shp)
1778 return (char *)shp->shm_perm.security;
1782 * smack_shm_alloc_security - Set the security blob for shm
1787 static int smack_shm_alloc_security(struct shmid_kernel *shp)
1789 struct kern_ipc_perm *isp = &shp->shm_perm;
1791 isp->security = current_security();
1796 * smack_shm_free_security - Clear the security blob for shm
1799 * Clears the blob pointer
1801 static void smack_shm_free_security(struct shmid_kernel *shp)
1803 struct kern_ipc_perm *isp = &shp->shm_perm;
1805 isp->security = NULL;
1809 * smk_curacc_shm : check if current has access on shm
1811 * @access : access requested
1813 * Returns 0 if current has the requested access, error code otherwise
1815 static int smk_curacc_shm(struct shmid_kernel *shp, int access)
1817 char *ssp = smack_of_shm(shp);
1818 struct smk_audit_info ad;
1821 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
1822 ad.a.u.ipc_id = shp->shm_perm.id;
1824 return smk_curacc(ssp, access, &ad);
1828 * smack_shm_associate - Smack access check for shm
1830 * @shmflg: access requested
1832 * Returns 0 if current has the requested access, error code otherwise
1834 static int smack_shm_associate(struct shmid_kernel *shp, int shmflg)
1838 may = smack_flags_to_may(shmflg);
1839 return smk_curacc_shm(shp, may);
1843 * smack_shm_shmctl - Smack access check for shm
1845 * @cmd: what it wants to do
1847 * Returns 0 if current has the requested access, error code otherwise
1849 static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd)
1862 may = MAY_READWRITE;
1867 * System level information.
1873 return smk_curacc_shm(shp, may);
1877 * smack_shm_shmat - Smack access for shmat
1880 * @shmflg: access requested
1882 * Returns 0 if current has the requested access, error code otherwise
1884 static int smack_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr,
1889 may = smack_flags_to_may(shmflg);
1890 return smk_curacc_shm(shp, may);
1894 * smack_of_sem - the smack pointer for the sem
1897 * Returns a pointer to the smack value
1899 static char *smack_of_sem(struct sem_array *sma)
1901 return (char *)sma->sem_perm.security;
1905 * smack_sem_alloc_security - Set the security blob for sem
1910 static int smack_sem_alloc_security(struct sem_array *sma)
1912 struct kern_ipc_perm *isp = &sma->sem_perm;
1914 isp->security = current_security();
1919 * smack_sem_free_security - Clear the security blob for sem
1922 * Clears the blob pointer
1924 static void smack_sem_free_security(struct sem_array *sma)
1926 struct kern_ipc_perm *isp = &sma->sem_perm;
1928 isp->security = NULL;
1932 * smk_curacc_sem : check if current has access on sem
1934 * @access : access requested
1936 * Returns 0 if current has the requested access, error code otherwise
1938 static int smk_curacc_sem(struct sem_array *sma, int access)
1940 char *ssp = smack_of_sem(sma);
1941 struct smk_audit_info ad;
1944 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
1945 ad.a.u.ipc_id = sma->sem_perm.id;
1947 return smk_curacc(ssp, access, &ad);
1951 * smack_sem_associate - Smack access check for sem
1953 * @semflg: access requested
1955 * Returns 0 if current has the requested access, error code otherwise
1957 static int smack_sem_associate(struct sem_array *sma, int semflg)
1961 may = smack_flags_to_may(semflg);
1962 return smk_curacc_sem(sma, may);
1966 * smack_sem_shmctl - Smack access check for sem
1968 * @cmd: what it wants to do
1970 * Returns 0 if current has the requested access, error code otherwise
1972 static int smack_sem_semctl(struct sem_array *sma, int cmd)
1990 may = MAY_READWRITE;
1995 * System level information
2002 return smk_curacc_sem(sma, may);
2006 * smack_sem_semop - Smack checks of semaphore operations
2012 * Treated as read and write in all cases.
2014 * Returns 0 if access is allowed, error code otherwise
2016 static int smack_sem_semop(struct sem_array *sma, struct sembuf *sops,
2017 unsigned nsops, int alter)
2019 return smk_curacc_sem(sma, MAY_READWRITE);
2023 * smack_msg_alloc_security - Set the security blob for msg
2028 static int smack_msg_queue_alloc_security(struct msg_queue *msq)
2030 struct kern_ipc_perm *kisp = &msq->q_perm;
2032 kisp->security = current_security();
2037 * smack_msg_free_security - Clear the security blob for msg
2040 * Clears the blob pointer
2042 static void smack_msg_queue_free_security(struct msg_queue *msq)
2044 struct kern_ipc_perm *kisp = &msq->q_perm;
2046 kisp->security = NULL;
2050 * smack_of_msq - the smack pointer for the msq
2053 * Returns a pointer to the smack value
2055 static char *smack_of_msq(struct msg_queue *msq)
2057 return (char *)msq->q_perm.security;
2061 * smk_curacc_msq : helper to check if current has access on msq
2063 * @access : access requested
2065 * return 0 if current has access, error otherwise
2067 static int smk_curacc_msq(struct msg_queue *msq, int access)
2069 char *msp = smack_of_msq(msq);
2070 struct smk_audit_info ad;
2073 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2074 ad.a.u.ipc_id = msq->q_perm.id;
2076 return smk_curacc(msp, access, &ad);
2080 * smack_msg_queue_associate - Smack access check for msg_queue
2082 * @msqflg: access requested
2084 * Returns 0 if current has the requested access, error code otherwise
2086 static int smack_msg_queue_associate(struct msg_queue *msq, int msqflg)
2090 may = smack_flags_to_may(msqflg);
2091 return smk_curacc_msq(msq, may);
2095 * smack_msg_queue_msgctl - Smack access check for msg_queue
2097 * @cmd: what it wants to do
2099 * Returns 0 if current has the requested access, error code otherwise
2101 static int smack_msg_queue_msgctl(struct msg_queue *msq, int cmd)
2112 may = MAY_READWRITE;
2117 * System level information
2124 return smk_curacc_msq(msq, may);
2128 * smack_msg_queue_msgsnd - Smack access check for msg_queue
2131 * @msqflg: access requested
2133 * Returns 0 if current has the requested access, error code otherwise
2135 static int smack_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
2140 may = smack_flags_to_may(msqflg);
2141 return smk_curacc_msq(msq, may);
2145 * smack_msg_queue_msgsnd - Smack access check for msg_queue
2152 * Returns 0 if current has read and write access, error code otherwise
2154 static int smack_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
2155 struct task_struct *target, long type, int mode)
2157 return smk_curacc_msq(msq, MAY_READWRITE);
2161 * smack_ipc_permission - Smack access for ipc_permission()
2162 * @ipp: the object permissions
2163 * @flag: access requested
2165 * Returns 0 if current has read and write access, error code otherwise
2167 static int smack_ipc_permission(struct kern_ipc_perm *ipp, short flag)
2169 char *isp = ipp->security;
2170 int may = smack_flags_to_may(flag);
2171 struct smk_audit_info ad;
2174 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2175 ad.a.u.ipc_id = ipp->id;
2177 return smk_curacc(isp, may, &ad);
2181 * smack_ipc_getsecid - Extract smack security id
2182 * @ipp: the object permissions
2183 * @secid: where result will be saved
2185 static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, u32 *secid)
2187 char *smack = ipp->security;
2189 *secid = smack_to_secid(smack);
2193 * smack_d_instantiate - Make sure the blob is correct on an inode
2194 * @opt_dentry: dentry where inode will be attached
2195 * @inode: the object
2197 * Set the inode's security blob if it hasn't been done already.
2199 static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
2201 struct super_block *sbp;
2202 struct superblock_smack *sbsp;
2203 struct inode_smack *isp;
2204 char *csp = current_security();
2212 isp = inode->i_security;
2214 mutex_lock(&isp->smk_lock);
2216 * If the inode is already instantiated
2217 * take the quick way out
2219 if (isp->smk_flags & SMK_INODE_INSTANT)
2223 sbsp = sbp->s_security;
2225 * We're going to use the superblock default label
2226 * if there's no label on the file.
2228 final = sbsp->smk_default;
2231 * If this is the root inode the superblock
2232 * may be in the process of initialization.
2233 * If that is the case use the root value out
2234 * of the superblock.
2236 if (opt_dentry->d_parent == opt_dentry) {
2237 isp->smk_inode = sbsp->smk_root;
2238 isp->smk_flags |= SMK_INODE_INSTANT;
2243 * This is pretty hackish.
2244 * Casey says that we shouldn't have to do
2245 * file system specific code, but it does help
2246 * with keeping it simple.
2248 switch (sbp->s_magic) {
2251 * Casey says that it's a little embarassing
2252 * that the smack file system doesn't do
2253 * extended attributes.
2255 final = smack_known_star.smk_known;
2259 * Casey says pipes are easy (?)
2261 final = smack_known_star.smk_known;
2263 case DEVPTS_SUPER_MAGIC:
2265 * devpts seems content with the label of the task.
2266 * Programs that change smack have to treat the
2273 * Socket access is controlled by the socket
2274 * structures associated with the task involved.
2276 final = smack_known_star.smk_known;
2278 case PROC_SUPER_MAGIC:
2280 * Casey says procfs appears not to care.
2281 * The superblock default suffices.
2286 * Device labels should come from the filesystem,
2287 * but watch out, because they're volitile,
2288 * getting recreated on every reboot.
2290 final = smack_known_star.smk_known;
2294 * If a smack value has been set we want to use it,
2295 * but since tmpfs isn't giving us the opportunity
2296 * to set mount options simulate setting the
2297 * superblock default.
2301 * This isn't an understood special case.
2302 * Get the value from the xattr.
2306 * UNIX domain sockets use lower level socket data.
2308 if (S_ISSOCK(inode->i_mode)) {
2309 final = smack_known_star.smk_known;
2313 * No xattr support means, alas, no SMACK label.
2314 * Use the aforeapplied default.
2315 * It would be curious if the label of the task
2316 * does not match that assigned.
2318 if (inode->i_op->getxattr == NULL)
2321 * Get the dentry for xattr.
2323 dp = dget(opt_dentry);
2324 fetched = smk_fetch(inode, dp);
2325 if (fetched != NULL)
2332 isp->smk_inode = csp;
2334 isp->smk_inode = final;
2336 isp->smk_flags |= SMK_INODE_INSTANT;
2339 mutex_unlock(&isp->smk_lock);
2344 * smack_getprocattr - Smack process attribute access
2345 * @p: the object task
2346 * @name: the name of the attribute in /proc/.../attr
2347 * @value: where to put the result
2349 * Places a copy of the task Smack into value
2351 * Returns the length of the smack label or an error code
2353 static int smack_getprocattr(struct task_struct *p, char *name, char **value)
2358 if (strcmp(name, "current") != 0)
2361 cp = kstrdup(task_security(p), GFP_KERNEL);
2371 * smack_setprocattr - Smack process attribute setting
2372 * @p: the object task
2373 * @name: the name of the attribute in /proc/.../attr
2374 * @value: the value to set
2375 * @size: the size of the value
2377 * Sets the Smack value of the task. Only setting self
2378 * is permitted and only with privilege
2380 * Returns the length of the smack label or an error code
2382 static int smack_setprocattr(struct task_struct *p, char *name,
2383 void *value, size_t size)
2389 * Changing another process' Smack value is too dangerous
2390 * and supports no sane use case.
2395 if (!capable(CAP_MAC_ADMIN))
2398 if (value == NULL || size == 0 || size >= SMK_LABELLEN)
2401 if (strcmp(name, "current") != 0)
2404 newsmack = smk_import(value, size);
2405 if (newsmack == NULL)
2409 * No process is ever allowed the web ("@") label.
2411 if (newsmack == smack_known_web.smk_known)
2414 new = prepare_creds();
2417 new->security = newsmack;
2423 * smack_unix_stream_connect - Smack access on UDS
2425 * @other: the other socket
2428 * Return 0 if a subject with the smack of sock could access
2429 * an object with the smack of other, otherwise an error code
2431 static int smack_unix_stream_connect(struct socket *sock,
2432 struct socket *other, struct sock *newsk)
2434 struct socket_smack *ssp = sock->sk->sk_security;
2435 struct socket_smack *osp = other->sk->sk_security;
2436 struct smk_audit_info ad;
2439 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2440 smk_ad_setfield_u_net_sk(&ad, other->sk);
2442 if (!capable(CAP_MAC_OVERRIDE))
2443 rc = smk_access(ssp->smk_out, osp->smk_in, MAY_WRITE, &ad);
2449 * smack_unix_may_send - Smack access on UDS
2451 * @other: the other socket
2453 * Return 0 if a subject with the smack of sock could access
2454 * an object with the smack of other, otherwise an error code
2456 static int smack_unix_may_send(struct socket *sock, struct socket *other)
2458 struct socket_smack *ssp = sock->sk->sk_security;
2459 struct socket_smack *osp = other->sk->sk_security;
2460 struct smk_audit_info ad;
2463 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2464 smk_ad_setfield_u_net_sk(&ad, other->sk);
2466 if (!capable(CAP_MAC_OVERRIDE))
2467 rc = smk_access(ssp->smk_out, osp->smk_in, MAY_WRITE, &ad);
2473 * smack_socket_sendmsg - Smack check based on destination host
2476 * @size: the size of the message
2478 * Return 0 if the current subject can write to the destination
2479 * host. This is only a question if the destination is a single
2482 static int smack_socket_sendmsg(struct socket *sock, struct msghdr *msg,
2485 struct sockaddr_in *sip = (struct sockaddr_in *) msg->msg_name;
2488 * Perfectly reasonable for this to be NULL
2490 if (sip == NULL || sip->sin_family != AF_INET)
2493 return smack_netlabel_send(sock->sk, sip);
2498 * smack_from_secattr - Convert a netlabel attr.mls.lvl/attr.mls.cat pair to smack
2499 * @sap: netlabel secattr
2500 * @sip: where to put the result
2502 * Copies a smack label into sip
2504 static void smack_from_secattr(struct netlbl_lsm_secattr *sap, char *sip)
2506 char smack[SMK_LABELLEN];
2510 if ((sap->flags & NETLBL_SECATTR_MLS_LVL) != 0) {
2512 * Looks like a CIPSO packet.
2513 * If there are flags but no level netlabel isn't
2514 * behaving the way we expect it to.
2516 * Get the categories, if any
2517 * Without guidance regarding the smack value
2518 * for the packet fall back on the network
2521 memset(smack, '\0', SMK_LABELLEN);
2522 if ((sap->flags & NETLBL_SECATTR_MLS_CAT) != 0)
2524 pcat = netlbl_secattr_catmap_walk(
2525 sap->attr.mls.cat, pcat + 1);
2528 smack_catset_bit(pcat, smack);
2531 * If it is CIPSO using smack direct mapping
2532 * we are already done. WeeHee.
2534 if (sap->attr.mls.lvl == smack_cipso_direct) {
2535 memcpy(sip, smack, SMK_MAXLEN);
2539 * Look it up in the supplied table if it is not
2542 smack_from_cipso(sap->attr.mls.lvl, smack, sip);
2545 if ((sap->flags & NETLBL_SECATTR_SECID) != 0) {
2547 * Looks like a fallback, which gives us a secid.
2549 sp = smack_from_secid(sap->attr.secid);
2551 * This has got to be a bug because it is
2552 * impossible to specify a fallback without
2553 * specifying the label, which will ensure
2554 * it has a secid, and the only way to get a
2555 * secid is from a fallback.
2558 strncpy(sip, sp, SMK_MAXLEN);
2562 * Without guidance regarding the smack value
2563 * for the packet fall back on the network
2566 strncpy(sip, smack_net_ambient, SMK_MAXLEN);
2571 * smack_socket_sock_rcv_skb - Smack packet delivery access check
2575 * Returns 0 if the packet should be delivered, an error code otherwise
2577 static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
2579 struct netlbl_lsm_secattr secattr;
2580 struct socket_smack *ssp = sk->sk_security;
2581 char smack[SMK_LABELLEN];
2584 struct smk_audit_info ad;
2585 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2589 * Translate what netlabel gave us.
2591 netlbl_secattr_init(&secattr);
2593 rc = netlbl_skbuff_getattr(skb, sk->sk_family, &secattr);
2595 smack_from_secattr(&secattr, smack);
2598 csp = smack_net_ambient;
2600 netlbl_secattr_destroy(&secattr);
2603 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2604 ad.a.u.net.family = sk->sk_family;
2605 ad.a.u.net.netif = skb->skb_iif;
2606 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
2609 * Receiving a packet requires that the other end
2610 * be able to write here. Read access is not required.
2611 * This is the simplist possible security model
2614 rc = smk_access(csp, ssp->smk_in, MAY_WRITE, &ad);
2616 netlbl_skbuff_err(skb, rc, 0);
2621 * smack_socket_getpeersec_stream - pull in packet label
2623 * @optval: user's destination
2624 * @optlen: size thereof
2627 * returns zero on success, an error code otherwise
2629 static int smack_socket_getpeersec_stream(struct socket *sock,
2630 char __user *optval,
2631 int __user *optlen, unsigned len)
2633 struct socket_smack *ssp;
2637 ssp = sock->sk->sk_security;
2638 slen = strlen(ssp->smk_packet) + 1;
2642 else if (copy_to_user(optval, ssp->smk_packet, slen) != 0)
2645 if (put_user(slen, optlen) != 0)
2653 * smack_socket_getpeersec_dgram - pull in packet label
2654 * @sock: the peer socket
2656 * @secid: pointer to where to put the secid of the packet
2658 * Sets the netlabel socket state on sk from parent
2660 static int smack_socket_getpeersec_dgram(struct socket *sock,
2661 struct sk_buff *skb, u32 *secid)
2664 struct netlbl_lsm_secattr secattr;
2665 struct socket_smack *sp;
2666 char smack[SMK_LABELLEN];
2667 int family = PF_UNSPEC;
2668 u32 s = 0; /* 0 is the invalid secid */
2672 if (skb->protocol == htons(ETH_P_IP))
2674 else if (skb->protocol == htons(ETH_P_IPV6))
2677 if (family == PF_UNSPEC && sock != NULL)
2678 family = sock->sk->sk_family;
2680 if (family == PF_UNIX) {
2681 sp = sock->sk->sk_security;
2682 s = smack_to_secid(sp->smk_out);
2683 } else if (family == PF_INET || family == PF_INET6) {
2685 * Translate what netlabel gave us.
2687 netlbl_secattr_init(&secattr);
2688 rc = netlbl_skbuff_getattr(skb, family, &secattr);
2690 smack_from_secattr(&secattr, smack);
2691 s = smack_to_secid(smack);
2693 netlbl_secattr_destroy(&secattr);
2702 * smack_sock_graft - Initialize a newly created socket with an existing sock
2704 * @parent: parent socket
2706 * Set the smk_{in,out} state of an existing sock based on the process that
2707 * is creating the new socket.
2709 static void smack_sock_graft(struct sock *sk, struct socket *parent)
2711 struct socket_smack *ssp;
2714 (sk->sk_family != PF_INET && sk->sk_family != PF_INET6))
2717 ssp = sk->sk_security;
2718 ssp->smk_in = ssp->smk_out = current_security();
2719 /* cssp->smk_packet is already set in smack_inet_csk_clone() */
2723 * smack_inet_conn_request - Smack access check on connect
2724 * @sk: socket involved
2728 * Returns 0 if a task with the packet label could write to
2729 * the socket, otherwise an error code
2731 static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
2732 struct request_sock *req)
2734 u16 family = sk->sk_family;
2735 struct socket_smack *ssp = sk->sk_security;
2736 struct netlbl_lsm_secattr secattr;
2737 struct sockaddr_in addr;
2739 char smack[SMK_LABELLEN];
2741 struct smk_audit_info ad;
2743 /* handle mapped IPv4 packets arriving via IPv6 sockets */
2744 if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP))
2747 netlbl_secattr_init(&secattr);
2748 rc = netlbl_skbuff_getattr(skb, family, &secattr);
2750 smack_from_secattr(&secattr, smack);
2752 strncpy(smack, smack_known_huh.smk_known, SMK_MAXLEN);
2753 netlbl_secattr_destroy(&secattr);
2756 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2757 ad.a.u.net.family = family;
2758 ad.a.u.net.netif = skb->skb_iif;
2759 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
2762 * Receiving a packet requires that the other end be able to write
2763 * here. Read access is not required.
2765 rc = smk_access(smack, ssp->smk_in, MAY_WRITE, &ad);
2770 * Save the peer's label in the request_sock so we can later setup
2771 * smk_packet in the child socket so that SO_PEERCRED can report it.
2773 req->peer_secid = smack_to_secid(smack);
2776 * We need to decide if we want to label the incoming connection here
2777 * if we do we only need to label the request_sock and the stack will
2778 * propogate the wire-label to the sock when it is created.
2781 addr.sin_addr.s_addr = hdr->saddr;
2783 if (smack_host_label(&addr) == NULL) {
2785 netlbl_secattr_init(&secattr);
2786 smack_to_secattr(smack, &secattr);
2787 rc = netlbl_req_setattr(req, &secattr);
2788 netlbl_secattr_destroy(&secattr);
2791 netlbl_req_delattr(req);
2798 * smack_inet_csk_clone - Copy the connection information to the new socket
2799 * @sk: the new socket
2800 * @req: the connection's request_sock
2802 * Transfer the connection's peer label to the newly created socket.
2804 static void smack_inet_csk_clone(struct sock *sk,
2805 const struct request_sock *req)
2807 struct socket_smack *ssp = sk->sk_security;
2810 if (req->peer_secid != 0) {
2811 smack = smack_from_secid(req->peer_secid);
2812 strncpy(ssp->smk_packet, smack, SMK_MAXLEN);
2814 ssp->smk_packet[0] = '\0';
2818 * Key management security hooks
2820 * Casey has not tested key support very heavily.
2821 * The permission check is most likely too restrictive.
2822 * If you care about keys please have a look.
2827 * smack_key_alloc - Set the key security blob
2829 * @cred: the credentials to use
2832 * No allocation required
2836 static int smack_key_alloc(struct key *key, const struct cred *cred,
2837 unsigned long flags)
2839 key->security = cred->security;
2844 * smack_key_free - Clear the key security blob
2847 * Clear the blob pointer
2849 static void smack_key_free(struct key *key)
2851 key->security = NULL;
2855 * smack_key_permission - Smack access on a key
2856 * @key_ref: gets to the object
2857 * @cred: the credentials to use
2860 * Return 0 if the task has read and write to the object,
2861 * an error code otherwise
2863 static int smack_key_permission(key_ref_t key_ref,
2864 const struct cred *cred, key_perm_t perm)
2867 struct smk_audit_info ad;
2869 keyp = key_ref_to_ptr(key_ref);
2873 * If the key hasn't been initialized give it access so that
2876 if (keyp->security == NULL)
2879 * This should not occur
2881 if (cred->security == NULL)
2884 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_KEY);
2885 ad.a.u.key_struct.key = keyp->serial;
2886 ad.a.u.key_struct.key_desc = keyp->description;
2888 return smk_access(cred->security, keyp->security,
2889 MAY_READWRITE, &ad);
2891 #endif /* CONFIG_KEYS */
2896 * Audit requires a unique representation of each Smack specific
2897 * rule. This unique representation is used to distinguish the
2898 * object to be audited from remaining kernel objects and also
2899 * works as a glue between the audit hooks.
2901 * Since repository entries are added but never deleted, we'll use
2902 * the smack_known label address related to the given audit rule as
2903 * the needed unique representation. This also better fits the smack
2904 * model where nearly everything is a label.
2909 * smack_audit_rule_init - Initialize a smack audit rule
2910 * @field: audit rule fields given from user-space (audit.h)
2911 * @op: required testing operator (=, !=, >, <, ...)
2912 * @rulestr: smack label to be audited
2913 * @vrule: pointer to save our own audit rule representation
2915 * Prepare to audit cases where (@field @op @rulestr) is true.
2916 * The label to be audited is created if necessay.
2918 static int smack_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
2920 char **rule = (char **)vrule;
2923 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
2926 if (op != Audit_equal && op != Audit_not_equal)
2929 *rule = smk_import(rulestr, 0);
2935 * smack_audit_rule_known - Distinguish Smack audit rules
2936 * @krule: rule of interest, in Audit kernel representation format
2938 * This is used to filter Smack rules from remaining Audit ones.
2939 * If it's proved that this rule belongs to us, the
2940 * audit_rule_match hook will be called to do the final judgement.
2942 static int smack_audit_rule_known(struct audit_krule *krule)
2944 struct audit_field *f;
2947 for (i = 0; i < krule->field_count; i++) {
2948 f = &krule->fields[i];
2950 if (f->type == AUDIT_SUBJ_USER || f->type == AUDIT_OBJ_USER)
2958 * smack_audit_rule_match - Audit given object ?
2959 * @secid: security id for identifying the object to test
2960 * @field: audit rule flags given from user-space
2961 * @op: required testing operator
2962 * @vrule: smack internal rule presentation
2963 * @actx: audit context associated with the check
2965 * The core Audit hook. It's used to take the decision of
2966 * whether to audit or not to audit a given object.
2968 static int smack_audit_rule_match(u32 secid, u32 field, u32 op, void *vrule,
2969 struct audit_context *actx)
2975 audit_log(actx, GFP_KERNEL, AUDIT_SELINUX_ERR,
2976 "Smack: missing rule\n");
2980 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
2983 smack = smack_from_secid(secid);
2986 * No need to do string comparisons. If a match occurs,
2987 * both pointers will point to the same smack_known
2990 if (op == Audit_equal)
2991 return (rule == smack);
2992 if (op == Audit_not_equal)
2993 return (rule != smack);
2999 * smack_audit_rule_free - free smack rule representation
3000 * @vrule: rule to be freed.
3002 * No memory was allocated.
3004 static void smack_audit_rule_free(void *vrule)
3009 #endif /* CONFIG_AUDIT */
3012 * smack_secid_to_secctx - return the smack label for a secid
3013 * @secid: incoming integer
3014 * @secdata: destination
3015 * @seclen: how long it is
3017 * Exists for networking code.
3019 static int smack_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
3021 char *sp = smack_from_secid(secid);
3025 *seclen = strlen(sp);
3030 * smack_secctx_to_secid - return the secid for a smack label
3031 * @secdata: smack label
3032 * @seclen: how long result is
3033 * @secid: outgoing integer
3035 * Exists for audit and networking code.
3037 static int smack_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
3039 *secid = smack_to_secid(secdata);
3044 * smack_release_secctx - don't do anything.
3048 * Exists to make sure nothing gets done, and properly
3050 static void smack_release_secctx(char *secdata, u32 seclen)
3054 static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
3056 return smack_inode_setsecurity(inode, XATTR_SMACK_SUFFIX, ctx, ctxlen, 0);
3059 static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
3061 return __vfs_setxattr_noperm(dentry, XATTR_NAME_SMACK, ctx, ctxlen, 0);
3064 static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
3067 len = smack_inode_getsecurity(inode, XATTR_SMACK_SUFFIX, ctx, true);
3075 struct security_operations smack_ops = {
3078 .ptrace_access_check = smack_ptrace_access_check,
3079 .ptrace_traceme = smack_ptrace_traceme,
3080 .syslog = smack_syslog,
3082 .sb_alloc_security = smack_sb_alloc_security,
3083 .sb_free_security = smack_sb_free_security,
3084 .sb_copy_data = smack_sb_copy_data,
3085 .sb_kern_mount = smack_sb_kern_mount,
3086 .sb_statfs = smack_sb_statfs,
3087 .sb_mount = smack_sb_mount,
3088 .sb_umount = smack_sb_umount,
3090 .inode_alloc_security = smack_inode_alloc_security,
3091 .inode_free_security = smack_inode_free_security,
3092 .inode_init_security = smack_inode_init_security,
3093 .inode_link = smack_inode_link,
3094 .inode_unlink = smack_inode_unlink,
3095 .inode_rmdir = smack_inode_rmdir,
3096 .inode_rename = smack_inode_rename,
3097 .inode_permission = smack_inode_permission,
3098 .inode_setattr = smack_inode_setattr,
3099 .inode_getattr = smack_inode_getattr,
3100 .inode_setxattr = smack_inode_setxattr,
3101 .inode_post_setxattr = smack_inode_post_setxattr,
3102 .inode_getxattr = smack_inode_getxattr,
3103 .inode_removexattr = smack_inode_removexattr,
3104 .inode_getsecurity = smack_inode_getsecurity,
3105 .inode_setsecurity = smack_inode_setsecurity,
3106 .inode_listsecurity = smack_inode_listsecurity,
3107 .inode_getsecid = smack_inode_getsecid,
3109 .file_permission = smack_file_permission,
3110 .file_alloc_security = smack_file_alloc_security,
3111 .file_free_security = smack_file_free_security,
3112 .file_ioctl = smack_file_ioctl,
3113 .file_lock = smack_file_lock,
3114 .file_fcntl = smack_file_fcntl,
3115 .file_set_fowner = smack_file_set_fowner,
3116 .file_send_sigiotask = smack_file_send_sigiotask,
3117 .file_receive = smack_file_receive,
3119 .cred_alloc_blank = smack_cred_alloc_blank,
3120 .cred_free = smack_cred_free,
3121 .cred_prepare = smack_cred_prepare,
3122 .cred_transfer = smack_cred_transfer,
3123 .kernel_act_as = smack_kernel_act_as,
3124 .kernel_create_files_as = smack_kernel_create_files_as,
3125 .task_setpgid = smack_task_setpgid,
3126 .task_getpgid = smack_task_getpgid,
3127 .task_getsid = smack_task_getsid,
3128 .task_getsecid = smack_task_getsecid,
3129 .task_setnice = smack_task_setnice,
3130 .task_setioprio = smack_task_setioprio,
3131 .task_getioprio = smack_task_getioprio,
3132 .task_setscheduler = smack_task_setscheduler,
3133 .task_getscheduler = smack_task_getscheduler,
3134 .task_movememory = smack_task_movememory,
3135 .task_kill = smack_task_kill,
3136 .task_wait = smack_task_wait,
3137 .task_to_inode = smack_task_to_inode,
3139 .ipc_permission = smack_ipc_permission,
3140 .ipc_getsecid = smack_ipc_getsecid,
3142 .msg_msg_alloc_security = smack_msg_msg_alloc_security,
3143 .msg_msg_free_security = smack_msg_msg_free_security,
3145 .msg_queue_alloc_security = smack_msg_queue_alloc_security,
3146 .msg_queue_free_security = smack_msg_queue_free_security,
3147 .msg_queue_associate = smack_msg_queue_associate,
3148 .msg_queue_msgctl = smack_msg_queue_msgctl,
3149 .msg_queue_msgsnd = smack_msg_queue_msgsnd,
3150 .msg_queue_msgrcv = smack_msg_queue_msgrcv,
3152 .shm_alloc_security = smack_shm_alloc_security,
3153 .shm_free_security = smack_shm_free_security,
3154 .shm_associate = smack_shm_associate,
3155 .shm_shmctl = smack_shm_shmctl,
3156 .shm_shmat = smack_shm_shmat,
3158 .sem_alloc_security = smack_sem_alloc_security,
3159 .sem_free_security = smack_sem_free_security,
3160 .sem_associate = smack_sem_associate,
3161 .sem_semctl = smack_sem_semctl,
3162 .sem_semop = smack_sem_semop,
3164 .d_instantiate = smack_d_instantiate,
3166 .getprocattr = smack_getprocattr,
3167 .setprocattr = smack_setprocattr,
3169 .unix_stream_connect = smack_unix_stream_connect,
3170 .unix_may_send = smack_unix_may_send,
3172 .socket_post_create = smack_socket_post_create,
3173 .socket_connect = smack_socket_connect,
3174 .socket_sendmsg = smack_socket_sendmsg,
3175 .socket_sock_rcv_skb = smack_socket_sock_rcv_skb,
3176 .socket_getpeersec_stream = smack_socket_getpeersec_stream,
3177 .socket_getpeersec_dgram = smack_socket_getpeersec_dgram,
3178 .sk_alloc_security = smack_sk_alloc_security,
3179 .sk_free_security = smack_sk_free_security,
3180 .sock_graft = smack_sock_graft,
3181 .inet_conn_request = smack_inet_conn_request,
3182 .inet_csk_clone = smack_inet_csk_clone,
3184 /* key management security hooks */
3186 .key_alloc = smack_key_alloc,
3187 .key_free = smack_key_free,
3188 .key_permission = smack_key_permission,
3189 #endif /* CONFIG_KEYS */
3193 .audit_rule_init = smack_audit_rule_init,
3194 .audit_rule_known = smack_audit_rule_known,
3195 .audit_rule_match = smack_audit_rule_match,
3196 .audit_rule_free = smack_audit_rule_free,
3197 #endif /* CONFIG_AUDIT */
3199 .secid_to_secctx = smack_secid_to_secctx,
3200 .secctx_to_secid = smack_secctx_to_secid,
3201 .release_secctx = smack_release_secctx,
3202 .inode_notifysecctx = smack_inode_notifysecctx,
3203 .inode_setsecctx = smack_inode_setsecctx,
3204 .inode_getsecctx = smack_inode_getsecctx,
3208 static __init void init_smack_know_list(void)
3210 list_add(&smack_known_huh.list, &smack_known_list);
3211 list_add(&smack_known_hat.list, &smack_known_list);
3212 list_add(&smack_known_star.list, &smack_known_list);
3213 list_add(&smack_known_floor.list, &smack_known_list);
3214 list_add(&smack_known_invalid.list, &smack_known_list);
3215 list_add(&smack_known_web.list, &smack_known_list);
3219 * smack_init - initialize the smack system
3223 static __init int smack_init(void)
3227 if (!security_module_enable(&smack_ops))
3230 printk(KERN_INFO "Smack: Initializing.\n");
3233 * Set the security state for the initial task.
3235 cred = (struct cred *) current->cred;
3236 cred->security = &smack_known_floor.smk_known;
3238 /* initialize the smack_know_list */
3239 init_smack_know_list();
3243 spin_lock_init(&smack_known_huh.smk_cipsolock);
3244 spin_lock_init(&smack_known_hat.smk_cipsolock);
3245 spin_lock_init(&smack_known_star.smk_cipsolock);
3246 spin_lock_init(&smack_known_floor.smk_cipsolock);
3247 spin_lock_init(&smack_known_invalid.smk_cipsolock);
3252 if (register_security(&smack_ops))
3253 panic("smack: Unable to register with kernel.\n");
3259 * Smack requires early initialization in order to label
3260 * all processes and objects when they are created.
3262 security_initcall(smack_init);