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/mutex.h>
28 #include <linux/pipe_fs_i.h>
29 #include <net/netlabel.h>
30 #include <net/cipso_ipv4.h>
31 #include <linux/audit.h>
32 #include <linux/magic.h>
35 #define task_security(task) (task_cred_xxx((task), security))
38 * smk_fetch - Fetch the smack label from a file.
39 * @ip: a pointer to the inode
40 * @dp: a pointer to the dentry
42 * Returns a pointer to the master list entry for the Smack label
43 * or NULL if there was no label to fetch.
45 static char *smk_fetch(struct inode *ip, struct dentry *dp)
48 char in[SMK_LABELLEN];
50 if (ip->i_op->getxattr == NULL)
53 rc = ip->i_op->getxattr(dp, XATTR_NAME_SMACK, in, SMK_LABELLEN);
57 return smk_import(in, rc);
61 * new_inode_smack - allocate an inode security blob
62 * @smack: a pointer to the Smack label to use in the blob
64 * Returns the new blob or NULL if there's no memory available
66 struct inode_smack *new_inode_smack(char *smack)
68 struct inode_smack *isp;
70 isp = kzalloc(sizeof(struct inode_smack), GFP_KERNEL);
74 isp->smk_inode = smack;
76 mutex_init(&isp->smk_lock);
87 * smack_ptrace_access_check - Smack approval on PTRACE_ATTACH
88 * @ctp: child task pointer
89 * @mode: ptrace attachment mode
91 * Returns 0 if access is OK, an error code otherwise
93 * Do the capability checks, and require read and write.
95 static int smack_ptrace_access_check(struct task_struct *ctp, unsigned int mode)
98 struct smk_audit_info ad;
101 rc = cap_ptrace_access_check(ctp, mode);
105 sp = current_security();
106 tsp = task_security(ctp);
107 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
108 smk_ad_setfield_u_tsk(&ad, ctp);
110 /* we won't log here, because rc can be overriden */
111 rc = smk_access(sp, tsp, MAY_READWRITE, NULL);
112 if (rc != 0 && capable(CAP_MAC_OVERRIDE))
115 smack_log(sp, tsp, MAY_READWRITE, rc, &ad);
120 * smack_ptrace_traceme - Smack approval on PTRACE_TRACEME
121 * @ptp: parent task pointer
123 * Returns 0 if access is OK, an error code otherwise
125 * Do the capability checks, and require read and write.
127 static int smack_ptrace_traceme(struct task_struct *ptp)
130 struct smk_audit_info ad;
133 rc = cap_ptrace_traceme(ptp);
137 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
138 smk_ad_setfield_u_tsk(&ad, ptp);
140 sp = current_security();
141 tsp = task_security(ptp);
142 /* we won't log here, because rc can be overriden */
143 rc = smk_access(tsp, sp, MAY_READWRITE, NULL);
144 if (rc != 0 && has_capability(ptp, CAP_MAC_OVERRIDE))
147 smack_log(tsp, sp, MAY_READWRITE, rc, &ad);
152 * smack_syslog - Smack approval on syslog
153 * @type: message type
155 * Require that the task has the floor label
157 * Returns 0 on success, error code otherwise.
159 static int smack_syslog(int type, bool from_file)
162 char *sp = current_security();
164 rc = cap_syslog(type, from_file);
168 if (capable(CAP_MAC_OVERRIDE))
171 if (sp != smack_known_floor.smk_known)
183 * smack_sb_alloc_security - allocate a superblock blob
184 * @sb: the superblock getting the blob
186 * Returns 0 on success or -ENOMEM on error.
188 static int smack_sb_alloc_security(struct super_block *sb)
190 struct superblock_smack *sbsp;
192 sbsp = kzalloc(sizeof(struct superblock_smack), GFP_KERNEL);
197 sbsp->smk_root = smack_known_floor.smk_known;
198 sbsp->smk_default = smack_known_floor.smk_known;
199 sbsp->smk_floor = smack_known_floor.smk_known;
200 sbsp->smk_hat = smack_known_hat.smk_known;
201 sbsp->smk_initialized = 0;
202 spin_lock_init(&sbsp->smk_sblock);
204 sb->s_security = sbsp;
210 * smack_sb_free_security - free a superblock blob
211 * @sb: the superblock getting the blob
214 static void smack_sb_free_security(struct super_block *sb)
216 kfree(sb->s_security);
217 sb->s_security = NULL;
221 * smack_sb_copy_data - copy mount options data for processing
222 * @orig: where to start
223 * @smackopts: mount options string
225 * Returns 0 on success or -ENOMEM on error.
227 * Copy the Smack specific mount options out of the mount
230 static int smack_sb_copy_data(char *orig, char *smackopts)
232 char *cp, *commap, *otheropts, *dp;
234 otheropts = (char *)get_zeroed_page(GFP_KERNEL);
235 if (otheropts == NULL)
238 for (cp = orig, commap = orig; commap != NULL; cp = commap + 1) {
239 if (strstr(cp, SMK_FSDEFAULT) == cp)
241 else if (strstr(cp, SMK_FSFLOOR) == cp)
243 else if (strstr(cp, SMK_FSHAT) == cp)
245 else if (strstr(cp, SMK_FSROOT) == cp)
250 commap = strchr(cp, ',');
259 strcpy(orig, otheropts);
260 free_page((unsigned long)otheropts);
266 * smack_sb_kern_mount - Smack specific mount processing
267 * @sb: the file system superblock
268 * @flags: the mount flags
269 * @data: the smack mount options
271 * Returns 0 on success, an error code on failure
273 static int smack_sb_kern_mount(struct super_block *sb, int flags, void *data)
275 struct dentry *root = sb->s_root;
276 struct inode *inode = root->d_inode;
277 struct superblock_smack *sp = sb->s_security;
278 struct inode_smack *isp;
283 spin_lock(&sp->smk_sblock);
284 if (sp->smk_initialized != 0) {
285 spin_unlock(&sp->smk_sblock);
288 sp->smk_initialized = 1;
289 spin_unlock(&sp->smk_sblock);
291 for (op = data; op != NULL; op = commap) {
292 commap = strchr(op, ',');
296 if (strncmp(op, SMK_FSHAT, strlen(SMK_FSHAT)) == 0) {
297 op += strlen(SMK_FSHAT);
298 nsp = smk_import(op, 0);
301 } else if (strncmp(op, SMK_FSFLOOR, strlen(SMK_FSFLOOR)) == 0) {
302 op += strlen(SMK_FSFLOOR);
303 nsp = smk_import(op, 0);
306 } else if (strncmp(op, SMK_FSDEFAULT,
307 strlen(SMK_FSDEFAULT)) == 0) {
308 op += strlen(SMK_FSDEFAULT);
309 nsp = smk_import(op, 0);
311 sp->smk_default = nsp;
312 } else if (strncmp(op, SMK_FSROOT, strlen(SMK_FSROOT)) == 0) {
313 op += strlen(SMK_FSROOT);
314 nsp = smk_import(op, 0);
321 * Initialize the root inode.
323 isp = inode->i_security;
325 inode->i_security = new_inode_smack(sp->smk_root);
327 isp->smk_inode = sp->smk_root;
333 * smack_sb_statfs - Smack check on statfs
334 * @dentry: identifies the file system in question
336 * Returns 0 if current can read the floor of the filesystem,
337 * and error code otherwise
339 static int smack_sb_statfs(struct dentry *dentry)
341 struct superblock_smack *sbp = dentry->d_sb->s_security;
343 struct smk_audit_info ad;
345 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
346 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
348 rc = smk_curacc(sbp->smk_floor, MAY_READ, &ad);
353 * smack_sb_mount - Smack check for mounting
360 * Returns 0 if current can write the floor of the filesystem
361 * being mounted on, an error code otherwise.
363 static int smack_sb_mount(char *dev_name, struct path *path,
364 char *type, unsigned long flags, void *data)
366 struct superblock_smack *sbp = path->mnt->mnt_sb->s_security;
367 struct smk_audit_info ad;
369 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
370 smk_ad_setfield_u_fs_path(&ad, *path);
372 return smk_curacc(sbp->smk_floor, MAY_WRITE, &ad);
376 * smack_sb_umount - Smack check for unmounting
377 * @mnt: file system to unmount
380 * Returns 0 if current can write the floor of the filesystem
381 * being unmounted, an error code otherwise.
383 static int smack_sb_umount(struct vfsmount *mnt, int flags)
385 struct superblock_smack *sbp;
386 struct smk_audit_info ad;
388 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
389 smk_ad_setfield_u_fs_path_dentry(&ad, mnt->mnt_root);
390 smk_ad_setfield_u_fs_path_mnt(&ad, mnt);
392 sbp = mnt->mnt_sb->s_security;
393 return smk_curacc(sbp->smk_floor, MAY_WRITE, &ad);
401 * smack_inode_alloc_security - allocate an inode blob
402 * @inode: the inode in need of a blob
404 * Returns 0 if it gets a blob, -ENOMEM otherwise
406 static int smack_inode_alloc_security(struct inode *inode)
408 inode->i_security = new_inode_smack(current_security());
409 if (inode->i_security == NULL)
415 * smack_inode_free_security - free an inode blob
416 * @inode: the inode with a blob
418 * Clears the blob pointer in inode
420 static void smack_inode_free_security(struct inode *inode)
422 kfree(inode->i_security);
423 inode->i_security = NULL;
427 * smack_inode_init_security - copy out the smack from an inode
430 * @name: where to put the attribute name
431 * @value: where to put the attribute value
432 * @len: where to put the length of the attribute
434 * Returns 0 if it all works out, -ENOMEM if there's no memory
436 static int smack_inode_init_security(struct inode *inode, struct inode *dir,
437 char **name, void **value, size_t *len)
439 char *isp = smk_of_inode(inode);
442 *name = kstrdup(XATTR_SMACK_SUFFIX, GFP_KERNEL);
448 *value = kstrdup(isp, GFP_KERNEL);
454 *len = strlen(isp) + 1;
460 * smack_inode_link - Smack check on link
461 * @old_dentry: the existing object
463 * @new_dentry: the new object
465 * Returns 0 if access is permitted, an error code otherwise
467 static int smack_inode_link(struct dentry *old_dentry, struct inode *dir,
468 struct dentry *new_dentry)
471 struct smk_audit_info ad;
474 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
475 smk_ad_setfield_u_fs_path_dentry(&ad, old_dentry);
477 isp = smk_of_inode(old_dentry->d_inode);
478 rc = smk_curacc(isp, MAY_WRITE, &ad);
480 if (rc == 0 && new_dentry->d_inode != NULL) {
481 isp = smk_of_inode(new_dentry->d_inode);
482 smk_ad_setfield_u_fs_path_dentry(&ad, new_dentry);
483 rc = smk_curacc(isp, MAY_WRITE, &ad);
490 * smack_inode_unlink - Smack check on inode deletion
491 * @dir: containing directory object
492 * @dentry: file to unlink
494 * Returns 0 if current can write the containing directory
495 * and the object, error code otherwise
497 static int smack_inode_unlink(struct inode *dir, struct dentry *dentry)
499 struct inode *ip = dentry->d_inode;
500 struct smk_audit_info ad;
503 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
504 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
507 * You need write access to the thing you're unlinking
509 rc = smk_curacc(smk_of_inode(ip), MAY_WRITE, &ad);
512 * You also need write access to the containing directory
514 smk_ad_setfield_u_fs_path_dentry(&ad, NULL);
515 smk_ad_setfield_u_fs_inode(&ad, dir);
516 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE, &ad);
522 * smack_inode_rmdir - Smack check on directory deletion
523 * @dir: containing directory object
524 * @dentry: directory to unlink
526 * Returns 0 if current can write the containing directory
527 * and the directory, error code otherwise
529 static int smack_inode_rmdir(struct inode *dir, struct dentry *dentry)
531 struct smk_audit_info ad;
534 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
535 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
538 * You need write access to the thing you're removing
540 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
543 * You also need write access to the containing directory
545 smk_ad_setfield_u_fs_path_dentry(&ad, NULL);
546 smk_ad_setfield_u_fs_inode(&ad, dir);
547 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE, &ad);
554 * smack_inode_rename - Smack check on rename
555 * @old_inode: the old directory
556 * @old_dentry: unused
557 * @new_inode: the new directory
558 * @new_dentry: unused
560 * Read and write access is required on both the old and
563 * Returns 0 if access is permitted, an error code otherwise
565 static int smack_inode_rename(struct inode *old_inode,
566 struct dentry *old_dentry,
567 struct inode *new_inode,
568 struct dentry *new_dentry)
572 struct smk_audit_info ad;
574 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
575 smk_ad_setfield_u_fs_path_dentry(&ad, old_dentry);
577 isp = smk_of_inode(old_dentry->d_inode);
578 rc = smk_curacc(isp, MAY_READWRITE, &ad);
580 if (rc == 0 && new_dentry->d_inode != NULL) {
581 isp = smk_of_inode(new_dentry->d_inode);
582 smk_ad_setfield_u_fs_path_dentry(&ad, new_dentry);
583 rc = smk_curacc(isp, MAY_READWRITE, &ad);
589 * smack_inode_permission - Smack version of permission()
590 * @inode: the inode in question
591 * @mask: the access requested
593 * This is the important Smack hook.
595 * Returns 0 if access is permitted, -EACCES otherwise
597 static int smack_inode_permission(struct inode *inode, int mask)
599 struct smk_audit_info ad;
601 * No permission to check. Existence test. Yup, it's there.
605 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
606 smk_ad_setfield_u_fs_inode(&ad, inode);
607 return smk_curacc(smk_of_inode(inode), mask, &ad);
611 * smack_inode_setattr - Smack check for setting attributes
612 * @dentry: the object
613 * @iattr: for the force flag
615 * Returns 0 if access is permitted, an error code otherwise
617 static int smack_inode_setattr(struct dentry *dentry, struct iattr *iattr)
619 struct smk_audit_info ad;
621 * Need to allow for clearing the setuid bit.
623 if (iattr->ia_valid & ATTR_FORCE)
625 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
626 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
628 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
632 * smack_inode_getattr - Smack check for getting attributes
634 * @dentry: the object
636 * Returns 0 if access is permitted, an error code otherwise
638 static int smack_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
640 struct smk_audit_info ad;
642 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
643 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
644 smk_ad_setfield_u_fs_path_mnt(&ad, mnt);
645 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ, &ad);
649 * smack_inode_setxattr - Smack check for setting xattrs
650 * @dentry: the object
651 * @name: name of the attribute
656 * This protects the Smack attribute explicitly.
658 * Returns 0 if access is permitted, an error code otherwise
660 static int smack_inode_setxattr(struct dentry *dentry, const char *name,
661 const void *value, size_t size, int flags)
663 struct smk_audit_info ad;
666 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
667 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
668 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0) {
669 if (!capable(CAP_MAC_ADMIN))
672 * check label validity here so import wont fail on
675 if (size == 0 || size >= SMK_LABELLEN ||
676 smk_import(value, size) == NULL)
679 rc = cap_inode_setxattr(dentry, name, value, size, flags);
681 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
682 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
685 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
691 * smack_inode_post_setxattr - Apply the Smack update approved above
693 * @name: attribute name
694 * @value: attribute value
695 * @size: attribute size
698 * Set the pointer in the inode blob to the entry found
699 * in the master label list.
701 static void smack_inode_post_setxattr(struct dentry *dentry, const char *name,
702 const void *value, size_t size, int flags)
704 struct inode_smack *isp;
710 if (strcmp(name, XATTR_NAME_SMACK))
713 isp = dentry->d_inode->i_security;
716 * No locking is done here. This is a pointer
719 nsp = smk_import(value, size);
721 isp->smk_inode = nsp;
723 isp->smk_inode = smack_known_invalid.smk_known;
729 * smack_inode_getxattr - Smack check on getxattr
730 * @dentry: the object
733 * Returns 0 if access is permitted, an error code otherwise
735 static int smack_inode_getxattr(struct dentry *dentry, const char *name)
737 struct smk_audit_info ad;
739 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
740 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
742 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ, &ad);
746 * smack_inode_removexattr - Smack check on removexattr
747 * @dentry: the object
748 * @name: name of the attribute
750 * Removing the Smack attribute requires CAP_MAC_ADMIN
752 * Returns 0 if access is permitted, an error code otherwise
754 static int smack_inode_removexattr(struct dentry *dentry, const char *name)
756 struct smk_audit_info ad;
759 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
760 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
761 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0) {
762 if (!capable(CAP_MAC_ADMIN))
765 rc = cap_inode_removexattr(dentry, name);
767 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
768 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
770 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
776 * smack_inode_getsecurity - get smack xattrs
778 * @name: attribute name
779 * @buffer: where to put the result
782 * Returns the size of the attribute or an error code
784 static int smack_inode_getsecurity(const struct inode *inode,
785 const char *name, void **buffer,
788 struct socket_smack *ssp;
790 struct super_block *sbp;
791 struct inode *ip = (struct inode *)inode;
796 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
797 isp = smk_of_inode(inode);
798 ilen = strlen(isp) + 1;
804 * The rest of the Smack xattrs are only on sockets.
807 if (sbp->s_magic != SOCKFS_MAGIC)
811 if (sock == NULL || sock->sk == NULL)
814 ssp = sock->sk->sk_security;
816 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
818 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0)
823 ilen = strlen(isp) + 1;
834 * smack_inode_listsecurity - list the Smack attributes
836 * @buffer: where they go
837 * @buffer_size: size of buffer
839 * Returns 0 on success, -EINVAL otherwise
841 static int smack_inode_listsecurity(struct inode *inode, char *buffer,
844 int len = strlen(XATTR_NAME_SMACK);
846 if (buffer != NULL && len <= buffer_size) {
847 memcpy(buffer, XATTR_NAME_SMACK, len);
854 * smack_inode_getsecid - Extract inode's security id
855 * @inode: inode to extract the info from
856 * @secid: where result will be saved
858 static void smack_inode_getsecid(const struct inode *inode, u32 *secid)
860 struct inode_smack *isp = inode->i_security;
862 *secid = smack_to_secid(isp->smk_inode);
870 * smack_file_permission - Smack check on file operations
876 * Should access checks be done on each read or write?
877 * UNICOS and SELinux say yes.
878 * Trusted Solaris, Trusted Irix, and just about everyone else says no.
880 * I'll say no for now. Smack does not do the frequent
881 * label changing that SELinux does.
883 static int smack_file_permission(struct file *file, int mask)
889 * smack_file_alloc_security - assign a file security blob
892 * The security blob for a file is a pointer to the master
893 * label list, so no allocation is done.
897 static int smack_file_alloc_security(struct file *file)
899 file->f_security = current_security();
904 * smack_file_free_security - clear a file security blob
907 * The security blob for a file is a pointer to the master
908 * label list, so no memory is freed.
910 static void smack_file_free_security(struct file *file)
912 file->f_security = NULL;
916 * smack_file_ioctl - Smack check on ioctls
921 * Relies heavily on the correct use of the ioctl command conventions.
923 * Returns 0 if allowed, error code otherwise
925 static int smack_file_ioctl(struct file *file, unsigned int cmd,
929 struct smk_audit_info ad;
931 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
932 smk_ad_setfield_u_fs_path(&ad, file->f_path);
934 if (_IOC_DIR(cmd) & _IOC_WRITE)
935 rc = smk_curacc(file->f_security, MAY_WRITE, &ad);
937 if (rc == 0 && (_IOC_DIR(cmd) & _IOC_READ))
938 rc = smk_curacc(file->f_security, MAY_READ, &ad);
944 * smack_file_lock - Smack check on file locking
948 * Returns 0 if current has write access, error code otherwise
950 static int smack_file_lock(struct file *file, unsigned int cmd)
952 struct smk_audit_info ad;
954 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
955 smk_ad_setfield_u_fs_path_dentry(&ad, file->f_path.dentry);
956 return smk_curacc(file->f_security, MAY_WRITE, &ad);
960 * smack_file_fcntl - Smack check on fcntl
962 * @cmd: what action to check
965 * Returns 0 if current has access, error code otherwise
967 static int smack_file_fcntl(struct file *file, unsigned int cmd,
970 struct smk_audit_info ad;
973 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
974 smk_ad_setfield_u_fs_path(&ad, file->f_path);
983 rc = smk_curacc(file->f_security, MAY_READ, &ad);
991 rc = smk_curacc(file->f_security, MAY_WRITE, &ad);
994 rc = smk_curacc(file->f_security, MAY_READWRITE, &ad);
1001 * smack_file_set_fowner - set the file security blob value
1002 * @file: object in question
1005 * Further research may be required on this one.
1007 static int smack_file_set_fowner(struct file *file)
1009 file->f_security = current_security();
1014 * smack_file_send_sigiotask - Smack on sigio
1015 * @tsk: The target task
1016 * @fown: the object the signal come from
1019 * Allow a privileged task to get signals even if it shouldn't
1021 * Returns 0 if a subject with the object's smack could
1022 * write to the task, an error code otherwise.
1024 static int smack_file_send_sigiotask(struct task_struct *tsk,
1025 struct fown_struct *fown, int signum)
1029 char *tsp = tsk->cred->security;
1030 struct smk_audit_info ad;
1033 * struct fown_struct is never outside the context of a struct file
1035 file = container_of(fown, struct file, f_owner);
1036 /* we don't log here as rc can be overriden */
1037 rc = smk_access(file->f_security, tsp, MAY_WRITE, NULL);
1038 if (rc != 0 && has_capability(tsk, CAP_MAC_OVERRIDE))
1041 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1042 smk_ad_setfield_u_tsk(&ad, tsk);
1043 smack_log(file->f_security, tsp, MAY_WRITE, rc, &ad);
1048 * smack_file_receive - Smack file receive check
1051 * Returns 0 if current has access, error code otherwise
1053 static int smack_file_receive(struct file *file)
1056 struct smk_audit_info ad;
1058 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1059 smk_ad_setfield_u_fs_path(&ad, file->f_path);
1061 * This code relies on bitmasks.
1063 if (file->f_mode & FMODE_READ)
1065 if (file->f_mode & FMODE_WRITE)
1068 return smk_curacc(file->f_security, may, &ad);
1076 * smack_cred_alloc_blank - "allocate" blank task-level security credentials
1077 * @new: the new credentials
1078 * @gfp: the atomicity of any memory allocations
1080 * Prepare a blank set of credentials for modification. This must allocate all
1081 * the memory the LSM module might require such that cred_transfer() can
1082 * complete without error.
1084 static int smack_cred_alloc_blank(struct cred *cred, gfp_t gfp)
1086 cred->security = NULL;
1092 * smack_cred_free - "free" task-level security credentials
1093 * @cred: the credentials in question
1095 * Smack isn't using copies of blobs. Everyone
1096 * points to an immutable list. The blobs never go away.
1097 * There is no leak here.
1099 static void smack_cred_free(struct cred *cred)
1101 cred->security = NULL;
1105 * smack_cred_prepare - prepare new set of credentials for modification
1106 * @new: the new credentials
1107 * @old: the original credentials
1108 * @gfp: the atomicity of any memory allocations
1110 * Prepare a new set of credentials for modification.
1112 static int smack_cred_prepare(struct cred *new, const struct cred *old,
1115 new->security = old->security;
1120 * smack_cred_transfer - Transfer the old credentials to the new credentials
1121 * @new: the new credentials
1122 * @old: the original credentials
1124 * Fill in a set of blank credentials from another set of credentials.
1126 static void smack_cred_transfer(struct cred *new, const struct cred *old)
1128 new->security = old->security;
1132 * smack_kernel_act_as - Set the subjective context in a set of credentials
1133 * @new: points to the set of credentials to be modified.
1134 * @secid: specifies the security ID to be set
1136 * Set the security data for a kernel service.
1138 static int smack_kernel_act_as(struct cred *new, u32 secid)
1140 char *smack = smack_from_secid(secid);
1145 new->security = smack;
1150 * smack_kernel_create_files_as - Set the file creation label in a set of creds
1151 * @new: points to the set of credentials to be modified
1152 * @inode: points to the inode to use as a reference
1154 * Set the file creation context in a set of credentials to the same
1155 * as the objective context of the specified inode
1157 static int smack_kernel_create_files_as(struct cred *new,
1158 struct inode *inode)
1160 struct inode_smack *isp = inode->i_security;
1162 new->security = isp->smk_inode;
1167 * smk_curacc_on_task - helper to log task related access
1168 * @p: the task object
1169 * @access : the access requested
1171 * Return 0 if access is permitted
1173 static int smk_curacc_on_task(struct task_struct *p, int access)
1175 struct smk_audit_info ad;
1177 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1178 smk_ad_setfield_u_tsk(&ad, p);
1179 return smk_curacc(task_security(p), access, &ad);
1183 * smack_task_setpgid - Smack check on setting pgid
1184 * @p: the task object
1187 * Return 0 if write access is permitted
1189 static int smack_task_setpgid(struct task_struct *p, pid_t pgid)
1191 return smk_curacc_on_task(p, MAY_WRITE);
1195 * smack_task_getpgid - Smack access check for getpgid
1196 * @p: the object task
1198 * Returns 0 if current can read the object task, error code otherwise
1200 static int smack_task_getpgid(struct task_struct *p)
1202 return smk_curacc_on_task(p, MAY_READ);
1206 * smack_task_getsid - Smack access check for getsid
1207 * @p: the object task
1209 * Returns 0 if current can read the object task, error code otherwise
1211 static int smack_task_getsid(struct task_struct *p)
1213 return smk_curacc_on_task(p, MAY_READ);
1217 * smack_task_getsecid - get the secid of the task
1218 * @p: the object task
1219 * @secid: where to put the result
1221 * Sets the secid to contain a u32 version of the smack label.
1223 static void smack_task_getsecid(struct task_struct *p, u32 *secid)
1225 *secid = smack_to_secid(task_security(p));
1229 * smack_task_setnice - Smack check on setting nice
1230 * @p: the task object
1233 * Return 0 if write access is permitted
1235 static int smack_task_setnice(struct task_struct *p, int nice)
1239 rc = cap_task_setnice(p, nice);
1241 rc = smk_curacc_on_task(p, MAY_WRITE);
1246 * smack_task_setioprio - Smack check on setting ioprio
1247 * @p: the task object
1250 * Return 0 if write access is permitted
1252 static int smack_task_setioprio(struct task_struct *p, int ioprio)
1256 rc = cap_task_setioprio(p, ioprio);
1258 rc = smk_curacc_on_task(p, MAY_WRITE);
1263 * smack_task_getioprio - Smack check on reading ioprio
1264 * @p: the task object
1266 * Return 0 if read access is permitted
1268 static int smack_task_getioprio(struct task_struct *p)
1270 return smk_curacc_on_task(p, MAY_READ);
1274 * smack_task_setscheduler - Smack check on setting scheduler
1275 * @p: the task object
1279 * Return 0 if read access is permitted
1281 static int smack_task_setscheduler(struct task_struct *p, int policy,
1282 struct sched_param *lp)
1286 rc = cap_task_setscheduler(p, policy, lp);
1288 rc = smk_curacc_on_task(p, MAY_WRITE);
1293 * smack_task_getscheduler - Smack check on reading scheduler
1294 * @p: the task object
1296 * Return 0 if read access is permitted
1298 static int smack_task_getscheduler(struct task_struct *p)
1300 return smk_curacc_on_task(p, MAY_READ);
1304 * smack_task_movememory - Smack check on moving memory
1305 * @p: the task object
1307 * Return 0 if write access is permitted
1309 static int smack_task_movememory(struct task_struct *p)
1311 return smk_curacc_on_task(p, MAY_WRITE);
1315 * smack_task_kill - Smack check on signal delivery
1316 * @p: the task object
1319 * @secid: identifies the smack to use in lieu of current's
1321 * Return 0 if write access is permitted
1323 * The secid behavior is an artifact of an SELinux hack
1324 * in the USB code. Someday it may go away.
1326 static int smack_task_kill(struct task_struct *p, struct siginfo *info,
1329 struct smk_audit_info ad;
1331 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1332 smk_ad_setfield_u_tsk(&ad, p);
1334 * Sending a signal requires that the sender
1335 * can write the receiver.
1338 return smk_curacc(task_security(p), MAY_WRITE, &ad);
1340 * If the secid isn't 0 we're dealing with some USB IO
1341 * specific behavior. This is not clean. For one thing
1342 * we can't take privilege into account.
1344 return smk_access(smack_from_secid(secid), task_security(p),
1349 * smack_task_wait - Smack access check for waiting
1350 * @p: task to wait for
1352 * Returns 0 if current can wait for p, error code otherwise
1354 static int smack_task_wait(struct task_struct *p)
1356 struct smk_audit_info ad;
1357 char *sp = current_security();
1358 char *tsp = task_security(p);
1361 /* we don't log here, we can be overriden */
1362 rc = smk_access(sp, tsp, MAY_WRITE, NULL);
1367 * Allow the operation to succeed if either task
1368 * has privilege to perform operations that might
1369 * account for the smack labels having gotten to
1370 * be different in the first place.
1372 * This breaks the strict subject/object access
1373 * control ideal, taking the object's privilege
1374 * state into account in the decision as well as
1377 if (capable(CAP_MAC_OVERRIDE) || has_capability(p, CAP_MAC_OVERRIDE))
1379 /* we log only if we didn't get overriden */
1381 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1382 smk_ad_setfield_u_tsk(&ad, p);
1383 smack_log(sp, tsp, MAY_WRITE, rc, &ad);
1388 * smack_task_to_inode - copy task smack into the inode blob
1389 * @p: task to copy from
1390 * @inode: inode to copy to
1392 * Sets the smack pointer in the inode security blob
1394 static void smack_task_to_inode(struct task_struct *p, struct inode *inode)
1396 struct inode_smack *isp = inode->i_security;
1397 isp->smk_inode = task_security(p);
1405 * smack_sk_alloc_security - Allocate a socket blob
1408 * @gfp_flags: memory allocation flags
1410 * Assign Smack pointers to current
1412 * Returns 0 on success, -ENOMEM is there's no memory
1414 static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags)
1416 char *csp = current_security();
1417 struct socket_smack *ssp;
1419 ssp = kzalloc(sizeof(struct socket_smack), gfp_flags);
1425 ssp->smk_packet[0] = '\0';
1427 sk->sk_security = ssp;
1433 * smack_sk_free_security - Free a socket blob
1436 * Clears the blob pointer
1438 static void smack_sk_free_security(struct sock *sk)
1440 kfree(sk->sk_security);
1444 * smack_host_label - check host based restrictions
1445 * @sip: the object end
1447 * looks for host based access restrictions
1449 * This version will only be appropriate for really small sets of single label
1450 * hosts. The caller is responsible for ensuring that the RCU read lock is
1451 * taken before calling this function.
1453 * Returns the label of the far end or NULL if it's not special.
1455 static char *smack_host_label(struct sockaddr_in *sip)
1457 struct smk_netlbladdr *snp;
1458 struct in_addr *siap = &sip->sin_addr;
1460 if (siap->s_addr == 0)
1463 list_for_each_entry_rcu(snp, &smk_netlbladdr_list, list)
1465 * we break after finding the first match because
1466 * the list is sorted from longest to shortest mask
1467 * so we have found the most specific match
1469 if ((&snp->smk_host.sin_addr)->s_addr ==
1470 (siap->s_addr & (&snp->smk_mask)->s_addr)) {
1471 /* we have found the special CIPSO option */
1472 if (snp->smk_label == smack_cipso_option)
1474 return snp->smk_label;
1481 * smack_set_catset - convert a capset to netlabel mls categories
1482 * @catset: the Smack categories
1483 * @sap: where to put the netlabel categories
1485 * Allocates and fills attr.mls.cat
1487 static void smack_set_catset(char *catset, struct netlbl_lsm_secattr *sap)
1498 sap->flags |= NETLBL_SECATTR_MLS_CAT;
1499 sap->attr.mls.cat = netlbl_secattr_catmap_alloc(GFP_ATOMIC);
1500 sap->attr.mls.cat->startbit = 0;
1502 for (cat = 1, cp = catset, byte = 0; byte < SMK_LABELLEN; cp++, byte++)
1503 for (m = 0x80; m != 0; m >>= 1, cat++) {
1506 rc = netlbl_secattr_catmap_setbit(sap->attr.mls.cat,
1512 * smack_to_secattr - fill a secattr from a smack value
1513 * @smack: the smack value
1514 * @nlsp: where the result goes
1516 * Casey says that CIPSO is good enough for now.
1517 * It can be used to effect.
1518 * It can also be abused to effect when necessary.
1519 * Appologies to the TSIG group in general and GW in particular.
1521 static void smack_to_secattr(char *smack, struct netlbl_lsm_secattr *nlsp)
1523 struct smack_cipso cipso;
1526 nlsp->domain = smack;
1527 nlsp->flags = NETLBL_SECATTR_DOMAIN | NETLBL_SECATTR_MLS_LVL;
1529 rc = smack_to_cipso(smack, &cipso);
1531 nlsp->attr.mls.lvl = cipso.smk_level;
1532 smack_set_catset(cipso.smk_catset, nlsp);
1534 nlsp->attr.mls.lvl = smack_cipso_direct;
1535 smack_set_catset(smack, nlsp);
1540 * smack_netlabel - Set the secattr on a socket
1542 * @labeled: socket label scheme
1544 * Convert the outbound smack value (smk_out) to a
1545 * secattr and attach it to the socket.
1547 * Returns 0 on success or an error code
1549 static int smack_netlabel(struct sock *sk, int labeled)
1551 struct socket_smack *ssp = sk->sk_security;
1552 struct netlbl_lsm_secattr secattr;
1556 * Usually the netlabel code will handle changing the
1557 * packet labeling based on the label.
1558 * The case of a single label host is different, because
1559 * a single label host should never get a labeled packet
1560 * even though the label is usually associated with a packet
1564 bh_lock_sock_nested(sk);
1566 if (ssp->smk_out == smack_net_ambient ||
1567 labeled == SMACK_UNLABELED_SOCKET)
1568 netlbl_sock_delattr(sk);
1570 netlbl_secattr_init(&secattr);
1571 smack_to_secattr(ssp->smk_out, &secattr);
1572 rc = netlbl_sock_setattr(sk, sk->sk_family, &secattr);
1573 netlbl_secattr_destroy(&secattr);
1583 * smack_netlbel_send - Set the secattr on a socket and perform access checks
1585 * @sap: the destination address
1587 * Set the correct secattr for the given socket based on the destination
1588 * address and perform any outbound access checks needed.
1590 * Returns 0 on success or an error code.
1593 static int smack_netlabel_send(struct sock *sk, struct sockaddr_in *sap)
1598 struct socket_smack *ssp = sk->sk_security;
1599 struct smk_audit_info ad;
1602 hostsp = smack_host_label(sap);
1603 if (hostsp != NULL) {
1604 sk_lbl = SMACK_UNLABELED_SOCKET;
1606 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
1607 ad.a.u.net.family = sap->sin_family;
1608 ad.a.u.net.dport = sap->sin_port;
1609 ad.a.u.net.v4info.daddr = sap->sin_addr.s_addr;
1611 rc = smk_access(ssp->smk_out, hostsp, MAY_WRITE, &ad);
1613 sk_lbl = SMACK_CIPSO_SOCKET;
1620 return smack_netlabel(sk, sk_lbl);
1624 * smack_inode_setsecurity - set smack xattrs
1625 * @inode: the object
1626 * @name: attribute name
1627 * @value: attribute value
1628 * @size: size of the attribute
1631 * Sets the named attribute in the appropriate blob
1633 * Returns 0 on success, or an error code
1635 static int smack_inode_setsecurity(struct inode *inode, const char *name,
1636 const void *value, size_t size, int flags)
1639 struct inode_smack *nsp = inode->i_security;
1640 struct socket_smack *ssp;
1641 struct socket *sock;
1644 if (value == NULL || size > SMK_LABELLEN || size == 0)
1647 sp = smk_import(value, size);
1651 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
1652 nsp->smk_inode = sp;
1653 nsp->smk_flags |= SMK_INODE_INSTANT;
1657 * The rest of the Smack xattrs are only on sockets.
1659 if (inode->i_sb->s_magic != SOCKFS_MAGIC)
1662 sock = SOCKET_I(inode);
1663 if (sock == NULL || sock->sk == NULL)
1666 ssp = sock->sk->sk_security;
1668 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
1670 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0) {
1672 rc = smack_netlabel(sock->sk, SMACK_CIPSO_SOCKET);
1674 printk(KERN_WARNING "Smack: \"%s\" netlbl error %d.\n",
1683 * smack_socket_post_create - finish socket setup
1685 * @family: protocol family
1690 * Sets the netlabel information on the socket
1692 * Returns 0 on success, and error code otherwise
1694 static int smack_socket_post_create(struct socket *sock, int family,
1695 int type, int protocol, int kern)
1697 if (family != PF_INET || sock->sk == NULL)
1700 * Set the outbound netlbl.
1702 return smack_netlabel(sock->sk, SMACK_CIPSO_SOCKET);
1706 * smack_socket_connect - connect access check
1708 * @sap: the other end
1709 * @addrlen: size of sap
1711 * Verifies that a connection may be possible
1713 * Returns 0 on success, and error code otherwise
1715 static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
1718 if (sock->sk == NULL || sock->sk->sk_family != PF_INET)
1720 if (addrlen < sizeof(struct sockaddr_in))
1723 return smack_netlabel_send(sock->sk, (struct sockaddr_in *)sap);
1727 * smack_flags_to_may - convert S_ to MAY_ values
1728 * @flags: the S_ value
1730 * Returns the equivalent MAY_ value
1732 static int smack_flags_to_may(int flags)
1736 if (flags & S_IRUGO)
1738 if (flags & S_IWUGO)
1740 if (flags & S_IXUGO)
1747 * smack_msg_msg_alloc_security - Set the security blob for msg_msg
1752 static int smack_msg_msg_alloc_security(struct msg_msg *msg)
1754 msg->security = current_security();
1759 * smack_msg_msg_free_security - Clear the security blob for msg_msg
1762 * Clears the blob pointer
1764 static void smack_msg_msg_free_security(struct msg_msg *msg)
1766 msg->security = NULL;
1770 * smack_of_shm - the smack pointer for the shm
1773 * Returns a pointer to the smack value
1775 static char *smack_of_shm(struct shmid_kernel *shp)
1777 return (char *)shp->shm_perm.security;
1781 * smack_shm_alloc_security - Set the security blob for shm
1786 static int smack_shm_alloc_security(struct shmid_kernel *shp)
1788 struct kern_ipc_perm *isp = &shp->shm_perm;
1790 isp->security = current_security();
1795 * smack_shm_free_security - Clear the security blob for shm
1798 * Clears the blob pointer
1800 static void smack_shm_free_security(struct shmid_kernel *shp)
1802 struct kern_ipc_perm *isp = &shp->shm_perm;
1804 isp->security = NULL;
1808 * smk_curacc_shm : check if current has access on shm
1810 * @access : access requested
1812 * Returns 0 if current has the requested access, error code otherwise
1814 static int smk_curacc_shm(struct shmid_kernel *shp, int access)
1816 char *ssp = smack_of_shm(shp);
1817 struct smk_audit_info ad;
1820 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
1821 ad.a.u.ipc_id = shp->shm_perm.id;
1823 return smk_curacc(ssp, access, &ad);
1827 * smack_shm_associate - Smack access check for shm
1829 * @shmflg: access requested
1831 * Returns 0 if current has the requested access, error code otherwise
1833 static int smack_shm_associate(struct shmid_kernel *shp, int shmflg)
1837 may = smack_flags_to_may(shmflg);
1838 return smk_curacc_shm(shp, may);
1842 * smack_shm_shmctl - Smack access check for shm
1844 * @cmd: what it wants to do
1846 * Returns 0 if current has the requested access, error code otherwise
1848 static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd)
1861 may = MAY_READWRITE;
1866 * System level information.
1872 return smk_curacc_shm(shp, may);
1876 * smack_shm_shmat - Smack access for shmat
1879 * @shmflg: access requested
1881 * Returns 0 if current has the requested access, error code otherwise
1883 static int smack_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr,
1888 may = smack_flags_to_may(shmflg);
1889 return smk_curacc_shm(shp, may);
1893 * smack_of_sem - the smack pointer for the sem
1896 * Returns a pointer to the smack value
1898 static char *smack_of_sem(struct sem_array *sma)
1900 return (char *)sma->sem_perm.security;
1904 * smack_sem_alloc_security - Set the security blob for sem
1909 static int smack_sem_alloc_security(struct sem_array *sma)
1911 struct kern_ipc_perm *isp = &sma->sem_perm;
1913 isp->security = current_security();
1918 * smack_sem_free_security - Clear the security blob for sem
1921 * Clears the blob pointer
1923 static void smack_sem_free_security(struct sem_array *sma)
1925 struct kern_ipc_perm *isp = &sma->sem_perm;
1927 isp->security = NULL;
1931 * smk_curacc_sem : check if current has access on sem
1933 * @access : access requested
1935 * Returns 0 if current has the requested access, error code otherwise
1937 static int smk_curacc_sem(struct sem_array *sma, int access)
1939 char *ssp = smack_of_sem(sma);
1940 struct smk_audit_info ad;
1943 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
1944 ad.a.u.ipc_id = sma->sem_perm.id;
1946 return smk_curacc(ssp, access, &ad);
1950 * smack_sem_associate - Smack access check for sem
1952 * @semflg: access requested
1954 * Returns 0 if current has the requested access, error code otherwise
1956 static int smack_sem_associate(struct sem_array *sma, int semflg)
1960 may = smack_flags_to_may(semflg);
1961 return smk_curacc_sem(sma, may);
1965 * smack_sem_shmctl - Smack access check for sem
1967 * @cmd: what it wants to do
1969 * Returns 0 if current has the requested access, error code otherwise
1971 static int smack_sem_semctl(struct sem_array *sma, int cmd)
1989 may = MAY_READWRITE;
1994 * System level information
2001 return smk_curacc_sem(sma, may);
2005 * smack_sem_semop - Smack checks of semaphore operations
2011 * Treated as read and write in all cases.
2013 * Returns 0 if access is allowed, error code otherwise
2015 static int smack_sem_semop(struct sem_array *sma, struct sembuf *sops,
2016 unsigned nsops, int alter)
2018 return smk_curacc_sem(sma, MAY_READWRITE);
2022 * smack_msg_alloc_security - Set the security blob for msg
2027 static int smack_msg_queue_alloc_security(struct msg_queue *msq)
2029 struct kern_ipc_perm *kisp = &msq->q_perm;
2031 kisp->security = current_security();
2036 * smack_msg_free_security - Clear the security blob for msg
2039 * Clears the blob pointer
2041 static void smack_msg_queue_free_security(struct msg_queue *msq)
2043 struct kern_ipc_perm *kisp = &msq->q_perm;
2045 kisp->security = NULL;
2049 * smack_of_msq - the smack pointer for the msq
2052 * Returns a pointer to the smack value
2054 static char *smack_of_msq(struct msg_queue *msq)
2056 return (char *)msq->q_perm.security;
2060 * smk_curacc_msq : helper to check if current has access on msq
2062 * @access : access requested
2064 * return 0 if current has access, error otherwise
2066 static int smk_curacc_msq(struct msg_queue *msq, int access)
2068 char *msp = smack_of_msq(msq);
2069 struct smk_audit_info ad;
2072 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2073 ad.a.u.ipc_id = msq->q_perm.id;
2075 return smk_curacc(msp, access, &ad);
2079 * smack_msg_queue_associate - Smack access check for msg_queue
2081 * @msqflg: access requested
2083 * Returns 0 if current has the requested access, error code otherwise
2085 static int smack_msg_queue_associate(struct msg_queue *msq, int msqflg)
2089 may = smack_flags_to_may(msqflg);
2090 return smk_curacc_msq(msq, may);
2094 * smack_msg_queue_msgctl - Smack access check for msg_queue
2096 * @cmd: what it wants to do
2098 * Returns 0 if current has the requested access, error code otherwise
2100 static int smack_msg_queue_msgctl(struct msg_queue *msq, int cmd)
2111 may = MAY_READWRITE;
2116 * System level information
2123 return smk_curacc_msq(msq, may);
2127 * smack_msg_queue_msgsnd - Smack access check for msg_queue
2130 * @msqflg: access requested
2132 * Returns 0 if current has the requested access, error code otherwise
2134 static int smack_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
2139 may = smack_flags_to_may(msqflg);
2140 return smk_curacc_msq(msq, may);
2144 * smack_msg_queue_msgsnd - Smack access check for msg_queue
2151 * Returns 0 if current has read and write access, error code otherwise
2153 static int smack_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
2154 struct task_struct *target, long type, int mode)
2156 return smk_curacc_msq(msq, MAY_READWRITE);
2160 * smack_ipc_permission - Smack access for ipc_permission()
2161 * @ipp: the object permissions
2162 * @flag: access requested
2164 * Returns 0 if current has read and write access, error code otherwise
2166 static int smack_ipc_permission(struct kern_ipc_perm *ipp, short flag)
2168 char *isp = ipp->security;
2169 int may = smack_flags_to_may(flag);
2170 struct smk_audit_info ad;
2173 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2174 ad.a.u.ipc_id = ipp->id;
2176 return smk_curacc(isp, may, &ad);
2180 * smack_ipc_getsecid - Extract smack security id
2181 * @ipp: the object permissions
2182 * @secid: where result will be saved
2184 static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, u32 *secid)
2186 char *smack = ipp->security;
2188 *secid = smack_to_secid(smack);
2192 * smack_d_instantiate - Make sure the blob is correct on an inode
2193 * @opt_dentry: unused
2194 * @inode: the object
2196 * Set the inode's security blob if it hasn't been done already.
2198 static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
2200 struct super_block *sbp;
2201 struct superblock_smack *sbsp;
2202 struct inode_smack *isp;
2203 char *csp = current_security();
2211 isp = inode->i_security;
2213 mutex_lock(&isp->smk_lock);
2215 * If the inode is already instantiated
2216 * take the quick way out
2218 if (isp->smk_flags & SMK_INODE_INSTANT)
2222 sbsp = sbp->s_security;
2224 * We're going to use the superblock default label
2225 * if there's no label on the file.
2227 final = sbsp->smk_default;
2230 * If this is the root inode the superblock
2231 * may be in the process of initialization.
2232 * If that is the case use the root value out
2233 * of the superblock.
2235 if (opt_dentry->d_parent == opt_dentry) {
2236 isp->smk_inode = sbsp->smk_root;
2237 isp->smk_flags |= SMK_INODE_INSTANT;
2242 * This is pretty hackish.
2243 * Casey says that we shouldn't have to do
2244 * file system specific code, but it does help
2245 * with keeping it simple.
2247 switch (sbp->s_magic) {
2250 * Casey says that it's a little embarassing
2251 * that the smack file system doesn't do
2252 * extended attributes.
2254 final = smack_known_star.smk_known;
2258 * Casey says pipes are easy (?)
2260 final = smack_known_star.smk_known;
2262 case DEVPTS_SUPER_MAGIC:
2264 * devpts seems content with the label of the task.
2265 * Programs that change smack have to treat the
2272 * Casey says sockets get the smack of the task.
2276 case PROC_SUPER_MAGIC:
2278 * Casey says procfs appears not to care.
2279 * The superblock default suffices.
2284 * Device labels should come from the filesystem,
2285 * but watch out, because they're volitile,
2286 * getting recreated on every reboot.
2288 final = smack_known_star.smk_known;
2292 * If a smack value has been set we want to use it,
2293 * but since tmpfs isn't giving us the opportunity
2294 * to set mount options simulate setting the
2295 * superblock default.
2299 * This isn't an understood special case.
2300 * Get the value from the xattr.
2302 * No xattr support means, alas, no SMACK label.
2303 * Use the aforeapplied default.
2304 * It would be curious if the label of the task
2305 * does not match that assigned.
2307 if (inode->i_op->getxattr == NULL)
2310 * Get the dentry for xattr.
2312 if (opt_dentry == NULL) {
2313 dp = d_find_alias(inode);
2317 dp = dget(opt_dentry);
2322 fetched = smk_fetch(inode, dp);
2323 if (fetched != NULL)
2331 isp->smk_inode = csp;
2333 isp->smk_inode = final;
2335 isp->smk_flags |= SMK_INODE_INSTANT;
2338 mutex_unlock(&isp->smk_lock);
2343 * smack_getprocattr - Smack process attribute access
2344 * @p: the object task
2345 * @name: the name of the attribute in /proc/.../attr
2346 * @value: where to put the result
2348 * Places a copy of the task Smack into value
2350 * Returns the length of the smack label or an error code
2352 static int smack_getprocattr(struct task_struct *p, char *name, char **value)
2357 if (strcmp(name, "current") != 0)
2360 cp = kstrdup(task_security(p), GFP_KERNEL);
2370 * smack_setprocattr - Smack process attribute setting
2371 * @p: the object task
2372 * @name: the name of the attribute in /proc/.../attr
2373 * @value: the value to set
2374 * @size: the size of the value
2376 * Sets the Smack value of the task. Only setting self
2377 * is permitted and only with privilege
2379 * Returns the length of the smack label or an error code
2381 static int smack_setprocattr(struct task_struct *p, char *name,
2382 void *value, size_t size)
2388 * Changing another process' Smack value is too dangerous
2389 * and supports no sane use case.
2394 if (!capable(CAP_MAC_ADMIN))
2397 if (value == NULL || size == 0 || size >= SMK_LABELLEN)
2400 if (strcmp(name, "current") != 0)
2403 newsmack = smk_import(value, size);
2404 if (newsmack == NULL)
2408 * No process is ever allowed the web ("@") label.
2410 if (newsmack == smack_known_web.smk_known)
2413 new = prepare_creds();
2416 new->security = newsmack;
2422 * smack_unix_stream_connect - Smack access on UDS
2424 * @other: the other socket
2427 * Return 0 if a subject with the smack of sock could access
2428 * an object with the smack of other, otherwise an error code
2430 static int smack_unix_stream_connect(struct socket *sock,
2431 struct socket *other, struct sock *newsk)
2433 struct inode *sp = SOCK_INODE(sock);
2434 struct inode *op = SOCK_INODE(other);
2435 struct smk_audit_info ad;
2437 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2438 smk_ad_setfield_u_net_sk(&ad, other->sk);
2439 return smk_access(smk_of_inode(sp), smk_of_inode(op),
2440 MAY_READWRITE, &ad);
2444 * smack_unix_may_send - Smack access on UDS
2446 * @other: the other socket
2448 * Return 0 if a subject with the smack of sock could access
2449 * an object with the smack of other, otherwise an error code
2451 static int smack_unix_may_send(struct socket *sock, struct socket *other)
2453 struct inode *sp = SOCK_INODE(sock);
2454 struct inode *op = SOCK_INODE(other);
2455 struct smk_audit_info ad;
2457 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2458 smk_ad_setfield_u_net_sk(&ad, other->sk);
2459 return smk_access(smk_of_inode(sp), smk_of_inode(op), MAY_WRITE, &ad);
2463 * smack_socket_sendmsg - Smack check based on destination host
2466 * @size: the size of the message
2468 * Return 0 if the current subject can write to the destination
2469 * host. This is only a question if the destination is a single
2472 static int smack_socket_sendmsg(struct socket *sock, struct msghdr *msg,
2475 struct sockaddr_in *sip = (struct sockaddr_in *) msg->msg_name;
2478 * Perfectly reasonable for this to be NULL
2480 if (sip == NULL || sip->sin_family != AF_INET)
2483 return smack_netlabel_send(sock->sk, sip);
2488 * smack_from_secattr - Convert a netlabel attr.mls.lvl/attr.mls.cat pair to smack
2489 * @sap: netlabel secattr
2490 * @sip: where to put the result
2492 * Copies a smack label into sip
2494 static void smack_from_secattr(struct netlbl_lsm_secattr *sap, char *sip)
2496 char smack[SMK_LABELLEN];
2500 if ((sap->flags & NETLBL_SECATTR_MLS_LVL) != 0) {
2502 * Looks like a CIPSO packet.
2503 * If there are flags but no level netlabel isn't
2504 * behaving the way we expect it to.
2506 * Get the categories, if any
2507 * Without guidance regarding the smack value
2508 * for the packet fall back on the network
2511 memset(smack, '\0', SMK_LABELLEN);
2512 if ((sap->flags & NETLBL_SECATTR_MLS_CAT) != 0)
2514 pcat = netlbl_secattr_catmap_walk(
2515 sap->attr.mls.cat, pcat + 1);
2518 smack_catset_bit(pcat, smack);
2521 * If it is CIPSO using smack direct mapping
2522 * we are already done. WeeHee.
2524 if (sap->attr.mls.lvl == smack_cipso_direct) {
2525 memcpy(sip, smack, SMK_MAXLEN);
2529 * Look it up in the supplied table if it is not
2532 smack_from_cipso(sap->attr.mls.lvl, smack, sip);
2535 if ((sap->flags & NETLBL_SECATTR_SECID) != 0) {
2537 * Looks like a fallback, which gives us a secid.
2539 sp = smack_from_secid(sap->attr.secid);
2541 * This has got to be a bug because it is
2542 * impossible to specify a fallback without
2543 * specifying the label, which will ensure
2544 * it has a secid, and the only way to get a
2545 * secid is from a fallback.
2548 strncpy(sip, sp, SMK_MAXLEN);
2552 * Without guidance regarding the smack value
2553 * for the packet fall back on the network
2556 strncpy(sip, smack_net_ambient, SMK_MAXLEN);
2561 * smack_socket_sock_rcv_skb - Smack packet delivery access check
2565 * Returns 0 if the packet should be delivered, an error code otherwise
2567 static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
2569 struct netlbl_lsm_secattr secattr;
2570 struct socket_smack *ssp = sk->sk_security;
2571 char smack[SMK_LABELLEN];
2574 struct smk_audit_info ad;
2575 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2579 * Translate what netlabel gave us.
2581 netlbl_secattr_init(&secattr);
2583 rc = netlbl_skbuff_getattr(skb, sk->sk_family, &secattr);
2585 smack_from_secattr(&secattr, smack);
2588 csp = smack_net_ambient;
2590 netlbl_secattr_destroy(&secattr);
2593 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2594 ad.a.u.net.family = sk->sk_family;
2595 ad.a.u.net.netif = skb->skb_iif;
2596 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
2599 * Receiving a packet requires that the other end
2600 * be able to write here. Read access is not required.
2601 * This is the simplist possible security model
2604 rc = smk_access(csp, ssp->smk_in, MAY_WRITE, &ad);
2606 netlbl_skbuff_err(skb, rc, 0);
2611 * smack_socket_getpeersec_stream - pull in packet label
2613 * @optval: user's destination
2614 * @optlen: size thereof
2617 * returns zero on success, an error code otherwise
2619 static int smack_socket_getpeersec_stream(struct socket *sock,
2620 char __user *optval,
2621 int __user *optlen, unsigned len)
2623 struct socket_smack *ssp;
2627 ssp = sock->sk->sk_security;
2628 slen = strlen(ssp->smk_packet) + 1;
2632 else if (copy_to_user(optval, ssp->smk_packet, slen) != 0)
2635 if (put_user(slen, optlen) != 0)
2643 * smack_socket_getpeersec_dgram - pull in packet label
2646 * @secid: pointer to where to put the secid of the packet
2648 * Sets the netlabel socket state on sk from parent
2650 static int smack_socket_getpeersec_dgram(struct socket *sock,
2651 struct sk_buff *skb, u32 *secid)
2654 struct netlbl_lsm_secattr secattr;
2656 char smack[SMK_LABELLEN];
2657 int family = PF_INET;
2662 * Only works for families with packets.
2666 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2668 family = sk->sk_family;
2671 * Translate what netlabel gave us.
2673 netlbl_secattr_init(&secattr);
2674 rc = netlbl_skbuff_getattr(skb, family, &secattr);
2676 smack_from_secattr(&secattr, smack);
2677 netlbl_secattr_destroy(&secattr);
2680 * Give up if we couldn't get anything
2685 s = smack_to_secid(smack);
2694 * smack_sock_graft - Initialize a newly created socket with an existing sock
2696 * @parent: parent socket
2698 * Set the smk_{in,out} state of an existing sock based on the process that
2699 * is creating the new socket.
2701 static void smack_sock_graft(struct sock *sk, struct socket *parent)
2703 struct socket_smack *ssp;
2706 (sk->sk_family != PF_INET && sk->sk_family != PF_INET6))
2709 ssp = sk->sk_security;
2710 ssp->smk_in = ssp->smk_out = current_security();
2711 /* cssp->smk_packet is already set in smack_inet_csk_clone() */
2715 * smack_inet_conn_request - Smack access check on connect
2716 * @sk: socket involved
2720 * Returns 0 if a task with the packet label could write to
2721 * the socket, otherwise an error code
2723 static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
2724 struct request_sock *req)
2726 u16 family = sk->sk_family;
2727 struct socket_smack *ssp = sk->sk_security;
2728 struct netlbl_lsm_secattr secattr;
2729 struct sockaddr_in addr;
2731 char smack[SMK_LABELLEN];
2733 struct smk_audit_info ad;
2735 /* handle mapped IPv4 packets arriving via IPv6 sockets */
2736 if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP))
2739 netlbl_secattr_init(&secattr);
2740 rc = netlbl_skbuff_getattr(skb, family, &secattr);
2742 smack_from_secattr(&secattr, smack);
2744 strncpy(smack, smack_known_huh.smk_known, SMK_MAXLEN);
2745 netlbl_secattr_destroy(&secattr);
2748 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2749 ad.a.u.net.family = family;
2750 ad.a.u.net.netif = skb->skb_iif;
2751 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
2754 * Receiving a packet requires that the other end be able to write
2755 * here. Read access is not required.
2757 rc = smk_access(smack, ssp->smk_in, MAY_WRITE, &ad);
2762 * Save the peer's label in the request_sock so we can later setup
2763 * smk_packet in the child socket so that SO_PEERCRED can report it.
2765 req->peer_secid = smack_to_secid(smack);
2768 * We need to decide if we want to label the incoming connection here
2769 * if we do we only need to label the request_sock and the stack will
2770 * propogate the wire-label to the sock when it is created.
2773 addr.sin_addr.s_addr = hdr->saddr;
2775 if (smack_host_label(&addr) == NULL) {
2777 netlbl_secattr_init(&secattr);
2778 smack_to_secattr(smack, &secattr);
2779 rc = netlbl_req_setattr(req, &secattr);
2780 netlbl_secattr_destroy(&secattr);
2783 netlbl_req_delattr(req);
2790 * smack_inet_csk_clone - Copy the connection information to the new socket
2791 * @sk: the new socket
2792 * @req: the connection's request_sock
2794 * Transfer the connection's peer label to the newly created socket.
2796 static void smack_inet_csk_clone(struct sock *sk,
2797 const struct request_sock *req)
2799 struct socket_smack *ssp = sk->sk_security;
2802 if (req->peer_secid != 0) {
2803 smack = smack_from_secid(req->peer_secid);
2804 strncpy(ssp->smk_packet, smack, SMK_MAXLEN);
2806 ssp->smk_packet[0] = '\0';
2810 * Key management security hooks
2812 * Casey has not tested key support very heavily.
2813 * The permission check is most likely too restrictive.
2814 * If you care about keys please have a look.
2819 * smack_key_alloc - Set the key security blob
2821 * @cred: the credentials to use
2824 * No allocation required
2828 static int smack_key_alloc(struct key *key, const struct cred *cred,
2829 unsigned long flags)
2831 key->security = cred->security;
2836 * smack_key_free - Clear the key security blob
2839 * Clear the blob pointer
2841 static void smack_key_free(struct key *key)
2843 key->security = NULL;
2847 * smack_key_permission - Smack access on a key
2848 * @key_ref: gets to the object
2849 * @cred: the credentials to use
2852 * Return 0 if the task has read and write to the object,
2853 * an error code otherwise
2855 static int smack_key_permission(key_ref_t key_ref,
2856 const struct cred *cred, key_perm_t perm)
2859 struct smk_audit_info ad;
2861 keyp = key_ref_to_ptr(key_ref);
2865 * If the key hasn't been initialized give it access so that
2868 if (keyp->security == NULL)
2871 * This should not occur
2873 if (cred->security == NULL)
2876 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_KEY);
2877 ad.a.u.key_struct.key = keyp->serial;
2878 ad.a.u.key_struct.key_desc = keyp->description;
2880 return smk_access(cred->security, keyp->security,
2881 MAY_READWRITE, &ad);
2883 #endif /* CONFIG_KEYS */
2888 * Audit requires a unique representation of each Smack specific
2889 * rule. This unique representation is used to distinguish the
2890 * object to be audited from remaining kernel objects and also
2891 * works as a glue between the audit hooks.
2893 * Since repository entries are added but never deleted, we'll use
2894 * the smack_known label address related to the given audit rule as
2895 * the needed unique representation. This also better fits the smack
2896 * model where nearly everything is a label.
2901 * smack_audit_rule_init - Initialize a smack audit rule
2902 * @field: audit rule fields given from user-space (audit.h)
2903 * @op: required testing operator (=, !=, >, <, ...)
2904 * @rulestr: smack label to be audited
2905 * @vrule: pointer to save our own audit rule representation
2907 * Prepare to audit cases where (@field @op @rulestr) is true.
2908 * The label to be audited is created if necessay.
2910 static int smack_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
2912 char **rule = (char **)vrule;
2915 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
2918 if (op != Audit_equal && op != Audit_not_equal)
2921 *rule = smk_import(rulestr, 0);
2927 * smack_audit_rule_known - Distinguish Smack audit rules
2928 * @krule: rule of interest, in Audit kernel representation format
2930 * This is used to filter Smack rules from remaining Audit ones.
2931 * If it's proved that this rule belongs to us, the
2932 * audit_rule_match hook will be called to do the final judgement.
2934 static int smack_audit_rule_known(struct audit_krule *krule)
2936 struct audit_field *f;
2939 for (i = 0; i < krule->field_count; i++) {
2940 f = &krule->fields[i];
2942 if (f->type == AUDIT_SUBJ_USER || f->type == AUDIT_OBJ_USER)
2950 * smack_audit_rule_match - Audit given object ?
2951 * @secid: security id for identifying the object to test
2952 * @field: audit rule flags given from user-space
2953 * @op: required testing operator
2954 * @vrule: smack internal rule presentation
2955 * @actx: audit context associated with the check
2957 * The core Audit hook. It's used to take the decision of
2958 * whether to audit or not to audit a given object.
2960 static int smack_audit_rule_match(u32 secid, u32 field, u32 op, void *vrule,
2961 struct audit_context *actx)
2967 audit_log(actx, GFP_KERNEL, AUDIT_SELINUX_ERR,
2968 "Smack: missing rule\n");
2972 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
2975 smack = smack_from_secid(secid);
2978 * No need to do string comparisons. If a match occurs,
2979 * both pointers will point to the same smack_known
2982 if (op == Audit_equal)
2983 return (rule == smack);
2984 if (op == Audit_not_equal)
2985 return (rule != smack);
2991 * smack_audit_rule_free - free smack rule representation
2992 * @vrule: rule to be freed.
2994 * No memory was allocated.
2996 static void smack_audit_rule_free(void *vrule)
3001 #endif /* CONFIG_AUDIT */
3004 * smack_secid_to_secctx - return the smack label for a secid
3005 * @secid: incoming integer
3006 * @secdata: destination
3007 * @seclen: how long it is
3009 * Exists for networking code.
3011 static int smack_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
3013 char *sp = smack_from_secid(secid);
3016 *seclen = strlen(sp);
3021 * smack_secctx_to_secid - return the secid for a smack label
3022 * @secdata: smack label
3023 * @seclen: how long result is
3024 * @secid: outgoing integer
3026 * Exists for audit and networking code.
3028 static int smack_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
3030 *secid = smack_to_secid(secdata);
3035 * smack_release_secctx - don't do anything.
3039 * Exists to make sure nothing gets done, and properly
3041 static void smack_release_secctx(char *secdata, u32 seclen)
3045 static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
3047 return smack_inode_setsecurity(inode, XATTR_SMACK_SUFFIX, ctx, ctxlen, 0);
3050 static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
3052 return __vfs_setxattr_noperm(dentry, XATTR_NAME_SMACK, ctx, ctxlen, 0);
3055 static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
3058 len = smack_inode_getsecurity(inode, XATTR_SMACK_SUFFIX, ctx, true);
3066 struct security_operations smack_ops = {
3069 .ptrace_access_check = smack_ptrace_access_check,
3070 .ptrace_traceme = smack_ptrace_traceme,
3071 .syslog = smack_syslog,
3073 .sb_alloc_security = smack_sb_alloc_security,
3074 .sb_free_security = smack_sb_free_security,
3075 .sb_copy_data = smack_sb_copy_data,
3076 .sb_kern_mount = smack_sb_kern_mount,
3077 .sb_statfs = smack_sb_statfs,
3078 .sb_mount = smack_sb_mount,
3079 .sb_umount = smack_sb_umount,
3081 .inode_alloc_security = smack_inode_alloc_security,
3082 .inode_free_security = smack_inode_free_security,
3083 .inode_init_security = smack_inode_init_security,
3084 .inode_link = smack_inode_link,
3085 .inode_unlink = smack_inode_unlink,
3086 .inode_rmdir = smack_inode_rmdir,
3087 .inode_rename = smack_inode_rename,
3088 .inode_permission = smack_inode_permission,
3089 .inode_setattr = smack_inode_setattr,
3090 .inode_getattr = smack_inode_getattr,
3091 .inode_setxattr = smack_inode_setxattr,
3092 .inode_post_setxattr = smack_inode_post_setxattr,
3093 .inode_getxattr = smack_inode_getxattr,
3094 .inode_removexattr = smack_inode_removexattr,
3095 .inode_getsecurity = smack_inode_getsecurity,
3096 .inode_setsecurity = smack_inode_setsecurity,
3097 .inode_listsecurity = smack_inode_listsecurity,
3098 .inode_getsecid = smack_inode_getsecid,
3100 .file_permission = smack_file_permission,
3101 .file_alloc_security = smack_file_alloc_security,
3102 .file_free_security = smack_file_free_security,
3103 .file_ioctl = smack_file_ioctl,
3104 .file_lock = smack_file_lock,
3105 .file_fcntl = smack_file_fcntl,
3106 .file_set_fowner = smack_file_set_fowner,
3107 .file_send_sigiotask = smack_file_send_sigiotask,
3108 .file_receive = smack_file_receive,
3110 .cred_alloc_blank = smack_cred_alloc_blank,
3111 .cred_free = smack_cred_free,
3112 .cred_prepare = smack_cred_prepare,
3113 .cred_transfer = smack_cred_transfer,
3114 .kernel_act_as = smack_kernel_act_as,
3115 .kernel_create_files_as = smack_kernel_create_files_as,
3116 .task_setpgid = smack_task_setpgid,
3117 .task_getpgid = smack_task_getpgid,
3118 .task_getsid = smack_task_getsid,
3119 .task_getsecid = smack_task_getsecid,
3120 .task_setnice = smack_task_setnice,
3121 .task_setioprio = smack_task_setioprio,
3122 .task_getioprio = smack_task_getioprio,
3123 .task_setscheduler = smack_task_setscheduler,
3124 .task_getscheduler = smack_task_getscheduler,
3125 .task_movememory = smack_task_movememory,
3126 .task_kill = smack_task_kill,
3127 .task_wait = smack_task_wait,
3128 .task_to_inode = smack_task_to_inode,
3130 .ipc_permission = smack_ipc_permission,
3131 .ipc_getsecid = smack_ipc_getsecid,
3133 .msg_msg_alloc_security = smack_msg_msg_alloc_security,
3134 .msg_msg_free_security = smack_msg_msg_free_security,
3136 .msg_queue_alloc_security = smack_msg_queue_alloc_security,
3137 .msg_queue_free_security = smack_msg_queue_free_security,
3138 .msg_queue_associate = smack_msg_queue_associate,
3139 .msg_queue_msgctl = smack_msg_queue_msgctl,
3140 .msg_queue_msgsnd = smack_msg_queue_msgsnd,
3141 .msg_queue_msgrcv = smack_msg_queue_msgrcv,
3143 .shm_alloc_security = smack_shm_alloc_security,
3144 .shm_free_security = smack_shm_free_security,
3145 .shm_associate = smack_shm_associate,
3146 .shm_shmctl = smack_shm_shmctl,
3147 .shm_shmat = smack_shm_shmat,
3149 .sem_alloc_security = smack_sem_alloc_security,
3150 .sem_free_security = smack_sem_free_security,
3151 .sem_associate = smack_sem_associate,
3152 .sem_semctl = smack_sem_semctl,
3153 .sem_semop = smack_sem_semop,
3155 .d_instantiate = smack_d_instantiate,
3157 .getprocattr = smack_getprocattr,
3158 .setprocattr = smack_setprocattr,
3160 .unix_stream_connect = smack_unix_stream_connect,
3161 .unix_may_send = smack_unix_may_send,
3163 .socket_post_create = smack_socket_post_create,
3164 .socket_connect = smack_socket_connect,
3165 .socket_sendmsg = smack_socket_sendmsg,
3166 .socket_sock_rcv_skb = smack_socket_sock_rcv_skb,
3167 .socket_getpeersec_stream = smack_socket_getpeersec_stream,
3168 .socket_getpeersec_dgram = smack_socket_getpeersec_dgram,
3169 .sk_alloc_security = smack_sk_alloc_security,
3170 .sk_free_security = smack_sk_free_security,
3171 .sock_graft = smack_sock_graft,
3172 .inet_conn_request = smack_inet_conn_request,
3173 .inet_csk_clone = smack_inet_csk_clone,
3175 /* key management security hooks */
3177 .key_alloc = smack_key_alloc,
3178 .key_free = smack_key_free,
3179 .key_permission = smack_key_permission,
3180 #endif /* CONFIG_KEYS */
3184 .audit_rule_init = smack_audit_rule_init,
3185 .audit_rule_known = smack_audit_rule_known,
3186 .audit_rule_match = smack_audit_rule_match,
3187 .audit_rule_free = smack_audit_rule_free,
3188 #endif /* CONFIG_AUDIT */
3190 .secid_to_secctx = smack_secid_to_secctx,
3191 .secctx_to_secid = smack_secctx_to_secid,
3192 .release_secctx = smack_release_secctx,
3193 .inode_notifysecctx = smack_inode_notifysecctx,
3194 .inode_setsecctx = smack_inode_setsecctx,
3195 .inode_getsecctx = smack_inode_getsecctx,
3199 static __init void init_smack_know_list(void)
3201 list_add(&smack_known_huh.list, &smack_known_list);
3202 list_add(&smack_known_hat.list, &smack_known_list);
3203 list_add(&smack_known_star.list, &smack_known_list);
3204 list_add(&smack_known_floor.list, &smack_known_list);
3205 list_add(&smack_known_invalid.list, &smack_known_list);
3206 list_add(&smack_known_web.list, &smack_known_list);
3210 * smack_init - initialize the smack system
3214 static __init int smack_init(void)
3218 if (!security_module_enable(&smack_ops))
3221 printk(KERN_INFO "Smack: Initializing.\n");
3224 * Set the security state for the initial task.
3226 cred = (struct cred *) current->cred;
3227 cred->security = &smack_known_floor.smk_known;
3229 /* initilize the smack_know_list */
3230 init_smack_know_list();
3234 spin_lock_init(&smack_known_huh.smk_cipsolock);
3235 spin_lock_init(&smack_known_hat.smk_cipsolock);
3236 spin_lock_init(&smack_known_star.smk_cipsolock);
3237 spin_lock_init(&smack_known_floor.smk_cipsolock);
3238 spin_lock_init(&smack_known_invalid.smk_cipsolock);
3243 if (register_security(&smack_ops))
3244 panic("smack: Unable to register with kernel.\n");
3250 * Smack requires early initialization in order to label
3251 * all processes and objects when they are created.
3253 security_initcall(smack_init);