[MTD] [NAND] Blackfin NFC Driver: fix bug - do not clobber the status from the first...
[linux-2.6/mini2440.git] / security / smack / smack_lsm.c
blob1b40e558f98329a718a76c7a4b4458380a63057e
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 - Smack approval on ptrace
91 * @ptp: parent task pointer
92 * @ctp: child task pointer
94 * Returns 0 if access is OK, an error code otherwise
96 * Do the capability checks, and require read and write.
98 static int smack_ptrace(struct task_struct *ptp, struct task_struct *ctp,
99 unsigned int mode)
101 int rc;
103 rc = cap_ptrace(ptp, ctp, mode);
104 if (rc != 0)
105 return rc;
107 rc = smk_access(ptp->security, ctp->security, MAY_READWRITE);
108 if (rc != 0 && __capable(ptp, CAP_MAC_OVERRIDE))
109 return 0;
111 return rc;
115 * smack_syslog - Smack approval on syslog
116 * @type: message type
118 * Require that the task has the floor label
120 * Returns 0 on success, error code otherwise.
122 static int smack_syslog(int type)
124 int rc;
125 char *sp = current->security;
127 rc = cap_syslog(type);
128 if (rc != 0)
129 return rc;
131 if (capable(CAP_MAC_OVERRIDE))
132 return 0;
134 if (sp != smack_known_floor.smk_known)
135 rc = -EACCES;
137 return rc;
142 * Superblock Hooks.
146 * smack_sb_alloc_security - allocate a superblock blob
147 * @sb: the superblock getting the blob
149 * Returns 0 on success or -ENOMEM on error.
151 static int smack_sb_alloc_security(struct super_block *sb)
153 struct superblock_smack *sbsp;
155 sbsp = kzalloc(sizeof(struct superblock_smack), GFP_KERNEL);
157 if (sbsp == NULL)
158 return -ENOMEM;
160 sbsp->smk_root = smack_known_floor.smk_known;
161 sbsp->smk_default = smack_known_floor.smk_known;
162 sbsp->smk_floor = smack_known_floor.smk_known;
163 sbsp->smk_hat = smack_known_hat.smk_known;
164 sbsp->smk_initialized = 0;
165 spin_lock_init(&sbsp->smk_sblock);
167 sb->s_security = sbsp;
169 return 0;
173 * smack_sb_free_security - free a superblock blob
174 * @sb: the superblock getting the blob
177 static void smack_sb_free_security(struct super_block *sb)
179 kfree(sb->s_security);
180 sb->s_security = NULL;
184 * smack_sb_copy_data - copy mount options data for processing
185 * @type: file system type
186 * @orig: where to start
187 * @smackopts
189 * Returns 0 on success or -ENOMEM on error.
191 * Copy the Smack specific mount options out of the mount
192 * options list.
194 static int smack_sb_copy_data(char *orig, char *smackopts)
196 char *cp, *commap, *otheropts, *dp;
198 otheropts = (char *)get_zeroed_page(GFP_KERNEL);
199 if (otheropts == NULL)
200 return -ENOMEM;
202 for (cp = orig, commap = orig; commap != NULL; cp = commap + 1) {
203 if (strstr(cp, SMK_FSDEFAULT) == cp)
204 dp = smackopts;
205 else if (strstr(cp, SMK_FSFLOOR) == cp)
206 dp = smackopts;
207 else if (strstr(cp, SMK_FSHAT) == cp)
208 dp = smackopts;
209 else if (strstr(cp, SMK_FSROOT) == cp)
210 dp = smackopts;
211 else
212 dp = otheropts;
214 commap = strchr(cp, ',');
215 if (commap != NULL)
216 *commap = '\0';
218 if (*dp != '\0')
219 strcat(dp, ",");
220 strcat(dp, cp);
223 strcpy(orig, otheropts);
224 free_page((unsigned long)otheropts);
226 return 0;
230 * smack_sb_kern_mount - Smack specific mount processing
231 * @sb: the file system superblock
232 * @data: the smack mount options
234 * Returns 0 on success, an error code on failure
236 static int smack_sb_kern_mount(struct super_block *sb, void *data)
238 struct dentry *root = sb->s_root;
239 struct inode *inode = root->d_inode;
240 struct superblock_smack *sp = sb->s_security;
241 struct inode_smack *isp;
242 char *op;
243 char *commap;
244 char *nsp;
246 spin_lock(&sp->smk_sblock);
247 if (sp->smk_initialized != 0) {
248 spin_unlock(&sp->smk_sblock);
249 return 0;
251 sp->smk_initialized = 1;
252 spin_unlock(&sp->smk_sblock);
254 for (op = data; op != NULL; op = commap) {
255 commap = strchr(op, ',');
256 if (commap != NULL)
257 *commap++ = '\0';
259 if (strncmp(op, SMK_FSHAT, strlen(SMK_FSHAT)) == 0) {
260 op += strlen(SMK_FSHAT);
261 nsp = smk_import(op, 0);
262 if (nsp != NULL)
263 sp->smk_hat = nsp;
264 } else if (strncmp(op, SMK_FSFLOOR, strlen(SMK_FSFLOOR)) == 0) {
265 op += strlen(SMK_FSFLOOR);
266 nsp = smk_import(op, 0);
267 if (nsp != NULL)
268 sp->smk_floor = nsp;
269 } else if (strncmp(op, SMK_FSDEFAULT,
270 strlen(SMK_FSDEFAULT)) == 0) {
271 op += strlen(SMK_FSDEFAULT);
272 nsp = smk_import(op, 0);
273 if (nsp != NULL)
274 sp->smk_default = nsp;
275 } else if (strncmp(op, SMK_FSROOT, strlen(SMK_FSROOT)) == 0) {
276 op += strlen(SMK_FSROOT);
277 nsp = smk_import(op, 0);
278 if (nsp != NULL)
279 sp->smk_root = nsp;
284 * Initialize the root inode.
286 isp = inode->i_security;
287 if (isp == NULL)
288 inode->i_security = new_inode_smack(sp->smk_root);
289 else
290 isp->smk_inode = sp->smk_root;
292 return 0;
296 * smack_sb_statfs - Smack check on statfs
297 * @dentry: identifies the file system in question
299 * Returns 0 if current can read the floor of the filesystem,
300 * and error code otherwise
302 static int smack_sb_statfs(struct dentry *dentry)
304 struct superblock_smack *sbp = dentry->d_sb->s_security;
306 return smk_curacc(sbp->smk_floor, MAY_READ);
310 * smack_sb_mount - Smack check for mounting
311 * @dev_name: unused
312 * @nd: mount point
313 * @type: unused
314 * @flags: unused
315 * @data: unused
317 * Returns 0 if current can write the floor of the filesystem
318 * being mounted on, an error code otherwise.
320 static int smack_sb_mount(char *dev_name, struct path *path,
321 char *type, unsigned long flags, void *data)
323 struct superblock_smack *sbp = path->mnt->mnt_sb->s_security;
325 return smk_curacc(sbp->smk_floor, MAY_WRITE);
329 * smack_sb_umount - Smack check for unmounting
330 * @mnt: file system to unmount
331 * @flags: unused
333 * Returns 0 if current can write the floor of the filesystem
334 * being unmounted, an error code otherwise.
336 static int smack_sb_umount(struct vfsmount *mnt, int flags)
338 struct superblock_smack *sbp;
340 sbp = mnt->mnt_sb->s_security;
342 return smk_curacc(sbp->smk_floor, MAY_WRITE);
346 * Inode hooks
350 * smack_inode_alloc_security - allocate an inode blob
351 * @inode - the inode in need of a blob
353 * Returns 0 if it gets a blob, -ENOMEM otherwise
355 static int smack_inode_alloc_security(struct inode *inode)
357 inode->i_security = new_inode_smack(current->security);
358 if (inode->i_security == NULL)
359 return -ENOMEM;
360 return 0;
364 * smack_inode_free_security - free an inode blob
365 * @inode - the inode with a blob
367 * Clears the blob pointer in inode
369 static void smack_inode_free_security(struct inode *inode)
371 kfree(inode->i_security);
372 inode->i_security = NULL;
376 * smack_inode_init_security - copy out the smack from an inode
377 * @inode: the inode
378 * @dir: unused
379 * @name: where to put the attribute name
380 * @value: where to put the attribute value
381 * @len: where to put the length of the attribute
383 * Returns 0 if it all works out, -ENOMEM if there's no memory
385 static int smack_inode_init_security(struct inode *inode, struct inode *dir,
386 char **name, void **value, size_t *len)
388 char *isp = smk_of_inode(inode);
390 if (name) {
391 *name = kstrdup(XATTR_SMACK_SUFFIX, GFP_KERNEL);
392 if (*name == NULL)
393 return -ENOMEM;
396 if (value) {
397 *value = kstrdup(isp, GFP_KERNEL);
398 if (*value == NULL)
399 return -ENOMEM;
402 if (len)
403 *len = strlen(isp) + 1;
405 return 0;
409 * smack_inode_link - Smack check on link
410 * @old_dentry: the existing object
411 * @dir: unused
412 * @new_dentry: the new object
414 * Returns 0 if access is permitted, an error code otherwise
416 static int smack_inode_link(struct dentry *old_dentry, struct inode *dir,
417 struct dentry *new_dentry)
419 int rc;
420 char *isp;
422 isp = smk_of_inode(old_dentry->d_inode);
423 rc = smk_curacc(isp, MAY_WRITE);
425 if (rc == 0 && new_dentry->d_inode != NULL) {
426 isp = smk_of_inode(new_dentry->d_inode);
427 rc = smk_curacc(isp, MAY_WRITE);
430 return rc;
434 * smack_inode_unlink - Smack check on inode deletion
435 * @dir: containing directory object
436 * @dentry: file to unlink
438 * Returns 0 if current can write the containing directory
439 * and the object, error code otherwise
441 static int smack_inode_unlink(struct inode *dir, struct dentry *dentry)
443 struct inode *ip = dentry->d_inode;
444 int rc;
447 * You need write access to the thing you're unlinking
449 rc = smk_curacc(smk_of_inode(ip), MAY_WRITE);
450 if (rc == 0)
452 * You also need write access to the containing directory
454 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE);
456 return rc;
460 * smack_inode_rmdir - Smack check on directory deletion
461 * @dir: containing directory object
462 * @dentry: directory to unlink
464 * Returns 0 if current can write the containing directory
465 * and the directory, error code otherwise
467 static int smack_inode_rmdir(struct inode *dir, struct dentry *dentry)
469 int rc;
472 * You need write access to the thing you're removing
474 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
475 if (rc == 0)
477 * You also need write access to the containing directory
479 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE);
481 return rc;
485 * smack_inode_rename - Smack check on rename
486 * @old_inode: the old directory
487 * @old_dentry: unused
488 * @new_inode: the new directory
489 * @new_dentry: unused
491 * Read and write access is required on both the old and
492 * new directories.
494 * Returns 0 if access is permitted, an error code otherwise
496 static int smack_inode_rename(struct inode *old_inode,
497 struct dentry *old_dentry,
498 struct inode *new_inode,
499 struct dentry *new_dentry)
501 int rc;
502 char *isp;
504 isp = smk_of_inode(old_dentry->d_inode);
505 rc = smk_curacc(isp, MAY_READWRITE);
507 if (rc == 0 && new_dentry->d_inode != NULL) {
508 isp = smk_of_inode(new_dentry->d_inode);
509 rc = smk_curacc(isp, MAY_READWRITE);
512 return rc;
516 * smack_inode_permission - Smack version of permission()
517 * @inode: the inode in question
518 * @mask: the access requested
519 * @nd: unused
521 * This is the important Smack hook.
523 * Returns 0 if access is permitted, -EACCES otherwise
525 static int smack_inode_permission(struct inode *inode, int mask)
528 * No permission to check. Existence test. Yup, it's there.
530 if (mask == 0)
531 return 0;
533 return smk_curacc(smk_of_inode(inode), mask);
537 * smack_inode_setattr - Smack check for setting attributes
538 * @dentry: the object
539 * @iattr: for the force flag
541 * Returns 0 if access is permitted, an error code otherwise
543 static int smack_inode_setattr(struct dentry *dentry, struct iattr *iattr)
546 * Need to allow for clearing the setuid bit.
548 if (iattr->ia_valid & ATTR_FORCE)
549 return 0;
551 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
555 * smack_inode_getattr - Smack check for getting attributes
556 * @mnt: unused
557 * @dentry: the object
559 * Returns 0 if access is permitted, an error code otherwise
561 static int smack_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
563 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ);
567 * smack_inode_setxattr - Smack check for setting xattrs
568 * @dentry: the object
569 * @name: name of the attribute
570 * @value: unused
571 * @size: unused
572 * @flags: unused
574 * This protects the Smack attribute explicitly.
576 * Returns 0 if access is permitted, an error code otherwise
578 static int smack_inode_setxattr(struct dentry *dentry, const char *name,
579 const void *value, size_t size, int flags)
581 int rc = 0;
583 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
584 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
585 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0) {
586 if (!capable(CAP_MAC_ADMIN))
587 rc = -EPERM;
588 } else
589 rc = cap_inode_setxattr(dentry, name, value, size, flags);
591 if (rc == 0)
592 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
594 return rc;
598 * smack_inode_post_setxattr - Apply the Smack update approved above
599 * @dentry: object
600 * @name: attribute name
601 * @value: attribute value
602 * @size: attribute size
603 * @flags: unused
605 * Set the pointer in the inode blob to the entry found
606 * in the master label list.
608 static void smack_inode_post_setxattr(struct dentry *dentry, const char *name,
609 const void *value, size_t size, int flags)
611 struct inode_smack *isp;
612 char *nsp;
615 * Not SMACK
617 if (strcmp(name, XATTR_NAME_SMACK))
618 return;
620 if (size >= SMK_LABELLEN)
621 return;
623 isp = dentry->d_inode->i_security;
626 * No locking is done here. This is a pointer
627 * assignment.
629 nsp = smk_import(value, size);
630 if (nsp != NULL)
631 isp->smk_inode = nsp;
632 else
633 isp->smk_inode = smack_known_invalid.smk_known;
635 return;
639 * smack_inode_getxattr - Smack check on getxattr
640 * @dentry: the object
641 * @name: unused
643 * Returns 0 if access is permitted, an error code otherwise
645 static int smack_inode_getxattr(struct dentry *dentry, const char *name)
647 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ);
651 * smack_inode_removexattr - Smack check on removexattr
652 * @dentry: the object
653 * @name: name of the attribute
655 * Removing the Smack attribute requires CAP_MAC_ADMIN
657 * Returns 0 if access is permitted, an error code otherwise
659 static int smack_inode_removexattr(struct dentry *dentry, const char *name)
661 int rc = 0;
663 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
664 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
665 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0) {
666 if (!capable(CAP_MAC_ADMIN))
667 rc = -EPERM;
668 } else
669 rc = cap_inode_removexattr(dentry, name);
671 if (rc == 0)
672 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE);
674 return rc;
678 * smack_inode_getsecurity - get smack xattrs
679 * @inode: the object
680 * @name: attribute name
681 * @buffer: where to put the result
682 * @size: size of the buffer
683 * @err: unused
685 * Returns the size of the attribute or an error code
687 static int smack_inode_getsecurity(const struct inode *inode,
688 const char *name, void **buffer,
689 bool alloc)
691 struct socket_smack *ssp;
692 struct socket *sock;
693 struct super_block *sbp;
694 struct inode *ip = (struct inode *)inode;
695 char *isp;
696 int ilen;
697 int rc = 0;
699 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
700 isp = smk_of_inode(inode);
701 ilen = strlen(isp) + 1;
702 *buffer = isp;
703 return ilen;
707 * The rest of the Smack xattrs are only on sockets.
709 sbp = ip->i_sb;
710 if (sbp->s_magic != SOCKFS_MAGIC)
711 return -EOPNOTSUPP;
713 sock = SOCKET_I(ip);
714 if (sock == NULL || sock->sk == NULL)
715 return -EOPNOTSUPP;
717 ssp = sock->sk->sk_security;
719 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
720 isp = ssp->smk_in;
721 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0)
722 isp = ssp->smk_out;
723 else
724 return -EOPNOTSUPP;
726 ilen = strlen(isp) + 1;
727 if (rc == 0) {
728 *buffer = isp;
729 rc = ilen;
732 return rc;
737 * smack_inode_listsecurity - list the Smack attributes
738 * @inode: the object
739 * @buffer: where they go
740 * @buffer_size: size of buffer
742 * Returns 0 on success, -EINVAL otherwise
744 static int smack_inode_listsecurity(struct inode *inode, char *buffer,
745 size_t buffer_size)
747 int len = strlen(XATTR_NAME_SMACK);
749 if (buffer != NULL && len <= buffer_size) {
750 memcpy(buffer, XATTR_NAME_SMACK, len);
751 return len;
753 return -EINVAL;
757 * smack_inode_getsecid - Extract inode's security id
758 * @inode: inode to extract the info from
759 * @secid: where result will be saved
761 static void smack_inode_getsecid(const struct inode *inode, u32 *secid)
763 struct inode_smack *isp = inode->i_security;
765 *secid = smack_to_secid(isp->smk_inode);
769 * File Hooks
773 * smack_file_permission - Smack check on file operations
774 * @file: unused
775 * @mask: unused
777 * Returns 0
779 * Should access checks be done on each read or write?
780 * UNICOS and SELinux say yes.
781 * Trusted Solaris, Trusted Irix, and just about everyone else says no.
783 * I'll say no for now. Smack does not do the frequent
784 * label changing that SELinux does.
786 static int smack_file_permission(struct file *file, int mask)
788 return 0;
792 * smack_file_alloc_security - assign a file security blob
793 * @file: the object
795 * The security blob for a file is a pointer to the master
796 * label list, so no allocation is done.
798 * Returns 0
800 static int smack_file_alloc_security(struct file *file)
802 file->f_security = current->security;
803 return 0;
807 * smack_file_free_security - clear a file security blob
808 * @file: the object
810 * The security blob for a file is a pointer to the master
811 * label list, so no memory is freed.
813 static void smack_file_free_security(struct file *file)
815 file->f_security = NULL;
819 * smack_file_ioctl - Smack check on ioctls
820 * @file: the object
821 * @cmd: what to do
822 * @arg: unused
824 * Relies heavily on the correct use of the ioctl command conventions.
826 * Returns 0 if allowed, error code otherwise
828 static int smack_file_ioctl(struct file *file, unsigned int cmd,
829 unsigned long arg)
831 int rc = 0;
833 if (_IOC_DIR(cmd) & _IOC_WRITE)
834 rc = smk_curacc(file->f_security, MAY_WRITE);
836 if (rc == 0 && (_IOC_DIR(cmd) & _IOC_READ))
837 rc = smk_curacc(file->f_security, MAY_READ);
839 return rc;
843 * smack_file_lock - Smack check on file locking
844 * @file: the object
845 * @cmd unused
847 * Returns 0 if current has write access, error code otherwise
849 static int smack_file_lock(struct file *file, unsigned int cmd)
851 return smk_curacc(file->f_security, MAY_WRITE);
855 * smack_file_fcntl - Smack check on fcntl
856 * @file: the object
857 * @cmd: what action to check
858 * @arg: unused
860 * Returns 0 if current has access, error code otherwise
862 static int smack_file_fcntl(struct file *file, unsigned int cmd,
863 unsigned long arg)
865 int rc;
867 switch (cmd) {
868 case F_DUPFD:
869 case F_GETFD:
870 case F_GETFL:
871 case F_GETLK:
872 case F_GETOWN:
873 case F_GETSIG:
874 rc = smk_curacc(file->f_security, MAY_READ);
875 break;
876 case F_SETFD:
877 case F_SETFL:
878 case F_SETLK:
879 case F_SETLKW:
880 case F_SETOWN:
881 case F_SETSIG:
882 rc = smk_curacc(file->f_security, MAY_WRITE);
883 break;
884 default:
885 rc = smk_curacc(file->f_security, MAY_READWRITE);
888 return rc;
892 * smack_file_set_fowner - set the file security blob value
893 * @file: object in question
895 * Returns 0
896 * Further research may be required on this one.
898 static int smack_file_set_fowner(struct file *file)
900 file->f_security = current->security;
901 return 0;
905 * smack_file_send_sigiotask - Smack on sigio
906 * @tsk: The target task
907 * @fown: the object the signal come from
908 * @signum: unused
910 * Allow a privileged task to get signals even if it shouldn't
912 * Returns 0 if a subject with the object's smack could
913 * write to the task, an error code otherwise.
915 static int smack_file_send_sigiotask(struct task_struct *tsk,
916 struct fown_struct *fown, int signum)
918 struct file *file;
919 int rc;
922 * struct fown_struct is never outside the context of a struct file
924 file = container_of(fown, struct file, f_owner);
925 rc = smk_access(file->f_security, tsk->security, MAY_WRITE);
926 if (rc != 0 && __capable(tsk, CAP_MAC_OVERRIDE))
927 return 0;
928 return rc;
932 * smack_file_receive - Smack file receive check
933 * @file: the object
935 * Returns 0 if current has access, error code otherwise
937 static int smack_file_receive(struct file *file)
939 int may = 0;
942 * This code relies on bitmasks.
944 if (file->f_mode & FMODE_READ)
945 may = MAY_READ;
946 if (file->f_mode & FMODE_WRITE)
947 may |= MAY_WRITE;
949 return smk_curacc(file->f_security, may);
953 * Task hooks
957 * smack_task_alloc_security - "allocate" a task blob
958 * @tsk: the task in need of a blob
960 * Smack isn't using copies of blobs. Everyone
961 * points to an immutable list. No alloc required.
962 * No data copy required.
964 * Always returns 0
966 static int smack_task_alloc_security(struct task_struct *tsk)
968 tsk->security = current->security;
970 return 0;
974 * smack_task_free_security - "free" a task blob
975 * @task: the task with the blob
977 * Smack isn't using copies of blobs. Everyone
978 * points to an immutable list. The blobs never go away.
979 * There is no leak here.
981 static void smack_task_free_security(struct task_struct *task)
983 task->security = NULL;
987 * smack_task_setpgid - Smack check on setting pgid
988 * @p: the task object
989 * @pgid: unused
991 * Return 0 if write access is permitted
993 static int smack_task_setpgid(struct task_struct *p, pid_t pgid)
995 return smk_curacc(p->security, MAY_WRITE);
999 * smack_task_getpgid - Smack access check for getpgid
1000 * @p: the object task
1002 * Returns 0 if current can read the object task, error code otherwise
1004 static int smack_task_getpgid(struct task_struct *p)
1006 return smk_curacc(p->security, MAY_READ);
1010 * smack_task_getsid - Smack access check for getsid
1011 * @p: the object task
1013 * Returns 0 if current can read the object task, error code otherwise
1015 static int smack_task_getsid(struct task_struct *p)
1017 return smk_curacc(p->security, MAY_READ);
1021 * smack_task_getsecid - get the secid of the task
1022 * @p: the object task
1023 * @secid: where to put the result
1025 * Sets the secid to contain a u32 version of the smack label.
1027 static void smack_task_getsecid(struct task_struct *p, u32 *secid)
1029 *secid = smack_to_secid(p->security);
1033 * smack_task_setnice - Smack check on setting nice
1034 * @p: the task object
1035 * @nice: unused
1037 * Return 0 if write access is permitted
1039 static int smack_task_setnice(struct task_struct *p, int nice)
1041 int rc;
1043 rc = cap_task_setnice(p, nice);
1044 if (rc == 0)
1045 rc = smk_curacc(p->security, MAY_WRITE);
1046 return rc;
1050 * smack_task_setioprio - Smack check on setting ioprio
1051 * @p: the task object
1052 * @ioprio: unused
1054 * Return 0 if write access is permitted
1056 static int smack_task_setioprio(struct task_struct *p, int ioprio)
1058 int rc;
1060 rc = cap_task_setioprio(p, ioprio);
1061 if (rc == 0)
1062 rc = smk_curacc(p->security, MAY_WRITE);
1063 return rc;
1067 * smack_task_getioprio - Smack check on reading ioprio
1068 * @p: the task object
1070 * Return 0 if read access is permitted
1072 static int smack_task_getioprio(struct task_struct *p)
1074 return smk_curacc(p->security, MAY_READ);
1078 * smack_task_setscheduler - Smack check on setting scheduler
1079 * @p: the task object
1080 * @policy: unused
1081 * @lp: unused
1083 * Return 0 if read access is permitted
1085 static int smack_task_setscheduler(struct task_struct *p, int policy,
1086 struct sched_param *lp)
1088 int rc;
1090 rc = cap_task_setscheduler(p, policy, lp);
1091 if (rc == 0)
1092 rc = smk_curacc(p->security, MAY_WRITE);
1093 return rc;
1097 * smack_task_getscheduler - Smack check on reading scheduler
1098 * @p: the task object
1100 * Return 0 if read access is permitted
1102 static int smack_task_getscheduler(struct task_struct *p)
1104 return smk_curacc(p->security, MAY_READ);
1108 * smack_task_movememory - Smack check on moving memory
1109 * @p: the task object
1111 * Return 0 if write access is permitted
1113 static int smack_task_movememory(struct task_struct *p)
1115 return smk_curacc(p->security, MAY_WRITE);
1119 * smack_task_kill - Smack check on signal delivery
1120 * @p: the task object
1121 * @info: unused
1122 * @sig: unused
1123 * @secid: identifies the smack to use in lieu of current's
1125 * Return 0 if write access is permitted
1127 * The secid behavior is an artifact of an SELinux hack
1128 * in the USB code. Someday it may go away.
1130 static int smack_task_kill(struct task_struct *p, struct siginfo *info,
1131 int sig, u32 secid)
1134 * Sending a signal requires that the sender
1135 * can write the receiver.
1137 if (secid == 0)
1138 return smk_curacc(p->security, MAY_WRITE);
1140 * If the secid isn't 0 we're dealing with some USB IO
1141 * specific behavior. This is not clean. For one thing
1142 * we can't take privilege into account.
1144 return smk_access(smack_from_secid(secid), p->security, MAY_WRITE);
1148 * smack_task_wait - Smack access check for waiting
1149 * @p: task to wait for
1151 * Returns 0 if current can wait for p, error code otherwise
1153 static int smack_task_wait(struct task_struct *p)
1155 int rc;
1157 rc = smk_access(current->security, p->security, MAY_WRITE);
1158 if (rc == 0)
1159 return 0;
1162 * Allow the operation to succeed if either task
1163 * has privilege to perform operations that might
1164 * account for the smack labels having gotten to
1165 * be different in the first place.
1167 * This breaks the strict subjet/object access
1168 * control ideal, taking the object's privilege
1169 * state into account in the decision as well as
1170 * the smack value.
1172 if (capable(CAP_MAC_OVERRIDE) || __capable(p, CAP_MAC_OVERRIDE))
1173 return 0;
1175 return rc;
1179 * smack_task_to_inode - copy task smack into the inode blob
1180 * @p: task to copy from
1181 * inode: inode to copy to
1183 * Sets the smack pointer in the inode security blob
1185 static void smack_task_to_inode(struct task_struct *p, struct inode *inode)
1187 struct inode_smack *isp = inode->i_security;
1188 isp->smk_inode = p->security;
1192 * Socket hooks.
1196 * smack_sk_alloc_security - Allocate a socket blob
1197 * @sk: the socket
1198 * @family: unused
1199 * @priority: memory allocation priority
1201 * Assign Smack pointers to current
1203 * Returns 0 on success, -ENOMEM is there's no memory
1205 static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags)
1207 char *csp = current->security;
1208 struct socket_smack *ssp;
1210 ssp = kzalloc(sizeof(struct socket_smack), gfp_flags);
1211 if (ssp == NULL)
1212 return -ENOMEM;
1214 ssp->smk_in = csp;
1215 ssp->smk_out = csp;
1216 ssp->smk_packet[0] = '\0';
1218 sk->sk_security = ssp;
1220 return 0;
1224 * smack_sk_free_security - Free a socket blob
1225 * @sk: the socket
1227 * Clears the blob pointer
1229 static void smack_sk_free_security(struct sock *sk)
1231 kfree(sk->sk_security);
1235 * smack_set_catset - convert a capset to netlabel mls categories
1236 * @catset: the Smack categories
1237 * @sap: where to put the netlabel categories
1239 * Allocates and fills attr.mls.cat
1241 static void smack_set_catset(char *catset, struct netlbl_lsm_secattr *sap)
1243 unsigned char *cp;
1244 unsigned char m;
1245 int cat;
1246 int rc;
1247 int byte;
1249 if (!catset)
1250 return;
1252 sap->flags |= NETLBL_SECATTR_MLS_CAT;
1253 sap->attr.mls.cat = netlbl_secattr_catmap_alloc(GFP_ATOMIC);
1254 sap->attr.mls.cat->startbit = 0;
1256 for (cat = 1, cp = catset, byte = 0; byte < SMK_LABELLEN; cp++, byte++)
1257 for (m = 0x80; m != 0; m >>= 1, cat++) {
1258 if ((m & *cp) == 0)
1259 continue;
1260 rc = netlbl_secattr_catmap_setbit(sap->attr.mls.cat,
1261 cat, GFP_ATOMIC);
1266 * smack_to_secattr - fill a secattr from a smack value
1267 * @smack: the smack value
1268 * @nlsp: where the result goes
1270 * Casey says that CIPSO is good enough for now.
1271 * It can be used to effect.
1272 * It can also be abused to effect when necessary.
1273 * Appologies to the TSIG group in general and GW in particular.
1275 static void smack_to_secattr(char *smack, struct netlbl_lsm_secattr *nlsp)
1277 struct smack_cipso cipso;
1278 int rc;
1280 switch (smack_net_nltype) {
1281 case NETLBL_NLTYPE_CIPSOV4:
1282 nlsp->domain = smack;
1283 nlsp->flags = NETLBL_SECATTR_DOMAIN | NETLBL_SECATTR_MLS_LVL;
1285 rc = smack_to_cipso(smack, &cipso);
1286 if (rc == 0) {
1287 nlsp->attr.mls.lvl = cipso.smk_level;
1288 smack_set_catset(cipso.smk_catset, nlsp);
1289 } else {
1290 nlsp->attr.mls.lvl = smack_cipso_direct;
1291 smack_set_catset(smack, nlsp);
1293 break;
1294 default:
1295 break;
1300 * smack_netlabel - Set the secattr on a socket
1301 * @sk: the socket
1303 * Convert the outbound smack value (smk_out) to a
1304 * secattr and attach it to the socket.
1306 * Returns 0 on success or an error code
1308 static int smack_netlabel(struct sock *sk)
1310 struct socket_smack *ssp;
1311 struct netlbl_lsm_secattr secattr;
1312 int rc;
1314 ssp = sk->sk_security;
1315 netlbl_secattr_init(&secattr);
1316 smack_to_secattr(ssp->smk_out, &secattr);
1317 rc = netlbl_sock_setattr(sk, &secattr);
1318 netlbl_secattr_destroy(&secattr);
1320 return rc;
1324 * smack_inode_setsecurity - set smack xattrs
1325 * @inode: the object
1326 * @name: attribute name
1327 * @value: attribute value
1328 * @size: size of the attribute
1329 * @flags: unused
1331 * Sets the named attribute in the appropriate blob
1333 * Returns 0 on success, or an error code
1335 static int smack_inode_setsecurity(struct inode *inode, const char *name,
1336 const void *value, size_t size, int flags)
1338 char *sp;
1339 struct inode_smack *nsp = inode->i_security;
1340 struct socket_smack *ssp;
1341 struct socket *sock;
1342 int rc = 0;
1344 if (value == NULL || size > SMK_LABELLEN)
1345 return -EACCES;
1347 sp = smk_import(value, size);
1348 if (sp == NULL)
1349 return -EINVAL;
1351 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
1352 nsp->smk_inode = sp;
1353 return 0;
1356 * The rest of the Smack xattrs are only on sockets.
1358 if (inode->i_sb->s_magic != SOCKFS_MAGIC)
1359 return -EOPNOTSUPP;
1361 sock = SOCKET_I(inode);
1362 if (sock == NULL || sock->sk == NULL)
1363 return -EOPNOTSUPP;
1365 ssp = sock->sk->sk_security;
1367 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
1368 ssp->smk_in = sp;
1369 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0) {
1370 ssp->smk_out = sp;
1371 rc = smack_netlabel(sock->sk);
1372 if (rc != 0)
1373 printk(KERN_WARNING "Smack: \"%s\" netlbl error %d.\n",
1374 __func__, -rc);
1375 } else
1376 return -EOPNOTSUPP;
1378 return 0;
1382 * smack_socket_post_create - finish socket setup
1383 * @sock: the socket
1384 * @family: protocol family
1385 * @type: unused
1386 * @protocol: unused
1387 * @kern: unused
1389 * Sets the netlabel information on the socket
1391 * Returns 0 on success, and error code otherwise
1393 static int smack_socket_post_create(struct socket *sock, int family,
1394 int type, int protocol, int kern)
1396 if (family != PF_INET || sock->sk == NULL)
1397 return 0;
1399 * Set the outbound netlbl.
1401 return smack_netlabel(sock->sk);
1405 * smack_flags_to_may - convert S_ to MAY_ values
1406 * @flags: the S_ value
1408 * Returns the equivalent MAY_ value
1410 static int smack_flags_to_may(int flags)
1412 int may = 0;
1414 if (flags & S_IRUGO)
1415 may |= MAY_READ;
1416 if (flags & S_IWUGO)
1417 may |= MAY_WRITE;
1418 if (flags & S_IXUGO)
1419 may |= MAY_EXEC;
1421 return may;
1425 * smack_msg_msg_alloc_security - Set the security blob for msg_msg
1426 * @msg: the object
1428 * Returns 0
1430 static int smack_msg_msg_alloc_security(struct msg_msg *msg)
1432 msg->security = current->security;
1433 return 0;
1437 * smack_msg_msg_free_security - Clear the security blob for msg_msg
1438 * @msg: the object
1440 * Clears the blob pointer
1442 static void smack_msg_msg_free_security(struct msg_msg *msg)
1444 msg->security = NULL;
1448 * smack_of_shm - the smack pointer for the shm
1449 * @shp: the object
1451 * Returns a pointer to the smack value
1453 static char *smack_of_shm(struct shmid_kernel *shp)
1455 return (char *)shp->shm_perm.security;
1459 * smack_shm_alloc_security - Set the security blob for shm
1460 * @shp: the object
1462 * Returns 0
1464 static int smack_shm_alloc_security(struct shmid_kernel *shp)
1466 struct kern_ipc_perm *isp = &shp->shm_perm;
1468 isp->security = current->security;
1469 return 0;
1473 * smack_shm_free_security - Clear the security blob for shm
1474 * @shp: the object
1476 * Clears the blob pointer
1478 static void smack_shm_free_security(struct shmid_kernel *shp)
1480 struct kern_ipc_perm *isp = &shp->shm_perm;
1482 isp->security = NULL;
1486 * smack_shm_associate - Smack access check for shm
1487 * @shp: the object
1488 * @shmflg: access requested
1490 * Returns 0 if current has the requested access, error code otherwise
1492 static int smack_shm_associate(struct shmid_kernel *shp, int shmflg)
1494 char *ssp = smack_of_shm(shp);
1495 int may;
1497 may = smack_flags_to_may(shmflg);
1498 return smk_curacc(ssp, may);
1502 * smack_shm_shmctl - Smack access check for shm
1503 * @shp: the object
1504 * @cmd: what it wants to do
1506 * Returns 0 if current has the requested access, error code otherwise
1508 static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd)
1510 char *ssp;
1511 int may;
1513 switch (cmd) {
1514 case IPC_STAT:
1515 case SHM_STAT:
1516 may = MAY_READ;
1517 break;
1518 case IPC_SET:
1519 case SHM_LOCK:
1520 case SHM_UNLOCK:
1521 case IPC_RMID:
1522 may = MAY_READWRITE;
1523 break;
1524 case IPC_INFO:
1525 case SHM_INFO:
1527 * System level information.
1529 return 0;
1530 default:
1531 return -EINVAL;
1534 ssp = smack_of_shm(shp);
1535 return smk_curacc(ssp, may);
1539 * smack_shm_shmat - Smack access for shmat
1540 * @shp: the object
1541 * @shmaddr: unused
1542 * @shmflg: access requested
1544 * Returns 0 if current has the requested access, error code otherwise
1546 static int smack_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr,
1547 int shmflg)
1549 char *ssp = smack_of_shm(shp);
1550 int may;
1552 may = smack_flags_to_may(shmflg);
1553 return smk_curacc(ssp, may);
1557 * smack_of_sem - the smack pointer for the sem
1558 * @sma: the object
1560 * Returns a pointer to the smack value
1562 static char *smack_of_sem(struct sem_array *sma)
1564 return (char *)sma->sem_perm.security;
1568 * smack_sem_alloc_security - Set the security blob for sem
1569 * @sma: the object
1571 * Returns 0
1573 static int smack_sem_alloc_security(struct sem_array *sma)
1575 struct kern_ipc_perm *isp = &sma->sem_perm;
1577 isp->security = current->security;
1578 return 0;
1582 * smack_sem_free_security - Clear the security blob for sem
1583 * @sma: the object
1585 * Clears the blob pointer
1587 static void smack_sem_free_security(struct sem_array *sma)
1589 struct kern_ipc_perm *isp = &sma->sem_perm;
1591 isp->security = NULL;
1595 * smack_sem_associate - Smack access check for sem
1596 * @sma: the object
1597 * @semflg: access requested
1599 * Returns 0 if current has the requested access, error code otherwise
1601 static int smack_sem_associate(struct sem_array *sma, int semflg)
1603 char *ssp = smack_of_sem(sma);
1604 int may;
1606 may = smack_flags_to_may(semflg);
1607 return smk_curacc(ssp, may);
1611 * smack_sem_shmctl - Smack access check for sem
1612 * @sma: the object
1613 * @cmd: what it wants to do
1615 * Returns 0 if current has the requested access, error code otherwise
1617 static int smack_sem_semctl(struct sem_array *sma, int cmd)
1619 char *ssp;
1620 int may;
1622 switch (cmd) {
1623 case GETPID:
1624 case GETNCNT:
1625 case GETZCNT:
1626 case GETVAL:
1627 case GETALL:
1628 case IPC_STAT:
1629 case SEM_STAT:
1630 may = MAY_READ;
1631 break;
1632 case SETVAL:
1633 case SETALL:
1634 case IPC_RMID:
1635 case IPC_SET:
1636 may = MAY_READWRITE;
1637 break;
1638 case IPC_INFO:
1639 case SEM_INFO:
1641 * System level information
1643 return 0;
1644 default:
1645 return -EINVAL;
1648 ssp = smack_of_sem(sma);
1649 return smk_curacc(ssp, may);
1653 * smack_sem_semop - Smack checks of semaphore operations
1654 * @sma: the object
1655 * @sops: unused
1656 * @nsops: unused
1657 * @alter: unused
1659 * Treated as read and write in all cases.
1661 * Returns 0 if access is allowed, error code otherwise
1663 static int smack_sem_semop(struct sem_array *sma, struct sembuf *sops,
1664 unsigned nsops, int alter)
1666 char *ssp = smack_of_sem(sma);
1668 return smk_curacc(ssp, MAY_READWRITE);
1672 * smack_msg_alloc_security - Set the security blob for msg
1673 * @msq: the object
1675 * Returns 0
1677 static int smack_msg_queue_alloc_security(struct msg_queue *msq)
1679 struct kern_ipc_perm *kisp = &msq->q_perm;
1681 kisp->security = current->security;
1682 return 0;
1686 * smack_msg_free_security - Clear the security blob for msg
1687 * @msq: the object
1689 * Clears the blob pointer
1691 static void smack_msg_queue_free_security(struct msg_queue *msq)
1693 struct kern_ipc_perm *kisp = &msq->q_perm;
1695 kisp->security = NULL;
1699 * smack_of_msq - the smack pointer for the msq
1700 * @msq: the object
1702 * Returns a pointer to the smack value
1704 static char *smack_of_msq(struct msg_queue *msq)
1706 return (char *)msq->q_perm.security;
1710 * smack_msg_queue_associate - Smack access check for msg_queue
1711 * @msq: the object
1712 * @msqflg: access requested
1714 * Returns 0 if current has the requested access, error code otherwise
1716 static int smack_msg_queue_associate(struct msg_queue *msq, int msqflg)
1718 char *msp = smack_of_msq(msq);
1719 int may;
1721 may = smack_flags_to_may(msqflg);
1722 return smk_curacc(msp, may);
1726 * smack_msg_queue_msgctl - Smack access check for msg_queue
1727 * @msq: the object
1728 * @cmd: what it wants to do
1730 * Returns 0 if current has the requested access, error code otherwise
1732 static int smack_msg_queue_msgctl(struct msg_queue *msq, int cmd)
1734 char *msp;
1735 int may;
1737 switch (cmd) {
1738 case IPC_STAT:
1739 case MSG_STAT:
1740 may = MAY_READ;
1741 break;
1742 case IPC_SET:
1743 case IPC_RMID:
1744 may = MAY_READWRITE;
1745 break;
1746 case IPC_INFO:
1747 case MSG_INFO:
1749 * System level information
1751 return 0;
1752 default:
1753 return -EINVAL;
1756 msp = smack_of_msq(msq);
1757 return smk_curacc(msp, may);
1761 * smack_msg_queue_msgsnd - Smack access check for msg_queue
1762 * @msq: the object
1763 * @msg: unused
1764 * @msqflg: access requested
1766 * Returns 0 if current has the requested access, error code otherwise
1768 static int smack_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
1769 int msqflg)
1771 char *msp = smack_of_msq(msq);
1772 int rc;
1774 rc = smack_flags_to_may(msqflg);
1775 return smk_curacc(msp, rc);
1779 * smack_msg_queue_msgsnd - Smack access check for msg_queue
1780 * @msq: the object
1781 * @msg: unused
1782 * @target: unused
1783 * @type: unused
1784 * @mode: unused
1786 * Returns 0 if current has read and write access, error code otherwise
1788 static int smack_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
1789 struct task_struct *target, long type, int mode)
1791 char *msp = smack_of_msq(msq);
1793 return smk_curacc(msp, MAY_READWRITE);
1797 * smack_ipc_permission - Smack access for ipc_permission()
1798 * @ipp: the object permissions
1799 * @flag: access requested
1801 * Returns 0 if current has read and write access, error code otherwise
1803 static int smack_ipc_permission(struct kern_ipc_perm *ipp, short flag)
1805 char *isp = ipp->security;
1806 int may;
1808 may = smack_flags_to_may(flag);
1809 return smk_curacc(isp, may);
1813 * smack_ipc_getsecid - Extract smack security id
1814 * @ipcp: the object permissions
1815 * @secid: where result will be saved
1817 static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, u32 *secid)
1819 char *smack = ipp->security;
1821 *secid = smack_to_secid(smack);
1825 * smack_d_instantiate - Make sure the blob is correct on an inode
1826 * @opt_dentry: unused
1827 * @inode: the object
1829 * Set the inode's security blob if it hasn't been done already.
1831 static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
1833 struct super_block *sbp;
1834 struct superblock_smack *sbsp;
1835 struct inode_smack *isp;
1836 char *csp = current->security;
1837 char *fetched;
1838 char *final;
1839 struct dentry *dp;
1841 if (inode == NULL)
1842 return;
1844 isp = inode->i_security;
1846 mutex_lock(&isp->smk_lock);
1848 * If the inode is already instantiated
1849 * take the quick way out
1851 if (isp->smk_flags & SMK_INODE_INSTANT)
1852 goto unlockandout;
1854 sbp = inode->i_sb;
1855 sbsp = sbp->s_security;
1857 * We're going to use the superblock default label
1858 * if there's no label on the file.
1860 final = sbsp->smk_default;
1863 * If this is the root inode the superblock
1864 * may be in the process of initialization.
1865 * If that is the case use the root value out
1866 * of the superblock.
1868 if (opt_dentry->d_parent == opt_dentry) {
1869 isp->smk_inode = sbsp->smk_root;
1870 isp->smk_flags |= SMK_INODE_INSTANT;
1871 goto unlockandout;
1875 * This is pretty hackish.
1876 * Casey says that we shouldn't have to do
1877 * file system specific code, but it does help
1878 * with keeping it simple.
1880 switch (sbp->s_magic) {
1881 case SMACK_MAGIC:
1883 * Casey says that it's a little embarassing
1884 * that the smack file system doesn't do
1885 * extended attributes.
1887 final = smack_known_star.smk_known;
1888 break;
1889 case PIPEFS_MAGIC:
1891 * Casey says pipes are easy (?)
1893 final = smack_known_star.smk_known;
1894 break;
1895 case DEVPTS_SUPER_MAGIC:
1897 * devpts seems content with the label of the task.
1898 * Programs that change smack have to treat the
1899 * pty with respect.
1901 final = csp;
1902 break;
1903 case SOCKFS_MAGIC:
1905 * Casey says sockets get the smack of the task.
1907 final = csp;
1908 break;
1909 case PROC_SUPER_MAGIC:
1911 * Casey says procfs appears not to care.
1912 * The superblock default suffices.
1914 break;
1915 case TMPFS_MAGIC:
1917 * Device labels should come from the filesystem,
1918 * but watch out, because they're volitile,
1919 * getting recreated on every reboot.
1921 final = smack_known_star.smk_known;
1923 * No break.
1925 * If a smack value has been set we want to use it,
1926 * but since tmpfs isn't giving us the opportunity
1927 * to set mount options simulate setting the
1928 * superblock default.
1930 default:
1932 * This isn't an understood special case.
1933 * Get the value from the xattr.
1935 * No xattr support means, alas, no SMACK label.
1936 * Use the aforeapplied default.
1937 * It would be curious if the label of the task
1938 * does not match that assigned.
1940 if (inode->i_op->getxattr == NULL)
1941 break;
1943 * Get the dentry for xattr.
1945 if (opt_dentry == NULL) {
1946 dp = d_find_alias(inode);
1947 if (dp == NULL)
1948 break;
1949 } else {
1950 dp = dget(opt_dentry);
1951 if (dp == NULL)
1952 break;
1955 fetched = smk_fetch(inode, dp);
1956 if (fetched != NULL)
1957 final = fetched;
1959 dput(dp);
1960 break;
1963 if (final == NULL)
1964 isp->smk_inode = csp;
1965 else
1966 isp->smk_inode = final;
1968 isp->smk_flags |= SMK_INODE_INSTANT;
1970 unlockandout:
1971 mutex_unlock(&isp->smk_lock);
1972 return;
1976 * smack_getprocattr - Smack process attribute access
1977 * @p: the object task
1978 * @name: the name of the attribute in /proc/.../attr
1979 * @value: where to put the result
1981 * Places a copy of the task Smack into value
1983 * Returns the length of the smack label or an error code
1985 static int smack_getprocattr(struct task_struct *p, char *name, char **value)
1987 char *cp;
1988 int slen;
1990 if (strcmp(name, "current") != 0)
1991 return -EINVAL;
1993 cp = kstrdup(p->security, GFP_KERNEL);
1994 if (cp == NULL)
1995 return -ENOMEM;
1997 slen = strlen(cp);
1998 *value = cp;
1999 return slen;
2003 * smack_setprocattr - Smack process attribute setting
2004 * @p: the object task
2005 * @name: the name of the attribute in /proc/.../attr
2006 * @value: the value to set
2007 * @size: the size of the value
2009 * Sets the Smack value of the task. Only setting self
2010 * is permitted and only with privilege
2012 * Returns the length of the smack label or an error code
2014 static int smack_setprocattr(struct task_struct *p, char *name,
2015 void *value, size_t size)
2017 char *newsmack;
2019 if (!__capable(p, CAP_MAC_ADMIN))
2020 return -EPERM;
2023 * Changing another process' Smack value is too dangerous
2024 * and supports no sane use case.
2026 if (p != current)
2027 return -EPERM;
2029 if (value == NULL || size == 0 || size >= SMK_LABELLEN)
2030 return -EINVAL;
2032 if (strcmp(name, "current") != 0)
2033 return -EINVAL;
2035 newsmack = smk_import(value, size);
2036 if (newsmack == NULL)
2037 return -EINVAL;
2039 p->security = newsmack;
2040 return size;
2044 * smack_unix_stream_connect - Smack access on UDS
2045 * @sock: one socket
2046 * @other: the other socket
2047 * @newsk: unused
2049 * Return 0 if a subject with the smack of sock could access
2050 * an object with the smack of other, otherwise an error code
2052 static int smack_unix_stream_connect(struct socket *sock,
2053 struct socket *other, struct sock *newsk)
2055 struct inode *sp = SOCK_INODE(sock);
2056 struct inode *op = SOCK_INODE(other);
2058 return smk_access(smk_of_inode(sp), smk_of_inode(op), MAY_READWRITE);
2062 * smack_unix_may_send - Smack access on UDS
2063 * @sock: one socket
2064 * @other: the other socket
2066 * Return 0 if a subject with the smack of sock could access
2067 * an object with the smack of other, otherwise an error code
2069 static int smack_unix_may_send(struct socket *sock, struct socket *other)
2071 struct inode *sp = SOCK_INODE(sock);
2072 struct inode *op = SOCK_INODE(other);
2074 return smk_access(smk_of_inode(sp), smk_of_inode(op), MAY_WRITE);
2078 * smack_from_secattr - Convert a netlabel attr.mls.lvl/attr.mls.cat
2079 * pair to smack
2080 * @sap: netlabel secattr
2081 * @sip: where to put the result
2083 * Copies a smack label into sip
2085 static void smack_from_secattr(struct netlbl_lsm_secattr *sap, char *sip)
2087 char smack[SMK_LABELLEN];
2088 int pcat;
2090 if ((sap->flags & NETLBL_SECATTR_MLS_LVL) == 0) {
2092 * If there are flags but no level netlabel isn't
2093 * behaving the way we expect it to.
2095 * Without guidance regarding the smack value
2096 * for the packet fall back on the network
2097 * ambient value.
2099 strncpy(sip, smack_net_ambient, SMK_MAXLEN);
2100 return;
2103 * Get the categories, if any
2105 memset(smack, '\0', SMK_LABELLEN);
2106 if ((sap->flags & NETLBL_SECATTR_MLS_CAT) != 0)
2107 for (pcat = -1;;) {
2108 pcat = netlbl_secattr_catmap_walk(sap->attr.mls.cat,
2109 pcat + 1);
2110 if (pcat < 0)
2111 break;
2112 smack_catset_bit(pcat, smack);
2115 * If it is CIPSO using smack direct mapping
2116 * we are already done. WeeHee.
2118 if (sap->attr.mls.lvl == smack_cipso_direct) {
2119 memcpy(sip, smack, SMK_MAXLEN);
2120 return;
2123 * Look it up in the supplied table if it is not a direct mapping.
2125 smack_from_cipso(sap->attr.mls.lvl, smack, sip);
2126 return;
2130 * smack_socket_sock_rcv_skb - Smack packet delivery access check
2131 * @sk: socket
2132 * @skb: packet
2134 * Returns 0 if the packet should be delivered, an error code otherwise
2136 static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
2138 struct netlbl_lsm_secattr secattr;
2139 struct socket_smack *ssp = sk->sk_security;
2140 char smack[SMK_LABELLEN];
2141 int rc;
2143 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2144 return 0;
2147 * Translate what netlabel gave us.
2149 memset(smack, '\0', SMK_LABELLEN);
2150 netlbl_secattr_init(&secattr);
2151 rc = netlbl_skbuff_getattr(skb, sk->sk_family, &secattr);
2152 if (rc == 0)
2153 smack_from_secattr(&secattr, smack);
2154 else
2155 strncpy(smack, smack_net_ambient, SMK_MAXLEN);
2156 netlbl_secattr_destroy(&secattr);
2158 * Receiving a packet requires that the other end
2159 * be able to write here. Read access is not required.
2160 * This is the simplist possible security model
2161 * for networking.
2163 return smk_access(smack, ssp->smk_in, MAY_WRITE);
2167 * smack_socket_getpeersec_stream - pull in packet label
2168 * @sock: the socket
2169 * @optval: user's destination
2170 * @optlen: size thereof
2171 * @len: max thereoe
2173 * returns zero on success, an error code otherwise
2175 static int smack_socket_getpeersec_stream(struct socket *sock,
2176 char __user *optval,
2177 int __user *optlen, unsigned len)
2179 struct socket_smack *ssp;
2180 int slen;
2181 int rc = 0;
2183 ssp = sock->sk->sk_security;
2184 slen = strlen(ssp->smk_packet) + 1;
2186 if (slen > len)
2187 rc = -ERANGE;
2188 else if (copy_to_user(optval, ssp->smk_packet, slen) != 0)
2189 rc = -EFAULT;
2191 if (put_user(slen, optlen) != 0)
2192 rc = -EFAULT;
2194 return rc;
2199 * smack_socket_getpeersec_dgram - pull in packet label
2200 * @sock: the socket
2201 * @skb: packet data
2202 * @secid: pointer to where to put the secid of the packet
2204 * Sets the netlabel socket state on sk from parent
2206 static int smack_socket_getpeersec_dgram(struct socket *sock,
2207 struct sk_buff *skb, u32 *secid)
2210 struct netlbl_lsm_secattr secattr;
2211 struct sock *sk;
2212 char smack[SMK_LABELLEN];
2213 int family = PF_INET;
2214 u32 s;
2215 int rc;
2218 * Only works for families with packets.
2220 if (sock != NULL) {
2221 sk = sock->sk;
2222 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2223 return 0;
2224 family = sk->sk_family;
2227 * Translate what netlabel gave us.
2229 memset(smack, '\0', SMK_LABELLEN);
2230 netlbl_secattr_init(&secattr);
2231 rc = netlbl_skbuff_getattr(skb, family, &secattr);
2232 if (rc == 0)
2233 smack_from_secattr(&secattr, smack);
2234 netlbl_secattr_destroy(&secattr);
2237 * Give up if we couldn't get anything
2239 if (rc != 0)
2240 return rc;
2242 s = smack_to_secid(smack);
2243 if (s == 0)
2244 return -EINVAL;
2246 *secid = s;
2247 return 0;
2251 * smack_sock_graft - graft access state between two sockets
2252 * @sk: fresh sock
2253 * @parent: donor socket
2255 * Sets the netlabel socket state on sk from parent
2257 static void smack_sock_graft(struct sock *sk, struct socket *parent)
2259 struct socket_smack *ssp;
2260 int rc;
2262 if (sk == NULL)
2263 return;
2265 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2266 return;
2268 ssp = sk->sk_security;
2269 ssp->smk_in = current->security;
2270 ssp->smk_out = current->security;
2271 ssp->smk_packet[0] = '\0';
2273 rc = smack_netlabel(sk);
2274 if (rc != 0)
2275 printk(KERN_WARNING "Smack: \"%s\" netlbl error %d.\n",
2276 __func__, -rc);
2280 * smack_inet_conn_request - Smack access check on connect
2281 * @sk: socket involved
2282 * @skb: packet
2283 * @req: unused
2285 * Returns 0 if a task with the packet label could write to
2286 * the socket, otherwise an error code
2288 static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
2289 struct request_sock *req)
2291 struct netlbl_lsm_secattr skb_secattr;
2292 struct socket_smack *ssp = sk->sk_security;
2293 char smack[SMK_LABELLEN];
2294 int rc;
2296 if (skb == NULL)
2297 return -EACCES;
2299 memset(smack, '\0', SMK_LABELLEN);
2300 netlbl_secattr_init(&skb_secattr);
2301 rc = netlbl_skbuff_getattr(skb, sk->sk_family, &skb_secattr);
2302 if (rc == 0)
2303 smack_from_secattr(&skb_secattr, smack);
2304 else
2305 strncpy(smack, smack_known_huh.smk_known, SMK_MAXLEN);
2306 netlbl_secattr_destroy(&skb_secattr);
2308 * Receiving a packet requires that the other end
2309 * be able to write here. Read access is not required.
2311 * If the request is successful save the peer's label
2312 * so that SO_PEERCRED can report it.
2314 rc = smk_access(smack, ssp->smk_in, MAY_WRITE);
2315 if (rc == 0)
2316 strncpy(ssp->smk_packet, smack, SMK_MAXLEN);
2318 return rc;
2322 * Key management security hooks
2324 * Casey has not tested key support very heavily.
2325 * The permission check is most likely too restrictive.
2326 * If you care about keys please have a look.
2328 #ifdef CONFIG_KEYS
2331 * smack_key_alloc - Set the key security blob
2332 * @key: object
2333 * @tsk: the task associated with the key
2334 * @flags: unused
2336 * No allocation required
2338 * Returns 0
2340 static int smack_key_alloc(struct key *key, struct task_struct *tsk,
2341 unsigned long flags)
2343 key->security = tsk->security;
2344 return 0;
2348 * smack_key_free - Clear the key security blob
2349 * @key: the object
2351 * Clear the blob pointer
2353 static void smack_key_free(struct key *key)
2355 key->security = NULL;
2359 * smack_key_permission - Smack access on a key
2360 * @key_ref: gets to the object
2361 * @context: task involved
2362 * @perm: unused
2364 * Return 0 if the task has read and write to the object,
2365 * an error code otherwise
2367 static int smack_key_permission(key_ref_t key_ref,
2368 struct task_struct *context, key_perm_t perm)
2370 struct key *keyp;
2372 keyp = key_ref_to_ptr(key_ref);
2373 if (keyp == NULL)
2374 return -EINVAL;
2376 * If the key hasn't been initialized give it access so that
2377 * it may do so.
2379 if (keyp->security == NULL)
2380 return 0;
2382 * This should not occur
2384 if (context->security == NULL)
2385 return -EACCES;
2387 return smk_access(context->security, keyp->security, MAY_READWRITE);
2389 #endif /* CONFIG_KEYS */
2392 * Smack Audit hooks
2394 * Audit requires a unique representation of each Smack specific
2395 * rule. This unique representation is used to distinguish the
2396 * object to be audited from remaining kernel objects and also
2397 * works as a glue between the audit hooks.
2399 * Since repository entries are added but never deleted, we'll use
2400 * the smack_known label address related to the given audit rule as
2401 * the needed unique representation. This also better fits the smack
2402 * model where nearly everything is a label.
2404 #ifdef CONFIG_AUDIT
2407 * smack_audit_rule_init - Initialize a smack audit rule
2408 * @field: audit rule fields given from user-space (audit.h)
2409 * @op: required testing operator (=, !=, >, <, ...)
2410 * @rulestr: smack label to be audited
2411 * @vrule: pointer to save our own audit rule representation
2413 * Prepare to audit cases where (@field @op @rulestr) is true.
2414 * The label to be audited is created if necessay.
2416 static int smack_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
2418 char **rule = (char **)vrule;
2419 *rule = NULL;
2421 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
2422 return -EINVAL;
2424 if (op != AUDIT_EQUAL && op != AUDIT_NOT_EQUAL)
2425 return -EINVAL;
2427 *rule = smk_import(rulestr, 0);
2429 return 0;
2433 * smack_audit_rule_known - Distinguish Smack audit rules
2434 * @krule: rule of interest, in Audit kernel representation format
2436 * This is used to filter Smack rules from remaining Audit ones.
2437 * If it's proved that this rule belongs to us, the
2438 * audit_rule_match hook will be called to do the final judgement.
2440 static int smack_audit_rule_known(struct audit_krule *krule)
2442 struct audit_field *f;
2443 int i;
2445 for (i = 0; i < krule->field_count; i++) {
2446 f = &krule->fields[i];
2448 if (f->type == AUDIT_SUBJ_USER || f->type == AUDIT_OBJ_USER)
2449 return 1;
2452 return 0;
2456 * smack_audit_rule_match - Audit given object ?
2457 * @secid: security id for identifying the object to test
2458 * @field: audit rule flags given from user-space
2459 * @op: required testing operator
2460 * @vrule: smack internal rule presentation
2461 * @actx: audit context associated with the check
2463 * The core Audit hook. It's used to take the decision of
2464 * whether to audit or not to audit a given object.
2466 static int smack_audit_rule_match(u32 secid, u32 field, u32 op, void *vrule,
2467 struct audit_context *actx)
2469 char *smack;
2470 char *rule = vrule;
2472 if (!rule) {
2473 audit_log(actx, GFP_KERNEL, AUDIT_SELINUX_ERR,
2474 "Smack: missing rule\n");
2475 return -ENOENT;
2478 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
2479 return 0;
2481 smack = smack_from_secid(secid);
2484 * No need to do string comparisons. If a match occurs,
2485 * both pointers will point to the same smack_known
2486 * label.
2488 if (op == AUDIT_EQUAL)
2489 return (rule == smack);
2490 if (op == AUDIT_NOT_EQUAL)
2491 return (rule != smack);
2493 return 0;
2497 * smack_audit_rule_free - free smack rule representation
2498 * @vrule: rule to be freed.
2500 * No memory was allocated.
2502 static void smack_audit_rule_free(void *vrule)
2504 /* No-op */
2507 #endif /* CONFIG_AUDIT */
2510 * smack_secid_to_secctx - return the smack label for a secid
2511 * @secid: incoming integer
2512 * @secdata: destination
2513 * @seclen: how long it is
2515 * Exists for networking code.
2517 static int smack_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
2519 char *sp = smack_from_secid(secid);
2521 *secdata = sp;
2522 *seclen = strlen(sp);
2523 return 0;
2527 * smack_secctx_to_secid - return the secid for a smack label
2528 * @secdata: smack label
2529 * @seclen: how long result is
2530 * @secid: outgoing integer
2532 * Exists for audit and networking code.
2534 static int smack_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
2536 *secid = smack_to_secid(secdata);
2537 return 0;
2541 * smack_release_secctx - don't do anything.
2542 * @key_ref: unused
2543 * @context: unused
2544 * @perm: unused
2546 * Exists to make sure nothing gets done, and properly
2548 static void smack_release_secctx(char *secdata, u32 seclen)
2552 struct security_operations smack_ops = {
2553 .name = "smack",
2555 .ptrace = smack_ptrace,
2556 .capget = cap_capget,
2557 .capset_check = cap_capset_check,
2558 .capset_set = cap_capset_set,
2559 .capable = cap_capable,
2560 .syslog = smack_syslog,
2561 .settime = cap_settime,
2562 .vm_enough_memory = cap_vm_enough_memory,
2564 .bprm_apply_creds = cap_bprm_apply_creds,
2565 .bprm_set_security = cap_bprm_set_security,
2566 .bprm_secureexec = cap_bprm_secureexec,
2568 .sb_alloc_security = smack_sb_alloc_security,
2569 .sb_free_security = smack_sb_free_security,
2570 .sb_copy_data = smack_sb_copy_data,
2571 .sb_kern_mount = smack_sb_kern_mount,
2572 .sb_statfs = smack_sb_statfs,
2573 .sb_mount = smack_sb_mount,
2574 .sb_umount = smack_sb_umount,
2576 .inode_alloc_security = smack_inode_alloc_security,
2577 .inode_free_security = smack_inode_free_security,
2578 .inode_init_security = smack_inode_init_security,
2579 .inode_link = smack_inode_link,
2580 .inode_unlink = smack_inode_unlink,
2581 .inode_rmdir = smack_inode_rmdir,
2582 .inode_rename = smack_inode_rename,
2583 .inode_permission = smack_inode_permission,
2584 .inode_setattr = smack_inode_setattr,
2585 .inode_getattr = smack_inode_getattr,
2586 .inode_setxattr = smack_inode_setxattr,
2587 .inode_post_setxattr = smack_inode_post_setxattr,
2588 .inode_getxattr = smack_inode_getxattr,
2589 .inode_removexattr = smack_inode_removexattr,
2590 .inode_need_killpriv = cap_inode_need_killpriv,
2591 .inode_killpriv = cap_inode_killpriv,
2592 .inode_getsecurity = smack_inode_getsecurity,
2593 .inode_setsecurity = smack_inode_setsecurity,
2594 .inode_listsecurity = smack_inode_listsecurity,
2595 .inode_getsecid = smack_inode_getsecid,
2597 .file_permission = smack_file_permission,
2598 .file_alloc_security = smack_file_alloc_security,
2599 .file_free_security = smack_file_free_security,
2600 .file_ioctl = smack_file_ioctl,
2601 .file_lock = smack_file_lock,
2602 .file_fcntl = smack_file_fcntl,
2603 .file_set_fowner = smack_file_set_fowner,
2604 .file_send_sigiotask = smack_file_send_sigiotask,
2605 .file_receive = smack_file_receive,
2607 .task_alloc_security = smack_task_alloc_security,
2608 .task_free_security = smack_task_free_security,
2609 .task_post_setuid = cap_task_post_setuid,
2610 .task_setpgid = smack_task_setpgid,
2611 .task_getpgid = smack_task_getpgid,
2612 .task_getsid = smack_task_getsid,
2613 .task_getsecid = smack_task_getsecid,
2614 .task_setnice = smack_task_setnice,
2615 .task_setioprio = smack_task_setioprio,
2616 .task_getioprio = smack_task_getioprio,
2617 .task_setscheduler = smack_task_setscheduler,
2618 .task_getscheduler = smack_task_getscheduler,
2619 .task_movememory = smack_task_movememory,
2620 .task_kill = smack_task_kill,
2621 .task_wait = smack_task_wait,
2622 .task_reparent_to_init = cap_task_reparent_to_init,
2623 .task_to_inode = smack_task_to_inode,
2624 .task_prctl = cap_task_prctl,
2626 .ipc_permission = smack_ipc_permission,
2627 .ipc_getsecid = smack_ipc_getsecid,
2629 .msg_msg_alloc_security = smack_msg_msg_alloc_security,
2630 .msg_msg_free_security = smack_msg_msg_free_security,
2632 .msg_queue_alloc_security = smack_msg_queue_alloc_security,
2633 .msg_queue_free_security = smack_msg_queue_free_security,
2634 .msg_queue_associate = smack_msg_queue_associate,
2635 .msg_queue_msgctl = smack_msg_queue_msgctl,
2636 .msg_queue_msgsnd = smack_msg_queue_msgsnd,
2637 .msg_queue_msgrcv = smack_msg_queue_msgrcv,
2639 .shm_alloc_security = smack_shm_alloc_security,
2640 .shm_free_security = smack_shm_free_security,
2641 .shm_associate = smack_shm_associate,
2642 .shm_shmctl = smack_shm_shmctl,
2643 .shm_shmat = smack_shm_shmat,
2645 .sem_alloc_security = smack_sem_alloc_security,
2646 .sem_free_security = smack_sem_free_security,
2647 .sem_associate = smack_sem_associate,
2648 .sem_semctl = smack_sem_semctl,
2649 .sem_semop = smack_sem_semop,
2651 .netlink_send = cap_netlink_send,
2652 .netlink_recv = cap_netlink_recv,
2654 .d_instantiate = smack_d_instantiate,
2656 .getprocattr = smack_getprocattr,
2657 .setprocattr = smack_setprocattr,
2659 .unix_stream_connect = smack_unix_stream_connect,
2660 .unix_may_send = smack_unix_may_send,
2662 .socket_post_create = smack_socket_post_create,
2663 .socket_sock_rcv_skb = smack_socket_sock_rcv_skb,
2664 .socket_getpeersec_stream = smack_socket_getpeersec_stream,
2665 .socket_getpeersec_dgram = smack_socket_getpeersec_dgram,
2666 .sk_alloc_security = smack_sk_alloc_security,
2667 .sk_free_security = smack_sk_free_security,
2668 .sock_graft = smack_sock_graft,
2669 .inet_conn_request = smack_inet_conn_request,
2671 /* key management security hooks */
2672 #ifdef CONFIG_KEYS
2673 .key_alloc = smack_key_alloc,
2674 .key_free = smack_key_free,
2675 .key_permission = smack_key_permission,
2676 #endif /* CONFIG_KEYS */
2678 /* Audit hooks */
2679 #ifdef CONFIG_AUDIT
2680 .audit_rule_init = smack_audit_rule_init,
2681 .audit_rule_known = smack_audit_rule_known,
2682 .audit_rule_match = smack_audit_rule_match,
2683 .audit_rule_free = smack_audit_rule_free,
2684 #endif /* CONFIG_AUDIT */
2686 .secid_to_secctx = smack_secid_to_secctx,
2687 .secctx_to_secid = smack_secctx_to_secid,
2688 .release_secctx = smack_release_secctx,
2692 * smack_init - initialize the smack system
2694 * Returns 0
2696 static __init int smack_init(void)
2698 if (!security_module_enable(&smack_ops))
2699 return 0;
2701 printk(KERN_INFO "Smack: Initializing.\n");
2704 * Set the security state for the initial task.
2706 current->security = &smack_known_floor.smk_known;
2709 * Initialize locks
2711 spin_lock_init(&smack_known_unset.smk_cipsolock);
2712 spin_lock_init(&smack_known_huh.smk_cipsolock);
2713 spin_lock_init(&smack_known_hat.smk_cipsolock);
2714 spin_lock_init(&smack_known_star.smk_cipsolock);
2715 spin_lock_init(&smack_known_floor.smk_cipsolock);
2716 spin_lock_init(&smack_known_invalid.smk_cipsolock);
2719 * Register with LSM
2721 if (register_security(&smack_ops))
2722 panic("smack: Unable to register with kernel.\n");
2724 return 0;
2728 * Smack requires early initialization in order to label
2729 * all processes and objects when they are created.
2731 security_initcall(smack_init);