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>
11 * This program is free software; you can redistribute it and/or modify
12 * it under the terms of the GNU General Public License version 2,
13 * as published by the Free Software Foundation.
16 #include <linux/xattr.h>
17 #include <linux/pagemap.h>
18 #include <linux/mount.h>
19 #include <linux/stat.h>
20 #include <linux/ext2_fs.h>
22 #include <asm/ioctls.h>
23 #include <linux/tcp.h>
24 #include <linux/udp.h>
25 #include <linux/mutex.h>
26 #include <linux/pipe_fs_i.h>
27 #include <net/netlabel.h>
28 #include <net/cipso_ipv4.h>
33 * I hope these are the hokeyist lines of code in the module. Casey.
35 #define DEVPTS_SUPER_MAGIC 0x1cd1
36 #define SOCKFS_MAGIC 0x534F434B
37 #define TMPFS_MAGIC 0x01021994
40 * smk_fetch - Fetch the smack label from a file.
41 * @ip: a pointer to the inode
42 * @dp: a pointer to the dentry
44 * Returns a pointer to the master list entry for the Smack label
45 * or NULL if there was no label to fetch.
47 static char *smk_fetch(struct inode *ip, struct dentry *dp)
50 char in[SMK_LABELLEN];
52 if (ip->i_op->getxattr == NULL)
55 rc = ip->i_op->getxattr(dp, XATTR_NAME_SMACK, in, SMK_LABELLEN);
59 return smk_import(in, rc);
63 * new_inode_smack - allocate an inode security blob
64 * @smack: a pointer to the Smack label to use in the blob
66 * Returns the new blob or NULL if there's no memory available
68 struct inode_smack *new_inode_smack(char *smack)
70 struct inode_smack *isp;
72 isp = kzalloc(sizeof(struct inode_smack), GFP_KERNEL);
76 isp->smk_inode = smack;
78 mutex_init(&isp->smk_lock);
89 * smack_ptrace - Smack approval on ptrace
90 * @ptp: parent task pointer
91 * @ctp: child task pointer
93 * Returns 0 if access is OK, an error code otherwise
95 * Do the capability checks, and require read and write.
97 static int smack_ptrace(struct task_struct *ptp, struct task_struct *ctp)
101 rc = cap_ptrace(ptp, ctp);
105 rc = smk_access(ptp->security, ctp->security, MAY_READWRITE);
106 if (rc != 0 && __capable(ptp, CAP_MAC_OVERRIDE))
113 * smack_syslog - Smack approval on syslog
114 * @type: message type
116 * Require that the task has the floor label
118 * Returns 0 on success, error code otherwise.
120 static int smack_syslog(int type)
123 char *sp = current->security;
125 rc = cap_syslog(type);
129 if (capable(CAP_MAC_OVERRIDE))
132 if (sp != smack_known_floor.smk_known)
144 * smack_sb_alloc_security - allocate a superblock blob
145 * @sb: the superblock getting the blob
147 * Returns 0 on success or -ENOMEM on error.
149 static int smack_sb_alloc_security(struct super_block *sb)
151 struct superblock_smack *sbsp;
153 sbsp = kzalloc(sizeof(struct superblock_smack), GFP_KERNEL);
158 sbsp->smk_root = smack_known_floor.smk_known;
159 sbsp->smk_default = smack_known_floor.smk_known;
160 sbsp->smk_floor = smack_known_floor.smk_known;
161 sbsp->smk_hat = smack_known_hat.smk_known;
162 sbsp->smk_initialized = 0;
163 spin_lock_init(&sbsp->smk_sblock);
165 sb->s_security = sbsp;
171 * smack_sb_free_security - free a superblock blob
172 * @sb: the superblock getting the blob
175 static void smack_sb_free_security(struct super_block *sb)
177 kfree(sb->s_security);
178 sb->s_security = NULL;
182 * smack_sb_copy_data - copy mount options data for processing
183 * @type: file system type
184 * @orig: where to start
187 * Returns 0 on success or -ENOMEM on error.
189 * Copy the Smack specific mount options out of the mount
192 static int smack_sb_copy_data(struct file_system_type *type, void *orig,
195 char *cp, *commap, *otheropts, *dp;
197 /* Binary mount data: just copy */
198 if (type->fs_flags & FS_BINARY_MOUNTDATA) {
199 copy_page(smackopts, orig);
203 otheropts = (char *)get_zeroed_page(GFP_KERNEL);
204 if (otheropts == NULL)
207 for (cp = orig, commap = orig; commap != NULL; cp = commap + 1) {
208 if (strstr(cp, SMK_FSDEFAULT) == cp)
210 else if (strstr(cp, SMK_FSFLOOR) == cp)
212 else if (strstr(cp, SMK_FSHAT) == cp)
214 else if (strstr(cp, SMK_FSROOT) == cp)
219 commap = strchr(cp, ',');
228 strcpy(orig, otheropts);
229 free_page((unsigned long)otheropts);
235 * smack_sb_kern_mount - Smack specific mount processing
236 * @sb: the file system superblock
237 * @data: the smack mount options
239 * Returns 0 on success, an error code on failure
241 static int smack_sb_kern_mount(struct super_block *sb, void *data)
243 struct dentry *root = sb->s_root;
244 struct inode *inode = root->d_inode;
245 struct superblock_smack *sp = sb->s_security;
246 struct inode_smack *isp;
251 spin_lock(&sp->smk_sblock);
252 if (sp->smk_initialized != 0) {
253 spin_unlock(&sp->smk_sblock);
256 sp->smk_initialized = 1;
257 spin_unlock(&sp->smk_sblock);
259 for (op = data; op != NULL; op = commap) {
260 commap = strchr(op, ',');
264 if (strncmp(op, SMK_FSHAT, strlen(SMK_FSHAT)) == 0) {
265 op += strlen(SMK_FSHAT);
266 nsp = smk_import(op, 0);
269 } else if (strncmp(op, SMK_FSFLOOR, strlen(SMK_FSFLOOR)) == 0) {
270 op += strlen(SMK_FSFLOOR);
271 nsp = smk_import(op, 0);
274 } else if (strncmp(op, SMK_FSDEFAULT,
275 strlen(SMK_FSDEFAULT)) == 0) {
276 op += strlen(SMK_FSDEFAULT);
277 nsp = smk_import(op, 0);
279 sp->smk_default = nsp;
280 } else if (strncmp(op, SMK_FSROOT, strlen(SMK_FSROOT)) == 0) {
281 op += strlen(SMK_FSROOT);
282 nsp = smk_import(op, 0);
289 * Initialize the root inode.
291 isp = inode->i_security;
293 inode->i_security = new_inode_smack(sp->smk_root);
295 isp->smk_inode = sp->smk_root;
301 * smack_sb_statfs - Smack check on statfs
302 * @dentry: identifies the file system in question
304 * Returns 0 if current can read the floor of the filesystem,
305 * and error code otherwise
307 static int smack_sb_statfs(struct dentry *dentry)
309 struct superblock_smack *sbp = dentry->d_sb->s_security;
311 return smk_curacc(sbp->smk_floor, MAY_READ);
315 * smack_sb_mount - Smack check for mounting
322 * Returns 0 if current can write the floor of the filesystem
323 * being mounted on, an error code otherwise.
325 static int smack_sb_mount(char *dev_name, struct nameidata *nd,
326 char *type, unsigned long flags, void *data)
328 struct superblock_smack *sbp = nd->path.mnt->mnt_sb->s_security;
330 return smk_curacc(sbp->smk_floor, MAY_WRITE);
334 * smack_sb_umount - Smack check for unmounting
335 * @mnt: file system to unmount
338 * Returns 0 if current can write the floor of the filesystem
339 * being unmounted, an error code otherwise.
341 static int smack_sb_umount(struct vfsmount *mnt, int flags)
343 struct superblock_smack *sbp;
345 sbp = mnt->mnt_sb->s_security;
347 return smk_curacc(sbp->smk_floor, MAY_WRITE);
355 * smack_inode_alloc_security - allocate an inode blob
356 * @inode - the inode in need of a blob
358 * Returns 0 if it gets a blob, -ENOMEM otherwise
360 static int smack_inode_alloc_security(struct inode *inode)
362 inode->i_security = new_inode_smack(current->security);
363 if (inode->i_security == NULL)
369 * smack_inode_free_security - free an inode blob
370 * @inode - the inode with a blob
372 * Clears the blob pointer in inode
374 static void smack_inode_free_security(struct inode *inode)
376 kfree(inode->i_security);
377 inode->i_security = NULL;
381 * smack_inode_init_security - copy out the smack from an inode
384 * @name: where to put the attribute name
385 * @value: where to put the attribute value
386 * @len: where to put the length of the attribute
388 * Returns 0 if it all works out, -ENOMEM if there's no memory
390 static int smack_inode_init_security(struct inode *inode, struct inode *dir,
391 char **name, void **value, size_t *len)
393 char *isp = smk_of_inode(inode);
396 *name = kstrdup(XATTR_SMACK_SUFFIX, GFP_KERNEL);
402 *value = kstrdup(isp, GFP_KERNEL);
408 *len = strlen(isp) + 1;
414 * smack_inode_link - Smack check on link
415 * @old_dentry: the existing object
417 * @new_dentry: the new object
419 * Returns 0 if access is permitted, an error code otherwise
421 static int smack_inode_link(struct dentry *old_dentry, struct inode *dir,
422 struct dentry *new_dentry)
427 isp = smk_of_inode(old_dentry->d_inode);
428 rc = smk_curacc(isp, MAY_WRITE);
430 if (rc == 0 && new_dentry->d_inode != NULL) {
431 isp = smk_of_inode(new_dentry->d_inode);
432 rc = smk_curacc(isp, MAY_WRITE);
439 * smack_inode_unlink - Smack check on inode deletion
440 * @dir: containing directory object
441 * @dentry: file to unlink
443 * Returns 0 if current can write the containing directory
444 * and the object, error code otherwise
446 static int smack_inode_unlink(struct inode *dir, struct dentry *dentry)
448 struct inode *ip = dentry->d_inode;
452 * You need write access to the thing you're unlinking
454 rc = smk_curacc(smk_of_inode(ip), MAY_WRITE);
457 * You also need write access to the containing directory
459 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE);
465 * smack_inode_rmdir - Smack check on directory deletion
466 * @dir: containing directory object
467 * @dentry: directory to unlink
469 * Returns 0 if current can write the containing directory
470 * and the directory, error code otherwise
472 static int smack_inode_rmdir(struct inode *dir, struct dentry *dentry)
477 * You need write access to the thing you're removing
479 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
482 * You also need write access to the containing directory
484 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE);
490 * smack_inode_rename - Smack check on rename
491 * @old_inode: the old directory
492 * @old_dentry: unused
493 * @new_inode: the new directory
494 * @new_dentry: unused
496 * Read and write access is required on both the old and
499 * Returns 0 if access is permitted, an error code otherwise
501 static int smack_inode_rename(struct inode *old_inode,
502 struct dentry *old_dentry,
503 struct inode *new_inode,
504 struct dentry *new_dentry)
509 isp = smk_of_inode(old_dentry->d_inode);
510 rc = smk_curacc(isp, MAY_READWRITE);
512 if (rc == 0 && new_dentry->d_inode != NULL) {
513 isp = smk_of_inode(new_dentry->d_inode);
514 rc = smk_curacc(isp, MAY_READWRITE);
521 * smack_inode_permission - Smack version of permission()
522 * @inode: the inode in question
523 * @mask: the access requested
526 * This is the important Smack hook.
528 * Returns 0 if access is permitted, -EACCES otherwise
530 static int smack_inode_permission(struct inode *inode, int mask,
531 struct nameidata *nd)
534 * No permission to check. Existence test. Yup, it's there.
539 return smk_curacc(smk_of_inode(inode), mask);
543 * smack_inode_setattr - Smack check for setting attributes
544 * @dentry: the object
545 * @iattr: for the force flag
547 * Returns 0 if access is permitted, an error code otherwise
549 static int smack_inode_setattr(struct dentry *dentry, struct iattr *iattr)
552 * Need to allow for clearing the setuid bit.
554 if (iattr->ia_valid & ATTR_FORCE)
557 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
561 * smack_inode_getattr - Smack check for getting attributes
563 * @dentry: the object
565 * Returns 0 if access is permitted, an error code otherwise
567 static int smack_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
569 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ);
573 * smack_inode_setxattr - Smack check for setting xattrs
574 * @dentry: the object
575 * @name: name of the attribute
580 * This protects the Smack attribute explicitly.
582 * Returns 0 if access is permitted, an error code otherwise
584 static int smack_inode_setxattr(struct dentry *dentry, char *name,
585 void *value, size_t size, int flags)
587 if (!capable(CAP_MAC_ADMIN)) {
588 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
589 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
590 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0)
594 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
598 * smack_inode_post_setxattr - Apply the Smack update approved above
600 * @name: attribute name
601 * @value: attribute value
602 * @size: attribute size
605 * Set the pointer in the inode blob to the entry found
606 * in the master label list.
608 static void smack_inode_post_setxattr(struct dentry *dentry, char *name,
609 void *value, size_t size, int flags)
611 struct inode_smack *isp;
617 if (strcmp(name, XATTR_NAME_SMACK))
620 if (size >= SMK_LABELLEN)
623 isp = dentry->d_inode->i_security;
626 * No locking is done here. This is a pointer
629 nsp = smk_import(value, size);
631 isp->smk_inode = nsp;
633 isp->smk_inode = smack_known_invalid.smk_known;
639 * smack_inode_getxattr - Smack check on getxattr
640 * @dentry: the object
643 * Returns 0 if access is permitted, an error code otherwise
645 static int smack_inode_getxattr(struct dentry *dentry, char *name)
647 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ);
651 * smack_inode_removexattr - Smack check on removexattr
652 * @dentry: the object
653 * @name: name of the attribute
655 * Removing the Smack attribute requires CAP_MAC_ADMIN
657 * Returns 0 if access is permitted, an error code otherwise
659 static int smack_inode_removexattr(struct dentry *dentry, char *name)
661 if (strcmp(name, XATTR_NAME_SMACK) == 0 && !capable(CAP_MAC_ADMIN))
664 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
668 * smack_inode_getsecurity - get smack xattrs
670 * @name: attribute name
671 * @buffer: where to put the result
672 * @size: size of the buffer
675 * Returns the size of the attribute or an error code
677 static int smack_inode_getsecurity(const struct inode *inode,
678 const char *name, void **buffer,
681 struct socket_smack *ssp;
683 struct super_block *sbp;
684 struct inode *ip = (struct inode *)inode;
689 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
690 isp = smk_of_inode(inode);
691 ilen = strlen(isp) + 1;
697 * The rest of the Smack xattrs are only on sockets.
700 if (sbp->s_magic != SOCKFS_MAGIC)
704 if (sock == NULL || sock->sk == NULL)
707 ssp = sock->sk->sk_security;
709 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
711 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0)
716 ilen = strlen(isp) + 1;
727 * smack_inode_listsecurity - list the Smack attributes
729 * @buffer: where they go
730 * @buffer_size: size of buffer
732 * Returns 0 on success, -EINVAL otherwise
734 static int smack_inode_listsecurity(struct inode *inode, char *buffer,
737 int len = strlen(XATTR_NAME_SMACK);
739 if (buffer != NULL && len <= buffer_size) {
740 memcpy(buffer, XATTR_NAME_SMACK, len);
751 * smack_file_permission - Smack check on file operations
757 * Should access checks be done on each read or write?
758 * UNICOS and SELinux say yes.
759 * Trusted Solaris, Trusted Irix, and just about everyone else says no.
761 * I'll say no for now. Smack does not do the frequent
762 * label changing that SELinux does.
764 static int smack_file_permission(struct file *file, int mask)
770 * smack_file_alloc_security - assign a file security blob
773 * The security blob for a file is a pointer to the master
774 * label list, so no allocation is done.
778 static int smack_file_alloc_security(struct file *file)
780 file->f_security = current->security;
785 * smack_file_free_security - clear a file security blob
788 * The security blob for a file is a pointer to the master
789 * label list, so no memory is freed.
791 static void smack_file_free_security(struct file *file)
793 file->f_security = NULL;
797 * smack_file_ioctl - Smack check on ioctls
802 * Relies heavily on the correct use of the ioctl command conventions.
804 * Returns 0 if allowed, error code otherwise
806 static int smack_file_ioctl(struct file *file, unsigned int cmd,
811 if (_IOC_DIR(cmd) & _IOC_WRITE)
812 rc = smk_curacc(file->f_security, MAY_WRITE);
814 if (rc == 0 && (_IOC_DIR(cmd) & _IOC_READ))
815 rc = smk_curacc(file->f_security, MAY_READ);
821 * smack_file_lock - Smack check on file locking
825 * Returns 0 if current has write access, error code otherwise
827 static int smack_file_lock(struct file *file, unsigned int cmd)
829 return smk_curacc(file->f_security, MAY_WRITE);
833 * smack_file_fcntl - Smack check on fcntl
835 * @cmd: what action to check
838 * Returns 0 if current has access, error code otherwise
840 static int smack_file_fcntl(struct file *file, unsigned int cmd,
852 rc = smk_curacc(file->f_security, MAY_READ);
860 rc = smk_curacc(file->f_security, MAY_WRITE);
863 rc = smk_curacc(file->f_security, MAY_READWRITE);
870 * smack_file_set_fowner - set the file security blob value
871 * @file: object in question
874 * Further research may be required on this one.
876 static int smack_file_set_fowner(struct file *file)
878 file->f_security = current->security;
883 * smack_file_send_sigiotask - Smack on sigio
884 * @tsk: The target task
885 * @fown: the object the signal come from
888 * Allow a privileged task to get signals even if it shouldn't
890 * Returns 0 if a subject with the object's smack could
891 * write to the task, an error code otherwise.
893 static int smack_file_send_sigiotask(struct task_struct *tsk,
894 struct fown_struct *fown, int signum)
900 * struct fown_struct is never outside the context of a struct file
902 file = container_of(fown, struct file, f_owner);
903 rc = smk_access(file->f_security, tsk->security, MAY_WRITE);
904 if (rc != 0 && __capable(tsk, CAP_MAC_OVERRIDE))
910 * smack_file_receive - Smack file receive check
913 * Returns 0 if current has access, error code otherwise
915 static int smack_file_receive(struct file *file)
920 * This code relies on bitmasks.
922 if (file->f_mode & FMODE_READ)
924 if (file->f_mode & FMODE_WRITE)
927 return smk_curacc(file->f_security, may);
935 * smack_task_alloc_security - "allocate" a task blob
936 * @tsk: the task in need of a blob
938 * Smack isn't using copies of blobs. Everyone
939 * points to an immutable list. No alloc required.
940 * No data copy required.
944 static int smack_task_alloc_security(struct task_struct *tsk)
946 tsk->security = current->security;
952 * smack_task_free_security - "free" a task blob
953 * @task: the task with the blob
955 * Smack isn't using copies of blobs. Everyone
956 * points to an immutable list. The blobs never go away.
957 * There is no leak here.
959 static void smack_task_free_security(struct task_struct *task)
961 task->security = NULL;
965 * smack_task_setpgid - Smack check on setting pgid
966 * @p: the task object
969 * Return 0 if write access is permitted
971 static int smack_task_setpgid(struct task_struct *p, pid_t pgid)
973 return smk_curacc(p->security, MAY_WRITE);
977 * smack_task_getpgid - Smack access check for getpgid
978 * @p: the object task
980 * Returns 0 if current can read the object task, error code otherwise
982 static int smack_task_getpgid(struct task_struct *p)
984 return smk_curacc(p->security, MAY_READ);
988 * smack_task_getsid - Smack access check for getsid
989 * @p: the object task
991 * Returns 0 if current can read the object task, error code otherwise
993 static int smack_task_getsid(struct task_struct *p)
995 return smk_curacc(p->security, MAY_READ);
999 * smack_task_getsecid - get the secid of the task
1000 * @p: the object task
1001 * @secid: where to put the result
1003 * Sets the secid to contain a u32 version of the smack label.
1005 static void smack_task_getsecid(struct task_struct *p, u32 *secid)
1007 *secid = smack_to_secid(p->security);
1011 * smack_task_setnice - Smack check on setting nice
1012 * @p: the task object
1015 * Return 0 if write access is permitted
1017 static int smack_task_setnice(struct task_struct *p, int nice)
1019 return smk_curacc(p->security, MAY_WRITE);
1023 * smack_task_setioprio - Smack check on setting ioprio
1024 * @p: the task object
1027 * Return 0 if write access is permitted
1029 static int smack_task_setioprio(struct task_struct *p, int ioprio)
1031 return smk_curacc(p->security, MAY_WRITE);
1035 * smack_task_getioprio - Smack check on reading ioprio
1036 * @p: the task object
1038 * Return 0 if read access is permitted
1040 static int smack_task_getioprio(struct task_struct *p)
1042 return smk_curacc(p->security, MAY_READ);
1046 * smack_task_setscheduler - Smack check on setting scheduler
1047 * @p: the task object
1051 * Return 0 if read access is permitted
1053 static int smack_task_setscheduler(struct task_struct *p, int policy,
1054 struct sched_param *lp)
1056 return smk_curacc(p->security, MAY_WRITE);
1060 * smack_task_getscheduler - Smack check on reading scheduler
1061 * @p: the task object
1063 * Return 0 if read access is permitted
1065 static int smack_task_getscheduler(struct task_struct *p)
1067 return smk_curacc(p->security, MAY_READ);
1071 * smack_task_movememory - Smack check on moving memory
1072 * @p: the task object
1074 * Return 0 if write access is permitted
1076 static int smack_task_movememory(struct task_struct *p)
1078 return smk_curacc(p->security, MAY_WRITE);
1082 * smack_task_kill - Smack check on signal delivery
1083 * @p: the task object
1086 * @secid: identifies the smack to use in lieu of current's
1088 * Return 0 if write access is permitted
1090 * The secid behavior is an artifact of an SELinux hack
1091 * in the USB code. Someday it may go away.
1093 static int smack_task_kill(struct task_struct *p, struct siginfo *info,
1097 * Special cases where signals really ought to go through
1098 * in spite of policy. Stephen Smalley suggests it may
1099 * make sense to change the caller so that it doesn't
1100 * bother with the LSM hook in these cases.
1102 if (info != SEND_SIG_NOINFO &&
1103 (is_si_special(info) || SI_FROMKERNEL(info)))
1106 * Sending a signal requires that the sender
1107 * can write the receiver.
1110 return smk_curacc(p->security, MAY_WRITE);
1112 * If the secid isn't 0 we're dealing with some USB IO
1113 * specific behavior. This is not clean. For one thing
1114 * we can't take privilege into account.
1116 return smk_access(smack_from_secid(secid), p->security, MAY_WRITE);
1120 * smack_task_wait - Smack access check for waiting
1121 * @p: task to wait for
1123 * Returns 0 if current can wait for p, error code otherwise
1125 static int smack_task_wait(struct task_struct *p)
1129 rc = smk_access(current->security, p->security, MAY_WRITE);
1134 * Allow the operation to succeed if either task
1135 * has privilege to perform operations that might
1136 * account for the smack labels having gotten to
1137 * be different in the first place.
1139 * This breaks the strict subjet/object access
1140 * control ideal, taking the object's privilege
1141 * state into account in the decision as well as
1144 if (capable(CAP_MAC_OVERRIDE) || __capable(p, CAP_MAC_OVERRIDE))
1151 * smack_task_to_inode - copy task smack into the inode blob
1152 * @p: task to copy from
1153 * inode: inode to copy to
1155 * Sets the smack pointer in the inode security blob
1157 static void smack_task_to_inode(struct task_struct *p, struct inode *inode)
1159 struct inode_smack *isp = inode->i_security;
1160 isp->smk_inode = p->security;
1168 * smack_sk_alloc_security - Allocate a socket blob
1171 * @priority: memory allocation priority
1173 * Assign Smack pointers to current
1175 * Returns 0 on success, -ENOMEM is there's no memory
1177 static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags)
1179 char *csp = current->security;
1180 struct socket_smack *ssp;
1182 ssp = kzalloc(sizeof(struct socket_smack), gfp_flags);
1188 ssp->smk_packet[0] = '\0';
1190 sk->sk_security = ssp;
1196 * smack_sk_free_security - Free a socket blob
1199 * Clears the blob pointer
1201 static void smack_sk_free_security(struct sock *sk)
1203 kfree(sk->sk_security);
1207 * smack_set_catset - convert a capset to netlabel mls categories
1208 * @catset: the Smack categories
1209 * @sap: where to put the netlabel categories
1211 * Allocates and fills attr.mls.cat
1213 static void smack_set_catset(char *catset, struct netlbl_lsm_secattr *sap)
1224 sap->flags |= NETLBL_SECATTR_MLS_CAT;
1225 sap->attr.mls.cat = netlbl_secattr_catmap_alloc(GFP_ATOMIC);
1226 sap->attr.mls.cat->startbit = 0;
1228 for (cat = 1, cp = catset, byte = 0; byte < SMK_LABELLEN; cp++, byte++)
1229 for (m = 0x80; m != 0; m >>= 1, cat++) {
1232 rc = netlbl_secattr_catmap_setbit(sap->attr.mls.cat,
1238 * smack_to_secattr - fill a secattr from a smack value
1239 * @smack: the smack value
1240 * @nlsp: where the result goes
1242 * Casey says that CIPSO is good enough for now.
1243 * It can be used to effect.
1244 * It can also be abused to effect when necessary.
1245 * Appologies to the TSIG group in general and GW in particular.
1247 static void smack_to_secattr(char *smack, struct netlbl_lsm_secattr *nlsp)
1249 struct smack_cipso cipso;
1252 switch (smack_net_nltype) {
1253 case NETLBL_NLTYPE_CIPSOV4:
1254 nlsp->domain = NULL;
1255 nlsp->flags = NETLBL_SECATTR_DOMAIN;
1256 nlsp->flags |= NETLBL_SECATTR_MLS_LVL;
1258 rc = smack_to_cipso(smack, &cipso);
1260 nlsp->attr.mls.lvl = cipso.smk_level;
1261 smack_set_catset(cipso.smk_catset, nlsp);
1263 nlsp->attr.mls.lvl = smack_cipso_direct;
1264 smack_set_catset(smack, nlsp);
1273 * smack_netlabel - Set the secattr on a socket
1276 * Convert the outbound smack value (smk_out) to a
1277 * secattr and attach it to the socket.
1279 * Returns 0 on success or an error code
1281 static int smack_netlabel(struct sock *sk)
1283 struct socket_smack *ssp;
1284 struct netlbl_lsm_secattr secattr;
1287 ssp = sk->sk_security;
1288 netlbl_secattr_init(&secattr);
1289 smack_to_secattr(ssp->smk_out, &secattr);
1290 if (secattr.flags != NETLBL_SECATTR_NONE)
1291 rc = netlbl_sock_setattr(sk, &secattr);
1293 netlbl_secattr_destroy(&secattr);
1298 * smack_inode_setsecurity - set smack xattrs
1299 * @inode: the object
1300 * @name: attribute name
1301 * @value: attribute value
1302 * @size: size of the attribute
1305 * Sets the named attribute in the appropriate blob
1307 * Returns 0 on success, or an error code
1309 static int smack_inode_setsecurity(struct inode *inode, const char *name,
1310 const void *value, size_t size, int flags)
1313 struct inode_smack *nsp = inode->i_security;
1314 struct socket_smack *ssp;
1315 struct socket *sock;
1317 if (value == NULL || size > SMK_LABELLEN)
1320 sp = smk_import(value, size);
1324 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
1325 nsp->smk_inode = sp;
1329 * The rest of the Smack xattrs are only on sockets.
1331 if (inode->i_sb->s_magic != SOCKFS_MAGIC)
1334 sock = SOCKET_I(inode);
1335 if (sock == NULL || sock->sk == NULL)
1338 ssp = sock->sk->sk_security;
1340 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
1342 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0) {
1344 return smack_netlabel(sock->sk);
1352 * smack_socket_post_create - finish socket setup
1354 * @family: protocol family
1359 * Sets the netlabel information on the socket
1361 * Returns 0 on success, and error code otherwise
1363 static int smack_socket_post_create(struct socket *sock, int family,
1364 int type, int protocol, int kern)
1366 if (family != PF_INET || sock->sk == NULL)
1369 * Set the outbound netlbl.
1371 return smack_netlabel(sock->sk);
1375 * smack_flags_to_may - convert S_ to MAY_ values
1376 * @flags: the S_ value
1378 * Returns the equivalent MAY_ value
1380 static int smack_flags_to_may(int flags)
1384 if (flags & S_IRUGO)
1386 if (flags & S_IWUGO)
1388 if (flags & S_IXUGO)
1395 * smack_msg_msg_alloc_security - Set the security blob for msg_msg
1400 static int smack_msg_msg_alloc_security(struct msg_msg *msg)
1402 msg->security = current->security;
1407 * smack_msg_msg_free_security - Clear the security blob for msg_msg
1410 * Clears the blob pointer
1412 static void smack_msg_msg_free_security(struct msg_msg *msg)
1414 msg->security = NULL;
1418 * smack_of_shm - the smack pointer for the shm
1421 * Returns a pointer to the smack value
1423 static char *smack_of_shm(struct shmid_kernel *shp)
1425 return (char *)shp->shm_perm.security;
1429 * smack_shm_alloc_security - Set the security blob for shm
1434 static int smack_shm_alloc_security(struct shmid_kernel *shp)
1436 struct kern_ipc_perm *isp = &shp->shm_perm;
1438 isp->security = current->security;
1443 * smack_shm_free_security - Clear the security blob for shm
1446 * Clears the blob pointer
1448 static void smack_shm_free_security(struct shmid_kernel *shp)
1450 struct kern_ipc_perm *isp = &shp->shm_perm;
1452 isp->security = NULL;
1456 * smack_shm_associate - Smack access check for shm
1458 * @shmflg: access requested
1460 * Returns 0 if current has the requested access, error code otherwise
1462 static int smack_shm_associate(struct shmid_kernel *shp, int shmflg)
1464 char *ssp = smack_of_shm(shp);
1467 may = smack_flags_to_may(shmflg);
1468 return smk_curacc(ssp, may);
1472 * smack_shm_shmctl - Smack access check for shm
1474 * @cmd: what it wants to do
1476 * Returns 0 if current has the requested access, error code otherwise
1478 static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd)
1480 char *ssp = smack_of_shm(shp);
1492 may = MAY_READWRITE;
1497 * System level information.
1504 return smk_curacc(ssp, may);
1508 * smack_shm_shmat - Smack access for shmat
1511 * @shmflg: access requested
1513 * Returns 0 if current has the requested access, error code otherwise
1515 static int smack_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr,
1518 char *ssp = smack_of_shm(shp);
1521 may = smack_flags_to_may(shmflg);
1522 return smk_curacc(ssp, may);
1526 * smack_of_sem - the smack pointer for the sem
1529 * Returns a pointer to the smack value
1531 static char *smack_of_sem(struct sem_array *sma)
1533 return (char *)sma->sem_perm.security;
1537 * smack_sem_alloc_security - Set the security blob for sem
1542 static int smack_sem_alloc_security(struct sem_array *sma)
1544 struct kern_ipc_perm *isp = &sma->sem_perm;
1546 isp->security = current->security;
1551 * smack_sem_free_security - Clear the security blob for sem
1554 * Clears the blob pointer
1556 static void smack_sem_free_security(struct sem_array *sma)
1558 struct kern_ipc_perm *isp = &sma->sem_perm;
1560 isp->security = NULL;
1564 * smack_sem_associate - Smack access check for sem
1566 * @semflg: access requested
1568 * Returns 0 if current has the requested access, error code otherwise
1570 static int smack_sem_associate(struct sem_array *sma, int semflg)
1572 char *ssp = smack_of_sem(sma);
1575 may = smack_flags_to_may(semflg);
1576 return smk_curacc(ssp, may);
1580 * smack_sem_shmctl - Smack access check for sem
1582 * @cmd: what it wants to do
1584 * Returns 0 if current has the requested access, error code otherwise
1586 static int smack_sem_semctl(struct sem_array *sma, int cmd)
1588 char *ssp = smack_of_sem(sma);
1605 may = MAY_READWRITE;
1610 * System level information
1617 return smk_curacc(ssp, may);
1621 * smack_sem_semop - Smack checks of semaphore operations
1627 * Treated as read and write in all cases.
1629 * Returns 0 if access is allowed, error code otherwise
1631 static int smack_sem_semop(struct sem_array *sma, struct sembuf *sops,
1632 unsigned nsops, int alter)
1634 char *ssp = smack_of_sem(sma);
1636 return smk_curacc(ssp, MAY_READWRITE);
1640 * smack_msg_alloc_security - Set the security blob for msg
1645 static int smack_msg_queue_alloc_security(struct msg_queue *msq)
1647 struct kern_ipc_perm *kisp = &msq->q_perm;
1649 kisp->security = current->security;
1654 * smack_msg_free_security - Clear the security blob for msg
1657 * Clears the blob pointer
1659 static void smack_msg_queue_free_security(struct msg_queue *msq)
1661 struct kern_ipc_perm *kisp = &msq->q_perm;
1663 kisp->security = NULL;
1667 * smack_of_msq - the smack pointer for the msq
1670 * Returns a pointer to the smack value
1672 static char *smack_of_msq(struct msg_queue *msq)
1674 return (char *)msq->q_perm.security;
1678 * smack_msg_queue_associate - Smack access check for msg_queue
1680 * @msqflg: access requested
1682 * Returns 0 if current has the requested access, error code otherwise
1684 static int smack_msg_queue_associate(struct msg_queue *msq, int msqflg)
1686 char *msp = smack_of_msq(msq);
1689 may = smack_flags_to_may(msqflg);
1690 return smk_curacc(msp, may);
1694 * smack_msg_queue_msgctl - Smack access check for msg_queue
1696 * @cmd: what it wants to do
1698 * Returns 0 if current has the requested access, error code otherwise
1700 static int smack_msg_queue_msgctl(struct msg_queue *msq, int cmd)
1702 char *msp = smack_of_msq(msq);
1712 may = MAY_READWRITE;
1717 * System level information
1724 return smk_curacc(msp, may);
1728 * smack_msg_queue_msgsnd - Smack access check for msg_queue
1731 * @msqflg: access requested
1733 * Returns 0 if current has the requested access, error code otherwise
1735 static int smack_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
1738 char *msp = smack_of_msq(msq);
1741 rc = smack_flags_to_may(msqflg);
1742 return smk_curacc(msp, rc);
1746 * smack_msg_queue_msgsnd - Smack access check for msg_queue
1753 * Returns 0 if current has read and write access, error code otherwise
1755 static int smack_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
1756 struct task_struct *target, long type, int mode)
1758 char *msp = smack_of_msq(msq);
1760 return smk_curacc(msp, MAY_READWRITE);
1764 * smack_ipc_permission - Smack access for ipc_permission()
1765 * @ipp: the object permissions
1766 * @flag: access requested
1768 * Returns 0 if current has read and write access, error code otherwise
1770 static int smack_ipc_permission(struct kern_ipc_perm *ipp, short flag)
1772 char *isp = ipp->security;
1775 may = smack_flags_to_may(flag);
1776 return smk_curacc(isp, may);
1780 * smack_d_instantiate - Make sure the blob is correct on an inode
1781 * @opt_dentry: unused
1782 * @inode: the object
1784 * Set the inode's security blob if it hasn't been done already.
1786 static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
1788 struct super_block *sbp;
1789 struct superblock_smack *sbsp;
1790 struct inode_smack *isp;
1791 char *csp = current->security;
1799 isp = inode->i_security;
1801 mutex_lock(&isp->smk_lock);
1803 * If the inode is already instantiated
1804 * take the quick way out
1806 if (isp->smk_flags & SMK_INODE_INSTANT)
1810 sbsp = sbp->s_security;
1812 * We're going to use the superblock default label
1813 * if there's no label on the file.
1815 final = sbsp->smk_default;
1818 * This is pretty hackish.
1819 * Casey says that we shouldn't have to do
1820 * file system specific code, but it does help
1821 * with keeping it simple.
1823 switch (sbp->s_magic) {
1826 * Casey says that it's a little embarassing
1827 * that the smack file system doesn't do
1828 * extended attributes.
1830 final = smack_known_star.smk_known;
1834 * Casey says pipes are easy (?)
1836 final = smack_known_star.smk_known;
1838 case DEVPTS_SUPER_MAGIC:
1840 * devpts seems content with the label of the task.
1841 * Programs that change smack have to treat the
1848 * Casey says sockets get the smack of the task.
1852 case PROC_SUPER_MAGIC:
1854 * Casey says procfs appears not to care.
1855 * The superblock default suffices.
1860 * Device labels should come from the filesystem,
1861 * but watch out, because they're volitile,
1862 * getting recreated on every reboot.
1864 final = smack_known_star.smk_known;
1868 * If a smack value has been set we want to use it,
1869 * but since tmpfs isn't giving us the opportunity
1870 * to set mount options simulate setting the
1871 * superblock default.
1875 * This isn't an understood special case.
1876 * Get the value from the xattr.
1878 * No xattr support means, alas, no SMACK label.
1879 * Use the aforeapplied default.
1880 * It would be curious if the label of the task
1881 * does not match that assigned.
1883 if (inode->i_op->getxattr == NULL)
1886 * Get the dentry for xattr.
1888 if (opt_dentry == NULL) {
1889 dp = d_find_alias(inode);
1893 dp = dget(opt_dentry);
1898 fetched = smk_fetch(inode, dp);
1899 if (fetched != NULL)
1907 isp->smk_inode = csp;
1909 isp->smk_inode = final;
1911 isp->smk_flags |= SMK_INODE_INSTANT;
1914 mutex_unlock(&isp->smk_lock);
1919 * smack_getprocattr - Smack process attribute access
1920 * @p: the object task
1921 * @name: the name of the attribute in /proc/.../attr
1922 * @value: where to put the result
1924 * Places a copy of the task Smack into value
1926 * Returns the length of the smack label or an error code
1928 static int smack_getprocattr(struct task_struct *p, char *name, char **value)
1933 if (strcmp(name, "current") != 0)
1936 cp = kstrdup(p->security, GFP_KERNEL);
1946 * smack_setprocattr - Smack process attribute setting
1947 * @p: the object task
1948 * @name: the name of the attribute in /proc/.../attr
1949 * @value: the value to set
1950 * @size: the size of the value
1952 * Sets the Smack value of the task. Only setting self
1953 * is permitted and only with privilege
1955 * Returns the length of the smack label or an error code
1957 static int smack_setprocattr(struct task_struct *p, char *name,
1958 void *value, size_t size)
1962 if (!__capable(p, CAP_MAC_ADMIN))
1966 * Changing another process' Smack value is too dangerous
1967 * and supports no sane use case.
1972 if (value == NULL || size == 0 || size >= SMK_LABELLEN)
1975 if (strcmp(name, "current") != 0)
1978 newsmack = smk_import(value, size);
1979 if (newsmack == NULL)
1982 p->security = newsmack;
1987 * smack_unix_stream_connect - Smack access on UDS
1989 * @other: the other socket
1992 * Return 0 if a subject with the smack of sock could access
1993 * an object with the smack of other, otherwise an error code
1995 static int smack_unix_stream_connect(struct socket *sock,
1996 struct socket *other, struct sock *newsk)
1998 struct inode *sp = SOCK_INODE(sock);
1999 struct inode *op = SOCK_INODE(other);
2001 return smk_access(smk_of_inode(sp), smk_of_inode(op), MAY_READWRITE);
2005 * smack_unix_may_send - Smack access on UDS
2007 * @other: the other socket
2009 * Return 0 if a subject with the smack of sock could access
2010 * an object with the smack of other, otherwise an error code
2012 static int smack_unix_may_send(struct socket *sock, struct socket *other)
2014 struct inode *sp = SOCK_INODE(sock);
2015 struct inode *op = SOCK_INODE(other);
2017 return smk_access(smk_of_inode(sp), smk_of_inode(op), MAY_WRITE);
2021 * smack_from_secattr - Convert a netlabel attr.mls.lvl/attr.mls.cat
2023 * @sap: netlabel secattr
2024 * @sip: where to put the result
2026 * Copies a smack label into sip
2028 static void smack_from_secattr(struct netlbl_lsm_secattr *sap, char *sip)
2030 char smack[SMK_LABELLEN];
2033 if ((sap->flags & NETLBL_SECATTR_MLS_LVL) == 0) {
2035 * If there are flags but no level netlabel isn't
2036 * behaving the way we expect it to.
2038 * Without guidance regarding the smack value
2039 * for the packet fall back on the network
2042 strncpy(sip, smack_net_ambient, SMK_MAXLEN);
2046 * Get the categories, if any
2048 memset(smack, '\0', SMK_LABELLEN);
2049 if ((sap->flags & NETLBL_SECATTR_MLS_CAT) != 0)
2051 pcat = netlbl_secattr_catmap_walk(sap->attr.mls.cat,
2055 smack_catset_bit(pcat, smack);
2058 * If it is CIPSO using smack direct mapping
2059 * we are already done. WeeHee.
2061 if (sap->attr.mls.lvl == smack_cipso_direct) {
2062 memcpy(sip, smack, SMK_MAXLEN);
2066 * Look it up in the supplied table if it is not a direct mapping.
2068 smack_from_cipso(sap->attr.mls.lvl, smack, sip);
2073 * smack_socket_sock_rcv_skb - Smack packet delivery access check
2077 * Returns 0 if the packet should be delivered, an error code otherwise
2079 static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
2081 struct netlbl_lsm_secattr secattr;
2082 struct socket_smack *ssp = sk->sk_security;
2083 char smack[SMK_LABELLEN];
2086 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2090 * Translate what netlabel gave us.
2092 memset(smack, '\0', SMK_LABELLEN);
2093 netlbl_secattr_init(&secattr);
2094 rc = netlbl_skbuff_getattr(skb, sk->sk_family, &secattr);
2096 smack_from_secattr(&secattr, smack);
2098 strncpy(smack, smack_net_ambient, SMK_MAXLEN);
2099 netlbl_secattr_destroy(&secattr);
2101 * Receiving a packet requires that the other end
2102 * be able to write here. Read access is not required.
2103 * This is the simplist possible security model
2106 return smk_access(smack, ssp->smk_in, MAY_WRITE);
2110 * smack_socket_getpeersec_stream - pull in packet label
2112 * @optval: user's destination
2113 * @optlen: size thereof
2116 * returns zero on success, an error code otherwise
2118 static int smack_socket_getpeersec_stream(struct socket *sock,
2119 char __user *optval,
2120 int __user *optlen, unsigned len)
2122 struct socket_smack *ssp;
2126 ssp = sock->sk->sk_security;
2127 slen = strlen(ssp->smk_packet) + 1;
2131 else if (copy_to_user(optval, ssp->smk_packet, slen) != 0)
2134 if (put_user(slen, optlen) != 0)
2142 * smack_socket_getpeersec_dgram - pull in packet label
2145 * @secid: pointer to where to put the secid of the packet
2147 * Sets the netlabel socket state on sk from parent
2149 static int smack_socket_getpeersec_dgram(struct socket *sock,
2150 struct sk_buff *skb, u32 *secid)
2153 struct netlbl_lsm_secattr secattr;
2155 char smack[SMK_LABELLEN];
2156 int family = PF_INET;
2161 * Only works for families with packets.
2165 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2167 family = sk->sk_family;
2170 * Translate what netlabel gave us.
2172 memset(smack, '\0', SMK_LABELLEN);
2173 netlbl_secattr_init(&secattr);
2174 rc = netlbl_skbuff_getattr(skb, family, &secattr);
2176 smack_from_secattr(&secattr, smack);
2177 netlbl_secattr_destroy(&secattr);
2180 * Give up if we couldn't get anything
2185 s = smack_to_secid(smack);
2194 * smack_sock_graft - graft access state between two sockets
2196 * @parent: donor socket
2198 * Sets the netlabel socket state on sk from parent
2200 static void smack_sock_graft(struct sock *sk, struct socket *parent)
2202 struct socket_smack *ssp;
2208 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2211 ssp = sk->sk_security;
2212 ssp->smk_in = current->security;
2213 ssp->smk_out = current->security;
2214 ssp->smk_packet[0] = '\0';
2216 rc = smack_netlabel(sk);
2220 * smack_inet_conn_request - Smack access check on connect
2221 * @sk: socket involved
2225 * Returns 0 if a task with the packet label could write to
2226 * the socket, otherwise an error code
2228 static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
2229 struct request_sock *req)
2231 struct netlbl_lsm_secattr skb_secattr;
2232 struct socket_smack *ssp = sk->sk_security;
2233 char smack[SMK_LABELLEN];
2239 memset(smack, '\0', SMK_LABELLEN);
2240 netlbl_secattr_init(&skb_secattr);
2241 rc = netlbl_skbuff_getattr(skb, sk->sk_family, &skb_secattr);
2243 smack_from_secattr(&skb_secattr, smack);
2245 strncpy(smack, smack_known_huh.smk_known, SMK_MAXLEN);
2246 netlbl_secattr_destroy(&skb_secattr);
2248 * Receiving a packet requires that the other end
2249 * be able to write here. Read access is not required.
2251 * If the request is successful save the peer's label
2252 * so that SO_PEERCRED can report it.
2254 rc = smk_access(smack, ssp->smk_in, MAY_WRITE);
2256 strncpy(ssp->smk_packet, smack, SMK_MAXLEN);
2262 * Key management security hooks
2264 * Casey has not tested key support very heavily.
2265 * The permission check is most likely too restrictive.
2266 * If you care about keys please have a look.
2271 * smack_key_alloc - Set the key security blob
2273 * @tsk: the task associated with the key
2276 * No allocation required
2280 static int smack_key_alloc(struct key *key, struct task_struct *tsk,
2281 unsigned long flags)
2283 key->security = tsk->security;
2288 * smack_key_free - Clear the key security blob
2291 * Clear the blob pointer
2293 static void smack_key_free(struct key *key)
2295 key->security = NULL;
2299 * smack_key_permission - Smack access on a key
2300 * @key_ref: gets to the object
2301 * @context: task involved
2304 * Return 0 if the task has read and write to the object,
2305 * an error code otherwise
2307 static int smack_key_permission(key_ref_t key_ref,
2308 struct task_struct *context, key_perm_t perm)
2312 keyp = key_ref_to_ptr(key_ref);
2316 * If the key hasn't been initialized give it access so that
2319 if (keyp->security == NULL)
2322 * This should not occur
2324 if (context->security == NULL)
2327 return smk_access(context->security, keyp->security, MAY_READWRITE);
2329 #endif /* CONFIG_KEYS */
2332 * smack_secid_to_secctx - return the smack label for a secid
2333 * @secid: incoming integer
2334 * @secdata: destination
2335 * @seclen: how long it is
2337 * Exists for networking code.
2339 static int smack_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
2341 char *sp = smack_from_secid(secid);
2344 *seclen = strlen(sp);
2349 * smack_release_secctx - don't do anything.
2354 * Exists to make sure nothing gets done, and properly
2356 static void smack_release_secctx(char *secdata, u32 seclen)
2360 static struct security_operations smack_ops = {
2361 .ptrace = smack_ptrace,
2362 .capget = cap_capget,
2363 .capset_check = cap_capset_check,
2364 .capset_set = cap_capset_set,
2365 .capable = cap_capable,
2366 .syslog = smack_syslog,
2367 .settime = cap_settime,
2368 .vm_enough_memory = cap_vm_enough_memory,
2370 .bprm_apply_creds = cap_bprm_apply_creds,
2371 .bprm_set_security = cap_bprm_set_security,
2372 .bprm_secureexec = cap_bprm_secureexec,
2374 .sb_alloc_security = smack_sb_alloc_security,
2375 .sb_free_security = smack_sb_free_security,
2376 .sb_copy_data = smack_sb_copy_data,
2377 .sb_kern_mount = smack_sb_kern_mount,
2378 .sb_statfs = smack_sb_statfs,
2379 .sb_mount = smack_sb_mount,
2380 .sb_umount = smack_sb_umount,
2382 .inode_alloc_security = smack_inode_alloc_security,
2383 .inode_free_security = smack_inode_free_security,
2384 .inode_init_security = smack_inode_init_security,
2385 .inode_link = smack_inode_link,
2386 .inode_unlink = smack_inode_unlink,
2387 .inode_rmdir = smack_inode_rmdir,
2388 .inode_rename = smack_inode_rename,
2389 .inode_permission = smack_inode_permission,
2390 .inode_setattr = smack_inode_setattr,
2391 .inode_getattr = smack_inode_getattr,
2392 .inode_setxattr = smack_inode_setxattr,
2393 .inode_post_setxattr = smack_inode_post_setxattr,
2394 .inode_getxattr = smack_inode_getxattr,
2395 .inode_removexattr = smack_inode_removexattr,
2396 .inode_getsecurity = smack_inode_getsecurity,
2397 .inode_setsecurity = smack_inode_setsecurity,
2398 .inode_listsecurity = smack_inode_listsecurity,
2400 .file_permission = smack_file_permission,
2401 .file_alloc_security = smack_file_alloc_security,
2402 .file_free_security = smack_file_free_security,
2403 .file_ioctl = smack_file_ioctl,
2404 .file_lock = smack_file_lock,
2405 .file_fcntl = smack_file_fcntl,
2406 .file_set_fowner = smack_file_set_fowner,
2407 .file_send_sigiotask = smack_file_send_sigiotask,
2408 .file_receive = smack_file_receive,
2410 .task_alloc_security = smack_task_alloc_security,
2411 .task_free_security = smack_task_free_security,
2412 .task_post_setuid = cap_task_post_setuid,
2413 .task_setpgid = smack_task_setpgid,
2414 .task_getpgid = smack_task_getpgid,
2415 .task_getsid = smack_task_getsid,
2416 .task_getsecid = smack_task_getsecid,
2417 .task_setnice = smack_task_setnice,
2418 .task_setioprio = smack_task_setioprio,
2419 .task_getioprio = smack_task_getioprio,
2420 .task_setscheduler = smack_task_setscheduler,
2421 .task_getscheduler = smack_task_getscheduler,
2422 .task_movememory = smack_task_movememory,
2423 .task_kill = smack_task_kill,
2424 .task_wait = smack_task_wait,
2425 .task_reparent_to_init = cap_task_reparent_to_init,
2426 .task_to_inode = smack_task_to_inode,
2428 .ipc_permission = smack_ipc_permission,
2430 .msg_msg_alloc_security = smack_msg_msg_alloc_security,
2431 .msg_msg_free_security = smack_msg_msg_free_security,
2433 .msg_queue_alloc_security = smack_msg_queue_alloc_security,
2434 .msg_queue_free_security = smack_msg_queue_free_security,
2435 .msg_queue_associate = smack_msg_queue_associate,
2436 .msg_queue_msgctl = smack_msg_queue_msgctl,
2437 .msg_queue_msgsnd = smack_msg_queue_msgsnd,
2438 .msg_queue_msgrcv = smack_msg_queue_msgrcv,
2440 .shm_alloc_security = smack_shm_alloc_security,
2441 .shm_free_security = smack_shm_free_security,
2442 .shm_associate = smack_shm_associate,
2443 .shm_shmctl = smack_shm_shmctl,
2444 .shm_shmat = smack_shm_shmat,
2446 .sem_alloc_security = smack_sem_alloc_security,
2447 .sem_free_security = smack_sem_free_security,
2448 .sem_associate = smack_sem_associate,
2449 .sem_semctl = smack_sem_semctl,
2450 .sem_semop = smack_sem_semop,
2452 .netlink_send = cap_netlink_send,
2453 .netlink_recv = cap_netlink_recv,
2455 .d_instantiate = smack_d_instantiate,
2457 .getprocattr = smack_getprocattr,
2458 .setprocattr = smack_setprocattr,
2460 .unix_stream_connect = smack_unix_stream_connect,
2461 .unix_may_send = smack_unix_may_send,
2463 .socket_post_create = smack_socket_post_create,
2464 .socket_sock_rcv_skb = smack_socket_sock_rcv_skb,
2465 .socket_getpeersec_stream = smack_socket_getpeersec_stream,
2466 .socket_getpeersec_dgram = smack_socket_getpeersec_dgram,
2467 .sk_alloc_security = smack_sk_alloc_security,
2468 .sk_free_security = smack_sk_free_security,
2469 .sock_graft = smack_sock_graft,
2470 .inet_conn_request = smack_inet_conn_request,
2471 /* key management security hooks */
2473 .key_alloc = smack_key_alloc,
2474 .key_free = smack_key_free,
2475 .key_permission = smack_key_permission,
2476 #endif /* CONFIG_KEYS */
2477 .secid_to_secctx = smack_secid_to_secctx,
2478 .release_secctx = smack_release_secctx,
2482 * smack_init - initialize the smack system
2486 static __init int smack_init(void)
2488 printk(KERN_INFO "Smack: Initializing.\n");
2491 * Set the security state for the initial task.
2493 current->security = &smack_known_floor.smk_known;
2498 spin_lock_init(&smack_known_unset.smk_cipsolock);
2499 spin_lock_init(&smack_known_huh.smk_cipsolock);
2500 spin_lock_init(&smack_known_hat.smk_cipsolock);
2501 spin_lock_init(&smack_known_star.smk_cipsolock);
2502 spin_lock_init(&smack_known_floor.smk_cipsolock);
2503 spin_lock_init(&smack_known_invalid.smk_cipsolock);
2508 if (register_security(&smack_ops))
2509 panic("smack: Unable to register with kernel.\n");
2515 * Smack requires early initialization in order to label
2516 * all processes and objects when they are created.
2518 security_initcall(smack_init);