Merge git://git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux-2.6
[wrt350n-kernel.git] / security / smack / smack_lsm.c
blob2dd91cc51d167b53676695cccbc542a2fd2c0313
1 /*
2 * Simplified MAC Kernel (smack) security module
4 * This file contains the smack hook function implementations.
6 * Author:
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>
21 #include <linux/kd.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>
30 #include "smack.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
39 /**
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)
49 int rc;
50 char in[SMK_LABELLEN];
52 if (ip->i_op->getxattr == NULL)
53 return NULL;
55 rc = ip->i_op->getxattr(dp, XATTR_NAME_SMACK, in, SMK_LABELLEN);
56 if (rc < 0)
57 return NULL;
59 return smk_import(in, rc);
62 /**
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);
73 if (isp == NULL)
74 return NULL;
76 isp->smk_inode = smack;
77 isp->smk_flags = 0;
78 mutex_init(&isp->smk_lock);
80 return isp;
84 * LSM hooks.
85 * We he, that is fun!
88 /**
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)
99 int rc;
101 rc = cap_ptrace(ptp, ctp);
102 if (rc != 0)
103 return rc;
105 rc = smk_access(ptp->security, ctp->security, MAY_READWRITE);
106 if (rc != 0 && __capable(ptp, CAP_MAC_OVERRIDE))
107 return 0;
109 return rc;
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)
122 int rc;
123 char *sp = current->security;
125 rc = cap_syslog(type);
126 if (rc != 0)
127 return rc;
129 if (capable(CAP_MAC_OVERRIDE))
130 return 0;
132 if (sp != smack_known_floor.smk_known)
133 rc = -EACCES;
135 return rc;
140 * Superblock Hooks.
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);
155 if (sbsp == NULL)
156 return -ENOMEM;
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;
167 return 0;
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
185 * @smackopts
187 * Returns 0 on success or -ENOMEM on error.
189 * Copy the Smack specific mount options out of the mount
190 * options list.
192 <<<<<<< HEAD:security/smack/smack_lsm.c
193 static int smack_sb_copy_data(struct file_system_type *type, void *orig,
194 void *smackopts)
195 =======
196 static int smack_sb_copy_data(char *orig, char *smackopts)
197 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
199 char *cp, *commap, *otheropts, *dp;
201 <<<<<<< HEAD:security/smack/smack_lsm.c
202 /* Binary mount data: just copy */
203 if (type->fs_flags & FS_BINARY_MOUNTDATA) {
204 copy_page(smackopts, orig);
205 return 0;
208 =======
209 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
210 otheropts = (char *)get_zeroed_page(GFP_KERNEL);
211 if (otheropts == NULL)
212 return -ENOMEM;
214 for (cp = orig, commap = orig; commap != NULL; cp = commap + 1) {
215 if (strstr(cp, SMK_FSDEFAULT) == cp)
216 dp = smackopts;
217 else if (strstr(cp, SMK_FSFLOOR) == cp)
218 dp = smackopts;
219 else if (strstr(cp, SMK_FSHAT) == cp)
220 dp = smackopts;
221 else if (strstr(cp, SMK_FSROOT) == cp)
222 dp = smackopts;
223 else
224 dp = otheropts;
226 commap = strchr(cp, ',');
227 if (commap != NULL)
228 *commap = '\0';
230 if (*dp != '\0')
231 strcat(dp, ",");
232 strcat(dp, cp);
235 strcpy(orig, otheropts);
236 free_page((unsigned long)otheropts);
238 return 0;
242 * smack_sb_kern_mount - Smack specific mount processing
243 * @sb: the file system superblock
244 * @data: the smack mount options
246 * Returns 0 on success, an error code on failure
248 static int smack_sb_kern_mount(struct super_block *sb, void *data)
250 struct dentry *root = sb->s_root;
251 struct inode *inode = root->d_inode;
252 struct superblock_smack *sp = sb->s_security;
253 struct inode_smack *isp;
254 char *op;
255 char *commap;
256 char *nsp;
258 spin_lock(&sp->smk_sblock);
259 if (sp->smk_initialized != 0) {
260 spin_unlock(&sp->smk_sblock);
261 return 0;
263 sp->smk_initialized = 1;
264 spin_unlock(&sp->smk_sblock);
266 for (op = data; op != NULL; op = commap) {
267 commap = strchr(op, ',');
268 if (commap != NULL)
269 *commap++ = '\0';
271 if (strncmp(op, SMK_FSHAT, strlen(SMK_FSHAT)) == 0) {
272 op += strlen(SMK_FSHAT);
273 nsp = smk_import(op, 0);
274 if (nsp != NULL)
275 sp->smk_hat = nsp;
276 } else if (strncmp(op, SMK_FSFLOOR, strlen(SMK_FSFLOOR)) == 0) {
277 op += strlen(SMK_FSFLOOR);
278 nsp = smk_import(op, 0);
279 if (nsp != NULL)
280 sp->smk_floor = nsp;
281 } else if (strncmp(op, SMK_FSDEFAULT,
282 strlen(SMK_FSDEFAULT)) == 0) {
283 op += strlen(SMK_FSDEFAULT);
284 nsp = smk_import(op, 0);
285 if (nsp != NULL)
286 sp->smk_default = nsp;
287 } else if (strncmp(op, SMK_FSROOT, strlen(SMK_FSROOT)) == 0) {
288 op += strlen(SMK_FSROOT);
289 nsp = smk_import(op, 0);
290 if (nsp != NULL)
291 sp->smk_root = nsp;
296 * Initialize the root inode.
298 isp = inode->i_security;
299 if (isp == NULL)
300 inode->i_security = new_inode_smack(sp->smk_root);
301 else
302 isp->smk_inode = sp->smk_root;
304 return 0;
308 * smack_sb_statfs - Smack check on statfs
309 * @dentry: identifies the file system in question
311 * Returns 0 if current can read the floor of the filesystem,
312 * and error code otherwise
314 static int smack_sb_statfs(struct dentry *dentry)
316 struct superblock_smack *sbp = dentry->d_sb->s_security;
318 return smk_curacc(sbp->smk_floor, MAY_READ);
322 * smack_sb_mount - Smack check for mounting
323 * @dev_name: unused
324 * @nd: mount point
325 * @type: unused
326 * @flags: unused
327 * @data: unused
329 * Returns 0 if current can write the floor of the filesystem
330 * being mounted on, an error code otherwise.
332 static int smack_sb_mount(char *dev_name, struct nameidata *nd,
333 char *type, unsigned long flags, void *data)
335 struct superblock_smack *sbp = nd->path.mnt->mnt_sb->s_security;
337 return smk_curacc(sbp->smk_floor, MAY_WRITE);
341 * smack_sb_umount - Smack check for unmounting
342 * @mnt: file system to unmount
343 * @flags: unused
345 * Returns 0 if current can write the floor of the filesystem
346 * being unmounted, an error code otherwise.
348 static int smack_sb_umount(struct vfsmount *mnt, int flags)
350 struct superblock_smack *sbp;
352 sbp = mnt->mnt_sb->s_security;
354 return smk_curacc(sbp->smk_floor, MAY_WRITE);
358 * Inode hooks
362 * smack_inode_alloc_security - allocate an inode blob
363 * @inode - the inode in need of a blob
365 * Returns 0 if it gets a blob, -ENOMEM otherwise
367 static int smack_inode_alloc_security(struct inode *inode)
369 inode->i_security = new_inode_smack(current->security);
370 if (inode->i_security == NULL)
371 return -ENOMEM;
372 return 0;
376 * smack_inode_free_security - free an inode blob
377 * @inode - the inode with a blob
379 * Clears the blob pointer in inode
381 static void smack_inode_free_security(struct inode *inode)
383 kfree(inode->i_security);
384 inode->i_security = NULL;
388 * smack_inode_init_security - copy out the smack from an inode
389 * @inode: the inode
390 * @dir: unused
391 * @name: where to put the attribute name
392 * @value: where to put the attribute value
393 * @len: where to put the length of the attribute
395 * Returns 0 if it all works out, -ENOMEM if there's no memory
397 static int smack_inode_init_security(struct inode *inode, struct inode *dir,
398 char **name, void **value, size_t *len)
400 char *isp = smk_of_inode(inode);
402 if (name) {
403 *name = kstrdup(XATTR_SMACK_SUFFIX, GFP_KERNEL);
404 if (*name == NULL)
405 return -ENOMEM;
408 if (value) {
409 *value = kstrdup(isp, GFP_KERNEL);
410 if (*value == NULL)
411 return -ENOMEM;
414 if (len)
415 *len = strlen(isp) + 1;
417 return 0;
421 * smack_inode_link - Smack check on link
422 * @old_dentry: the existing object
423 * @dir: unused
424 * @new_dentry: the new object
426 * Returns 0 if access is permitted, an error code otherwise
428 static int smack_inode_link(struct dentry *old_dentry, struct inode *dir,
429 struct dentry *new_dentry)
431 int rc;
432 char *isp;
434 isp = smk_of_inode(old_dentry->d_inode);
435 rc = smk_curacc(isp, MAY_WRITE);
437 if (rc == 0 && new_dentry->d_inode != NULL) {
438 isp = smk_of_inode(new_dentry->d_inode);
439 rc = smk_curacc(isp, MAY_WRITE);
442 return rc;
446 * smack_inode_unlink - Smack check on inode deletion
447 * @dir: containing directory object
448 * @dentry: file to unlink
450 * Returns 0 if current can write the containing directory
451 * and the object, error code otherwise
453 static int smack_inode_unlink(struct inode *dir, struct dentry *dentry)
455 struct inode *ip = dentry->d_inode;
456 int rc;
459 * You need write access to the thing you're unlinking
461 rc = smk_curacc(smk_of_inode(ip), MAY_WRITE);
462 if (rc == 0)
464 * You also need write access to the containing directory
466 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE);
468 return rc;
472 * smack_inode_rmdir - Smack check on directory deletion
473 * @dir: containing directory object
474 * @dentry: directory to unlink
476 * Returns 0 if current can write the containing directory
477 * and the directory, error code otherwise
479 static int smack_inode_rmdir(struct inode *dir, struct dentry *dentry)
481 int rc;
484 * You need write access to the thing you're removing
486 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
487 if (rc == 0)
489 * You also need write access to the containing directory
491 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE);
493 return rc;
497 * smack_inode_rename - Smack check on rename
498 * @old_inode: the old directory
499 * @old_dentry: unused
500 * @new_inode: the new directory
501 * @new_dentry: unused
503 * Read and write access is required on both the old and
504 * new directories.
506 * Returns 0 if access is permitted, an error code otherwise
508 static int smack_inode_rename(struct inode *old_inode,
509 struct dentry *old_dentry,
510 struct inode *new_inode,
511 struct dentry *new_dentry)
513 int rc;
514 char *isp;
516 isp = smk_of_inode(old_dentry->d_inode);
517 rc = smk_curacc(isp, MAY_READWRITE);
519 if (rc == 0 && new_dentry->d_inode != NULL) {
520 isp = smk_of_inode(new_dentry->d_inode);
521 rc = smk_curacc(isp, MAY_READWRITE);
524 return rc;
528 * smack_inode_permission - Smack version of permission()
529 * @inode: the inode in question
530 * @mask: the access requested
531 * @nd: unused
533 * This is the important Smack hook.
535 * Returns 0 if access is permitted, -EACCES otherwise
537 static int smack_inode_permission(struct inode *inode, int mask,
538 struct nameidata *nd)
541 * No permission to check. Existence test. Yup, it's there.
543 if (mask == 0)
544 return 0;
546 return smk_curacc(smk_of_inode(inode), mask);
550 * smack_inode_setattr - Smack check for setting attributes
551 * @dentry: the object
552 * @iattr: for the force flag
554 * Returns 0 if access is permitted, an error code otherwise
556 static int smack_inode_setattr(struct dentry *dentry, struct iattr *iattr)
559 * Need to allow for clearing the setuid bit.
561 if (iattr->ia_valid & ATTR_FORCE)
562 return 0;
564 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
568 * smack_inode_getattr - Smack check for getting attributes
569 * @mnt: unused
570 * @dentry: the object
572 * Returns 0 if access is permitted, an error code otherwise
574 static int smack_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
576 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ);
580 * smack_inode_setxattr - Smack check for setting xattrs
581 * @dentry: the object
582 * @name: name of the attribute
583 * @value: unused
584 * @size: unused
585 * @flags: unused
587 * This protects the Smack attribute explicitly.
589 * Returns 0 if access is permitted, an error code otherwise
591 static int smack_inode_setxattr(struct dentry *dentry, char *name,
592 void *value, size_t size, int flags)
594 <<<<<<< HEAD:security/smack/smack_lsm.c
595 if (!capable(CAP_MAC_ADMIN)) {
596 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
597 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
598 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0)
599 return -EPERM;
601 =======
602 int rc = 0;
603 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
605 <<<<<<< HEAD:security/smack/smack_lsm.c
606 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
607 =======
608 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
609 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
610 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0) {
611 if (!capable(CAP_MAC_ADMIN))
612 rc = -EPERM;
613 } else
614 rc = cap_inode_setxattr(dentry, name, value, size, flags);
616 if (rc == 0)
617 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
619 return rc;
620 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
624 * smack_inode_post_setxattr - Apply the Smack update approved above
625 * @dentry: object
626 * @name: attribute name
627 * @value: attribute value
628 * @size: attribute size
629 * @flags: unused
631 * Set the pointer in the inode blob to the entry found
632 * in the master label list.
634 static void smack_inode_post_setxattr(struct dentry *dentry, char *name,
635 void *value, size_t size, int flags)
637 struct inode_smack *isp;
638 char *nsp;
641 * Not SMACK
643 if (strcmp(name, XATTR_NAME_SMACK))
644 return;
646 if (size >= SMK_LABELLEN)
647 return;
649 isp = dentry->d_inode->i_security;
652 * No locking is done here. This is a pointer
653 * assignment.
655 nsp = smk_import(value, size);
656 if (nsp != NULL)
657 isp->smk_inode = nsp;
658 else
659 isp->smk_inode = smack_known_invalid.smk_known;
661 return;
665 * smack_inode_getxattr - Smack check on getxattr
666 * @dentry: the object
667 * @name: unused
669 * Returns 0 if access is permitted, an error code otherwise
671 static int smack_inode_getxattr(struct dentry *dentry, char *name)
673 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ);
677 * smack_inode_removexattr - Smack check on removexattr
678 * @dentry: the object
679 * @name: name of the attribute
681 * Removing the Smack attribute requires CAP_MAC_ADMIN
683 * Returns 0 if access is permitted, an error code otherwise
685 static int smack_inode_removexattr(struct dentry *dentry, char *name)
687 <<<<<<< HEAD:security/smack/smack_lsm.c
688 if (strcmp(name, XATTR_NAME_SMACK) == 0 && !capable(CAP_MAC_ADMIN))
689 return -EPERM;
690 =======
691 int rc = 0;
692 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
694 <<<<<<< HEAD:security/smack/smack_lsm.c
695 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
696 =======
697 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
698 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
699 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0) {
700 if (!capable(CAP_MAC_ADMIN))
701 rc = -EPERM;
702 } else
703 rc = cap_inode_removexattr(dentry, name);
705 if (rc == 0)
706 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
708 return rc;
709 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
713 * smack_inode_getsecurity - get smack xattrs
714 * @inode: the object
715 * @name: attribute name
716 * @buffer: where to put the result
717 * @size: size of the buffer
718 * @err: unused
720 * Returns the size of the attribute or an error code
722 static int smack_inode_getsecurity(const struct inode *inode,
723 const char *name, void **buffer,
724 bool alloc)
726 struct socket_smack *ssp;
727 struct socket *sock;
728 struct super_block *sbp;
729 struct inode *ip = (struct inode *)inode;
730 char *isp;
731 int ilen;
732 int rc = 0;
734 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
735 isp = smk_of_inode(inode);
736 ilen = strlen(isp) + 1;
737 *buffer = isp;
738 return ilen;
742 * The rest of the Smack xattrs are only on sockets.
744 sbp = ip->i_sb;
745 if (sbp->s_magic != SOCKFS_MAGIC)
746 return -EOPNOTSUPP;
748 sock = SOCKET_I(ip);
749 if (sock == NULL || sock->sk == NULL)
750 return -EOPNOTSUPP;
752 ssp = sock->sk->sk_security;
754 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
755 isp = ssp->smk_in;
756 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0)
757 isp = ssp->smk_out;
758 else
759 return -EOPNOTSUPP;
761 ilen = strlen(isp) + 1;
762 if (rc == 0) {
763 *buffer = isp;
764 rc = ilen;
767 return rc;
772 * smack_inode_listsecurity - list the Smack attributes
773 * @inode: the object
774 * @buffer: where they go
775 * @buffer_size: size of buffer
777 * Returns 0 on success, -EINVAL otherwise
779 static int smack_inode_listsecurity(struct inode *inode, char *buffer,
780 size_t buffer_size)
782 int len = strlen(XATTR_NAME_SMACK);
784 if (buffer != NULL && len <= buffer_size) {
785 memcpy(buffer, XATTR_NAME_SMACK, len);
786 return len;
788 return -EINVAL;
792 * File Hooks
796 * smack_file_permission - Smack check on file operations
797 * @file: unused
798 * @mask: unused
800 * Returns 0
802 * Should access checks be done on each read or write?
803 * UNICOS and SELinux say yes.
804 * Trusted Solaris, Trusted Irix, and just about everyone else says no.
806 * I'll say no for now. Smack does not do the frequent
807 * label changing that SELinux does.
809 static int smack_file_permission(struct file *file, int mask)
811 return 0;
815 * smack_file_alloc_security - assign a file security blob
816 * @file: the object
818 * The security blob for a file is a pointer to the master
819 * label list, so no allocation is done.
821 * Returns 0
823 static int smack_file_alloc_security(struct file *file)
825 file->f_security = current->security;
826 return 0;
830 * smack_file_free_security - clear a file security blob
831 * @file: the object
833 * The security blob for a file is a pointer to the master
834 * label list, so no memory is freed.
836 static void smack_file_free_security(struct file *file)
838 file->f_security = NULL;
842 * smack_file_ioctl - Smack check on ioctls
843 * @file: the object
844 * @cmd: what to do
845 * @arg: unused
847 * Relies heavily on the correct use of the ioctl command conventions.
849 * Returns 0 if allowed, error code otherwise
851 static int smack_file_ioctl(struct file *file, unsigned int cmd,
852 unsigned long arg)
854 int rc = 0;
856 if (_IOC_DIR(cmd) & _IOC_WRITE)
857 rc = smk_curacc(file->f_security, MAY_WRITE);
859 if (rc == 0 && (_IOC_DIR(cmd) & _IOC_READ))
860 rc = smk_curacc(file->f_security, MAY_READ);
862 return rc;
866 * smack_file_lock - Smack check on file locking
867 * @file: the object
868 * @cmd unused
870 * Returns 0 if current has write access, error code otherwise
872 static int smack_file_lock(struct file *file, unsigned int cmd)
874 return smk_curacc(file->f_security, MAY_WRITE);
878 * smack_file_fcntl - Smack check on fcntl
879 * @file: the object
880 * @cmd: what action to check
881 * @arg: unused
883 * Returns 0 if current has access, error code otherwise
885 static int smack_file_fcntl(struct file *file, unsigned int cmd,
886 unsigned long arg)
888 int rc;
890 switch (cmd) {
891 case F_DUPFD:
892 case F_GETFD:
893 case F_GETFL:
894 case F_GETLK:
895 case F_GETOWN:
896 case F_GETSIG:
897 rc = smk_curacc(file->f_security, MAY_READ);
898 break;
899 case F_SETFD:
900 case F_SETFL:
901 case F_SETLK:
902 case F_SETLKW:
903 case F_SETOWN:
904 case F_SETSIG:
905 rc = smk_curacc(file->f_security, MAY_WRITE);
906 break;
907 default:
908 rc = smk_curacc(file->f_security, MAY_READWRITE);
911 return rc;
915 * smack_file_set_fowner - set the file security blob value
916 * @file: object in question
918 * Returns 0
919 * Further research may be required on this one.
921 static int smack_file_set_fowner(struct file *file)
923 file->f_security = current->security;
924 return 0;
928 * smack_file_send_sigiotask - Smack on sigio
929 * @tsk: The target task
930 * @fown: the object the signal come from
931 * @signum: unused
933 * Allow a privileged task to get signals even if it shouldn't
935 * Returns 0 if a subject with the object's smack could
936 * write to the task, an error code otherwise.
938 static int smack_file_send_sigiotask(struct task_struct *tsk,
939 struct fown_struct *fown, int signum)
941 struct file *file;
942 int rc;
945 * struct fown_struct is never outside the context of a struct file
947 file = container_of(fown, struct file, f_owner);
948 rc = smk_access(file->f_security, tsk->security, MAY_WRITE);
949 if (rc != 0 && __capable(tsk, CAP_MAC_OVERRIDE))
950 return 0;
951 return rc;
955 * smack_file_receive - Smack file receive check
956 * @file: the object
958 * Returns 0 if current has access, error code otherwise
960 static int smack_file_receive(struct file *file)
962 int may = 0;
965 * This code relies on bitmasks.
967 if (file->f_mode & FMODE_READ)
968 may = MAY_READ;
969 if (file->f_mode & FMODE_WRITE)
970 may |= MAY_WRITE;
972 return smk_curacc(file->f_security, may);
976 * Task hooks
980 * smack_task_alloc_security - "allocate" a task blob
981 * @tsk: the task in need of a blob
983 * Smack isn't using copies of blobs. Everyone
984 * points to an immutable list. No alloc required.
985 * No data copy required.
987 * Always returns 0
989 static int smack_task_alloc_security(struct task_struct *tsk)
991 tsk->security = current->security;
993 return 0;
997 * smack_task_free_security - "free" a task blob
998 * @task: the task with the blob
1000 * Smack isn't using copies of blobs. Everyone
1001 * points to an immutable list. The blobs never go away.
1002 * There is no leak here.
1004 static void smack_task_free_security(struct task_struct *task)
1006 task->security = NULL;
1010 * smack_task_setpgid - Smack check on setting pgid
1011 * @p: the task object
1012 * @pgid: unused
1014 * Return 0 if write access is permitted
1016 static int smack_task_setpgid(struct task_struct *p, pid_t pgid)
1018 return smk_curacc(p->security, MAY_WRITE);
1022 * smack_task_getpgid - Smack access check for getpgid
1023 * @p: the object task
1025 * Returns 0 if current can read the object task, error code otherwise
1027 static int smack_task_getpgid(struct task_struct *p)
1029 return smk_curacc(p->security, MAY_READ);
1033 * smack_task_getsid - Smack access check for getsid
1034 * @p: the object task
1036 * Returns 0 if current can read the object task, error code otherwise
1038 static int smack_task_getsid(struct task_struct *p)
1040 return smk_curacc(p->security, MAY_READ);
1044 * smack_task_getsecid - get the secid of the task
1045 * @p: the object task
1046 * @secid: where to put the result
1048 * Sets the secid to contain a u32 version of the smack label.
1050 static void smack_task_getsecid(struct task_struct *p, u32 *secid)
1052 *secid = smack_to_secid(p->security);
1056 * smack_task_setnice - Smack check on setting nice
1057 * @p: the task object
1058 * @nice: unused
1060 * Return 0 if write access is permitted
1062 static int smack_task_setnice(struct task_struct *p, int nice)
1064 <<<<<<< HEAD:security/smack/smack_lsm.c
1065 return smk_curacc(p->security, MAY_WRITE);
1066 =======
1067 int rc;
1069 rc = cap_task_setnice(p, nice);
1070 if (rc == 0)
1071 rc = smk_curacc(p->security, MAY_WRITE);
1072 return rc;
1073 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
1077 * smack_task_setioprio - Smack check on setting ioprio
1078 * @p: the task object
1079 * @ioprio: unused
1081 * Return 0 if write access is permitted
1083 static int smack_task_setioprio(struct task_struct *p, int ioprio)
1085 <<<<<<< HEAD:security/smack/smack_lsm.c
1086 return smk_curacc(p->security, MAY_WRITE);
1087 =======
1088 int rc;
1090 rc = cap_task_setioprio(p, ioprio);
1091 if (rc == 0)
1092 rc = smk_curacc(p->security, MAY_WRITE);
1093 return rc;
1094 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
1098 * smack_task_getioprio - Smack check on reading ioprio
1099 * @p: the task object
1101 * Return 0 if read access is permitted
1103 static int smack_task_getioprio(struct task_struct *p)
1105 return smk_curacc(p->security, MAY_READ);
1109 * smack_task_setscheduler - Smack check on setting scheduler
1110 * @p: the task object
1111 * @policy: unused
1112 * @lp: unused
1114 * Return 0 if read access is permitted
1116 static int smack_task_setscheduler(struct task_struct *p, int policy,
1117 struct sched_param *lp)
1119 <<<<<<< HEAD:security/smack/smack_lsm.c
1120 return smk_curacc(p->security, MAY_WRITE);
1121 =======
1122 int rc;
1124 rc = cap_task_setscheduler(p, policy, lp);
1125 if (rc == 0)
1126 rc = smk_curacc(p->security, MAY_WRITE);
1127 return rc;
1128 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
1132 * smack_task_getscheduler - Smack check on reading scheduler
1133 * @p: the task object
1135 * Return 0 if read access is permitted
1137 static int smack_task_getscheduler(struct task_struct *p)
1139 return smk_curacc(p->security, MAY_READ);
1143 * smack_task_movememory - Smack check on moving memory
1144 * @p: the task object
1146 * Return 0 if write access is permitted
1148 static int smack_task_movememory(struct task_struct *p)
1150 return smk_curacc(p->security, MAY_WRITE);
1154 * smack_task_kill - Smack check on signal delivery
1155 * @p: the task object
1156 * @info: unused
1157 * @sig: unused
1158 * @secid: identifies the smack to use in lieu of current's
1160 * Return 0 if write access is permitted
1162 * The secid behavior is an artifact of an SELinux hack
1163 * in the USB code. Someday it may go away.
1165 static int smack_task_kill(struct task_struct *p, struct siginfo *info,
1166 int sig, u32 secid)
1168 <<<<<<< HEAD:security/smack/smack_lsm.c
1169 =======
1170 int rc;
1172 rc = cap_task_kill(p, info, sig, secid);
1173 if (rc != 0)
1174 return rc;
1175 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
1177 * Special cases where signals really ought to go through
1178 * in spite of policy. Stephen Smalley suggests it may
1179 * make sense to change the caller so that it doesn't
1180 * bother with the LSM hook in these cases.
1182 if (info != SEND_SIG_NOINFO &&
1183 (is_si_special(info) || SI_FROMKERNEL(info)))
1184 return 0;
1186 * Sending a signal requires that the sender
1187 * can write the receiver.
1189 if (secid == 0)
1190 return smk_curacc(p->security, MAY_WRITE);
1192 * If the secid isn't 0 we're dealing with some USB IO
1193 * specific behavior. This is not clean. For one thing
1194 * we can't take privilege into account.
1196 return smk_access(smack_from_secid(secid), p->security, MAY_WRITE);
1200 * smack_task_wait - Smack access check for waiting
1201 * @p: task to wait for
1203 * Returns 0 if current can wait for p, error code otherwise
1205 static int smack_task_wait(struct task_struct *p)
1207 int rc;
1209 rc = smk_access(current->security, p->security, MAY_WRITE);
1210 if (rc == 0)
1211 return 0;
1214 * Allow the operation to succeed if either task
1215 * has privilege to perform operations that might
1216 * account for the smack labels having gotten to
1217 * be different in the first place.
1219 * This breaks the strict subjet/object access
1220 * control ideal, taking the object's privilege
1221 * state into account in the decision as well as
1222 * the smack value.
1224 if (capable(CAP_MAC_OVERRIDE) || __capable(p, CAP_MAC_OVERRIDE))
1225 return 0;
1227 return rc;
1231 * smack_task_to_inode - copy task smack into the inode blob
1232 * @p: task to copy from
1233 * inode: inode to copy to
1235 * Sets the smack pointer in the inode security blob
1237 static void smack_task_to_inode(struct task_struct *p, struct inode *inode)
1239 struct inode_smack *isp = inode->i_security;
1240 isp->smk_inode = p->security;
1244 * Socket hooks.
1248 * smack_sk_alloc_security - Allocate a socket blob
1249 * @sk: the socket
1250 * @family: unused
1251 * @priority: memory allocation priority
1253 * Assign Smack pointers to current
1255 * Returns 0 on success, -ENOMEM is there's no memory
1257 static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags)
1259 char *csp = current->security;
1260 struct socket_smack *ssp;
1262 ssp = kzalloc(sizeof(struct socket_smack), gfp_flags);
1263 if (ssp == NULL)
1264 return -ENOMEM;
1266 ssp->smk_in = csp;
1267 ssp->smk_out = csp;
1268 ssp->smk_packet[0] = '\0';
1270 sk->sk_security = ssp;
1272 return 0;
1276 * smack_sk_free_security - Free a socket blob
1277 * @sk: the socket
1279 * Clears the blob pointer
1281 static void smack_sk_free_security(struct sock *sk)
1283 kfree(sk->sk_security);
1287 * smack_set_catset - convert a capset to netlabel mls categories
1288 * @catset: the Smack categories
1289 * @sap: where to put the netlabel categories
1291 * Allocates and fills attr.mls.cat
1293 static void smack_set_catset(char *catset, struct netlbl_lsm_secattr *sap)
1295 unsigned char *cp;
1296 unsigned char m;
1297 int cat;
1298 int rc;
1299 int byte;
1301 if (catset == 0)
1302 return;
1304 sap->flags |= NETLBL_SECATTR_MLS_CAT;
1305 sap->attr.mls.cat = netlbl_secattr_catmap_alloc(GFP_ATOMIC);
1306 sap->attr.mls.cat->startbit = 0;
1308 for (cat = 1, cp = catset, byte = 0; byte < SMK_LABELLEN; cp++, byte++)
1309 for (m = 0x80; m != 0; m >>= 1, cat++) {
1310 if ((m & *cp) == 0)
1311 continue;
1312 rc = netlbl_secattr_catmap_setbit(sap->attr.mls.cat,
1313 cat, GFP_ATOMIC);
1318 * smack_to_secattr - fill a secattr from a smack value
1319 * @smack: the smack value
1320 * @nlsp: where the result goes
1322 * Casey says that CIPSO is good enough for now.
1323 * It can be used to effect.
1324 * It can also be abused to effect when necessary.
1325 * Appologies to the TSIG group in general and GW in particular.
1327 static void smack_to_secattr(char *smack, struct netlbl_lsm_secattr *nlsp)
1329 struct smack_cipso cipso;
1330 int rc;
1332 switch (smack_net_nltype) {
1333 case NETLBL_NLTYPE_CIPSOV4:
1334 <<<<<<< HEAD:security/smack/smack_lsm.c
1335 nlsp->domain = NULL;
1336 nlsp->flags = NETLBL_SECATTR_DOMAIN;
1337 nlsp->flags |= NETLBL_SECATTR_MLS_LVL;
1338 =======
1339 nlsp->domain = kstrdup(smack, GFP_ATOMIC);
1340 nlsp->flags = NETLBL_SECATTR_DOMAIN | NETLBL_SECATTR_MLS_LVL;
1341 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
1343 rc = smack_to_cipso(smack, &cipso);
1344 if (rc == 0) {
1345 nlsp->attr.mls.lvl = cipso.smk_level;
1346 smack_set_catset(cipso.smk_catset, nlsp);
1347 } else {
1348 nlsp->attr.mls.lvl = smack_cipso_direct;
1349 smack_set_catset(smack, nlsp);
1351 break;
1352 default:
1353 break;
1358 * smack_netlabel - Set the secattr on a socket
1359 * @sk: the socket
1361 * Convert the outbound smack value (smk_out) to a
1362 * secattr and attach it to the socket.
1364 * Returns 0 on success or an error code
1366 static int smack_netlabel(struct sock *sk)
1368 struct socket_smack *ssp;
1369 struct netlbl_lsm_secattr secattr;
1370 <<<<<<< HEAD:security/smack/smack_lsm.c
1371 int rc = 0;
1372 =======
1373 int rc;
1374 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
1376 ssp = sk->sk_security;
1377 netlbl_secattr_init(&secattr);
1378 smack_to_secattr(ssp->smk_out, &secattr);
1379 <<<<<<< HEAD:security/smack/smack_lsm.c
1380 if (secattr.flags != NETLBL_SECATTR_NONE)
1381 rc = netlbl_sock_setattr(sk, &secattr);
1383 =======
1384 rc = netlbl_sock_setattr(sk, &secattr);
1385 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
1386 netlbl_secattr_destroy(&secattr);
1387 <<<<<<< HEAD:security/smack/smack_lsm.c
1388 =======
1390 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
1391 return rc;
1395 * smack_inode_setsecurity - set smack xattrs
1396 * @inode: the object
1397 * @name: attribute name
1398 * @value: attribute value
1399 * @size: size of the attribute
1400 * @flags: unused
1402 * Sets the named attribute in the appropriate blob
1404 * Returns 0 on success, or an error code
1406 static int smack_inode_setsecurity(struct inode *inode, const char *name,
1407 const void *value, size_t size, int flags)
1409 char *sp;
1410 struct inode_smack *nsp = inode->i_security;
1411 struct socket_smack *ssp;
1412 struct socket *sock;
1413 <<<<<<< HEAD:security/smack/smack_lsm.c
1414 =======
1415 int rc = 0;
1416 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
1418 if (value == NULL || size > SMK_LABELLEN)
1419 return -EACCES;
1421 sp = smk_import(value, size);
1422 if (sp == NULL)
1423 return -EINVAL;
1425 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
1426 nsp->smk_inode = sp;
1427 return 0;
1430 * The rest of the Smack xattrs are only on sockets.
1432 if (inode->i_sb->s_magic != SOCKFS_MAGIC)
1433 return -EOPNOTSUPP;
1435 sock = SOCKET_I(inode);
1436 if (sock == NULL || sock->sk == NULL)
1437 return -EOPNOTSUPP;
1439 ssp = sock->sk->sk_security;
1441 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
1442 ssp->smk_in = sp;
1443 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0) {
1444 ssp->smk_out = sp;
1445 <<<<<<< HEAD:security/smack/smack_lsm.c
1446 return smack_netlabel(sock->sk);
1447 =======
1448 rc = smack_netlabel(sock->sk);
1449 if (rc != 0)
1450 printk(KERN_WARNING "Smack: \"%s\" netlbl error %d.\n",
1451 __func__, -rc);
1452 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
1453 } else
1454 return -EOPNOTSUPP;
1456 return 0;
1460 * smack_socket_post_create - finish socket setup
1461 * @sock: the socket
1462 * @family: protocol family
1463 * @type: unused
1464 * @protocol: unused
1465 * @kern: unused
1467 * Sets the netlabel information on the socket
1469 * Returns 0 on success, and error code otherwise
1471 static int smack_socket_post_create(struct socket *sock, int family,
1472 int type, int protocol, int kern)
1474 if (family != PF_INET || sock->sk == NULL)
1475 return 0;
1477 * Set the outbound netlbl.
1479 return smack_netlabel(sock->sk);
1483 * smack_flags_to_may - convert S_ to MAY_ values
1484 * @flags: the S_ value
1486 * Returns the equivalent MAY_ value
1488 static int smack_flags_to_may(int flags)
1490 int may = 0;
1492 if (flags & S_IRUGO)
1493 may |= MAY_READ;
1494 if (flags & S_IWUGO)
1495 may |= MAY_WRITE;
1496 if (flags & S_IXUGO)
1497 may |= MAY_EXEC;
1499 return may;
1503 * smack_msg_msg_alloc_security - Set the security blob for msg_msg
1504 * @msg: the object
1506 * Returns 0
1508 static int smack_msg_msg_alloc_security(struct msg_msg *msg)
1510 msg->security = current->security;
1511 return 0;
1515 * smack_msg_msg_free_security - Clear the security blob for msg_msg
1516 * @msg: the object
1518 * Clears the blob pointer
1520 static void smack_msg_msg_free_security(struct msg_msg *msg)
1522 msg->security = NULL;
1526 * smack_of_shm - the smack pointer for the shm
1527 * @shp: the object
1529 * Returns a pointer to the smack value
1531 static char *smack_of_shm(struct shmid_kernel *shp)
1533 return (char *)shp->shm_perm.security;
1537 * smack_shm_alloc_security - Set the security blob for shm
1538 * @shp: the object
1540 * Returns 0
1542 static int smack_shm_alloc_security(struct shmid_kernel *shp)
1544 struct kern_ipc_perm *isp = &shp->shm_perm;
1546 isp->security = current->security;
1547 return 0;
1551 * smack_shm_free_security - Clear the security blob for shm
1552 * @shp: the object
1554 * Clears the blob pointer
1556 static void smack_shm_free_security(struct shmid_kernel *shp)
1558 struct kern_ipc_perm *isp = &shp->shm_perm;
1560 isp->security = NULL;
1564 * smack_shm_associate - Smack access check for shm
1565 * @shp: the object
1566 * @shmflg: access requested
1568 * Returns 0 if current has the requested access, error code otherwise
1570 static int smack_shm_associate(struct shmid_kernel *shp, int shmflg)
1572 char *ssp = smack_of_shm(shp);
1573 int may;
1575 may = smack_flags_to_may(shmflg);
1576 return smk_curacc(ssp, may);
1580 * smack_shm_shmctl - Smack access check for shm
1581 * @shp: the object
1582 * @cmd: what it wants to do
1584 * Returns 0 if current has the requested access, error code otherwise
1586 static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd)
1588 char *ssp = smack_of_shm(shp);
1589 int may;
1591 switch (cmd) {
1592 case IPC_STAT:
1593 case SHM_STAT:
1594 may = MAY_READ;
1595 break;
1596 case IPC_SET:
1597 case SHM_LOCK:
1598 case SHM_UNLOCK:
1599 case IPC_RMID:
1600 may = MAY_READWRITE;
1601 break;
1602 case IPC_INFO:
1603 case SHM_INFO:
1605 * System level information.
1607 return 0;
1608 default:
1609 return -EINVAL;
1612 return smk_curacc(ssp, may);
1616 * smack_shm_shmat - Smack access for shmat
1617 * @shp: the object
1618 * @shmaddr: unused
1619 * @shmflg: access requested
1621 * Returns 0 if current has the requested access, error code otherwise
1623 static int smack_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr,
1624 int shmflg)
1626 char *ssp = smack_of_shm(shp);
1627 int may;
1629 may = smack_flags_to_may(shmflg);
1630 return smk_curacc(ssp, may);
1634 * smack_of_sem - the smack pointer for the sem
1635 * @sma: the object
1637 * Returns a pointer to the smack value
1639 static char *smack_of_sem(struct sem_array *sma)
1641 return (char *)sma->sem_perm.security;
1645 * smack_sem_alloc_security - Set the security blob for sem
1646 * @sma: the object
1648 * Returns 0
1650 static int smack_sem_alloc_security(struct sem_array *sma)
1652 struct kern_ipc_perm *isp = &sma->sem_perm;
1654 isp->security = current->security;
1655 return 0;
1659 * smack_sem_free_security - Clear the security blob for sem
1660 * @sma: the object
1662 * Clears the blob pointer
1664 static void smack_sem_free_security(struct sem_array *sma)
1666 struct kern_ipc_perm *isp = &sma->sem_perm;
1668 isp->security = NULL;
1672 * smack_sem_associate - Smack access check for sem
1673 * @sma: the object
1674 * @semflg: access requested
1676 * Returns 0 if current has the requested access, error code otherwise
1678 static int smack_sem_associate(struct sem_array *sma, int semflg)
1680 char *ssp = smack_of_sem(sma);
1681 int may;
1683 may = smack_flags_to_may(semflg);
1684 return smk_curacc(ssp, may);
1688 * smack_sem_shmctl - Smack access check for sem
1689 * @sma: the object
1690 * @cmd: what it wants to do
1692 * Returns 0 if current has the requested access, error code otherwise
1694 static int smack_sem_semctl(struct sem_array *sma, int cmd)
1696 char *ssp = smack_of_sem(sma);
1697 int may;
1699 switch (cmd) {
1700 case GETPID:
1701 case GETNCNT:
1702 case GETZCNT:
1703 case GETVAL:
1704 case GETALL:
1705 case IPC_STAT:
1706 case SEM_STAT:
1707 may = MAY_READ;
1708 break;
1709 case SETVAL:
1710 case SETALL:
1711 case IPC_RMID:
1712 case IPC_SET:
1713 may = MAY_READWRITE;
1714 break;
1715 case IPC_INFO:
1716 case SEM_INFO:
1718 * System level information
1720 return 0;
1721 default:
1722 return -EINVAL;
1725 return smk_curacc(ssp, may);
1729 * smack_sem_semop - Smack checks of semaphore operations
1730 * @sma: the object
1731 * @sops: unused
1732 * @nsops: unused
1733 * @alter: unused
1735 * Treated as read and write in all cases.
1737 * Returns 0 if access is allowed, error code otherwise
1739 static int smack_sem_semop(struct sem_array *sma, struct sembuf *sops,
1740 unsigned nsops, int alter)
1742 char *ssp = smack_of_sem(sma);
1744 return smk_curacc(ssp, MAY_READWRITE);
1748 * smack_msg_alloc_security - Set the security blob for msg
1749 * @msq: the object
1751 * Returns 0
1753 static int smack_msg_queue_alloc_security(struct msg_queue *msq)
1755 struct kern_ipc_perm *kisp = &msq->q_perm;
1757 kisp->security = current->security;
1758 return 0;
1762 * smack_msg_free_security - Clear the security blob for msg
1763 * @msq: the object
1765 * Clears the blob pointer
1767 static void smack_msg_queue_free_security(struct msg_queue *msq)
1769 struct kern_ipc_perm *kisp = &msq->q_perm;
1771 kisp->security = NULL;
1775 * smack_of_msq - the smack pointer for the msq
1776 * @msq: the object
1778 * Returns a pointer to the smack value
1780 static char *smack_of_msq(struct msg_queue *msq)
1782 return (char *)msq->q_perm.security;
1786 * smack_msg_queue_associate - Smack access check for msg_queue
1787 * @msq: the object
1788 * @msqflg: access requested
1790 * Returns 0 if current has the requested access, error code otherwise
1792 static int smack_msg_queue_associate(struct msg_queue *msq, int msqflg)
1794 char *msp = smack_of_msq(msq);
1795 int may;
1797 may = smack_flags_to_may(msqflg);
1798 return smk_curacc(msp, may);
1802 * smack_msg_queue_msgctl - Smack access check for msg_queue
1803 * @msq: the object
1804 * @cmd: what it wants to do
1806 * Returns 0 if current has the requested access, error code otherwise
1808 static int smack_msg_queue_msgctl(struct msg_queue *msq, int cmd)
1810 char *msp = smack_of_msq(msq);
1811 int may;
1813 switch (cmd) {
1814 case IPC_STAT:
1815 case MSG_STAT:
1816 may = MAY_READ;
1817 break;
1818 case IPC_SET:
1819 case IPC_RMID:
1820 may = MAY_READWRITE;
1821 break;
1822 case IPC_INFO:
1823 case MSG_INFO:
1825 * System level information
1827 return 0;
1828 default:
1829 return -EINVAL;
1832 return smk_curacc(msp, may);
1836 * smack_msg_queue_msgsnd - Smack access check for msg_queue
1837 * @msq: the object
1838 * @msg: unused
1839 * @msqflg: access requested
1841 * Returns 0 if current has the requested access, error code otherwise
1843 static int smack_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
1844 int msqflg)
1846 char *msp = smack_of_msq(msq);
1847 int rc;
1849 rc = smack_flags_to_may(msqflg);
1850 return smk_curacc(msp, rc);
1854 * smack_msg_queue_msgsnd - Smack access check for msg_queue
1855 * @msq: the object
1856 * @msg: unused
1857 * @target: unused
1858 * @type: unused
1859 * @mode: unused
1861 * Returns 0 if current has read and write access, error code otherwise
1863 static int smack_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
1864 struct task_struct *target, long type, int mode)
1866 char *msp = smack_of_msq(msq);
1868 return smk_curacc(msp, MAY_READWRITE);
1872 * smack_ipc_permission - Smack access for ipc_permission()
1873 * @ipp: the object permissions
1874 * @flag: access requested
1876 * Returns 0 if current has read and write access, error code otherwise
1878 static int smack_ipc_permission(struct kern_ipc_perm *ipp, short flag)
1880 char *isp = ipp->security;
1881 int may;
1883 may = smack_flags_to_may(flag);
1884 return smk_curacc(isp, may);
1887 <<<<<<< HEAD:security/smack/smack_lsm.c
1888 =======
1889 /* module stacking operations */
1892 * smack_register_security - stack capability module
1893 * @name: module name
1894 * @ops: module operations - ignored
1896 * Allow the capability module to register.
1898 static int smack_register_security(const char *name,
1899 struct security_operations *ops)
1901 if (strcmp(name, "capability") != 0)
1902 return -EINVAL;
1904 printk(KERN_INFO "%s: Registering secondary module %s\n",
1905 __func__, name);
1907 return 0;
1910 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
1912 * smack_d_instantiate - Make sure the blob is correct on an inode
1913 * @opt_dentry: unused
1914 * @inode: the object
1916 * Set the inode's security blob if it hasn't been done already.
1918 static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
1920 struct super_block *sbp;
1921 struct superblock_smack *sbsp;
1922 struct inode_smack *isp;
1923 char *csp = current->security;
1924 char *fetched;
1925 char *final;
1926 struct dentry *dp;
1928 if (inode == NULL)
1929 return;
1931 isp = inode->i_security;
1933 mutex_lock(&isp->smk_lock);
1935 * If the inode is already instantiated
1936 * take the quick way out
1938 if (isp->smk_flags & SMK_INODE_INSTANT)
1939 goto unlockandout;
1941 sbp = inode->i_sb;
1942 sbsp = sbp->s_security;
1944 * We're going to use the superblock default label
1945 * if there's no label on the file.
1947 final = sbsp->smk_default;
1950 * This is pretty hackish.
1951 * Casey says that we shouldn't have to do
1952 * file system specific code, but it does help
1953 * with keeping it simple.
1955 switch (sbp->s_magic) {
1956 case SMACK_MAGIC:
1958 * Casey says that it's a little embarassing
1959 * that the smack file system doesn't do
1960 * extended attributes.
1962 final = smack_known_star.smk_known;
1963 break;
1964 case PIPEFS_MAGIC:
1966 * Casey says pipes are easy (?)
1968 final = smack_known_star.smk_known;
1969 break;
1970 case DEVPTS_SUPER_MAGIC:
1972 * devpts seems content with the label of the task.
1973 * Programs that change smack have to treat the
1974 * pty with respect.
1976 final = csp;
1977 break;
1978 case SOCKFS_MAGIC:
1980 * Casey says sockets get the smack of the task.
1982 final = csp;
1983 break;
1984 case PROC_SUPER_MAGIC:
1986 * Casey says procfs appears not to care.
1987 * The superblock default suffices.
1989 break;
1990 case TMPFS_MAGIC:
1992 * Device labels should come from the filesystem,
1993 * but watch out, because they're volitile,
1994 * getting recreated on every reboot.
1996 final = smack_known_star.smk_known;
1998 * No break.
2000 * If a smack value has been set we want to use it,
2001 * but since tmpfs isn't giving us the opportunity
2002 * to set mount options simulate setting the
2003 * superblock default.
2005 default:
2007 * This isn't an understood special case.
2008 * Get the value from the xattr.
2010 * No xattr support means, alas, no SMACK label.
2011 * Use the aforeapplied default.
2012 * It would be curious if the label of the task
2013 * does not match that assigned.
2015 if (inode->i_op->getxattr == NULL)
2016 break;
2018 * Get the dentry for xattr.
2020 if (opt_dentry == NULL) {
2021 dp = d_find_alias(inode);
2022 if (dp == NULL)
2023 break;
2024 } else {
2025 dp = dget(opt_dentry);
2026 if (dp == NULL)
2027 break;
2030 fetched = smk_fetch(inode, dp);
2031 if (fetched != NULL)
2032 final = fetched;
2034 dput(dp);
2035 break;
2038 if (final == NULL)
2039 isp->smk_inode = csp;
2040 else
2041 isp->smk_inode = final;
2043 isp->smk_flags |= SMK_INODE_INSTANT;
2045 unlockandout:
2046 mutex_unlock(&isp->smk_lock);
2047 return;
2051 * smack_getprocattr - Smack process attribute access
2052 * @p: the object task
2053 * @name: the name of the attribute in /proc/.../attr
2054 * @value: where to put the result
2056 * Places a copy of the task Smack into value
2058 * Returns the length of the smack label or an error code
2060 static int smack_getprocattr(struct task_struct *p, char *name, char **value)
2062 char *cp;
2063 int slen;
2065 if (strcmp(name, "current") != 0)
2066 return -EINVAL;
2068 cp = kstrdup(p->security, GFP_KERNEL);
2069 if (cp == NULL)
2070 return -ENOMEM;
2072 slen = strlen(cp);
2073 *value = cp;
2074 return slen;
2078 * smack_setprocattr - Smack process attribute setting
2079 * @p: the object task
2080 * @name: the name of the attribute in /proc/.../attr
2081 * @value: the value to set
2082 * @size: the size of the value
2084 * Sets the Smack value of the task. Only setting self
2085 * is permitted and only with privilege
2087 * Returns the length of the smack label or an error code
2089 static int smack_setprocattr(struct task_struct *p, char *name,
2090 void *value, size_t size)
2092 char *newsmack;
2094 if (!__capable(p, CAP_MAC_ADMIN))
2095 return -EPERM;
2098 * Changing another process' Smack value is too dangerous
2099 * and supports no sane use case.
2101 if (p != current)
2102 return -EPERM;
2104 if (value == NULL || size == 0 || size >= SMK_LABELLEN)
2105 return -EINVAL;
2107 if (strcmp(name, "current") != 0)
2108 return -EINVAL;
2110 newsmack = smk_import(value, size);
2111 if (newsmack == NULL)
2112 return -EINVAL;
2114 p->security = newsmack;
2115 return size;
2119 * smack_unix_stream_connect - Smack access on UDS
2120 * @sock: one socket
2121 * @other: the other socket
2122 * @newsk: unused
2124 * Return 0 if a subject with the smack of sock could access
2125 * an object with the smack of other, otherwise an error code
2127 static int smack_unix_stream_connect(struct socket *sock,
2128 struct socket *other, struct sock *newsk)
2130 struct inode *sp = SOCK_INODE(sock);
2131 struct inode *op = SOCK_INODE(other);
2133 return smk_access(smk_of_inode(sp), smk_of_inode(op), MAY_READWRITE);
2137 * smack_unix_may_send - Smack access on UDS
2138 * @sock: one socket
2139 * @other: the other socket
2141 * Return 0 if a subject with the smack of sock could access
2142 * an object with the smack of other, otherwise an error code
2144 static int smack_unix_may_send(struct socket *sock, struct socket *other)
2146 struct inode *sp = SOCK_INODE(sock);
2147 struct inode *op = SOCK_INODE(other);
2149 return smk_access(smk_of_inode(sp), smk_of_inode(op), MAY_WRITE);
2153 * smack_from_secattr - Convert a netlabel attr.mls.lvl/attr.mls.cat
2154 * pair to smack
2155 * @sap: netlabel secattr
2156 * @sip: where to put the result
2158 * Copies a smack label into sip
2160 static void smack_from_secattr(struct netlbl_lsm_secattr *sap, char *sip)
2162 char smack[SMK_LABELLEN];
2163 int pcat;
2165 if ((sap->flags & NETLBL_SECATTR_MLS_LVL) == 0) {
2167 * If there are flags but no level netlabel isn't
2168 * behaving the way we expect it to.
2170 * Without guidance regarding the smack value
2171 * for the packet fall back on the network
2172 * ambient value.
2174 strncpy(sip, smack_net_ambient, SMK_MAXLEN);
2175 return;
2178 * Get the categories, if any
2180 memset(smack, '\0', SMK_LABELLEN);
2181 if ((sap->flags & NETLBL_SECATTR_MLS_CAT) != 0)
2182 for (pcat = -1;;) {
2183 pcat = netlbl_secattr_catmap_walk(sap->attr.mls.cat,
2184 pcat + 1);
2185 if (pcat < 0)
2186 break;
2187 smack_catset_bit(pcat, smack);
2190 * If it is CIPSO using smack direct mapping
2191 * we are already done. WeeHee.
2193 if (sap->attr.mls.lvl == smack_cipso_direct) {
2194 memcpy(sip, smack, SMK_MAXLEN);
2195 return;
2198 * Look it up in the supplied table if it is not a direct mapping.
2200 smack_from_cipso(sap->attr.mls.lvl, smack, sip);
2201 return;
2205 * smack_socket_sock_rcv_skb - Smack packet delivery access check
2206 * @sk: socket
2207 * @skb: packet
2209 * Returns 0 if the packet should be delivered, an error code otherwise
2211 static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
2213 struct netlbl_lsm_secattr secattr;
2214 struct socket_smack *ssp = sk->sk_security;
2215 char smack[SMK_LABELLEN];
2216 int rc;
2218 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2219 return 0;
2222 * Translate what netlabel gave us.
2224 memset(smack, '\0', SMK_LABELLEN);
2225 netlbl_secattr_init(&secattr);
2226 rc = netlbl_skbuff_getattr(skb, sk->sk_family, &secattr);
2227 if (rc == 0)
2228 smack_from_secattr(&secattr, smack);
2229 else
2230 strncpy(smack, smack_net_ambient, SMK_MAXLEN);
2231 netlbl_secattr_destroy(&secattr);
2233 * Receiving a packet requires that the other end
2234 * be able to write here. Read access is not required.
2235 * This is the simplist possible security model
2236 * for networking.
2238 return smk_access(smack, ssp->smk_in, MAY_WRITE);
2242 * smack_socket_getpeersec_stream - pull in packet label
2243 * @sock: the socket
2244 * @optval: user's destination
2245 * @optlen: size thereof
2246 * @len: max thereoe
2248 * returns zero on success, an error code otherwise
2250 static int smack_socket_getpeersec_stream(struct socket *sock,
2251 char __user *optval,
2252 int __user *optlen, unsigned len)
2254 struct socket_smack *ssp;
2255 int slen;
2256 int rc = 0;
2258 ssp = sock->sk->sk_security;
2259 slen = strlen(ssp->smk_packet) + 1;
2261 if (slen > len)
2262 rc = -ERANGE;
2263 else if (copy_to_user(optval, ssp->smk_packet, slen) != 0)
2264 rc = -EFAULT;
2266 if (put_user(slen, optlen) != 0)
2267 rc = -EFAULT;
2269 return rc;
2274 * smack_socket_getpeersec_dgram - pull in packet label
2275 * @sock: the socket
2276 * @skb: packet data
2277 * @secid: pointer to where to put the secid of the packet
2279 * Sets the netlabel socket state on sk from parent
2281 static int smack_socket_getpeersec_dgram(struct socket *sock,
2282 struct sk_buff *skb, u32 *secid)
2285 struct netlbl_lsm_secattr secattr;
2286 struct sock *sk;
2287 char smack[SMK_LABELLEN];
2288 int family = PF_INET;
2289 u32 s;
2290 int rc;
2293 * Only works for families with packets.
2295 if (sock != NULL) {
2296 sk = sock->sk;
2297 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2298 return 0;
2299 family = sk->sk_family;
2302 * Translate what netlabel gave us.
2304 memset(smack, '\0', SMK_LABELLEN);
2305 netlbl_secattr_init(&secattr);
2306 rc = netlbl_skbuff_getattr(skb, family, &secattr);
2307 if (rc == 0)
2308 smack_from_secattr(&secattr, smack);
2309 netlbl_secattr_destroy(&secattr);
2312 * Give up if we couldn't get anything
2314 if (rc != 0)
2315 return rc;
2317 s = smack_to_secid(smack);
2318 if (s == 0)
2319 return -EINVAL;
2321 *secid = s;
2322 return 0;
2326 * smack_sock_graft - graft access state between two sockets
2327 * @sk: fresh sock
2328 * @parent: donor socket
2330 * Sets the netlabel socket state on sk from parent
2332 static void smack_sock_graft(struct sock *sk, struct socket *parent)
2334 struct socket_smack *ssp;
2335 int rc;
2337 if (sk == NULL)
2338 return;
2340 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2341 return;
2343 ssp = sk->sk_security;
2344 ssp->smk_in = current->security;
2345 ssp->smk_out = current->security;
2346 ssp->smk_packet[0] = '\0';
2348 rc = smack_netlabel(sk);
2349 <<<<<<< HEAD:security/smack/smack_lsm.c
2350 =======
2351 if (rc != 0)
2352 printk(KERN_WARNING "Smack: \"%s\" netlbl error %d.\n",
2353 __func__, -rc);
2354 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
2358 * smack_inet_conn_request - Smack access check on connect
2359 * @sk: socket involved
2360 * @skb: packet
2361 * @req: unused
2363 * Returns 0 if a task with the packet label could write to
2364 * the socket, otherwise an error code
2366 static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
2367 struct request_sock *req)
2369 struct netlbl_lsm_secattr skb_secattr;
2370 struct socket_smack *ssp = sk->sk_security;
2371 char smack[SMK_LABELLEN];
2372 int rc;
2374 if (skb == NULL)
2375 return -EACCES;
2377 memset(smack, '\0', SMK_LABELLEN);
2378 netlbl_secattr_init(&skb_secattr);
2379 rc = netlbl_skbuff_getattr(skb, sk->sk_family, &skb_secattr);
2380 if (rc == 0)
2381 smack_from_secattr(&skb_secattr, smack);
2382 else
2383 strncpy(smack, smack_known_huh.smk_known, SMK_MAXLEN);
2384 netlbl_secattr_destroy(&skb_secattr);
2386 * Receiving a packet requires that the other end
2387 * be able to write here. Read access is not required.
2389 * If the request is successful save the peer's label
2390 * so that SO_PEERCRED can report it.
2392 rc = smk_access(smack, ssp->smk_in, MAY_WRITE);
2393 if (rc == 0)
2394 strncpy(ssp->smk_packet, smack, SMK_MAXLEN);
2396 return rc;
2400 * Key management security hooks
2402 * Casey has not tested key support very heavily.
2403 * The permission check is most likely too restrictive.
2404 * If you care about keys please have a look.
2406 #ifdef CONFIG_KEYS
2409 * smack_key_alloc - Set the key security blob
2410 * @key: object
2411 * @tsk: the task associated with the key
2412 * @flags: unused
2414 * No allocation required
2416 * Returns 0
2418 static int smack_key_alloc(struct key *key, struct task_struct *tsk,
2419 unsigned long flags)
2421 key->security = tsk->security;
2422 return 0;
2426 * smack_key_free - Clear the key security blob
2427 * @key: the object
2429 * Clear the blob pointer
2431 static void smack_key_free(struct key *key)
2433 key->security = NULL;
2437 * smack_key_permission - Smack access on a key
2438 * @key_ref: gets to the object
2439 * @context: task involved
2440 * @perm: unused
2442 * Return 0 if the task has read and write to the object,
2443 * an error code otherwise
2445 static int smack_key_permission(key_ref_t key_ref,
2446 struct task_struct *context, key_perm_t perm)
2448 struct key *keyp;
2450 keyp = key_ref_to_ptr(key_ref);
2451 if (keyp == NULL)
2452 return -EINVAL;
2454 * If the key hasn't been initialized give it access so that
2455 * it may do so.
2457 if (keyp->security == NULL)
2458 return 0;
2460 * This should not occur
2462 if (context->security == NULL)
2463 return -EACCES;
2465 return smk_access(context->security, keyp->security, MAY_READWRITE);
2467 #endif /* CONFIG_KEYS */
2470 * smack_secid_to_secctx - return the smack label for a secid
2471 * @secid: incoming integer
2472 * @secdata: destination
2473 * @seclen: how long it is
2475 * Exists for networking code.
2477 static int smack_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
2479 char *sp = smack_from_secid(secid);
2481 *secdata = sp;
2482 *seclen = strlen(sp);
2483 return 0;
2487 <<<<<<< HEAD:security/smack/smack_lsm.c
2488 =======
2489 * smack_secctx_to_secid - return the secid for a smack label
2490 * @secdata: smack label
2491 * @seclen: how long result is
2492 * @secid: outgoing integer
2494 * Exists for audit and networking code.
2496 static int smack_secctx_to_secid(char *secdata, u32 seclen, u32 *secid)
2498 *secid = smack_to_secid(secdata);
2499 return 0;
2503 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
2504 * smack_release_secctx - don't do anything.
2505 * @key_ref: unused
2506 * @context: unused
2507 * @perm: unused
2509 * Exists to make sure nothing gets done, and properly
2511 static void smack_release_secctx(char *secdata, u32 seclen)
2515 static struct security_operations smack_ops = {
2516 .ptrace = smack_ptrace,
2517 .capget = cap_capget,
2518 .capset_check = cap_capset_check,
2519 .capset_set = cap_capset_set,
2520 .capable = cap_capable,
2521 .syslog = smack_syslog,
2522 .settime = cap_settime,
2523 .vm_enough_memory = cap_vm_enough_memory,
2525 .bprm_apply_creds = cap_bprm_apply_creds,
2526 .bprm_set_security = cap_bprm_set_security,
2527 .bprm_secureexec = cap_bprm_secureexec,
2529 .sb_alloc_security = smack_sb_alloc_security,
2530 .sb_free_security = smack_sb_free_security,
2531 .sb_copy_data = smack_sb_copy_data,
2532 .sb_kern_mount = smack_sb_kern_mount,
2533 .sb_statfs = smack_sb_statfs,
2534 .sb_mount = smack_sb_mount,
2535 .sb_umount = smack_sb_umount,
2537 .inode_alloc_security = smack_inode_alloc_security,
2538 .inode_free_security = smack_inode_free_security,
2539 .inode_init_security = smack_inode_init_security,
2540 .inode_link = smack_inode_link,
2541 .inode_unlink = smack_inode_unlink,
2542 .inode_rmdir = smack_inode_rmdir,
2543 .inode_rename = smack_inode_rename,
2544 .inode_permission = smack_inode_permission,
2545 .inode_setattr = smack_inode_setattr,
2546 .inode_getattr = smack_inode_getattr,
2547 .inode_setxattr = smack_inode_setxattr,
2548 .inode_post_setxattr = smack_inode_post_setxattr,
2549 .inode_getxattr = smack_inode_getxattr,
2550 .inode_removexattr = smack_inode_removexattr,
2551 <<<<<<< HEAD:security/smack/smack_lsm.c
2552 =======
2553 .inode_need_killpriv = cap_inode_need_killpriv,
2554 .inode_killpriv = cap_inode_killpriv,
2555 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
2556 .inode_getsecurity = smack_inode_getsecurity,
2557 .inode_setsecurity = smack_inode_setsecurity,
2558 .inode_listsecurity = smack_inode_listsecurity,
2560 .file_permission = smack_file_permission,
2561 .file_alloc_security = smack_file_alloc_security,
2562 .file_free_security = smack_file_free_security,
2563 .file_ioctl = smack_file_ioctl,
2564 .file_lock = smack_file_lock,
2565 .file_fcntl = smack_file_fcntl,
2566 .file_set_fowner = smack_file_set_fowner,
2567 .file_send_sigiotask = smack_file_send_sigiotask,
2568 .file_receive = smack_file_receive,
2570 .task_alloc_security = smack_task_alloc_security,
2571 .task_free_security = smack_task_free_security,
2572 .task_post_setuid = cap_task_post_setuid,
2573 .task_setpgid = smack_task_setpgid,
2574 .task_getpgid = smack_task_getpgid,
2575 .task_getsid = smack_task_getsid,
2576 .task_getsecid = smack_task_getsecid,
2577 .task_setnice = smack_task_setnice,
2578 .task_setioprio = smack_task_setioprio,
2579 .task_getioprio = smack_task_getioprio,
2580 .task_setscheduler = smack_task_setscheduler,
2581 .task_getscheduler = smack_task_getscheduler,
2582 .task_movememory = smack_task_movememory,
2583 .task_kill = smack_task_kill,
2584 .task_wait = smack_task_wait,
2585 .task_reparent_to_init = cap_task_reparent_to_init,
2586 .task_to_inode = smack_task_to_inode,
2588 .ipc_permission = smack_ipc_permission,
2590 .msg_msg_alloc_security = smack_msg_msg_alloc_security,
2591 .msg_msg_free_security = smack_msg_msg_free_security,
2593 .msg_queue_alloc_security = smack_msg_queue_alloc_security,
2594 .msg_queue_free_security = smack_msg_queue_free_security,
2595 .msg_queue_associate = smack_msg_queue_associate,
2596 .msg_queue_msgctl = smack_msg_queue_msgctl,
2597 .msg_queue_msgsnd = smack_msg_queue_msgsnd,
2598 .msg_queue_msgrcv = smack_msg_queue_msgrcv,
2600 .shm_alloc_security = smack_shm_alloc_security,
2601 .shm_free_security = smack_shm_free_security,
2602 .shm_associate = smack_shm_associate,
2603 .shm_shmctl = smack_shm_shmctl,
2604 .shm_shmat = smack_shm_shmat,
2606 .sem_alloc_security = smack_sem_alloc_security,
2607 .sem_free_security = smack_sem_free_security,
2608 .sem_associate = smack_sem_associate,
2609 .sem_semctl = smack_sem_semctl,
2610 .sem_semop = smack_sem_semop,
2612 .netlink_send = cap_netlink_send,
2613 .netlink_recv = cap_netlink_recv,
2615 <<<<<<< HEAD:security/smack/smack_lsm.c
2616 =======
2617 .register_security = smack_register_security,
2619 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
2620 .d_instantiate = smack_d_instantiate,
2622 .getprocattr = smack_getprocattr,
2623 .setprocattr = smack_setprocattr,
2625 .unix_stream_connect = smack_unix_stream_connect,
2626 .unix_may_send = smack_unix_may_send,
2628 .socket_post_create = smack_socket_post_create,
2629 .socket_sock_rcv_skb = smack_socket_sock_rcv_skb,
2630 .socket_getpeersec_stream = smack_socket_getpeersec_stream,
2631 .socket_getpeersec_dgram = smack_socket_getpeersec_dgram,
2632 .sk_alloc_security = smack_sk_alloc_security,
2633 .sk_free_security = smack_sk_free_security,
2634 .sock_graft = smack_sock_graft,
2635 .inet_conn_request = smack_inet_conn_request,
2636 /* key management security hooks */
2637 #ifdef CONFIG_KEYS
2638 .key_alloc = smack_key_alloc,
2639 .key_free = smack_key_free,
2640 .key_permission = smack_key_permission,
2641 #endif /* CONFIG_KEYS */
2642 .secid_to_secctx = smack_secid_to_secctx,
2643 <<<<<<< HEAD:security/smack/smack_lsm.c
2644 =======
2645 .secctx_to_secid = smack_secctx_to_secid,
2646 >>>>>>> 264e3e889d86e552b4191d69bb60f4f3b383135a:security/smack/smack_lsm.c
2647 .release_secctx = smack_release_secctx,
2651 * smack_init - initialize the smack system
2653 * Returns 0
2655 static __init int smack_init(void)
2657 printk(KERN_INFO "Smack: Initializing.\n");
2660 * Set the security state for the initial task.
2662 current->security = &smack_known_floor.smk_known;
2665 * Initialize locks
2667 spin_lock_init(&smack_known_unset.smk_cipsolock);
2668 spin_lock_init(&smack_known_huh.smk_cipsolock);
2669 spin_lock_init(&smack_known_hat.smk_cipsolock);
2670 spin_lock_init(&smack_known_star.smk_cipsolock);
2671 spin_lock_init(&smack_known_floor.smk_cipsolock);
2672 spin_lock_init(&smack_known_invalid.smk_cipsolock);
2675 * Register with LSM
2677 if (register_security(&smack_ops))
2678 panic("smack: Unable to register with kernel.\n");
2680 return 0;
2684 * Smack requires early initialization in order to label
2685 * all processes and objects when they are created.
2687 security_initcall(smack_init);