thinkpad-acpi: restrict access to some firmware LEDs
[linux-2.6/linux-acpi-2.6/ibm-acpi-2.6.git] / security / smack / smack_lsm.c
blobc1af84dd76dd64be1d4b1686342ca5dec4933895
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>
29 #include <linux/audit.h>
31 #include "smack.h"
34 * I hope these are the hokeyist lines of code in the module. Casey.
36 #define DEVPTS_SUPER_MAGIC 0x1cd1
37 #define SOCKFS_MAGIC 0x534F434B
38 #define TMPFS_MAGIC 0x01021994
40 /**
41 * smk_fetch - Fetch the smack label from a file.
42 * @ip: a pointer to the inode
43 * @dp: a pointer to the dentry
45 * Returns a pointer to the master list entry for the Smack label
46 * or NULL if there was no label to fetch.
48 static char *smk_fetch(struct inode *ip, struct dentry *dp)
50 int rc;
51 char in[SMK_LABELLEN];
53 if (ip->i_op->getxattr == NULL)
54 return NULL;
56 rc = ip->i_op->getxattr(dp, XATTR_NAME_SMACK, in, SMK_LABELLEN);
57 if (rc < 0)
58 return NULL;
60 return smk_import(in, rc);
63 /**
64 * new_inode_smack - allocate an inode security blob
65 * @smack: a pointer to the Smack label to use in the blob
67 * Returns the new blob or NULL if there's no memory available
69 struct inode_smack *new_inode_smack(char *smack)
71 struct inode_smack *isp;
73 isp = kzalloc(sizeof(struct inode_smack), GFP_KERNEL);
74 if (isp == NULL)
75 return NULL;
77 isp->smk_inode = smack;
78 isp->smk_flags = 0;
79 mutex_init(&isp->smk_lock);
81 return isp;
85 * LSM hooks.
86 * We he, that is fun!
89 /**
90 * smack_ptrace_may_access - Smack approval on PTRACE_ATTACH
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_may_access(struct task_struct *ctp, unsigned int mode)
99 int rc;
101 rc = cap_ptrace_may_access(ctp, mode);
102 if (rc != 0)
103 return rc;
105 rc = smk_access(current->security, ctp->security, MAY_READWRITE);
106 if (rc != 0 && capable(CAP_MAC_OVERRIDE))
107 return 0;
108 return rc;
112 * smack_ptrace_traceme - Smack approval on PTRACE_TRACEME
113 * @ptp: parent task pointer
115 * Returns 0 if access is OK, an error code otherwise
117 * Do the capability checks, and require read and write.
119 static int smack_ptrace_traceme(struct task_struct *ptp)
121 int rc;
123 rc = cap_ptrace_traceme(ptp);
124 if (rc != 0)
125 return rc;
127 rc = smk_access(ptp->security, current->security, MAY_READWRITE);
128 if (rc != 0 && has_capability(ptp, CAP_MAC_OVERRIDE))
129 return 0;
130 return rc;
134 * smack_syslog - Smack approval on syslog
135 * @type: message type
137 * Require that the task has the floor label
139 * Returns 0 on success, error code otherwise.
141 static int smack_syslog(int type)
143 int rc;
144 char *sp = current->security;
146 rc = cap_syslog(type);
147 if (rc != 0)
148 return rc;
150 if (capable(CAP_MAC_OVERRIDE))
151 return 0;
153 if (sp != smack_known_floor.smk_known)
154 rc = -EACCES;
156 return rc;
161 * Superblock Hooks.
165 * smack_sb_alloc_security - allocate a superblock blob
166 * @sb: the superblock getting the blob
168 * Returns 0 on success or -ENOMEM on error.
170 static int smack_sb_alloc_security(struct super_block *sb)
172 struct superblock_smack *sbsp;
174 sbsp = kzalloc(sizeof(struct superblock_smack), GFP_KERNEL);
176 if (sbsp == NULL)
177 return -ENOMEM;
179 sbsp->smk_root = smack_known_floor.smk_known;
180 sbsp->smk_default = smack_known_floor.smk_known;
181 sbsp->smk_floor = smack_known_floor.smk_known;
182 sbsp->smk_hat = smack_known_hat.smk_known;
183 sbsp->smk_initialized = 0;
184 spin_lock_init(&sbsp->smk_sblock);
186 sb->s_security = sbsp;
188 return 0;
192 * smack_sb_free_security - free a superblock blob
193 * @sb: the superblock getting the blob
196 static void smack_sb_free_security(struct super_block *sb)
198 kfree(sb->s_security);
199 sb->s_security = NULL;
203 * smack_sb_copy_data - copy mount options data for processing
204 * @type: file system type
205 * @orig: where to start
206 * @smackopts
208 * Returns 0 on success or -ENOMEM on error.
210 * Copy the Smack specific mount options out of the mount
211 * options list.
213 static int smack_sb_copy_data(char *orig, char *smackopts)
215 char *cp, *commap, *otheropts, *dp;
217 otheropts = (char *)get_zeroed_page(GFP_KERNEL);
218 if (otheropts == NULL)
219 return -ENOMEM;
221 for (cp = orig, commap = orig; commap != NULL; cp = commap + 1) {
222 if (strstr(cp, SMK_FSDEFAULT) == cp)
223 dp = smackopts;
224 else if (strstr(cp, SMK_FSFLOOR) == cp)
225 dp = smackopts;
226 else if (strstr(cp, SMK_FSHAT) == cp)
227 dp = smackopts;
228 else if (strstr(cp, SMK_FSROOT) == cp)
229 dp = smackopts;
230 else
231 dp = otheropts;
233 commap = strchr(cp, ',');
234 if (commap != NULL)
235 *commap = '\0';
237 if (*dp != '\0')
238 strcat(dp, ",");
239 strcat(dp, cp);
242 strcpy(orig, otheropts);
243 free_page((unsigned long)otheropts);
245 return 0;
249 * smack_sb_kern_mount - Smack specific mount processing
250 * @sb: the file system superblock
251 * @data: the smack mount options
253 * Returns 0 on success, an error code on failure
255 static int smack_sb_kern_mount(struct super_block *sb, void *data)
257 struct dentry *root = sb->s_root;
258 struct inode *inode = root->d_inode;
259 struct superblock_smack *sp = sb->s_security;
260 struct inode_smack *isp;
261 char *op;
262 char *commap;
263 char *nsp;
265 spin_lock(&sp->smk_sblock);
266 if (sp->smk_initialized != 0) {
267 spin_unlock(&sp->smk_sblock);
268 return 0;
270 sp->smk_initialized = 1;
271 spin_unlock(&sp->smk_sblock);
273 for (op = data; op != NULL; op = commap) {
274 commap = strchr(op, ',');
275 if (commap != NULL)
276 *commap++ = '\0';
278 if (strncmp(op, SMK_FSHAT, strlen(SMK_FSHAT)) == 0) {
279 op += strlen(SMK_FSHAT);
280 nsp = smk_import(op, 0);
281 if (nsp != NULL)
282 sp->smk_hat = nsp;
283 } else if (strncmp(op, SMK_FSFLOOR, strlen(SMK_FSFLOOR)) == 0) {
284 op += strlen(SMK_FSFLOOR);
285 nsp = smk_import(op, 0);
286 if (nsp != NULL)
287 sp->smk_floor = nsp;
288 } else if (strncmp(op, SMK_FSDEFAULT,
289 strlen(SMK_FSDEFAULT)) == 0) {
290 op += strlen(SMK_FSDEFAULT);
291 nsp = smk_import(op, 0);
292 if (nsp != NULL)
293 sp->smk_default = nsp;
294 } else if (strncmp(op, SMK_FSROOT, strlen(SMK_FSROOT)) == 0) {
295 op += strlen(SMK_FSROOT);
296 nsp = smk_import(op, 0);
297 if (nsp != NULL)
298 sp->smk_root = nsp;
303 * Initialize the root inode.
305 isp = inode->i_security;
306 if (isp == NULL)
307 inode->i_security = new_inode_smack(sp->smk_root);
308 else
309 isp->smk_inode = sp->smk_root;
311 return 0;
315 * smack_sb_statfs - Smack check on statfs
316 * @dentry: identifies the file system in question
318 * Returns 0 if current can read the floor of the filesystem,
319 * and error code otherwise
321 static int smack_sb_statfs(struct dentry *dentry)
323 struct superblock_smack *sbp = dentry->d_sb->s_security;
325 return smk_curacc(sbp->smk_floor, MAY_READ);
329 * smack_sb_mount - Smack check for mounting
330 * @dev_name: unused
331 * @nd: mount point
332 * @type: unused
333 * @flags: unused
334 * @data: unused
336 * Returns 0 if current can write the floor of the filesystem
337 * being mounted on, an error code otherwise.
339 static int smack_sb_mount(char *dev_name, struct path *path,
340 char *type, unsigned long flags, void *data)
342 struct superblock_smack *sbp = path->mnt->mnt_sb->s_security;
344 return smk_curacc(sbp->smk_floor, MAY_WRITE);
348 * smack_sb_umount - Smack check for unmounting
349 * @mnt: file system to unmount
350 * @flags: unused
352 * Returns 0 if current can write the floor of the filesystem
353 * being unmounted, an error code otherwise.
355 static int smack_sb_umount(struct vfsmount *mnt, int flags)
357 struct superblock_smack *sbp;
359 sbp = mnt->mnt_sb->s_security;
361 return smk_curacc(sbp->smk_floor, MAY_WRITE);
365 * Inode hooks
369 * smack_inode_alloc_security - allocate an inode blob
370 * @inode - the inode in need of a blob
372 * Returns 0 if it gets a blob, -ENOMEM otherwise
374 static int smack_inode_alloc_security(struct inode *inode)
376 inode->i_security = new_inode_smack(current->security);
377 if (inode->i_security == NULL)
378 return -ENOMEM;
379 return 0;
383 * smack_inode_free_security - free an inode blob
384 * @inode - the inode with a blob
386 * Clears the blob pointer in inode
388 static void smack_inode_free_security(struct inode *inode)
390 kfree(inode->i_security);
391 inode->i_security = NULL;
395 * smack_inode_init_security - copy out the smack from an inode
396 * @inode: the inode
397 * @dir: unused
398 * @name: where to put the attribute name
399 * @value: where to put the attribute value
400 * @len: where to put the length of the attribute
402 * Returns 0 if it all works out, -ENOMEM if there's no memory
404 static int smack_inode_init_security(struct inode *inode, struct inode *dir,
405 char **name, void **value, size_t *len)
407 char *isp = smk_of_inode(inode);
409 if (name) {
410 *name = kstrdup(XATTR_SMACK_SUFFIX, GFP_KERNEL);
411 if (*name == NULL)
412 return -ENOMEM;
415 if (value) {
416 *value = kstrdup(isp, GFP_KERNEL);
417 if (*value == NULL)
418 return -ENOMEM;
421 if (len)
422 *len = strlen(isp) + 1;
424 return 0;
428 * smack_inode_link - Smack check on link
429 * @old_dentry: the existing object
430 * @dir: unused
431 * @new_dentry: the new object
433 * Returns 0 if access is permitted, an error code otherwise
435 static int smack_inode_link(struct dentry *old_dentry, struct inode *dir,
436 struct dentry *new_dentry)
438 int rc;
439 char *isp;
441 isp = smk_of_inode(old_dentry->d_inode);
442 rc = smk_curacc(isp, MAY_WRITE);
444 if (rc == 0 && new_dentry->d_inode != NULL) {
445 isp = smk_of_inode(new_dentry->d_inode);
446 rc = smk_curacc(isp, MAY_WRITE);
449 return rc;
453 * smack_inode_unlink - Smack check on inode deletion
454 * @dir: containing directory object
455 * @dentry: file to unlink
457 * Returns 0 if current can write the containing directory
458 * and the object, error code otherwise
460 static int smack_inode_unlink(struct inode *dir, struct dentry *dentry)
462 struct inode *ip = dentry->d_inode;
463 int rc;
466 * You need write access to the thing you're unlinking
468 rc = smk_curacc(smk_of_inode(ip), MAY_WRITE);
469 if (rc == 0)
471 * You also need write access to the containing directory
473 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE);
475 return rc;
479 * smack_inode_rmdir - Smack check on directory deletion
480 * @dir: containing directory object
481 * @dentry: directory to unlink
483 * Returns 0 if current can write the containing directory
484 * and the directory, error code otherwise
486 static int smack_inode_rmdir(struct inode *dir, struct dentry *dentry)
488 int rc;
491 * You need write access to the thing you're removing
493 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
494 if (rc == 0)
496 * You also need write access to the containing directory
498 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE);
500 return rc;
504 * smack_inode_rename - Smack check on rename
505 * @old_inode: the old directory
506 * @old_dentry: unused
507 * @new_inode: the new directory
508 * @new_dentry: unused
510 * Read and write access is required on both the old and
511 * new directories.
513 * Returns 0 if access is permitted, an error code otherwise
515 static int smack_inode_rename(struct inode *old_inode,
516 struct dentry *old_dentry,
517 struct inode *new_inode,
518 struct dentry *new_dentry)
520 int rc;
521 char *isp;
523 isp = smk_of_inode(old_dentry->d_inode);
524 rc = smk_curacc(isp, MAY_READWRITE);
526 if (rc == 0 && new_dentry->d_inode != NULL) {
527 isp = smk_of_inode(new_dentry->d_inode);
528 rc = smk_curacc(isp, MAY_READWRITE);
531 return rc;
535 * smack_inode_permission - Smack version of permission()
536 * @inode: the inode in question
537 * @mask: the access requested
538 * @nd: unused
540 * This is the important Smack hook.
542 * Returns 0 if access is permitted, -EACCES otherwise
544 static int smack_inode_permission(struct inode *inode, int mask)
547 * No permission to check. Existence test. Yup, it's there.
549 if (mask == 0)
550 return 0;
552 return smk_curacc(smk_of_inode(inode), mask);
556 * smack_inode_setattr - Smack check for setting attributes
557 * @dentry: the object
558 * @iattr: for the force flag
560 * Returns 0 if access is permitted, an error code otherwise
562 static int smack_inode_setattr(struct dentry *dentry, struct iattr *iattr)
565 * Need to allow for clearing the setuid bit.
567 if (iattr->ia_valid & ATTR_FORCE)
568 return 0;
570 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
574 * smack_inode_getattr - Smack check for getting attributes
575 * @mnt: unused
576 * @dentry: the object
578 * Returns 0 if access is permitted, an error code otherwise
580 static int smack_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
582 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ);
586 * smack_inode_setxattr - Smack check for setting xattrs
587 * @dentry: the object
588 * @name: name of the attribute
589 * @value: unused
590 * @size: unused
591 * @flags: unused
593 * This protects the Smack attribute explicitly.
595 * Returns 0 if access is permitted, an error code otherwise
597 static int smack_inode_setxattr(struct dentry *dentry, const char *name,
598 const void *value, size_t size, int flags)
600 int rc = 0;
602 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
603 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
604 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0) {
605 if (!capable(CAP_MAC_ADMIN))
606 rc = -EPERM;
607 if (size == 0)
608 rc = -EINVAL;
609 } else
610 rc = cap_inode_setxattr(dentry, name, value, size, flags);
612 if (rc == 0)
613 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
615 return rc;
619 * smack_inode_post_setxattr - Apply the Smack update approved above
620 * @dentry: object
621 * @name: attribute name
622 * @value: attribute value
623 * @size: attribute size
624 * @flags: unused
626 * Set the pointer in the inode blob to the entry found
627 * in the master label list.
629 static void smack_inode_post_setxattr(struct dentry *dentry, const char *name,
630 const void *value, size_t size, int flags)
632 struct inode_smack *isp;
633 char *nsp;
636 * Not SMACK
638 if (strcmp(name, XATTR_NAME_SMACK))
639 return;
641 if (size >= SMK_LABELLEN)
642 return;
644 isp = dentry->d_inode->i_security;
647 * No locking is done here. This is a pointer
648 * assignment.
650 nsp = smk_import(value, size);
651 if (nsp != NULL)
652 isp->smk_inode = nsp;
653 else
654 isp->smk_inode = smack_known_invalid.smk_known;
656 return;
660 * smack_inode_getxattr - Smack check on getxattr
661 * @dentry: the object
662 * @name: unused
664 * Returns 0 if access is permitted, an error code otherwise
666 static int smack_inode_getxattr(struct dentry *dentry, const char *name)
668 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ);
672 * smack_inode_removexattr - Smack check on removexattr
673 * @dentry: the object
674 * @name: name of the attribute
676 * Removing the Smack attribute requires CAP_MAC_ADMIN
678 * Returns 0 if access is permitted, an error code otherwise
680 static int smack_inode_removexattr(struct dentry *dentry, const char *name)
682 int rc = 0;
684 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
685 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
686 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0) {
687 if (!capable(CAP_MAC_ADMIN))
688 rc = -EPERM;
689 } else
690 rc = cap_inode_removexattr(dentry, name);
692 if (rc == 0)
693 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
695 return rc;
699 * smack_inode_getsecurity - get smack xattrs
700 * @inode: the object
701 * @name: attribute name
702 * @buffer: where to put the result
703 * @size: size of the buffer
704 * @err: unused
706 * Returns the size of the attribute or an error code
708 static int smack_inode_getsecurity(const struct inode *inode,
709 const char *name, void **buffer,
710 bool alloc)
712 struct socket_smack *ssp;
713 struct socket *sock;
714 struct super_block *sbp;
715 struct inode *ip = (struct inode *)inode;
716 char *isp;
717 int ilen;
718 int rc = 0;
720 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
721 isp = smk_of_inode(inode);
722 ilen = strlen(isp) + 1;
723 *buffer = isp;
724 return ilen;
728 * The rest of the Smack xattrs are only on sockets.
730 sbp = ip->i_sb;
731 if (sbp->s_magic != SOCKFS_MAGIC)
732 return -EOPNOTSUPP;
734 sock = SOCKET_I(ip);
735 if (sock == NULL || sock->sk == NULL)
736 return -EOPNOTSUPP;
738 ssp = sock->sk->sk_security;
740 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
741 isp = ssp->smk_in;
742 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0)
743 isp = ssp->smk_out;
744 else
745 return -EOPNOTSUPP;
747 ilen = strlen(isp) + 1;
748 if (rc == 0) {
749 *buffer = isp;
750 rc = ilen;
753 return rc;
758 * smack_inode_listsecurity - list the Smack attributes
759 * @inode: the object
760 * @buffer: where they go
761 * @buffer_size: size of buffer
763 * Returns 0 on success, -EINVAL otherwise
765 static int smack_inode_listsecurity(struct inode *inode, char *buffer,
766 size_t buffer_size)
768 int len = strlen(XATTR_NAME_SMACK);
770 if (buffer != NULL && len <= buffer_size) {
771 memcpy(buffer, XATTR_NAME_SMACK, len);
772 return len;
774 return -EINVAL;
778 * smack_inode_getsecid - Extract inode's security id
779 * @inode: inode to extract the info from
780 * @secid: where result will be saved
782 static void smack_inode_getsecid(const struct inode *inode, u32 *secid)
784 struct inode_smack *isp = inode->i_security;
786 *secid = smack_to_secid(isp->smk_inode);
790 * File Hooks
794 * smack_file_permission - Smack check on file operations
795 * @file: unused
796 * @mask: unused
798 * Returns 0
800 * Should access checks be done on each read or write?
801 * UNICOS and SELinux say yes.
802 * Trusted Solaris, Trusted Irix, and just about everyone else says no.
804 * I'll say no for now. Smack does not do the frequent
805 * label changing that SELinux does.
807 static int smack_file_permission(struct file *file, int mask)
809 return 0;
813 * smack_file_alloc_security - assign a file security blob
814 * @file: the object
816 * The security blob for a file is a pointer to the master
817 * label list, so no allocation is done.
819 * Returns 0
821 static int smack_file_alloc_security(struct file *file)
823 file->f_security = current->security;
824 return 0;
828 * smack_file_free_security - clear a file security blob
829 * @file: the object
831 * The security blob for a file is a pointer to the master
832 * label list, so no memory is freed.
834 static void smack_file_free_security(struct file *file)
836 file->f_security = NULL;
840 * smack_file_ioctl - Smack check on ioctls
841 * @file: the object
842 * @cmd: what to do
843 * @arg: unused
845 * Relies heavily on the correct use of the ioctl command conventions.
847 * Returns 0 if allowed, error code otherwise
849 static int smack_file_ioctl(struct file *file, unsigned int cmd,
850 unsigned long arg)
852 int rc = 0;
854 if (_IOC_DIR(cmd) & _IOC_WRITE)
855 rc = smk_curacc(file->f_security, MAY_WRITE);
857 if (rc == 0 && (_IOC_DIR(cmd) & _IOC_READ))
858 rc = smk_curacc(file->f_security, MAY_READ);
860 return rc;
864 * smack_file_lock - Smack check on file locking
865 * @file: the object
866 * @cmd unused
868 * Returns 0 if current has write access, error code otherwise
870 static int smack_file_lock(struct file *file, unsigned int cmd)
872 return smk_curacc(file->f_security, MAY_WRITE);
876 * smack_file_fcntl - Smack check on fcntl
877 * @file: the object
878 * @cmd: what action to check
879 * @arg: unused
881 * Returns 0 if current has access, error code otherwise
883 static int smack_file_fcntl(struct file *file, unsigned int cmd,
884 unsigned long arg)
886 int rc;
888 switch (cmd) {
889 case F_DUPFD:
890 case F_GETFD:
891 case F_GETFL:
892 case F_GETLK:
893 case F_GETOWN:
894 case F_GETSIG:
895 rc = smk_curacc(file->f_security, MAY_READ);
896 break;
897 case F_SETFD:
898 case F_SETFL:
899 case F_SETLK:
900 case F_SETLKW:
901 case F_SETOWN:
902 case F_SETSIG:
903 rc = smk_curacc(file->f_security, MAY_WRITE);
904 break;
905 default:
906 rc = smk_curacc(file->f_security, MAY_READWRITE);
909 return rc;
913 * smack_file_set_fowner - set the file security blob value
914 * @file: object in question
916 * Returns 0
917 * Further research may be required on this one.
919 static int smack_file_set_fowner(struct file *file)
921 file->f_security = current->security;
922 return 0;
926 * smack_file_send_sigiotask - Smack on sigio
927 * @tsk: The target task
928 * @fown: the object the signal come from
929 * @signum: unused
931 * Allow a privileged task to get signals even if it shouldn't
933 * Returns 0 if a subject with the object's smack could
934 * write to the task, an error code otherwise.
936 static int smack_file_send_sigiotask(struct task_struct *tsk,
937 struct fown_struct *fown, int signum)
939 struct file *file;
940 int rc;
943 * struct fown_struct is never outside the context of a struct file
945 file = container_of(fown, struct file, f_owner);
946 rc = smk_access(file->f_security, tsk->security, MAY_WRITE);
947 if (rc != 0 && has_capability(tsk, CAP_MAC_OVERRIDE))
948 return 0;
949 return rc;
953 * smack_file_receive - Smack file receive check
954 * @file: the object
956 * Returns 0 if current has access, error code otherwise
958 static int smack_file_receive(struct file *file)
960 int may = 0;
963 * This code relies on bitmasks.
965 if (file->f_mode & FMODE_READ)
966 may = MAY_READ;
967 if (file->f_mode & FMODE_WRITE)
968 may |= MAY_WRITE;
970 return smk_curacc(file->f_security, may);
974 * Task hooks
978 * smack_task_alloc_security - "allocate" a task blob
979 * @tsk: the task in need of a blob
981 * Smack isn't using copies of blobs. Everyone
982 * points to an immutable list. No alloc required.
983 * No data copy required.
985 * Always returns 0
987 static int smack_task_alloc_security(struct task_struct *tsk)
989 tsk->security = current->security;
991 return 0;
995 * smack_task_free_security - "free" a task blob
996 * @task: the task with the blob
998 * Smack isn't using copies of blobs. Everyone
999 * points to an immutable list. The blobs never go away.
1000 * There is no leak here.
1002 static void smack_task_free_security(struct task_struct *task)
1004 task->security = NULL;
1008 * smack_task_setpgid - Smack check on setting pgid
1009 * @p: the task object
1010 * @pgid: unused
1012 * Return 0 if write access is permitted
1014 static int smack_task_setpgid(struct task_struct *p, pid_t pgid)
1016 return smk_curacc(p->security, MAY_WRITE);
1020 * smack_task_getpgid - Smack access check for getpgid
1021 * @p: the object task
1023 * Returns 0 if current can read the object task, error code otherwise
1025 static int smack_task_getpgid(struct task_struct *p)
1027 return smk_curacc(p->security, MAY_READ);
1031 * smack_task_getsid - Smack access check for getsid
1032 * @p: the object task
1034 * Returns 0 if current can read the object task, error code otherwise
1036 static int smack_task_getsid(struct task_struct *p)
1038 return smk_curacc(p->security, MAY_READ);
1042 * smack_task_getsecid - get the secid of the task
1043 * @p: the object task
1044 * @secid: where to put the result
1046 * Sets the secid to contain a u32 version of the smack label.
1048 static void smack_task_getsecid(struct task_struct *p, u32 *secid)
1050 *secid = smack_to_secid(p->security);
1054 * smack_task_setnice - Smack check on setting nice
1055 * @p: the task object
1056 * @nice: unused
1058 * Return 0 if write access is permitted
1060 static int smack_task_setnice(struct task_struct *p, int nice)
1062 int rc;
1064 rc = cap_task_setnice(p, nice);
1065 if (rc == 0)
1066 rc = smk_curacc(p->security, MAY_WRITE);
1067 return rc;
1071 * smack_task_setioprio - Smack check on setting ioprio
1072 * @p: the task object
1073 * @ioprio: unused
1075 * Return 0 if write access is permitted
1077 static int smack_task_setioprio(struct task_struct *p, int ioprio)
1079 int rc;
1081 rc = cap_task_setioprio(p, ioprio);
1082 if (rc == 0)
1083 rc = smk_curacc(p->security, MAY_WRITE);
1084 return rc;
1088 * smack_task_getioprio - Smack check on reading ioprio
1089 * @p: the task object
1091 * Return 0 if read access is permitted
1093 static int smack_task_getioprio(struct task_struct *p)
1095 return smk_curacc(p->security, MAY_READ);
1099 * smack_task_setscheduler - Smack check on setting scheduler
1100 * @p: the task object
1101 * @policy: unused
1102 * @lp: unused
1104 * Return 0 if read access is permitted
1106 static int smack_task_setscheduler(struct task_struct *p, int policy,
1107 struct sched_param *lp)
1109 int rc;
1111 rc = cap_task_setscheduler(p, policy, lp);
1112 if (rc == 0)
1113 rc = smk_curacc(p->security, MAY_WRITE);
1114 return rc;
1118 * smack_task_getscheduler - Smack check on reading scheduler
1119 * @p: the task object
1121 * Return 0 if read access is permitted
1123 static int smack_task_getscheduler(struct task_struct *p)
1125 return smk_curacc(p->security, MAY_READ);
1129 * smack_task_movememory - Smack check on moving memory
1130 * @p: the task object
1132 * Return 0 if write access is permitted
1134 static int smack_task_movememory(struct task_struct *p)
1136 return smk_curacc(p->security, MAY_WRITE);
1140 * smack_task_kill - Smack check on signal delivery
1141 * @p: the task object
1142 * @info: unused
1143 * @sig: unused
1144 * @secid: identifies the smack to use in lieu of current's
1146 * Return 0 if write access is permitted
1148 * The secid behavior is an artifact of an SELinux hack
1149 * in the USB code. Someday it may go away.
1151 static int smack_task_kill(struct task_struct *p, struct siginfo *info,
1152 int sig, u32 secid)
1155 * Sending a signal requires that the sender
1156 * can write the receiver.
1158 if (secid == 0)
1159 return smk_curacc(p->security, MAY_WRITE);
1161 * If the secid isn't 0 we're dealing with some USB IO
1162 * specific behavior. This is not clean. For one thing
1163 * we can't take privilege into account.
1165 return smk_access(smack_from_secid(secid), p->security, MAY_WRITE);
1169 * smack_task_wait - Smack access check for waiting
1170 * @p: task to wait for
1172 * Returns 0 if current can wait for p, error code otherwise
1174 static int smack_task_wait(struct task_struct *p)
1176 int rc;
1178 rc = smk_access(current->security, p->security, MAY_WRITE);
1179 if (rc == 0)
1180 return 0;
1183 * Allow the operation to succeed if either task
1184 * has privilege to perform operations that might
1185 * account for the smack labels having gotten to
1186 * be different in the first place.
1188 * This breaks the strict subject/object access
1189 * control ideal, taking the object's privilege
1190 * state into account in the decision as well as
1191 * the smack value.
1193 if (capable(CAP_MAC_OVERRIDE) || has_capability(p, CAP_MAC_OVERRIDE))
1194 return 0;
1196 return rc;
1200 * smack_task_to_inode - copy task smack into the inode blob
1201 * @p: task to copy from
1202 * inode: inode to copy to
1204 * Sets the smack pointer in the inode security blob
1206 static void smack_task_to_inode(struct task_struct *p, struct inode *inode)
1208 struct inode_smack *isp = inode->i_security;
1209 isp->smk_inode = p->security;
1213 * Socket hooks.
1217 * smack_sk_alloc_security - Allocate a socket blob
1218 * @sk: the socket
1219 * @family: unused
1220 * @priority: memory allocation priority
1222 * Assign Smack pointers to current
1224 * Returns 0 on success, -ENOMEM is there's no memory
1226 static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags)
1228 char *csp = current->security;
1229 struct socket_smack *ssp;
1231 ssp = kzalloc(sizeof(struct socket_smack), gfp_flags);
1232 if (ssp == NULL)
1233 return -ENOMEM;
1235 ssp->smk_in = csp;
1236 ssp->smk_out = csp;
1237 ssp->smk_packet[0] = '\0';
1239 sk->sk_security = ssp;
1241 return 0;
1245 * smack_sk_free_security - Free a socket blob
1246 * @sk: the socket
1248 * Clears the blob pointer
1250 static void smack_sk_free_security(struct sock *sk)
1252 kfree(sk->sk_security);
1256 * smack_set_catset - convert a capset to netlabel mls categories
1257 * @catset: the Smack categories
1258 * @sap: where to put the netlabel categories
1260 * Allocates and fills attr.mls.cat
1262 static void smack_set_catset(char *catset, struct netlbl_lsm_secattr *sap)
1264 unsigned char *cp;
1265 unsigned char m;
1266 int cat;
1267 int rc;
1268 int byte;
1270 if (!catset)
1271 return;
1273 sap->flags |= NETLBL_SECATTR_MLS_CAT;
1274 sap->attr.mls.cat = netlbl_secattr_catmap_alloc(GFP_ATOMIC);
1275 sap->attr.mls.cat->startbit = 0;
1277 for (cat = 1, cp = catset, byte = 0; byte < SMK_LABELLEN; cp++, byte++)
1278 for (m = 0x80; m != 0; m >>= 1, cat++) {
1279 if ((m & *cp) == 0)
1280 continue;
1281 rc = netlbl_secattr_catmap_setbit(sap->attr.mls.cat,
1282 cat, GFP_ATOMIC);
1287 * smack_to_secattr - fill a secattr from a smack value
1288 * @smack: the smack value
1289 * @nlsp: where the result goes
1291 * Casey says that CIPSO is good enough for now.
1292 * It can be used to effect.
1293 * It can also be abused to effect when necessary.
1294 * Appologies to the TSIG group in general and GW in particular.
1296 static void smack_to_secattr(char *smack, struct netlbl_lsm_secattr *nlsp)
1298 struct smack_cipso cipso;
1299 int rc;
1301 switch (smack_net_nltype) {
1302 case NETLBL_NLTYPE_CIPSOV4:
1303 nlsp->domain = smack;
1304 nlsp->flags = NETLBL_SECATTR_DOMAIN | NETLBL_SECATTR_MLS_LVL;
1306 rc = smack_to_cipso(smack, &cipso);
1307 if (rc == 0) {
1308 nlsp->attr.mls.lvl = cipso.smk_level;
1309 smack_set_catset(cipso.smk_catset, nlsp);
1310 } else {
1311 nlsp->attr.mls.lvl = smack_cipso_direct;
1312 smack_set_catset(smack, nlsp);
1314 break;
1315 default:
1316 break;
1321 * smack_netlabel - Set the secattr on a socket
1322 * @sk: the socket
1324 * Convert the outbound smack value (smk_out) to a
1325 * secattr and attach it to the socket.
1327 * Returns 0 on success or an error code
1329 static int smack_netlabel(struct sock *sk)
1331 struct socket_smack *ssp;
1332 struct netlbl_lsm_secattr secattr;
1333 int rc;
1335 ssp = sk->sk_security;
1336 netlbl_secattr_init(&secattr);
1337 smack_to_secattr(ssp->smk_out, &secattr);
1338 rc = netlbl_sock_setattr(sk, &secattr);
1339 netlbl_secattr_destroy(&secattr);
1341 return rc;
1345 * smack_inode_setsecurity - set smack xattrs
1346 * @inode: the object
1347 * @name: attribute name
1348 * @value: attribute value
1349 * @size: size of the attribute
1350 * @flags: unused
1352 * Sets the named attribute in the appropriate blob
1354 * Returns 0 on success, or an error code
1356 static int smack_inode_setsecurity(struct inode *inode, const char *name,
1357 const void *value, size_t size, int flags)
1359 char *sp;
1360 struct inode_smack *nsp = inode->i_security;
1361 struct socket_smack *ssp;
1362 struct socket *sock;
1363 int rc = 0;
1365 if (value == NULL || size > SMK_LABELLEN || size == 0)
1366 return -EACCES;
1368 sp = smk_import(value, size);
1369 if (sp == NULL)
1370 return -EINVAL;
1372 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
1373 nsp->smk_inode = sp;
1374 return 0;
1377 * The rest of the Smack xattrs are only on sockets.
1379 if (inode->i_sb->s_magic != SOCKFS_MAGIC)
1380 return -EOPNOTSUPP;
1382 sock = SOCKET_I(inode);
1383 if (sock == NULL || sock->sk == NULL)
1384 return -EOPNOTSUPP;
1386 ssp = sock->sk->sk_security;
1388 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
1389 ssp->smk_in = sp;
1390 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0) {
1391 ssp->smk_out = sp;
1392 rc = smack_netlabel(sock->sk);
1393 if (rc != 0)
1394 printk(KERN_WARNING "Smack: \"%s\" netlbl error %d.\n",
1395 __func__, -rc);
1396 } else
1397 return -EOPNOTSUPP;
1399 return 0;
1403 * smack_socket_post_create - finish socket setup
1404 * @sock: the socket
1405 * @family: protocol family
1406 * @type: unused
1407 * @protocol: unused
1408 * @kern: unused
1410 * Sets the netlabel information on the socket
1412 * Returns 0 on success, and error code otherwise
1414 static int smack_socket_post_create(struct socket *sock, int family,
1415 int type, int protocol, int kern)
1417 if (family != PF_INET || sock->sk == NULL)
1418 return 0;
1420 * Set the outbound netlbl.
1422 return smack_netlabel(sock->sk);
1426 * smack_flags_to_may - convert S_ to MAY_ values
1427 * @flags: the S_ value
1429 * Returns the equivalent MAY_ value
1431 static int smack_flags_to_may(int flags)
1433 int may = 0;
1435 if (flags & S_IRUGO)
1436 may |= MAY_READ;
1437 if (flags & S_IWUGO)
1438 may |= MAY_WRITE;
1439 if (flags & S_IXUGO)
1440 may |= MAY_EXEC;
1442 return may;
1446 * smack_msg_msg_alloc_security - Set the security blob for msg_msg
1447 * @msg: the object
1449 * Returns 0
1451 static int smack_msg_msg_alloc_security(struct msg_msg *msg)
1453 msg->security = current->security;
1454 return 0;
1458 * smack_msg_msg_free_security - Clear the security blob for msg_msg
1459 * @msg: the object
1461 * Clears the blob pointer
1463 static void smack_msg_msg_free_security(struct msg_msg *msg)
1465 msg->security = NULL;
1469 * smack_of_shm - the smack pointer for the shm
1470 * @shp: the object
1472 * Returns a pointer to the smack value
1474 static char *smack_of_shm(struct shmid_kernel *shp)
1476 return (char *)shp->shm_perm.security;
1480 * smack_shm_alloc_security - Set the security blob for shm
1481 * @shp: the object
1483 * Returns 0
1485 static int smack_shm_alloc_security(struct shmid_kernel *shp)
1487 struct kern_ipc_perm *isp = &shp->shm_perm;
1489 isp->security = current->security;
1490 return 0;
1494 * smack_shm_free_security - Clear the security blob for shm
1495 * @shp: the object
1497 * Clears the blob pointer
1499 static void smack_shm_free_security(struct shmid_kernel *shp)
1501 struct kern_ipc_perm *isp = &shp->shm_perm;
1503 isp->security = NULL;
1507 * smack_shm_associate - Smack access check for shm
1508 * @shp: the object
1509 * @shmflg: access requested
1511 * Returns 0 if current has the requested access, error code otherwise
1513 static int smack_shm_associate(struct shmid_kernel *shp, int shmflg)
1515 char *ssp = smack_of_shm(shp);
1516 int may;
1518 may = smack_flags_to_may(shmflg);
1519 return smk_curacc(ssp, may);
1523 * smack_shm_shmctl - Smack access check for shm
1524 * @shp: the object
1525 * @cmd: what it wants to do
1527 * Returns 0 if current has the requested access, error code otherwise
1529 static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd)
1531 char *ssp;
1532 int may;
1534 switch (cmd) {
1535 case IPC_STAT:
1536 case SHM_STAT:
1537 may = MAY_READ;
1538 break;
1539 case IPC_SET:
1540 case SHM_LOCK:
1541 case SHM_UNLOCK:
1542 case IPC_RMID:
1543 may = MAY_READWRITE;
1544 break;
1545 case IPC_INFO:
1546 case SHM_INFO:
1548 * System level information.
1550 return 0;
1551 default:
1552 return -EINVAL;
1555 ssp = smack_of_shm(shp);
1556 return smk_curacc(ssp, may);
1560 * smack_shm_shmat - Smack access for shmat
1561 * @shp: the object
1562 * @shmaddr: unused
1563 * @shmflg: access requested
1565 * Returns 0 if current has the requested access, error code otherwise
1567 static int smack_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr,
1568 int shmflg)
1570 char *ssp = smack_of_shm(shp);
1571 int may;
1573 may = smack_flags_to_may(shmflg);
1574 return smk_curacc(ssp, may);
1578 * smack_of_sem - the smack pointer for the sem
1579 * @sma: the object
1581 * Returns a pointer to the smack value
1583 static char *smack_of_sem(struct sem_array *sma)
1585 return (char *)sma->sem_perm.security;
1589 * smack_sem_alloc_security - Set the security blob for sem
1590 * @sma: the object
1592 * Returns 0
1594 static int smack_sem_alloc_security(struct sem_array *sma)
1596 struct kern_ipc_perm *isp = &sma->sem_perm;
1598 isp->security = current->security;
1599 return 0;
1603 * smack_sem_free_security - Clear the security blob for sem
1604 * @sma: the object
1606 * Clears the blob pointer
1608 static void smack_sem_free_security(struct sem_array *sma)
1610 struct kern_ipc_perm *isp = &sma->sem_perm;
1612 isp->security = NULL;
1616 * smack_sem_associate - Smack access check for sem
1617 * @sma: the object
1618 * @semflg: access requested
1620 * Returns 0 if current has the requested access, error code otherwise
1622 static int smack_sem_associate(struct sem_array *sma, int semflg)
1624 char *ssp = smack_of_sem(sma);
1625 int may;
1627 may = smack_flags_to_may(semflg);
1628 return smk_curacc(ssp, may);
1632 * smack_sem_shmctl - Smack access check for sem
1633 * @sma: the object
1634 * @cmd: what it wants to do
1636 * Returns 0 if current has the requested access, error code otherwise
1638 static int smack_sem_semctl(struct sem_array *sma, int cmd)
1640 char *ssp;
1641 int may;
1643 switch (cmd) {
1644 case GETPID:
1645 case GETNCNT:
1646 case GETZCNT:
1647 case GETVAL:
1648 case GETALL:
1649 case IPC_STAT:
1650 case SEM_STAT:
1651 may = MAY_READ;
1652 break;
1653 case SETVAL:
1654 case SETALL:
1655 case IPC_RMID:
1656 case IPC_SET:
1657 may = MAY_READWRITE;
1658 break;
1659 case IPC_INFO:
1660 case SEM_INFO:
1662 * System level information
1664 return 0;
1665 default:
1666 return -EINVAL;
1669 ssp = smack_of_sem(sma);
1670 return smk_curacc(ssp, may);
1674 * smack_sem_semop - Smack checks of semaphore operations
1675 * @sma: the object
1676 * @sops: unused
1677 * @nsops: unused
1678 * @alter: unused
1680 * Treated as read and write in all cases.
1682 * Returns 0 if access is allowed, error code otherwise
1684 static int smack_sem_semop(struct sem_array *sma, struct sembuf *sops,
1685 unsigned nsops, int alter)
1687 char *ssp = smack_of_sem(sma);
1689 return smk_curacc(ssp, MAY_READWRITE);
1693 * smack_msg_alloc_security - Set the security blob for msg
1694 * @msq: the object
1696 * Returns 0
1698 static int smack_msg_queue_alloc_security(struct msg_queue *msq)
1700 struct kern_ipc_perm *kisp = &msq->q_perm;
1702 kisp->security = current->security;
1703 return 0;
1707 * smack_msg_free_security - Clear the security blob for msg
1708 * @msq: the object
1710 * Clears the blob pointer
1712 static void smack_msg_queue_free_security(struct msg_queue *msq)
1714 struct kern_ipc_perm *kisp = &msq->q_perm;
1716 kisp->security = NULL;
1720 * smack_of_msq - the smack pointer for the msq
1721 * @msq: the object
1723 * Returns a pointer to the smack value
1725 static char *smack_of_msq(struct msg_queue *msq)
1727 return (char *)msq->q_perm.security;
1731 * smack_msg_queue_associate - Smack access check for msg_queue
1732 * @msq: the object
1733 * @msqflg: access requested
1735 * Returns 0 if current has the requested access, error code otherwise
1737 static int smack_msg_queue_associate(struct msg_queue *msq, int msqflg)
1739 char *msp = smack_of_msq(msq);
1740 int may;
1742 may = smack_flags_to_may(msqflg);
1743 return smk_curacc(msp, may);
1747 * smack_msg_queue_msgctl - Smack access check for msg_queue
1748 * @msq: the object
1749 * @cmd: what it wants to do
1751 * Returns 0 if current has the requested access, error code otherwise
1753 static int smack_msg_queue_msgctl(struct msg_queue *msq, int cmd)
1755 char *msp;
1756 int may;
1758 switch (cmd) {
1759 case IPC_STAT:
1760 case MSG_STAT:
1761 may = MAY_READ;
1762 break;
1763 case IPC_SET:
1764 case IPC_RMID:
1765 may = MAY_READWRITE;
1766 break;
1767 case IPC_INFO:
1768 case MSG_INFO:
1770 * System level information
1772 return 0;
1773 default:
1774 return -EINVAL;
1777 msp = smack_of_msq(msq);
1778 return smk_curacc(msp, may);
1782 * smack_msg_queue_msgsnd - Smack access check for msg_queue
1783 * @msq: the object
1784 * @msg: unused
1785 * @msqflg: access requested
1787 * Returns 0 if current has the requested access, error code otherwise
1789 static int smack_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
1790 int msqflg)
1792 char *msp = smack_of_msq(msq);
1793 int rc;
1795 rc = smack_flags_to_may(msqflg);
1796 return smk_curacc(msp, rc);
1800 * smack_msg_queue_msgsnd - Smack access check for msg_queue
1801 * @msq: the object
1802 * @msg: unused
1803 * @target: unused
1804 * @type: unused
1805 * @mode: unused
1807 * Returns 0 if current has read and write access, error code otherwise
1809 static int smack_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
1810 struct task_struct *target, long type, int mode)
1812 char *msp = smack_of_msq(msq);
1814 return smk_curacc(msp, MAY_READWRITE);
1818 * smack_ipc_permission - Smack access for ipc_permission()
1819 * @ipp: the object permissions
1820 * @flag: access requested
1822 * Returns 0 if current has read and write access, error code otherwise
1824 static int smack_ipc_permission(struct kern_ipc_perm *ipp, short flag)
1826 char *isp = ipp->security;
1827 int may;
1829 may = smack_flags_to_may(flag);
1830 return smk_curacc(isp, may);
1834 * smack_ipc_getsecid - Extract smack security id
1835 * @ipcp: the object permissions
1836 * @secid: where result will be saved
1838 static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, u32 *secid)
1840 char *smack = ipp->security;
1842 *secid = smack_to_secid(smack);
1846 * smack_d_instantiate - Make sure the blob is correct on an inode
1847 * @opt_dentry: unused
1848 * @inode: the object
1850 * Set the inode's security blob if it hasn't been done already.
1852 static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
1854 struct super_block *sbp;
1855 struct superblock_smack *sbsp;
1856 struct inode_smack *isp;
1857 char *csp = current->security;
1858 char *fetched;
1859 char *final;
1860 struct dentry *dp;
1862 if (inode == NULL)
1863 return;
1865 isp = inode->i_security;
1867 mutex_lock(&isp->smk_lock);
1869 * If the inode is already instantiated
1870 * take the quick way out
1872 if (isp->smk_flags & SMK_INODE_INSTANT)
1873 goto unlockandout;
1875 sbp = inode->i_sb;
1876 sbsp = sbp->s_security;
1878 * We're going to use the superblock default label
1879 * if there's no label on the file.
1881 final = sbsp->smk_default;
1884 * If this is the root inode the superblock
1885 * may be in the process of initialization.
1886 * If that is the case use the root value out
1887 * of the superblock.
1889 if (opt_dentry->d_parent == opt_dentry) {
1890 isp->smk_inode = sbsp->smk_root;
1891 isp->smk_flags |= SMK_INODE_INSTANT;
1892 goto unlockandout;
1896 * This is pretty hackish.
1897 * Casey says that we shouldn't have to do
1898 * file system specific code, but it does help
1899 * with keeping it simple.
1901 switch (sbp->s_magic) {
1902 case SMACK_MAGIC:
1904 * Casey says that it's a little embarassing
1905 * that the smack file system doesn't do
1906 * extended attributes.
1908 final = smack_known_star.smk_known;
1909 break;
1910 case PIPEFS_MAGIC:
1912 * Casey says pipes are easy (?)
1914 final = smack_known_star.smk_known;
1915 break;
1916 case DEVPTS_SUPER_MAGIC:
1918 * devpts seems content with the label of the task.
1919 * Programs that change smack have to treat the
1920 * pty with respect.
1922 final = csp;
1923 break;
1924 case SOCKFS_MAGIC:
1926 * Casey says sockets get the smack of the task.
1928 final = csp;
1929 break;
1930 case PROC_SUPER_MAGIC:
1932 * Casey says procfs appears not to care.
1933 * The superblock default suffices.
1935 break;
1936 case TMPFS_MAGIC:
1938 * Device labels should come from the filesystem,
1939 * but watch out, because they're volitile,
1940 * getting recreated on every reboot.
1942 final = smack_known_star.smk_known;
1944 * No break.
1946 * If a smack value has been set we want to use it,
1947 * but since tmpfs isn't giving us the opportunity
1948 * to set mount options simulate setting the
1949 * superblock default.
1951 default:
1953 * This isn't an understood special case.
1954 * Get the value from the xattr.
1956 * No xattr support means, alas, no SMACK label.
1957 * Use the aforeapplied default.
1958 * It would be curious if the label of the task
1959 * does not match that assigned.
1961 if (inode->i_op->getxattr == NULL)
1962 break;
1964 * Get the dentry for xattr.
1966 if (opt_dentry == NULL) {
1967 dp = d_find_alias(inode);
1968 if (dp == NULL)
1969 break;
1970 } else {
1971 dp = dget(opt_dentry);
1972 if (dp == NULL)
1973 break;
1976 fetched = smk_fetch(inode, dp);
1977 if (fetched != NULL)
1978 final = fetched;
1980 dput(dp);
1981 break;
1984 if (final == NULL)
1985 isp->smk_inode = csp;
1986 else
1987 isp->smk_inode = final;
1989 isp->smk_flags |= SMK_INODE_INSTANT;
1991 unlockandout:
1992 mutex_unlock(&isp->smk_lock);
1993 return;
1997 * smack_getprocattr - Smack process attribute access
1998 * @p: the object task
1999 * @name: the name of the attribute in /proc/.../attr
2000 * @value: where to put the result
2002 * Places a copy of the task Smack into value
2004 * Returns the length of the smack label or an error code
2006 static int smack_getprocattr(struct task_struct *p, char *name, char **value)
2008 char *cp;
2009 int slen;
2011 if (strcmp(name, "current") != 0)
2012 return -EINVAL;
2014 cp = kstrdup(p->security, GFP_KERNEL);
2015 if (cp == NULL)
2016 return -ENOMEM;
2018 slen = strlen(cp);
2019 *value = cp;
2020 return slen;
2024 * smack_setprocattr - Smack process attribute setting
2025 * @p: the object task
2026 * @name: the name of the attribute in /proc/.../attr
2027 * @value: the value to set
2028 * @size: the size of the value
2030 * Sets the Smack value of the task. Only setting self
2031 * is permitted and only with privilege
2033 * Returns the length of the smack label or an error code
2035 static int smack_setprocattr(struct task_struct *p, char *name,
2036 void *value, size_t size)
2038 char *newsmack;
2041 * Changing another process' Smack value is too dangerous
2042 * and supports no sane use case.
2044 if (p != current)
2045 return -EPERM;
2047 if (!capable(CAP_MAC_ADMIN))
2048 return -EPERM;
2050 if (value == NULL || size == 0 || size >= SMK_LABELLEN)
2051 return -EINVAL;
2053 if (strcmp(name, "current") != 0)
2054 return -EINVAL;
2056 newsmack = smk_import(value, size);
2057 if (newsmack == NULL)
2058 return -EINVAL;
2060 p->security = newsmack;
2061 return size;
2065 * smack_unix_stream_connect - Smack access on UDS
2066 * @sock: one socket
2067 * @other: the other socket
2068 * @newsk: unused
2070 * Return 0 if a subject with the smack of sock could access
2071 * an object with the smack of other, otherwise an error code
2073 static int smack_unix_stream_connect(struct socket *sock,
2074 struct socket *other, struct sock *newsk)
2076 struct inode *sp = SOCK_INODE(sock);
2077 struct inode *op = SOCK_INODE(other);
2079 return smk_access(smk_of_inode(sp), smk_of_inode(op), MAY_READWRITE);
2083 * smack_unix_may_send - Smack access on UDS
2084 * @sock: one socket
2085 * @other: the other socket
2087 * Return 0 if a subject with the smack of sock could access
2088 * an object with the smack of other, otherwise an error code
2090 static int smack_unix_may_send(struct socket *sock, struct socket *other)
2092 struct inode *sp = SOCK_INODE(sock);
2093 struct inode *op = SOCK_INODE(other);
2095 return smk_access(smk_of_inode(sp), smk_of_inode(op), MAY_WRITE);
2099 * smack_from_secattr - Convert a netlabel attr.mls.lvl/attr.mls.cat
2100 * pair to smack
2101 * @sap: netlabel secattr
2102 * @sip: where to put the result
2104 * Copies a smack label into sip
2106 static void smack_from_secattr(struct netlbl_lsm_secattr *sap, char *sip)
2108 char smack[SMK_LABELLEN];
2109 int pcat;
2111 if ((sap->flags & NETLBL_SECATTR_MLS_LVL) == 0) {
2113 * If there are flags but no level netlabel isn't
2114 * behaving the way we expect it to.
2116 * Without guidance regarding the smack value
2117 * for the packet fall back on the network
2118 * ambient value.
2120 strncpy(sip, smack_net_ambient, SMK_MAXLEN);
2121 return;
2124 * Get the categories, if any
2126 memset(smack, '\0', SMK_LABELLEN);
2127 if ((sap->flags & NETLBL_SECATTR_MLS_CAT) != 0)
2128 for (pcat = -1;;) {
2129 pcat = netlbl_secattr_catmap_walk(sap->attr.mls.cat,
2130 pcat + 1);
2131 if (pcat < 0)
2132 break;
2133 smack_catset_bit(pcat, smack);
2136 * If it is CIPSO using smack direct mapping
2137 * we are already done. WeeHee.
2139 if (sap->attr.mls.lvl == smack_cipso_direct) {
2140 memcpy(sip, smack, SMK_MAXLEN);
2141 return;
2144 * Look it up in the supplied table if it is not a direct mapping.
2146 smack_from_cipso(sap->attr.mls.lvl, smack, sip);
2147 return;
2151 * smack_socket_sock_rcv_skb - Smack packet delivery access check
2152 * @sk: socket
2153 * @skb: packet
2155 * Returns 0 if the packet should be delivered, an error code otherwise
2157 static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
2159 struct netlbl_lsm_secattr secattr;
2160 struct socket_smack *ssp = sk->sk_security;
2161 char smack[SMK_LABELLEN];
2162 int rc;
2164 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2165 return 0;
2168 * Translate what netlabel gave us.
2170 memset(smack, '\0', SMK_LABELLEN);
2171 netlbl_secattr_init(&secattr);
2172 rc = netlbl_skbuff_getattr(skb, sk->sk_family, &secattr);
2173 if (rc == 0)
2174 smack_from_secattr(&secattr, smack);
2175 else
2176 strncpy(smack, smack_net_ambient, SMK_MAXLEN);
2177 netlbl_secattr_destroy(&secattr);
2179 * Receiving a packet requires that the other end
2180 * be able to write here. Read access is not required.
2181 * This is the simplist possible security model
2182 * for networking.
2184 rc = smk_access(smack, ssp->smk_in, MAY_WRITE);
2185 if (rc != 0)
2186 netlbl_skbuff_err(skb, rc, 0);
2187 return rc;
2191 * smack_socket_getpeersec_stream - pull in packet label
2192 * @sock: the socket
2193 * @optval: user's destination
2194 * @optlen: size thereof
2195 * @len: max thereoe
2197 * returns zero on success, an error code otherwise
2199 static int smack_socket_getpeersec_stream(struct socket *sock,
2200 char __user *optval,
2201 int __user *optlen, unsigned len)
2203 struct socket_smack *ssp;
2204 int slen;
2205 int rc = 0;
2207 ssp = sock->sk->sk_security;
2208 slen = strlen(ssp->smk_packet) + 1;
2210 if (slen > len)
2211 rc = -ERANGE;
2212 else if (copy_to_user(optval, ssp->smk_packet, slen) != 0)
2213 rc = -EFAULT;
2215 if (put_user(slen, optlen) != 0)
2216 rc = -EFAULT;
2218 return rc;
2223 * smack_socket_getpeersec_dgram - pull in packet label
2224 * @sock: the socket
2225 * @skb: packet data
2226 * @secid: pointer to where to put the secid of the packet
2228 * Sets the netlabel socket state on sk from parent
2230 static int smack_socket_getpeersec_dgram(struct socket *sock,
2231 struct sk_buff *skb, u32 *secid)
2234 struct netlbl_lsm_secattr secattr;
2235 struct sock *sk;
2236 char smack[SMK_LABELLEN];
2237 int family = PF_INET;
2238 u32 s;
2239 int rc;
2242 * Only works for families with packets.
2244 if (sock != NULL) {
2245 sk = sock->sk;
2246 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2247 return 0;
2248 family = sk->sk_family;
2251 * Translate what netlabel gave us.
2253 memset(smack, '\0', SMK_LABELLEN);
2254 netlbl_secattr_init(&secattr);
2255 rc = netlbl_skbuff_getattr(skb, family, &secattr);
2256 if (rc == 0)
2257 smack_from_secattr(&secattr, smack);
2258 netlbl_secattr_destroy(&secattr);
2261 * Give up if we couldn't get anything
2263 if (rc != 0)
2264 return rc;
2266 s = smack_to_secid(smack);
2267 if (s == 0)
2268 return -EINVAL;
2270 *secid = s;
2271 return 0;
2275 * smack_sock_graft - graft access state between two sockets
2276 * @sk: fresh sock
2277 * @parent: donor socket
2279 * Sets the netlabel socket state on sk from parent
2281 static void smack_sock_graft(struct sock *sk, struct socket *parent)
2283 struct socket_smack *ssp;
2284 int rc;
2286 if (sk == NULL)
2287 return;
2289 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2290 return;
2292 ssp = sk->sk_security;
2293 ssp->smk_in = current->security;
2294 ssp->smk_out = current->security;
2295 ssp->smk_packet[0] = '\0';
2297 rc = smack_netlabel(sk);
2298 if (rc != 0)
2299 printk(KERN_WARNING "Smack: \"%s\" netlbl error %d.\n",
2300 __func__, -rc);
2304 * smack_inet_conn_request - Smack access check on connect
2305 * @sk: socket involved
2306 * @skb: packet
2307 * @req: unused
2309 * Returns 0 if a task with the packet label could write to
2310 * the socket, otherwise an error code
2312 static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
2313 struct request_sock *req)
2315 struct netlbl_lsm_secattr skb_secattr;
2316 struct socket_smack *ssp = sk->sk_security;
2317 char smack[SMK_LABELLEN];
2318 int rc;
2320 if (skb == NULL)
2321 return -EACCES;
2323 memset(smack, '\0', SMK_LABELLEN);
2324 netlbl_secattr_init(&skb_secattr);
2325 rc = netlbl_skbuff_getattr(skb, sk->sk_family, &skb_secattr);
2326 if (rc == 0)
2327 smack_from_secattr(&skb_secattr, smack);
2328 else
2329 strncpy(smack, smack_known_huh.smk_known, SMK_MAXLEN);
2330 netlbl_secattr_destroy(&skb_secattr);
2332 * Receiving a packet requires that the other end
2333 * be able to write here. Read access is not required.
2335 * If the request is successful save the peer's label
2336 * so that SO_PEERCRED can report it.
2338 rc = smk_access(smack, ssp->smk_in, MAY_WRITE);
2339 if (rc == 0)
2340 strncpy(ssp->smk_packet, smack, SMK_MAXLEN);
2342 return rc;
2346 * Key management security hooks
2348 * Casey has not tested key support very heavily.
2349 * The permission check is most likely too restrictive.
2350 * If you care about keys please have a look.
2352 #ifdef CONFIG_KEYS
2355 * smack_key_alloc - Set the key security blob
2356 * @key: object
2357 * @tsk: the task associated with the key
2358 * @flags: unused
2360 * No allocation required
2362 * Returns 0
2364 static int smack_key_alloc(struct key *key, struct task_struct *tsk,
2365 unsigned long flags)
2367 key->security = tsk->security;
2368 return 0;
2372 * smack_key_free - Clear the key security blob
2373 * @key: the object
2375 * Clear the blob pointer
2377 static void smack_key_free(struct key *key)
2379 key->security = NULL;
2383 * smack_key_permission - Smack access on a key
2384 * @key_ref: gets to the object
2385 * @context: task involved
2386 * @perm: unused
2388 * Return 0 if the task has read and write to the object,
2389 * an error code otherwise
2391 static int smack_key_permission(key_ref_t key_ref,
2392 struct task_struct *context, key_perm_t perm)
2394 struct key *keyp;
2396 keyp = key_ref_to_ptr(key_ref);
2397 if (keyp == NULL)
2398 return -EINVAL;
2400 * If the key hasn't been initialized give it access so that
2401 * it may do so.
2403 if (keyp->security == NULL)
2404 return 0;
2406 * This should not occur
2408 if (context->security == NULL)
2409 return -EACCES;
2411 return smk_access(context->security, keyp->security, MAY_READWRITE);
2413 #endif /* CONFIG_KEYS */
2416 * Smack Audit hooks
2418 * Audit requires a unique representation of each Smack specific
2419 * rule. This unique representation is used to distinguish the
2420 * object to be audited from remaining kernel objects and also
2421 * works as a glue between the audit hooks.
2423 * Since repository entries are added but never deleted, we'll use
2424 * the smack_known label address related to the given audit rule as
2425 * the needed unique representation. This also better fits the smack
2426 * model where nearly everything is a label.
2428 #ifdef CONFIG_AUDIT
2431 * smack_audit_rule_init - Initialize a smack audit rule
2432 * @field: audit rule fields given from user-space (audit.h)
2433 * @op: required testing operator (=, !=, >, <, ...)
2434 * @rulestr: smack label to be audited
2435 * @vrule: pointer to save our own audit rule representation
2437 * Prepare to audit cases where (@field @op @rulestr) is true.
2438 * The label to be audited is created if necessay.
2440 static int smack_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
2442 char **rule = (char **)vrule;
2443 *rule = NULL;
2445 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
2446 return -EINVAL;
2448 if (op != AUDIT_EQUAL && op != AUDIT_NOT_EQUAL)
2449 return -EINVAL;
2451 *rule = smk_import(rulestr, 0);
2453 return 0;
2457 * smack_audit_rule_known - Distinguish Smack audit rules
2458 * @krule: rule of interest, in Audit kernel representation format
2460 * This is used to filter Smack rules from remaining Audit ones.
2461 * If it's proved that this rule belongs to us, the
2462 * audit_rule_match hook will be called to do the final judgement.
2464 static int smack_audit_rule_known(struct audit_krule *krule)
2466 struct audit_field *f;
2467 int i;
2469 for (i = 0; i < krule->field_count; i++) {
2470 f = &krule->fields[i];
2472 if (f->type == AUDIT_SUBJ_USER || f->type == AUDIT_OBJ_USER)
2473 return 1;
2476 return 0;
2480 * smack_audit_rule_match - Audit given object ?
2481 * @secid: security id for identifying the object to test
2482 * @field: audit rule flags given from user-space
2483 * @op: required testing operator
2484 * @vrule: smack internal rule presentation
2485 * @actx: audit context associated with the check
2487 * The core Audit hook. It's used to take the decision of
2488 * whether to audit or not to audit a given object.
2490 static int smack_audit_rule_match(u32 secid, u32 field, u32 op, void *vrule,
2491 struct audit_context *actx)
2493 char *smack;
2494 char *rule = vrule;
2496 if (!rule) {
2497 audit_log(actx, GFP_KERNEL, AUDIT_SELINUX_ERR,
2498 "Smack: missing rule\n");
2499 return -ENOENT;
2502 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
2503 return 0;
2505 smack = smack_from_secid(secid);
2508 * No need to do string comparisons. If a match occurs,
2509 * both pointers will point to the same smack_known
2510 * label.
2512 if (op == AUDIT_EQUAL)
2513 return (rule == smack);
2514 if (op == AUDIT_NOT_EQUAL)
2515 return (rule != smack);
2517 return 0;
2521 * smack_audit_rule_free - free smack rule representation
2522 * @vrule: rule to be freed.
2524 * No memory was allocated.
2526 static void smack_audit_rule_free(void *vrule)
2528 /* No-op */
2531 #endif /* CONFIG_AUDIT */
2534 * smack_secid_to_secctx - return the smack label for a secid
2535 * @secid: incoming integer
2536 * @secdata: destination
2537 * @seclen: how long it is
2539 * Exists for networking code.
2541 static int smack_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
2543 char *sp = smack_from_secid(secid);
2545 *secdata = sp;
2546 *seclen = strlen(sp);
2547 return 0;
2551 * smack_secctx_to_secid - return the secid for a smack label
2552 * @secdata: smack label
2553 * @seclen: how long result is
2554 * @secid: outgoing integer
2556 * Exists for audit and networking code.
2558 static int smack_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
2560 *secid = smack_to_secid(secdata);
2561 return 0;
2565 * smack_release_secctx - don't do anything.
2566 * @key_ref: unused
2567 * @context: unused
2568 * @perm: unused
2570 * Exists to make sure nothing gets done, and properly
2572 static void smack_release_secctx(char *secdata, u32 seclen)
2576 struct security_operations smack_ops = {
2577 .name = "smack",
2579 .ptrace_may_access = smack_ptrace_may_access,
2580 .ptrace_traceme = smack_ptrace_traceme,
2581 .capget = cap_capget,
2582 .capset_check = cap_capset_check,
2583 .capset_set = cap_capset_set,
2584 .capable = cap_capable,
2585 .syslog = smack_syslog,
2586 .settime = cap_settime,
2587 .vm_enough_memory = cap_vm_enough_memory,
2589 .bprm_apply_creds = cap_bprm_apply_creds,
2590 .bprm_set_security = cap_bprm_set_security,
2591 .bprm_secureexec = cap_bprm_secureexec,
2593 .sb_alloc_security = smack_sb_alloc_security,
2594 .sb_free_security = smack_sb_free_security,
2595 .sb_copy_data = smack_sb_copy_data,
2596 .sb_kern_mount = smack_sb_kern_mount,
2597 .sb_statfs = smack_sb_statfs,
2598 .sb_mount = smack_sb_mount,
2599 .sb_umount = smack_sb_umount,
2601 .inode_alloc_security = smack_inode_alloc_security,
2602 .inode_free_security = smack_inode_free_security,
2603 .inode_init_security = smack_inode_init_security,
2604 .inode_link = smack_inode_link,
2605 .inode_unlink = smack_inode_unlink,
2606 .inode_rmdir = smack_inode_rmdir,
2607 .inode_rename = smack_inode_rename,
2608 .inode_permission = smack_inode_permission,
2609 .inode_setattr = smack_inode_setattr,
2610 .inode_getattr = smack_inode_getattr,
2611 .inode_setxattr = smack_inode_setxattr,
2612 .inode_post_setxattr = smack_inode_post_setxattr,
2613 .inode_getxattr = smack_inode_getxattr,
2614 .inode_removexattr = smack_inode_removexattr,
2615 .inode_need_killpriv = cap_inode_need_killpriv,
2616 .inode_killpriv = cap_inode_killpriv,
2617 .inode_getsecurity = smack_inode_getsecurity,
2618 .inode_setsecurity = smack_inode_setsecurity,
2619 .inode_listsecurity = smack_inode_listsecurity,
2620 .inode_getsecid = smack_inode_getsecid,
2622 .file_permission = smack_file_permission,
2623 .file_alloc_security = smack_file_alloc_security,
2624 .file_free_security = smack_file_free_security,
2625 .file_ioctl = smack_file_ioctl,
2626 .file_lock = smack_file_lock,
2627 .file_fcntl = smack_file_fcntl,
2628 .file_set_fowner = smack_file_set_fowner,
2629 .file_send_sigiotask = smack_file_send_sigiotask,
2630 .file_receive = smack_file_receive,
2632 .task_alloc_security = smack_task_alloc_security,
2633 .task_free_security = smack_task_free_security,
2634 .task_post_setuid = cap_task_post_setuid,
2635 .task_setpgid = smack_task_setpgid,
2636 .task_getpgid = smack_task_getpgid,
2637 .task_getsid = smack_task_getsid,
2638 .task_getsecid = smack_task_getsecid,
2639 .task_setnice = smack_task_setnice,
2640 .task_setioprio = smack_task_setioprio,
2641 .task_getioprio = smack_task_getioprio,
2642 .task_setscheduler = smack_task_setscheduler,
2643 .task_getscheduler = smack_task_getscheduler,
2644 .task_movememory = smack_task_movememory,
2645 .task_kill = smack_task_kill,
2646 .task_wait = smack_task_wait,
2647 .task_reparent_to_init = cap_task_reparent_to_init,
2648 .task_to_inode = smack_task_to_inode,
2649 .task_prctl = cap_task_prctl,
2651 .ipc_permission = smack_ipc_permission,
2652 .ipc_getsecid = smack_ipc_getsecid,
2654 .msg_msg_alloc_security = smack_msg_msg_alloc_security,
2655 .msg_msg_free_security = smack_msg_msg_free_security,
2657 .msg_queue_alloc_security = smack_msg_queue_alloc_security,
2658 .msg_queue_free_security = smack_msg_queue_free_security,
2659 .msg_queue_associate = smack_msg_queue_associate,
2660 .msg_queue_msgctl = smack_msg_queue_msgctl,
2661 .msg_queue_msgsnd = smack_msg_queue_msgsnd,
2662 .msg_queue_msgrcv = smack_msg_queue_msgrcv,
2664 .shm_alloc_security = smack_shm_alloc_security,
2665 .shm_free_security = smack_shm_free_security,
2666 .shm_associate = smack_shm_associate,
2667 .shm_shmctl = smack_shm_shmctl,
2668 .shm_shmat = smack_shm_shmat,
2670 .sem_alloc_security = smack_sem_alloc_security,
2671 .sem_free_security = smack_sem_free_security,
2672 .sem_associate = smack_sem_associate,
2673 .sem_semctl = smack_sem_semctl,
2674 .sem_semop = smack_sem_semop,
2676 .netlink_send = cap_netlink_send,
2677 .netlink_recv = cap_netlink_recv,
2679 .d_instantiate = smack_d_instantiate,
2681 .getprocattr = smack_getprocattr,
2682 .setprocattr = smack_setprocattr,
2684 .unix_stream_connect = smack_unix_stream_connect,
2685 .unix_may_send = smack_unix_may_send,
2687 .socket_post_create = smack_socket_post_create,
2688 .socket_sock_rcv_skb = smack_socket_sock_rcv_skb,
2689 .socket_getpeersec_stream = smack_socket_getpeersec_stream,
2690 .socket_getpeersec_dgram = smack_socket_getpeersec_dgram,
2691 .sk_alloc_security = smack_sk_alloc_security,
2692 .sk_free_security = smack_sk_free_security,
2693 .sock_graft = smack_sock_graft,
2694 .inet_conn_request = smack_inet_conn_request,
2696 /* key management security hooks */
2697 #ifdef CONFIG_KEYS
2698 .key_alloc = smack_key_alloc,
2699 .key_free = smack_key_free,
2700 .key_permission = smack_key_permission,
2701 #endif /* CONFIG_KEYS */
2703 /* Audit hooks */
2704 #ifdef CONFIG_AUDIT
2705 .audit_rule_init = smack_audit_rule_init,
2706 .audit_rule_known = smack_audit_rule_known,
2707 .audit_rule_match = smack_audit_rule_match,
2708 .audit_rule_free = smack_audit_rule_free,
2709 #endif /* CONFIG_AUDIT */
2711 .secid_to_secctx = smack_secid_to_secctx,
2712 .secctx_to_secid = smack_secctx_to_secid,
2713 .release_secctx = smack_release_secctx,
2717 * smack_init - initialize the smack system
2719 * Returns 0
2721 static __init int smack_init(void)
2723 if (!security_module_enable(&smack_ops))
2724 return 0;
2726 printk(KERN_INFO "Smack: Initializing.\n");
2729 * Set the security state for the initial task.
2731 current->security = &smack_known_floor.smk_known;
2734 * Initialize locks
2736 spin_lock_init(&smack_known_unset.smk_cipsolock);
2737 spin_lock_init(&smack_known_huh.smk_cipsolock);
2738 spin_lock_init(&smack_known_hat.smk_cipsolock);
2739 spin_lock_init(&smack_known_star.smk_cipsolock);
2740 spin_lock_init(&smack_known_floor.smk_cipsolock);
2741 spin_lock_init(&smack_known_invalid.smk_cipsolock);
2744 * Register with LSM
2746 if (register_security(&smack_ops))
2747 panic("smack: Unable to register with kernel.\n");
2749 return 0;
2753 * Smack requires early initialization in order to label
2754 * all processes and objects when they are created.
2756 security_initcall(smack_init);