2 * Simplified MAC Kernel (smack) security module
4 * This file contains the smack hook function implementations.
7 * Casey Schaufler <casey@schaufler-ca.com>
9 * Copyright (C) 2007 Casey Schaufler <casey@schaufler-ca.com>
10 * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
11 * Paul Moore <paul.moore@hp.com>
13 * This program is free software; you can redistribute it and/or modify
14 * it under the terms of the GNU General Public License version 2,
15 * as published by the Free Software Foundation.
18 #include <linux/xattr.h>
19 #include <linux/pagemap.h>
20 #include <linux/mount.h>
21 #include <linux/stat.h>
22 #include <linux/ext2_fs.h>
24 #include <asm/ioctls.h>
26 #include <linux/tcp.h>
27 #include <linux/udp.h>
28 #include <linux/slab.h>
29 #include <linux/mutex.h>
30 #include <linux/pipe_fs_i.h>
31 #include <net/netlabel.h>
32 #include <net/cipso_ipv4.h>
33 #include <linux/audit.h>
34 #include <linux/magic.h>
37 #define task_security(task) (task_cred_xxx((task), security))
40 * smk_fetch - Fetch the smack label from a file.
41 * @ip: a pointer to the inode
42 * @dp: a pointer to the dentry
44 * Returns a pointer to the master list entry for the Smack label
45 * or NULL if there was no label to fetch.
47 static char *smk_fetch(struct inode *ip, struct dentry *dp)
50 char in[SMK_LABELLEN];
52 if (ip->i_op->getxattr == NULL)
55 rc = ip->i_op->getxattr(dp, XATTR_NAME_SMACK, in, SMK_LABELLEN);
59 return smk_import(in, rc);
63 * new_inode_smack - allocate an inode security blob
64 * @smack: a pointer to the Smack label to use in the blob
66 * Returns the new blob or NULL if there's no memory available
68 struct inode_smack *new_inode_smack(char *smack)
70 struct inode_smack *isp;
72 isp = kzalloc(sizeof(struct inode_smack), GFP_KERNEL);
76 isp->smk_inode = smack;
78 mutex_init(&isp->smk_lock);
89 * smack_ptrace_access_check - Smack approval on PTRACE_ATTACH
90 * @ctp: child task pointer
91 * @mode: ptrace attachment mode
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_access_check(struct task_struct *ctp, unsigned int mode)
100 struct smk_audit_info ad;
103 rc = cap_ptrace_access_check(ctp, mode);
107 sp = current_security();
108 tsp = task_security(ctp);
109 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
110 smk_ad_setfield_u_tsk(&ad, ctp);
112 /* we won't log here, because rc can be overriden */
113 rc = smk_access(sp, tsp, MAY_READWRITE, NULL);
114 if (rc != 0 && capable(CAP_MAC_OVERRIDE))
117 smack_log(sp, tsp, MAY_READWRITE, rc, &ad);
122 * smack_ptrace_traceme - Smack approval on PTRACE_TRACEME
123 * @ptp: parent task pointer
125 * Returns 0 if access is OK, an error code otherwise
127 * Do the capability checks, and require read and write.
129 static int smack_ptrace_traceme(struct task_struct *ptp)
132 struct smk_audit_info ad;
135 rc = cap_ptrace_traceme(ptp);
139 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
140 smk_ad_setfield_u_tsk(&ad, ptp);
142 sp = current_security();
143 tsp = task_security(ptp);
144 /* we won't log here, because rc can be overriden */
145 rc = smk_access(tsp, sp, MAY_READWRITE, NULL);
146 if (rc != 0 && has_capability(ptp, CAP_MAC_OVERRIDE))
149 smack_log(tsp, sp, MAY_READWRITE, rc, &ad);
154 * smack_syslog - Smack approval on syslog
155 * @type: message type
157 * Require that the task has the floor label
159 * Returns 0 on success, error code otherwise.
161 static int smack_syslog(int type, bool from_file)
164 char *sp = current_security();
166 rc = cap_syslog(type, from_file);
170 if (capable(CAP_MAC_OVERRIDE))
173 if (sp != smack_known_floor.smk_known)
185 * smack_sb_alloc_security - allocate a superblock blob
186 * @sb: the superblock getting the blob
188 * Returns 0 on success or -ENOMEM on error.
190 static int smack_sb_alloc_security(struct super_block *sb)
192 struct superblock_smack *sbsp;
194 sbsp = kzalloc(sizeof(struct superblock_smack), GFP_KERNEL);
199 sbsp->smk_root = smack_known_floor.smk_known;
200 sbsp->smk_default = smack_known_floor.smk_known;
201 sbsp->smk_floor = smack_known_floor.smk_known;
202 sbsp->smk_hat = smack_known_hat.smk_known;
203 sbsp->smk_initialized = 0;
204 spin_lock_init(&sbsp->smk_sblock);
206 sb->s_security = sbsp;
212 * smack_sb_free_security - free a superblock blob
213 * @sb: the superblock getting the blob
216 static void smack_sb_free_security(struct super_block *sb)
218 kfree(sb->s_security);
219 sb->s_security = NULL;
223 * smack_sb_copy_data - copy mount options data for processing
224 * @orig: where to start
225 * @smackopts: mount options string
227 * Returns 0 on success or -ENOMEM on error.
229 * Copy the Smack specific mount options out of the mount
232 static int smack_sb_copy_data(char *orig, char *smackopts)
234 char *cp, *commap, *otheropts, *dp;
236 otheropts = (char *)get_zeroed_page(GFP_KERNEL);
237 if (otheropts == NULL)
240 for (cp = orig, commap = orig; commap != NULL; cp = commap + 1) {
241 if (strstr(cp, SMK_FSDEFAULT) == cp)
243 else if (strstr(cp, SMK_FSFLOOR) == cp)
245 else if (strstr(cp, SMK_FSHAT) == cp)
247 else if (strstr(cp, SMK_FSROOT) == cp)
252 commap = strchr(cp, ',');
261 strcpy(orig, otheropts);
262 free_page((unsigned long)otheropts);
268 * smack_sb_kern_mount - Smack specific mount processing
269 * @sb: the file system superblock
270 * @flags: the mount flags
271 * @data: the smack mount options
273 * Returns 0 on success, an error code on failure
275 static int smack_sb_kern_mount(struct super_block *sb, int flags, void *data)
277 struct dentry *root = sb->s_root;
278 struct inode *inode = root->d_inode;
279 struct superblock_smack *sp = sb->s_security;
280 struct inode_smack *isp;
285 spin_lock(&sp->smk_sblock);
286 if (sp->smk_initialized != 0) {
287 spin_unlock(&sp->smk_sblock);
290 sp->smk_initialized = 1;
291 spin_unlock(&sp->smk_sblock);
293 for (op = data; op != NULL; op = commap) {
294 commap = strchr(op, ',');
298 if (strncmp(op, SMK_FSHAT, strlen(SMK_FSHAT)) == 0) {
299 op += strlen(SMK_FSHAT);
300 nsp = smk_import(op, 0);
303 } else if (strncmp(op, SMK_FSFLOOR, strlen(SMK_FSFLOOR)) == 0) {
304 op += strlen(SMK_FSFLOOR);
305 nsp = smk_import(op, 0);
308 } else if (strncmp(op, SMK_FSDEFAULT,
309 strlen(SMK_FSDEFAULT)) == 0) {
310 op += strlen(SMK_FSDEFAULT);
311 nsp = smk_import(op, 0);
313 sp->smk_default = nsp;
314 } else if (strncmp(op, SMK_FSROOT, strlen(SMK_FSROOT)) == 0) {
315 op += strlen(SMK_FSROOT);
316 nsp = smk_import(op, 0);
323 * Initialize the root inode.
325 isp = inode->i_security;
327 inode->i_security = new_inode_smack(sp->smk_root);
329 isp->smk_inode = sp->smk_root;
335 * smack_sb_statfs - Smack check on statfs
336 * @dentry: identifies the file system in question
338 * Returns 0 if current can read the floor of the filesystem,
339 * and error code otherwise
341 static int smack_sb_statfs(struct dentry *dentry)
343 struct superblock_smack *sbp = dentry->d_sb->s_security;
345 struct smk_audit_info ad;
347 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
348 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
350 rc = smk_curacc(sbp->smk_floor, MAY_READ, &ad);
355 * smack_sb_mount - Smack check for mounting
362 * Returns 0 if current can write the floor of the filesystem
363 * being mounted on, an error code otherwise.
365 static int smack_sb_mount(char *dev_name, struct path *path,
366 char *type, unsigned long flags, void *data)
368 struct superblock_smack *sbp = path->mnt->mnt_sb->s_security;
369 struct smk_audit_info ad;
371 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
372 smk_ad_setfield_u_fs_path(&ad, *path);
374 return smk_curacc(sbp->smk_floor, MAY_WRITE, &ad);
378 * smack_sb_umount - Smack check for unmounting
379 * @mnt: file system to unmount
382 * Returns 0 if current can write the floor of the filesystem
383 * being unmounted, an error code otherwise.
385 static int smack_sb_umount(struct vfsmount *mnt, int flags)
387 struct superblock_smack *sbp;
388 struct smk_audit_info ad;
390 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
391 smk_ad_setfield_u_fs_path_dentry(&ad, mnt->mnt_root);
392 smk_ad_setfield_u_fs_path_mnt(&ad, mnt);
394 sbp = mnt->mnt_sb->s_security;
395 return smk_curacc(sbp->smk_floor, MAY_WRITE, &ad);
403 * smack_inode_alloc_security - allocate an inode blob
404 * @inode: the inode in need of a blob
406 * Returns 0 if it gets a blob, -ENOMEM otherwise
408 static int smack_inode_alloc_security(struct inode *inode)
410 inode->i_security = new_inode_smack(current_security());
411 if (inode->i_security == NULL)
417 * smack_inode_free_security - free an inode blob
418 * @inode: the inode with a blob
420 * Clears the blob pointer in inode
422 static void smack_inode_free_security(struct inode *inode)
424 kfree(inode->i_security);
425 inode->i_security = NULL;
429 * smack_inode_init_security - copy out the smack from an inode
432 * @name: where to put the attribute name
433 * @value: where to put the attribute value
434 * @len: where to put the length of the attribute
436 * Returns 0 if it all works out, -ENOMEM if there's no memory
438 static int smack_inode_init_security(struct inode *inode, struct inode *dir,
439 char **name, void **value, size_t *len)
441 char *isp = smk_of_inode(inode);
444 *name = kstrdup(XATTR_SMACK_SUFFIX, GFP_KERNEL);
450 *value = kstrdup(isp, GFP_KERNEL);
456 *len = strlen(isp) + 1;
462 * smack_inode_link - Smack check on link
463 * @old_dentry: the existing object
465 * @new_dentry: the new object
467 * Returns 0 if access is permitted, an error code otherwise
469 static int smack_inode_link(struct dentry *old_dentry, struct inode *dir,
470 struct dentry *new_dentry)
473 struct smk_audit_info ad;
476 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
477 smk_ad_setfield_u_fs_path_dentry(&ad, old_dentry);
479 isp = smk_of_inode(old_dentry->d_inode);
480 rc = smk_curacc(isp, MAY_WRITE, &ad);
482 if (rc == 0 && new_dentry->d_inode != NULL) {
483 isp = smk_of_inode(new_dentry->d_inode);
484 smk_ad_setfield_u_fs_path_dentry(&ad, new_dentry);
485 rc = smk_curacc(isp, MAY_WRITE, &ad);
492 * smack_inode_unlink - Smack check on inode deletion
493 * @dir: containing directory object
494 * @dentry: file to unlink
496 * Returns 0 if current can write the containing directory
497 * and the object, error code otherwise
499 static int smack_inode_unlink(struct inode *dir, struct dentry *dentry)
501 struct inode *ip = dentry->d_inode;
502 struct smk_audit_info ad;
505 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
506 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
509 * You need write access to the thing you're unlinking
511 rc = smk_curacc(smk_of_inode(ip), MAY_WRITE, &ad);
514 * You also need write access to the containing directory
516 smk_ad_setfield_u_fs_path_dentry(&ad, NULL);
517 smk_ad_setfield_u_fs_inode(&ad, dir);
518 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE, &ad);
524 * smack_inode_rmdir - Smack check on directory deletion
525 * @dir: containing directory object
526 * @dentry: directory to unlink
528 * Returns 0 if current can write the containing directory
529 * and the directory, error code otherwise
531 static int smack_inode_rmdir(struct inode *dir, struct dentry *dentry)
533 struct smk_audit_info ad;
536 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
537 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
540 * You need write access to the thing you're removing
542 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
545 * You also need write access to the containing directory
547 smk_ad_setfield_u_fs_path_dentry(&ad, NULL);
548 smk_ad_setfield_u_fs_inode(&ad, dir);
549 rc = smk_curacc(smk_of_inode(dir), MAY_WRITE, &ad);
556 * smack_inode_rename - Smack check on rename
557 * @old_inode: the old directory
558 * @old_dentry: unused
559 * @new_inode: the new directory
560 * @new_dentry: unused
562 * Read and write access is required on both the old and
565 * Returns 0 if access is permitted, an error code otherwise
567 static int smack_inode_rename(struct inode *old_inode,
568 struct dentry *old_dentry,
569 struct inode *new_inode,
570 struct dentry *new_dentry)
574 struct smk_audit_info ad;
576 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
577 smk_ad_setfield_u_fs_path_dentry(&ad, old_dentry);
579 isp = smk_of_inode(old_dentry->d_inode);
580 rc = smk_curacc(isp, MAY_READWRITE, &ad);
582 if (rc == 0 && new_dentry->d_inode != NULL) {
583 isp = smk_of_inode(new_dentry->d_inode);
584 smk_ad_setfield_u_fs_path_dentry(&ad, new_dentry);
585 rc = smk_curacc(isp, MAY_READWRITE, &ad);
591 * smack_inode_permission - Smack version of permission()
592 * @inode: the inode in question
593 * @mask: the access requested
595 * This is the important Smack hook.
597 * Returns 0 if access is permitted, -EACCES otherwise
599 static int smack_inode_permission(struct inode *inode, int mask)
601 struct smk_audit_info ad;
603 * No permission to check. Existence test. Yup, it's there.
607 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
608 smk_ad_setfield_u_fs_inode(&ad, inode);
609 return smk_curacc(smk_of_inode(inode), mask, &ad);
613 * smack_inode_setattr - Smack check for setting attributes
614 * @dentry: the object
615 * @iattr: for the force flag
617 * Returns 0 if access is permitted, an error code otherwise
619 static int smack_inode_setattr(struct dentry *dentry, struct iattr *iattr)
621 struct smk_audit_info ad;
623 * Need to allow for clearing the setuid bit.
625 if (iattr->ia_valid & ATTR_FORCE)
627 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
628 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
630 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
634 * smack_inode_getattr - Smack check for getting attributes
636 * @dentry: the object
638 * Returns 0 if access is permitted, an error code otherwise
640 static int smack_inode_getattr(struct vfsmount *mnt, struct dentry *dentry)
642 struct smk_audit_info ad;
644 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
645 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
646 smk_ad_setfield_u_fs_path_mnt(&ad, mnt);
647 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ, &ad);
651 * smack_inode_setxattr - Smack check for setting xattrs
652 * @dentry: the object
653 * @name: name of the attribute
658 * This protects the Smack attribute explicitly.
660 * Returns 0 if access is permitted, an error code otherwise
662 static int smack_inode_setxattr(struct dentry *dentry, const char *name,
663 const void *value, size_t size, int flags)
665 struct smk_audit_info ad;
668 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
669 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
670 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0) {
671 if (!capable(CAP_MAC_ADMIN))
674 * check label validity here so import wont fail on
677 if (size == 0 || size >= SMK_LABELLEN ||
678 smk_import(value, size) == NULL)
681 rc = cap_inode_setxattr(dentry, name, value, size, flags);
683 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
684 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
687 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
693 * smack_inode_post_setxattr - Apply the Smack update approved above
695 * @name: attribute name
696 * @value: attribute value
697 * @size: attribute size
700 * Set the pointer in the inode blob to the entry found
701 * in the master label list.
703 static void smack_inode_post_setxattr(struct dentry *dentry, const char *name,
704 const void *value, size_t size, int flags)
706 struct inode_smack *isp;
712 if (strcmp(name, XATTR_NAME_SMACK))
715 isp = dentry->d_inode->i_security;
718 * No locking is done here. This is a pointer
721 nsp = smk_import(value, size);
723 isp->smk_inode = nsp;
725 isp->smk_inode = smack_known_invalid.smk_known;
731 * smack_inode_getxattr - Smack check on getxattr
732 * @dentry: the object
735 * Returns 0 if access is permitted, an error code otherwise
737 static int smack_inode_getxattr(struct dentry *dentry, const char *name)
739 struct smk_audit_info ad;
741 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
742 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
744 return smk_curacc(smk_of_inode(dentry->d_inode), MAY_READ, &ad);
748 * smack_inode_removexattr - Smack check on removexattr
749 * @dentry: the object
750 * @name: name of the attribute
752 * Removing the Smack attribute requires CAP_MAC_ADMIN
754 * Returns 0 if access is permitted, an error code otherwise
756 static int smack_inode_removexattr(struct dentry *dentry, const char *name)
758 struct smk_audit_info ad;
761 if (strcmp(name, XATTR_NAME_SMACK) == 0 ||
762 strcmp(name, XATTR_NAME_SMACKIPIN) == 0 ||
763 strcmp(name, XATTR_NAME_SMACKIPOUT) == 0) {
764 if (!capable(CAP_MAC_ADMIN))
767 rc = cap_inode_removexattr(dentry, name);
769 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
770 smk_ad_setfield_u_fs_path_dentry(&ad, dentry);
772 rc = smk_curacc(smk_of_inode(dentry->d_inode), MAY_WRITE, &ad);
778 * smack_inode_getsecurity - get smack xattrs
780 * @name: attribute name
781 * @buffer: where to put the result
784 * Returns the size of the attribute or an error code
786 static int smack_inode_getsecurity(const struct inode *inode,
787 const char *name, void **buffer,
790 struct socket_smack *ssp;
792 struct super_block *sbp;
793 struct inode *ip = (struct inode *)inode;
798 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
799 isp = smk_of_inode(inode);
800 ilen = strlen(isp) + 1;
806 * The rest of the Smack xattrs are only on sockets.
809 if (sbp->s_magic != SOCKFS_MAGIC)
813 if (sock == NULL || sock->sk == NULL)
816 ssp = sock->sk->sk_security;
818 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
820 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0)
825 ilen = strlen(isp) + 1;
836 * smack_inode_listsecurity - list the Smack attributes
838 * @buffer: where they go
839 * @buffer_size: size of buffer
841 * Returns 0 on success, -EINVAL otherwise
843 static int smack_inode_listsecurity(struct inode *inode, char *buffer,
846 int len = strlen(XATTR_NAME_SMACK);
848 if (buffer != NULL && len <= buffer_size) {
849 memcpy(buffer, XATTR_NAME_SMACK, len);
856 * smack_inode_getsecid - Extract inode's security id
857 * @inode: inode to extract the info from
858 * @secid: where result will be saved
860 static void smack_inode_getsecid(const struct inode *inode, u32 *secid)
862 struct inode_smack *isp = inode->i_security;
864 *secid = smack_to_secid(isp->smk_inode);
872 * smack_file_permission - Smack check on file operations
878 * Should access checks be done on each read or write?
879 * UNICOS and SELinux say yes.
880 * Trusted Solaris, Trusted Irix, and just about everyone else says no.
882 * I'll say no for now. Smack does not do the frequent
883 * label changing that SELinux does.
885 static int smack_file_permission(struct file *file, int mask)
891 * smack_file_alloc_security - assign a file security blob
894 * The security blob for a file is a pointer to the master
895 * label list, so no allocation is done.
899 static int smack_file_alloc_security(struct file *file)
901 file->f_security = current_security();
906 * smack_file_free_security - clear a file security blob
909 * The security blob for a file is a pointer to the master
910 * label list, so no memory is freed.
912 static void smack_file_free_security(struct file *file)
914 file->f_security = NULL;
918 * smack_file_ioctl - Smack check on ioctls
923 * Relies heavily on the correct use of the ioctl command conventions.
925 * Returns 0 if allowed, error code otherwise
927 static int smack_file_ioctl(struct file *file, unsigned int cmd,
931 struct smk_audit_info ad;
933 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
934 smk_ad_setfield_u_fs_path(&ad, file->f_path);
936 if (_IOC_DIR(cmd) & _IOC_WRITE)
937 rc = smk_curacc(file->f_security, MAY_WRITE, &ad);
939 if (rc == 0 && (_IOC_DIR(cmd) & _IOC_READ))
940 rc = smk_curacc(file->f_security, MAY_READ, &ad);
946 * smack_file_lock - Smack check on file locking
950 * Returns 0 if current has write access, error code otherwise
952 static int smack_file_lock(struct file *file, unsigned int cmd)
954 struct smk_audit_info ad;
956 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
957 smk_ad_setfield_u_fs_path_dentry(&ad, file->f_path.dentry);
958 return smk_curacc(file->f_security, MAY_WRITE, &ad);
962 * smack_file_fcntl - Smack check on fcntl
964 * @cmd: what action to check
967 * Returns 0 if current has access, error code otherwise
969 static int smack_file_fcntl(struct file *file, unsigned int cmd,
972 struct smk_audit_info ad;
975 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_FS);
976 smk_ad_setfield_u_fs_path(&ad, file->f_path);
985 rc = smk_curacc(file->f_security, MAY_READ, &ad);
993 rc = smk_curacc(file->f_security, MAY_WRITE, &ad);
996 rc = smk_curacc(file->f_security, MAY_READWRITE, &ad);
1003 * smack_file_set_fowner - set the file security blob value
1004 * @file: object in question
1007 * Further research may be required on this one.
1009 static int smack_file_set_fowner(struct file *file)
1011 file->f_security = current_security();
1016 * smack_file_send_sigiotask - Smack on sigio
1017 * @tsk: The target task
1018 * @fown: the object the signal come from
1021 * Allow a privileged task to get signals even if it shouldn't
1023 * Returns 0 if a subject with the object's smack could
1024 * write to the task, an error code otherwise.
1026 static int smack_file_send_sigiotask(struct task_struct *tsk,
1027 struct fown_struct *fown, int signum)
1031 char *tsp = tsk->cred->security;
1032 struct smk_audit_info ad;
1035 * struct fown_struct is never outside the context of a struct file
1037 file = container_of(fown, struct file, f_owner);
1038 /* we don't log here as rc can be overriden */
1039 rc = smk_access(file->f_security, tsp, MAY_WRITE, NULL);
1040 if (rc != 0 && has_capability(tsk, CAP_MAC_OVERRIDE))
1043 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1044 smk_ad_setfield_u_tsk(&ad, tsk);
1045 smack_log(file->f_security, tsp, MAY_WRITE, rc, &ad);
1050 * smack_file_receive - Smack file receive check
1053 * Returns 0 if current has access, error code otherwise
1055 static int smack_file_receive(struct file *file)
1058 struct smk_audit_info ad;
1060 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1061 smk_ad_setfield_u_fs_path(&ad, file->f_path);
1063 * This code relies on bitmasks.
1065 if (file->f_mode & FMODE_READ)
1067 if (file->f_mode & FMODE_WRITE)
1070 return smk_curacc(file->f_security, may, &ad);
1078 * smack_cred_alloc_blank - "allocate" blank task-level security credentials
1079 * @new: the new credentials
1080 * @gfp: the atomicity of any memory allocations
1082 * Prepare a blank set of credentials for modification. This must allocate all
1083 * the memory the LSM module might require such that cred_transfer() can
1084 * complete without error.
1086 static int smack_cred_alloc_blank(struct cred *cred, gfp_t gfp)
1088 cred->security = NULL;
1094 * smack_cred_free - "free" task-level security credentials
1095 * @cred: the credentials in question
1097 * Smack isn't using copies of blobs. Everyone
1098 * points to an immutable list. The blobs never go away.
1099 * There is no leak here.
1101 static void smack_cred_free(struct cred *cred)
1103 cred->security = NULL;
1107 * smack_cred_prepare - prepare new set of credentials for modification
1108 * @new: the new credentials
1109 * @old: the original credentials
1110 * @gfp: the atomicity of any memory allocations
1112 * Prepare a new set of credentials for modification.
1114 static int smack_cred_prepare(struct cred *new, const struct cred *old,
1117 new->security = old->security;
1122 * smack_cred_commit - commit new credentials
1123 * @new: the new credentials
1124 * @old: the original credentials
1126 static void smack_cred_commit(struct cred *new, const struct cred *old)
1131 * smack_cred_transfer - Transfer the old credentials to the new credentials
1132 * @new: the new credentials
1133 * @old: the original credentials
1135 * Fill in a set of blank credentials from another set of credentials.
1137 static void smack_cred_transfer(struct cred *new, const struct cred *old)
1139 new->security = old->security;
1143 * smack_kernel_act_as - Set the subjective context in a set of credentials
1144 * @new: points to the set of credentials to be modified.
1145 * @secid: specifies the security ID to be set
1147 * Set the security data for a kernel service.
1149 static int smack_kernel_act_as(struct cred *new, u32 secid)
1151 char *smack = smack_from_secid(secid);
1156 new->security = smack;
1161 * smack_kernel_create_files_as - Set the file creation label in a set of creds
1162 * @new: points to the set of credentials to be modified
1163 * @inode: points to the inode to use as a reference
1165 * Set the file creation context in a set of credentials to the same
1166 * as the objective context of the specified inode
1168 static int smack_kernel_create_files_as(struct cred *new,
1169 struct inode *inode)
1171 struct inode_smack *isp = inode->i_security;
1173 new->security = isp->smk_inode;
1178 * smk_curacc_on_task - helper to log task related access
1179 * @p: the task object
1180 * @access : the access requested
1182 * Return 0 if access is permitted
1184 static int smk_curacc_on_task(struct task_struct *p, int access)
1186 struct smk_audit_info ad;
1188 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1189 smk_ad_setfield_u_tsk(&ad, p);
1190 return smk_curacc(task_security(p), access, &ad);
1194 * smack_task_setpgid - Smack check on setting pgid
1195 * @p: the task object
1198 * Return 0 if write access is permitted
1200 static int smack_task_setpgid(struct task_struct *p, pid_t pgid)
1202 return smk_curacc_on_task(p, MAY_WRITE);
1206 * smack_task_getpgid - Smack access check for getpgid
1207 * @p: the object task
1209 * Returns 0 if current can read the object task, error code otherwise
1211 static int smack_task_getpgid(struct task_struct *p)
1213 return smk_curacc_on_task(p, MAY_READ);
1217 * smack_task_getsid - Smack access check for getsid
1218 * @p: the object task
1220 * Returns 0 if current can read the object task, error code otherwise
1222 static int smack_task_getsid(struct task_struct *p)
1224 return smk_curacc_on_task(p, MAY_READ);
1228 * smack_task_getsecid - get the secid of the task
1229 * @p: the object task
1230 * @secid: where to put the result
1232 * Sets the secid to contain a u32 version of the smack label.
1234 static void smack_task_getsecid(struct task_struct *p, u32 *secid)
1236 *secid = smack_to_secid(task_security(p));
1240 * smack_task_setnice - Smack check on setting nice
1241 * @p: the task object
1244 * Return 0 if write access is permitted
1246 static int smack_task_setnice(struct task_struct *p, int nice)
1250 rc = cap_task_setnice(p, nice);
1252 rc = smk_curacc_on_task(p, MAY_WRITE);
1257 * smack_task_setioprio - Smack check on setting ioprio
1258 * @p: the task object
1261 * Return 0 if write access is permitted
1263 static int smack_task_setioprio(struct task_struct *p, int ioprio)
1267 rc = cap_task_setioprio(p, ioprio);
1269 rc = smk_curacc_on_task(p, MAY_WRITE);
1274 * smack_task_getioprio - Smack check on reading ioprio
1275 * @p: the task object
1277 * Return 0 if read access is permitted
1279 static int smack_task_getioprio(struct task_struct *p)
1281 return smk_curacc_on_task(p, MAY_READ);
1285 * smack_task_setscheduler - Smack check on setting scheduler
1286 * @p: the task object
1290 * Return 0 if read access is permitted
1292 static int smack_task_setscheduler(struct task_struct *p, int policy,
1293 struct sched_param *lp)
1297 rc = cap_task_setscheduler(p, policy, lp);
1299 rc = smk_curacc_on_task(p, MAY_WRITE);
1304 * smack_task_getscheduler - Smack check on reading scheduler
1305 * @p: the task object
1307 * Return 0 if read access is permitted
1309 static int smack_task_getscheduler(struct task_struct *p)
1311 return smk_curacc_on_task(p, MAY_READ);
1315 * smack_task_movememory - Smack check on moving memory
1316 * @p: the task object
1318 * Return 0 if write access is permitted
1320 static int smack_task_movememory(struct task_struct *p)
1322 return smk_curacc_on_task(p, MAY_WRITE);
1326 * smack_task_kill - Smack check on signal delivery
1327 * @p: the task object
1330 * @secid: identifies the smack to use in lieu of current's
1332 * Return 0 if write access is permitted
1334 * The secid behavior is an artifact of an SELinux hack
1335 * in the USB code. Someday it may go away.
1337 static int smack_task_kill(struct task_struct *p, struct siginfo *info,
1340 struct smk_audit_info ad;
1342 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1343 smk_ad_setfield_u_tsk(&ad, p);
1345 * Sending a signal requires that the sender
1346 * can write the receiver.
1349 return smk_curacc(task_security(p), MAY_WRITE, &ad);
1351 * If the secid isn't 0 we're dealing with some USB IO
1352 * specific behavior. This is not clean. For one thing
1353 * we can't take privilege into account.
1355 return smk_access(smack_from_secid(secid), task_security(p),
1360 * smack_task_wait - Smack access check for waiting
1361 * @p: task to wait for
1363 * Returns 0 if current can wait for p, error code otherwise
1365 static int smack_task_wait(struct task_struct *p)
1367 struct smk_audit_info ad;
1368 char *sp = current_security();
1369 char *tsp = task_security(p);
1372 /* we don't log here, we can be overriden */
1373 rc = smk_access(sp, tsp, MAY_WRITE, NULL);
1378 * Allow the operation to succeed if either task
1379 * has privilege to perform operations that might
1380 * account for the smack labels having gotten to
1381 * be different in the first place.
1383 * This breaks the strict subject/object access
1384 * control ideal, taking the object's privilege
1385 * state into account in the decision as well as
1388 if (capable(CAP_MAC_OVERRIDE) || has_capability(p, CAP_MAC_OVERRIDE))
1390 /* we log only if we didn't get overriden */
1392 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_TASK);
1393 smk_ad_setfield_u_tsk(&ad, p);
1394 smack_log(sp, tsp, MAY_WRITE, rc, &ad);
1399 * smack_task_to_inode - copy task smack into the inode blob
1400 * @p: task to copy from
1401 * @inode: inode to copy to
1403 * Sets the smack pointer in the inode security blob
1405 static void smack_task_to_inode(struct task_struct *p, struct inode *inode)
1407 struct inode_smack *isp = inode->i_security;
1408 isp->smk_inode = task_security(p);
1416 * smack_sk_alloc_security - Allocate a socket blob
1419 * @gfp_flags: memory allocation flags
1421 * Assign Smack pointers to current
1423 * Returns 0 on success, -ENOMEM is there's no memory
1425 static int smack_sk_alloc_security(struct sock *sk, int family, gfp_t gfp_flags)
1427 char *csp = current_security();
1428 struct socket_smack *ssp;
1430 ssp = kzalloc(sizeof(struct socket_smack), gfp_flags);
1436 ssp->smk_packet[0] = '\0';
1438 sk->sk_security = ssp;
1444 * smack_sk_free_security - Free a socket blob
1447 * Clears the blob pointer
1449 static void smack_sk_free_security(struct sock *sk)
1451 kfree(sk->sk_security);
1455 * smack_host_label - check host based restrictions
1456 * @sip: the object end
1458 * looks for host based access restrictions
1460 * This version will only be appropriate for really small sets of single label
1461 * hosts. The caller is responsible for ensuring that the RCU read lock is
1462 * taken before calling this function.
1464 * Returns the label of the far end or NULL if it's not special.
1466 static char *smack_host_label(struct sockaddr_in *sip)
1468 struct smk_netlbladdr *snp;
1469 struct in_addr *siap = &sip->sin_addr;
1471 if (siap->s_addr == 0)
1474 list_for_each_entry_rcu(snp, &smk_netlbladdr_list, list)
1476 * we break after finding the first match because
1477 * the list is sorted from longest to shortest mask
1478 * so we have found the most specific match
1480 if ((&snp->smk_host.sin_addr)->s_addr ==
1481 (siap->s_addr & (&snp->smk_mask)->s_addr)) {
1482 /* we have found the special CIPSO option */
1483 if (snp->smk_label == smack_cipso_option)
1485 return snp->smk_label;
1492 * smack_set_catset - convert a capset to netlabel mls categories
1493 * @catset: the Smack categories
1494 * @sap: where to put the netlabel categories
1496 * Allocates and fills attr.mls.cat
1498 static void smack_set_catset(char *catset, struct netlbl_lsm_secattr *sap)
1509 sap->flags |= NETLBL_SECATTR_MLS_CAT;
1510 sap->attr.mls.cat = netlbl_secattr_catmap_alloc(GFP_ATOMIC);
1511 sap->attr.mls.cat->startbit = 0;
1513 for (cat = 1, cp = catset, byte = 0; byte < SMK_LABELLEN; cp++, byte++)
1514 for (m = 0x80; m != 0; m >>= 1, cat++) {
1517 rc = netlbl_secattr_catmap_setbit(sap->attr.mls.cat,
1523 * smack_to_secattr - fill a secattr from a smack value
1524 * @smack: the smack value
1525 * @nlsp: where the result goes
1527 * Casey says that CIPSO is good enough for now.
1528 * It can be used to effect.
1529 * It can also be abused to effect when necessary.
1530 * Appologies to the TSIG group in general and GW in particular.
1532 static void smack_to_secattr(char *smack, struct netlbl_lsm_secattr *nlsp)
1534 struct smack_cipso cipso;
1537 nlsp->domain = smack;
1538 nlsp->flags = NETLBL_SECATTR_DOMAIN | NETLBL_SECATTR_MLS_LVL;
1540 rc = smack_to_cipso(smack, &cipso);
1542 nlsp->attr.mls.lvl = cipso.smk_level;
1543 smack_set_catset(cipso.smk_catset, nlsp);
1545 nlsp->attr.mls.lvl = smack_cipso_direct;
1546 smack_set_catset(smack, nlsp);
1551 * smack_netlabel - Set the secattr on a socket
1553 * @labeled: socket label scheme
1555 * Convert the outbound smack value (smk_out) to a
1556 * secattr and attach it to the socket.
1558 * Returns 0 on success or an error code
1560 static int smack_netlabel(struct sock *sk, int labeled)
1562 struct socket_smack *ssp = sk->sk_security;
1563 struct netlbl_lsm_secattr secattr;
1567 * Usually the netlabel code will handle changing the
1568 * packet labeling based on the label.
1569 * The case of a single label host is different, because
1570 * a single label host should never get a labeled packet
1571 * even though the label is usually associated with a packet
1575 bh_lock_sock_nested(sk);
1577 if (ssp->smk_out == smack_net_ambient ||
1578 labeled == SMACK_UNLABELED_SOCKET)
1579 netlbl_sock_delattr(sk);
1581 netlbl_secattr_init(&secattr);
1582 smack_to_secattr(ssp->smk_out, &secattr);
1583 rc = netlbl_sock_setattr(sk, sk->sk_family, &secattr);
1584 netlbl_secattr_destroy(&secattr);
1594 * smack_netlbel_send - Set the secattr on a socket and perform access checks
1596 * @sap: the destination address
1598 * Set the correct secattr for the given socket based on the destination
1599 * address and perform any outbound access checks needed.
1601 * Returns 0 on success or an error code.
1604 static int smack_netlabel_send(struct sock *sk, struct sockaddr_in *sap)
1609 struct socket_smack *ssp = sk->sk_security;
1610 struct smk_audit_info ad;
1613 hostsp = smack_host_label(sap);
1614 if (hostsp != NULL) {
1615 sk_lbl = SMACK_UNLABELED_SOCKET;
1617 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
1618 ad.a.u.net.family = sap->sin_family;
1619 ad.a.u.net.dport = sap->sin_port;
1620 ad.a.u.net.v4info.daddr = sap->sin_addr.s_addr;
1622 rc = smk_access(ssp->smk_out, hostsp, MAY_WRITE, &ad);
1624 sk_lbl = SMACK_CIPSO_SOCKET;
1631 return smack_netlabel(sk, sk_lbl);
1635 * smack_inode_setsecurity - set smack xattrs
1636 * @inode: the object
1637 * @name: attribute name
1638 * @value: attribute value
1639 * @size: size of the attribute
1642 * Sets the named attribute in the appropriate blob
1644 * Returns 0 on success, or an error code
1646 static int smack_inode_setsecurity(struct inode *inode, const char *name,
1647 const void *value, size_t size, int flags)
1650 struct inode_smack *nsp = inode->i_security;
1651 struct socket_smack *ssp;
1652 struct socket *sock;
1655 if (value == NULL || size > SMK_LABELLEN || size == 0)
1658 sp = smk_import(value, size);
1662 if (strcmp(name, XATTR_SMACK_SUFFIX) == 0) {
1663 nsp->smk_inode = sp;
1664 nsp->smk_flags |= SMK_INODE_INSTANT;
1668 * The rest of the Smack xattrs are only on sockets.
1670 if (inode->i_sb->s_magic != SOCKFS_MAGIC)
1673 sock = SOCKET_I(inode);
1674 if (sock == NULL || sock->sk == NULL)
1677 ssp = sock->sk->sk_security;
1679 if (strcmp(name, XATTR_SMACK_IPIN) == 0)
1681 else if (strcmp(name, XATTR_SMACK_IPOUT) == 0) {
1683 rc = smack_netlabel(sock->sk, SMACK_CIPSO_SOCKET);
1685 printk(KERN_WARNING "Smack: \"%s\" netlbl error %d.\n",
1694 * smack_socket_post_create - finish socket setup
1696 * @family: protocol family
1701 * Sets the netlabel information on the socket
1703 * Returns 0 on success, and error code otherwise
1705 static int smack_socket_post_create(struct socket *sock, int family,
1706 int type, int protocol, int kern)
1708 if (family != PF_INET || sock->sk == NULL)
1711 * Set the outbound netlbl.
1713 return smack_netlabel(sock->sk, SMACK_CIPSO_SOCKET);
1717 * smack_socket_connect - connect access check
1719 * @sap: the other end
1720 * @addrlen: size of sap
1722 * Verifies that a connection may be possible
1724 * Returns 0 on success, and error code otherwise
1726 static int smack_socket_connect(struct socket *sock, struct sockaddr *sap,
1729 if (sock->sk == NULL || sock->sk->sk_family != PF_INET)
1731 if (addrlen < sizeof(struct sockaddr_in))
1734 return smack_netlabel_send(sock->sk, (struct sockaddr_in *)sap);
1738 * smack_flags_to_may - convert S_ to MAY_ values
1739 * @flags: the S_ value
1741 * Returns the equivalent MAY_ value
1743 static int smack_flags_to_may(int flags)
1747 if (flags & S_IRUGO)
1749 if (flags & S_IWUGO)
1751 if (flags & S_IXUGO)
1758 * smack_msg_msg_alloc_security - Set the security blob for msg_msg
1763 static int smack_msg_msg_alloc_security(struct msg_msg *msg)
1765 msg->security = current_security();
1770 * smack_msg_msg_free_security - Clear the security blob for msg_msg
1773 * Clears the blob pointer
1775 static void smack_msg_msg_free_security(struct msg_msg *msg)
1777 msg->security = NULL;
1781 * smack_of_shm - the smack pointer for the shm
1784 * Returns a pointer to the smack value
1786 static char *smack_of_shm(struct shmid_kernel *shp)
1788 return (char *)shp->shm_perm.security;
1792 * smack_shm_alloc_security - Set the security blob for shm
1797 static int smack_shm_alloc_security(struct shmid_kernel *shp)
1799 struct kern_ipc_perm *isp = &shp->shm_perm;
1801 isp->security = current_security();
1806 * smack_shm_free_security - Clear the security blob for shm
1809 * Clears the blob pointer
1811 static void smack_shm_free_security(struct shmid_kernel *shp)
1813 struct kern_ipc_perm *isp = &shp->shm_perm;
1815 isp->security = NULL;
1819 * smk_curacc_shm : check if current has access on shm
1821 * @access : access requested
1823 * Returns 0 if current has the requested access, error code otherwise
1825 static int smk_curacc_shm(struct shmid_kernel *shp, int access)
1827 char *ssp = smack_of_shm(shp);
1828 struct smk_audit_info ad;
1831 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
1832 ad.a.u.ipc_id = shp->shm_perm.id;
1834 return smk_curacc(ssp, access, &ad);
1838 * smack_shm_associate - Smack access check for shm
1840 * @shmflg: access requested
1842 * Returns 0 if current has the requested access, error code otherwise
1844 static int smack_shm_associate(struct shmid_kernel *shp, int shmflg)
1848 may = smack_flags_to_may(shmflg);
1849 return smk_curacc_shm(shp, may);
1853 * smack_shm_shmctl - Smack access check for shm
1855 * @cmd: what it wants to do
1857 * Returns 0 if current has the requested access, error code otherwise
1859 static int smack_shm_shmctl(struct shmid_kernel *shp, int cmd)
1872 may = MAY_READWRITE;
1877 * System level information.
1883 return smk_curacc_shm(shp, may);
1887 * smack_shm_shmat - Smack access for shmat
1890 * @shmflg: access requested
1892 * Returns 0 if current has the requested access, error code otherwise
1894 static int smack_shm_shmat(struct shmid_kernel *shp, char __user *shmaddr,
1899 may = smack_flags_to_may(shmflg);
1900 return smk_curacc_shm(shp, may);
1904 * smack_of_sem - the smack pointer for the sem
1907 * Returns a pointer to the smack value
1909 static char *smack_of_sem(struct sem_array *sma)
1911 return (char *)sma->sem_perm.security;
1915 * smack_sem_alloc_security - Set the security blob for sem
1920 static int smack_sem_alloc_security(struct sem_array *sma)
1922 struct kern_ipc_perm *isp = &sma->sem_perm;
1924 isp->security = current_security();
1929 * smack_sem_free_security - Clear the security blob for sem
1932 * Clears the blob pointer
1934 static void smack_sem_free_security(struct sem_array *sma)
1936 struct kern_ipc_perm *isp = &sma->sem_perm;
1938 isp->security = NULL;
1942 * smk_curacc_sem : check if current has access on sem
1944 * @access : access requested
1946 * Returns 0 if current has the requested access, error code otherwise
1948 static int smk_curacc_sem(struct sem_array *sma, int access)
1950 char *ssp = smack_of_sem(sma);
1951 struct smk_audit_info ad;
1954 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
1955 ad.a.u.ipc_id = sma->sem_perm.id;
1957 return smk_curacc(ssp, access, &ad);
1961 * smack_sem_associate - Smack access check for sem
1963 * @semflg: access requested
1965 * Returns 0 if current has the requested access, error code otherwise
1967 static int smack_sem_associate(struct sem_array *sma, int semflg)
1971 may = smack_flags_to_may(semflg);
1972 return smk_curacc_sem(sma, may);
1976 * smack_sem_shmctl - Smack access check for sem
1978 * @cmd: what it wants to do
1980 * Returns 0 if current has the requested access, error code otherwise
1982 static int smack_sem_semctl(struct sem_array *sma, int cmd)
2000 may = MAY_READWRITE;
2005 * System level information
2012 return smk_curacc_sem(sma, may);
2016 * smack_sem_semop - Smack checks of semaphore operations
2022 * Treated as read and write in all cases.
2024 * Returns 0 if access is allowed, error code otherwise
2026 static int smack_sem_semop(struct sem_array *sma, struct sembuf *sops,
2027 unsigned nsops, int alter)
2029 return smk_curacc_sem(sma, MAY_READWRITE);
2033 * smack_msg_alloc_security - Set the security blob for msg
2038 static int smack_msg_queue_alloc_security(struct msg_queue *msq)
2040 struct kern_ipc_perm *kisp = &msq->q_perm;
2042 kisp->security = current_security();
2047 * smack_msg_free_security - Clear the security blob for msg
2050 * Clears the blob pointer
2052 static void smack_msg_queue_free_security(struct msg_queue *msq)
2054 struct kern_ipc_perm *kisp = &msq->q_perm;
2056 kisp->security = NULL;
2060 * smack_of_msq - the smack pointer for the msq
2063 * Returns a pointer to the smack value
2065 static char *smack_of_msq(struct msg_queue *msq)
2067 return (char *)msq->q_perm.security;
2071 * smk_curacc_msq : helper to check if current has access on msq
2073 * @access : access requested
2075 * return 0 if current has access, error otherwise
2077 static int smk_curacc_msq(struct msg_queue *msq, int access)
2079 char *msp = smack_of_msq(msq);
2080 struct smk_audit_info ad;
2083 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2084 ad.a.u.ipc_id = msq->q_perm.id;
2086 return smk_curacc(msp, access, &ad);
2090 * smack_msg_queue_associate - Smack access check for msg_queue
2092 * @msqflg: access requested
2094 * Returns 0 if current has the requested access, error code otherwise
2096 static int smack_msg_queue_associate(struct msg_queue *msq, int msqflg)
2100 may = smack_flags_to_may(msqflg);
2101 return smk_curacc_msq(msq, may);
2105 * smack_msg_queue_msgctl - Smack access check for msg_queue
2107 * @cmd: what it wants to do
2109 * Returns 0 if current has the requested access, error code otherwise
2111 static int smack_msg_queue_msgctl(struct msg_queue *msq, int cmd)
2122 may = MAY_READWRITE;
2127 * System level information
2134 return smk_curacc_msq(msq, may);
2138 * smack_msg_queue_msgsnd - Smack access check for msg_queue
2141 * @msqflg: access requested
2143 * Returns 0 if current has the requested access, error code otherwise
2145 static int smack_msg_queue_msgsnd(struct msg_queue *msq, struct msg_msg *msg,
2150 may = smack_flags_to_may(msqflg);
2151 return smk_curacc_msq(msq, may);
2155 * smack_msg_queue_msgsnd - Smack access check for msg_queue
2162 * Returns 0 if current has read and write access, error code otherwise
2164 static int smack_msg_queue_msgrcv(struct msg_queue *msq, struct msg_msg *msg,
2165 struct task_struct *target, long type, int mode)
2167 return smk_curacc_msq(msq, MAY_READWRITE);
2171 * smack_ipc_permission - Smack access for ipc_permission()
2172 * @ipp: the object permissions
2173 * @flag: access requested
2175 * Returns 0 if current has read and write access, error code otherwise
2177 static int smack_ipc_permission(struct kern_ipc_perm *ipp, short flag)
2179 char *isp = ipp->security;
2180 int may = smack_flags_to_may(flag);
2181 struct smk_audit_info ad;
2184 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_IPC);
2185 ad.a.u.ipc_id = ipp->id;
2187 return smk_curacc(isp, may, &ad);
2191 * smack_ipc_getsecid - Extract smack security id
2192 * @ipp: the object permissions
2193 * @secid: where result will be saved
2195 static void smack_ipc_getsecid(struct kern_ipc_perm *ipp, u32 *secid)
2197 char *smack = ipp->security;
2199 *secid = smack_to_secid(smack);
2203 * smack_d_instantiate - Make sure the blob is correct on an inode
2204 * @opt_dentry: unused
2205 * @inode: the object
2207 * Set the inode's security blob if it hasn't been done already.
2209 static void smack_d_instantiate(struct dentry *opt_dentry, struct inode *inode)
2211 struct super_block *sbp;
2212 struct superblock_smack *sbsp;
2213 struct inode_smack *isp;
2214 char *csp = current_security();
2222 isp = inode->i_security;
2224 mutex_lock(&isp->smk_lock);
2226 * If the inode is already instantiated
2227 * take the quick way out
2229 if (isp->smk_flags & SMK_INODE_INSTANT)
2233 sbsp = sbp->s_security;
2235 * We're going to use the superblock default label
2236 * if there's no label on the file.
2238 final = sbsp->smk_default;
2241 * If this is the root inode the superblock
2242 * may be in the process of initialization.
2243 * If that is the case use the root value out
2244 * of the superblock.
2246 if (opt_dentry->d_parent == opt_dentry) {
2247 isp->smk_inode = sbsp->smk_root;
2248 isp->smk_flags |= SMK_INODE_INSTANT;
2253 * This is pretty hackish.
2254 * Casey says that we shouldn't have to do
2255 * file system specific code, but it does help
2256 * with keeping it simple.
2258 switch (sbp->s_magic) {
2261 * Casey says that it's a little embarassing
2262 * that the smack file system doesn't do
2263 * extended attributes.
2265 final = smack_known_star.smk_known;
2269 * Casey says pipes are easy (?)
2271 final = smack_known_star.smk_known;
2273 case DEVPTS_SUPER_MAGIC:
2275 * devpts seems content with the label of the task.
2276 * Programs that change smack have to treat the
2283 * Casey says sockets get the smack of the task.
2287 case PROC_SUPER_MAGIC:
2289 * Casey says procfs appears not to care.
2290 * The superblock default suffices.
2295 * Device labels should come from the filesystem,
2296 * but watch out, because they're volitile,
2297 * getting recreated on every reboot.
2299 final = smack_known_star.smk_known;
2303 * If a smack value has been set we want to use it,
2304 * but since tmpfs isn't giving us the opportunity
2305 * to set mount options simulate setting the
2306 * superblock default.
2310 * This isn't an understood special case.
2311 * Get the value from the xattr.
2313 * No xattr support means, alas, no SMACK label.
2314 * Use the aforeapplied default.
2315 * It would be curious if the label of the task
2316 * does not match that assigned.
2318 if (inode->i_op->getxattr == NULL)
2321 * Get the dentry for xattr.
2323 if (opt_dentry == NULL) {
2324 dp = d_find_alias(inode);
2328 dp = dget(opt_dentry);
2333 fetched = smk_fetch(inode, dp);
2334 if (fetched != NULL)
2342 isp->smk_inode = csp;
2344 isp->smk_inode = final;
2346 isp->smk_flags |= SMK_INODE_INSTANT;
2349 mutex_unlock(&isp->smk_lock);
2354 * smack_getprocattr - Smack process attribute access
2355 * @p: the object task
2356 * @name: the name of the attribute in /proc/.../attr
2357 * @value: where to put the result
2359 * Places a copy of the task Smack into value
2361 * Returns the length of the smack label or an error code
2363 static int smack_getprocattr(struct task_struct *p, char *name, char **value)
2368 if (strcmp(name, "current") != 0)
2371 cp = kstrdup(task_security(p), GFP_KERNEL);
2381 * smack_setprocattr - Smack process attribute setting
2382 * @p: the object task
2383 * @name: the name of the attribute in /proc/.../attr
2384 * @value: the value to set
2385 * @size: the size of the value
2387 * Sets the Smack value of the task. Only setting self
2388 * is permitted and only with privilege
2390 * Returns the length of the smack label or an error code
2392 static int smack_setprocattr(struct task_struct *p, char *name,
2393 void *value, size_t size)
2399 * Changing another process' Smack value is too dangerous
2400 * and supports no sane use case.
2405 if (!capable(CAP_MAC_ADMIN))
2408 if (value == NULL || size == 0 || size >= SMK_LABELLEN)
2411 if (strcmp(name, "current") != 0)
2414 newsmack = smk_import(value, size);
2415 if (newsmack == NULL)
2419 * No process is ever allowed the web ("@") label.
2421 if (newsmack == smack_known_web.smk_known)
2424 new = prepare_creds();
2427 new->security = newsmack;
2433 * smack_unix_stream_connect - Smack access on UDS
2435 * @other: the other socket
2438 * Return 0 if a subject with the smack of sock could access
2439 * an object with the smack of other, otherwise an error code
2441 static int smack_unix_stream_connect(struct socket *sock,
2442 struct socket *other, struct sock *newsk)
2444 struct inode *sp = SOCK_INODE(sock);
2445 struct inode *op = SOCK_INODE(other);
2446 struct smk_audit_info ad;
2448 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2449 smk_ad_setfield_u_net_sk(&ad, other->sk);
2450 return smk_access(smk_of_inode(sp), smk_of_inode(op),
2451 MAY_READWRITE, &ad);
2455 * smack_unix_may_send - Smack access on UDS
2457 * @other: the other socket
2459 * Return 0 if a subject with the smack of sock could access
2460 * an object with the smack of other, otherwise an error code
2462 static int smack_unix_may_send(struct socket *sock, struct socket *other)
2464 struct inode *sp = SOCK_INODE(sock);
2465 struct inode *op = SOCK_INODE(other);
2466 struct smk_audit_info ad;
2468 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2469 smk_ad_setfield_u_net_sk(&ad, other->sk);
2470 return smk_access(smk_of_inode(sp), smk_of_inode(op), MAY_WRITE, &ad);
2474 * smack_socket_sendmsg - Smack check based on destination host
2477 * @size: the size of the message
2479 * Return 0 if the current subject can write to the destination
2480 * host. This is only a question if the destination is a single
2483 static int smack_socket_sendmsg(struct socket *sock, struct msghdr *msg,
2486 struct sockaddr_in *sip = (struct sockaddr_in *) msg->msg_name;
2489 * Perfectly reasonable for this to be NULL
2491 if (sip == NULL || sip->sin_family != AF_INET)
2494 return smack_netlabel_send(sock->sk, sip);
2499 * smack_from_secattr - Convert a netlabel attr.mls.lvl/attr.mls.cat pair to smack
2500 * @sap: netlabel secattr
2501 * @sip: where to put the result
2503 * Copies a smack label into sip
2505 static void smack_from_secattr(struct netlbl_lsm_secattr *sap, char *sip)
2507 char smack[SMK_LABELLEN];
2511 if ((sap->flags & NETLBL_SECATTR_MLS_LVL) != 0) {
2513 * Looks like a CIPSO packet.
2514 * If there are flags but no level netlabel isn't
2515 * behaving the way we expect it to.
2517 * Get the categories, if any
2518 * Without guidance regarding the smack value
2519 * for the packet fall back on the network
2522 memset(smack, '\0', SMK_LABELLEN);
2523 if ((sap->flags & NETLBL_SECATTR_MLS_CAT) != 0)
2525 pcat = netlbl_secattr_catmap_walk(
2526 sap->attr.mls.cat, pcat + 1);
2529 smack_catset_bit(pcat, smack);
2532 * If it is CIPSO using smack direct mapping
2533 * we are already done. WeeHee.
2535 if (sap->attr.mls.lvl == smack_cipso_direct) {
2536 memcpy(sip, smack, SMK_MAXLEN);
2540 * Look it up in the supplied table if it is not
2543 smack_from_cipso(sap->attr.mls.lvl, smack, sip);
2546 if ((sap->flags & NETLBL_SECATTR_SECID) != 0) {
2548 * Looks like a fallback, which gives us a secid.
2550 sp = smack_from_secid(sap->attr.secid);
2552 * This has got to be a bug because it is
2553 * impossible to specify a fallback without
2554 * specifying the label, which will ensure
2555 * it has a secid, and the only way to get a
2556 * secid is from a fallback.
2559 strncpy(sip, sp, SMK_MAXLEN);
2563 * Without guidance regarding the smack value
2564 * for the packet fall back on the network
2567 strncpy(sip, smack_net_ambient, SMK_MAXLEN);
2572 * smack_socket_sock_rcv_skb - Smack packet delivery access check
2576 * Returns 0 if the packet should be delivered, an error code otherwise
2578 static int smack_socket_sock_rcv_skb(struct sock *sk, struct sk_buff *skb)
2580 struct netlbl_lsm_secattr secattr;
2581 struct socket_smack *ssp = sk->sk_security;
2582 char smack[SMK_LABELLEN];
2585 struct smk_audit_info ad;
2586 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2590 * Translate what netlabel gave us.
2592 netlbl_secattr_init(&secattr);
2594 rc = netlbl_skbuff_getattr(skb, sk->sk_family, &secattr);
2596 smack_from_secattr(&secattr, smack);
2599 csp = smack_net_ambient;
2601 netlbl_secattr_destroy(&secattr);
2604 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2605 ad.a.u.net.family = sk->sk_family;
2606 ad.a.u.net.netif = skb->skb_iif;
2607 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
2610 * Receiving a packet requires that the other end
2611 * be able to write here. Read access is not required.
2612 * This is the simplist possible security model
2615 rc = smk_access(csp, ssp->smk_in, MAY_WRITE, &ad);
2617 netlbl_skbuff_err(skb, rc, 0);
2622 * smack_socket_getpeersec_stream - pull in packet label
2624 * @optval: user's destination
2625 * @optlen: size thereof
2628 * returns zero on success, an error code otherwise
2630 static int smack_socket_getpeersec_stream(struct socket *sock,
2631 char __user *optval,
2632 int __user *optlen, unsigned len)
2634 struct socket_smack *ssp;
2638 ssp = sock->sk->sk_security;
2639 slen = strlen(ssp->smk_packet) + 1;
2643 else if (copy_to_user(optval, ssp->smk_packet, slen) != 0)
2646 if (put_user(slen, optlen) != 0)
2654 * smack_socket_getpeersec_dgram - pull in packet label
2657 * @secid: pointer to where to put the secid of the packet
2659 * Sets the netlabel socket state on sk from parent
2661 static int smack_socket_getpeersec_dgram(struct socket *sock,
2662 struct sk_buff *skb, u32 *secid)
2665 struct netlbl_lsm_secattr secattr;
2667 char smack[SMK_LABELLEN];
2668 int family = PF_INET;
2673 * Only works for families with packets.
2677 if (sk->sk_family != PF_INET && sk->sk_family != PF_INET6)
2679 family = sk->sk_family;
2682 * Translate what netlabel gave us.
2684 netlbl_secattr_init(&secattr);
2685 rc = netlbl_skbuff_getattr(skb, family, &secattr);
2687 smack_from_secattr(&secattr, smack);
2688 netlbl_secattr_destroy(&secattr);
2691 * Give up if we couldn't get anything
2696 s = smack_to_secid(smack);
2705 * smack_sock_graft - Initialize a newly created socket with an existing sock
2707 * @parent: parent socket
2709 * Set the smk_{in,out} state of an existing sock based on the process that
2710 * is creating the new socket.
2712 static void smack_sock_graft(struct sock *sk, struct socket *parent)
2714 struct socket_smack *ssp;
2717 (sk->sk_family != PF_INET && sk->sk_family != PF_INET6))
2720 ssp = sk->sk_security;
2721 ssp->smk_in = ssp->smk_out = current_security();
2722 /* cssp->smk_packet is already set in smack_inet_csk_clone() */
2726 * smack_inet_conn_request - Smack access check on connect
2727 * @sk: socket involved
2731 * Returns 0 if a task with the packet label could write to
2732 * the socket, otherwise an error code
2734 static int smack_inet_conn_request(struct sock *sk, struct sk_buff *skb,
2735 struct request_sock *req)
2737 u16 family = sk->sk_family;
2738 struct socket_smack *ssp = sk->sk_security;
2739 struct netlbl_lsm_secattr secattr;
2740 struct sockaddr_in addr;
2742 char smack[SMK_LABELLEN];
2744 struct smk_audit_info ad;
2746 /* handle mapped IPv4 packets arriving via IPv6 sockets */
2747 if (family == PF_INET6 && skb->protocol == htons(ETH_P_IP))
2750 netlbl_secattr_init(&secattr);
2751 rc = netlbl_skbuff_getattr(skb, family, &secattr);
2753 smack_from_secattr(&secattr, smack);
2755 strncpy(smack, smack_known_huh.smk_known, SMK_MAXLEN);
2756 netlbl_secattr_destroy(&secattr);
2759 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_NET);
2760 ad.a.u.net.family = family;
2761 ad.a.u.net.netif = skb->skb_iif;
2762 ipv4_skb_to_auditdata(skb, &ad.a, NULL);
2765 * Receiving a packet requires that the other end be able to write
2766 * here. Read access is not required.
2768 rc = smk_access(smack, ssp->smk_in, MAY_WRITE, &ad);
2773 * Save the peer's label in the request_sock so we can later setup
2774 * smk_packet in the child socket so that SO_PEERCRED can report it.
2776 req->peer_secid = smack_to_secid(smack);
2779 * We need to decide if we want to label the incoming connection here
2780 * if we do we only need to label the request_sock and the stack will
2781 * propogate the wire-label to the sock when it is created.
2784 addr.sin_addr.s_addr = hdr->saddr;
2786 if (smack_host_label(&addr) == NULL) {
2788 netlbl_secattr_init(&secattr);
2789 smack_to_secattr(smack, &secattr);
2790 rc = netlbl_req_setattr(req, &secattr);
2791 netlbl_secattr_destroy(&secattr);
2794 netlbl_req_delattr(req);
2801 * smack_inet_csk_clone - Copy the connection information to the new socket
2802 * @sk: the new socket
2803 * @req: the connection's request_sock
2805 * Transfer the connection's peer label to the newly created socket.
2807 static void smack_inet_csk_clone(struct sock *sk,
2808 const struct request_sock *req)
2810 struct socket_smack *ssp = sk->sk_security;
2813 if (req->peer_secid != 0) {
2814 smack = smack_from_secid(req->peer_secid);
2815 strncpy(ssp->smk_packet, smack, SMK_MAXLEN);
2817 ssp->smk_packet[0] = '\0';
2821 * Key management security hooks
2823 * Casey has not tested key support very heavily.
2824 * The permission check is most likely too restrictive.
2825 * If you care about keys please have a look.
2830 * smack_key_alloc - Set the key security blob
2832 * @cred: the credentials to use
2835 * No allocation required
2839 static int smack_key_alloc(struct key *key, const struct cred *cred,
2840 unsigned long flags)
2842 key->security = cred->security;
2847 * smack_key_free - Clear the key security blob
2850 * Clear the blob pointer
2852 static void smack_key_free(struct key *key)
2854 key->security = NULL;
2858 * smack_key_permission - Smack access on a key
2859 * @key_ref: gets to the object
2860 * @cred: the credentials to use
2863 * Return 0 if the task has read and write to the object,
2864 * an error code otherwise
2866 static int smack_key_permission(key_ref_t key_ref,
2867 const struct cred *cred, key_perm_t perm)
2870 struct smk_audit_info ad;
2872 keyp = key_ref_to_ptr(key_ref);
2876 * If the key hasn't been initialized give it access so that
2879 if (keyp->security == NULL)
2882 * This should not occur
2884 if (cred->security == NULL)
2887 smk_ad_init(&ad, __func__, LSM_AUDIT_DATA_KEY);
2888 ad.a.u.key_struct.key = keyp->serial;
2889 ad.a.u.key_struct.key_desc = keyp->description;
2891 return smk_access(cred->security, keyp->security,
2892 MAY_READWRITE, &ad);
2894 #endif /* CONFIG_KEYS */
2899 * Audit requires a unique representation of each Smack specific
2900 * rule. This unique representation is used to distinguish the
2901 * object to be audited from remaining kernel objects and also
2902 * works as a glue between the audit hooks.
2904 * Since repository entries are added but never deleted, we'll use
2905 * the smack_known label address related to the given audit rule as
2906 * the needed unique representation. This also better fits the smack
2907 * model where nearly everything is a label.
2912 * smack_audit_rule_init - Initialize a smack audit rule
2913 * @field: audit rule fields given from user-space (audit.h)
2914 * @op: required testing operator (=, !=, >, <, ...)
2915 * @rulestr: smack label to be audited
2916 * @vrule: pointer to save our own audit rule representation
2918 * Prepare to audit cases where (@field @op @rulestr) is true.
2919 * The label to be audited is created if necessay.
2921 static int smack_audit_rule_init(u32 field, u32 op, char *rulestr, void **vrule)
2923 char **rule = (char **)vrule;
2926 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
2929 if (op != Audit_equal && op != Audit_not_equal)
2932 *rule = smk_import(rulestr, 0);
2938 * smack_audit_rule_known - Distinguish Smack audit rules
2939 * @krule: rule of interest, in Audit kernel representation format
2941 * This is used to filter Smack rules from remaining Audit ones.
2942 * If it's proved that this rule belongs to us, the
2943 * audit_rule_match hook will be called to do the final judgement.
2945 static int smack_audit_rule_known(struct audit_krule *krule)
2947 struct audit_field *f;
2950 for (i = 0; i < krule->field_count; i++) {
2951 f = &krule->fields[i];
2953 if (f->type == AUDIT_SUBJ_USER || f->type == AUDIT_OBJ_USER)
2961 * smack_audit_rule_match - Audit given object ?
2962 * @secid: security id for identifying the object to test
2963 * @field: audit rule flags given from user-space
2964 * @op: required testing operator
2965 * @vrule: smack internal rule presentation
2966 * @actx: audit context associated with the check
2968 * The core Audit hook. It's used to take the decision of
2969 * whether to audit or not to audit a given object.
2971 static int smack_audit_rule_match(u32 secid, u32 field, u32 op, void *vrule,
2972 struct audit_context *actx)
2978 audit_log(actx, GFP_KERNEL, AUDIT_SELINUX_ERR,
2979 "Smack: missing rule\n");
2983 if (field != AUDIT_SUBJ_USER && field != AUDIT_OBJ_USER)
2986 smack = smack_from_secid(secid);
2989 * No need to do string comparisons. If a match occurs,
2990 * both pointers will point to the same smack_known
2993 if (op == Audit_equal)
2994 return (rule == smack);
2995 if (op == Audit_not_equal)
2996 return (rule != smack);
3002 * smack_audit_rule_free - free smack rule representation
3003 * @vrule: rule to be freed.
3005 * No memory was allocated.
3007 static void smack_audit_rule_free(void *vrule)
3012 #endif /* CONFIG_AUDIT */
3015 * smack_secid_to_secctx - return the smack label for a secid
3016 * @secid: incoming integer
3017 * @secdata: destination
3018 * @seclen: how long it is
3020 * Exists for networking code.
3022 static int smack_secid_to_secctx(u32 secid, char **secdata, u32 *seclen)
3024 char *sp = smack_from_secid(secid);
3027 *seclen = strlen(sp);
3032 * smack_secctx_to_secid - return the secid for a smack label
3033 * @secdata: smack label
3034 * @seclen: how long result is
3035 * @secid: outgoing integer
3037 * Exists for audit and networking code.
3039 static int smack_secctx_to_secid(const char *secdata, u32 seclen, u32 *secid)
3041 *secid = smack_to_secid(secdata);
3046 * smack_release_secctx - don't do anything.
3050 * Exists to make sure nothing gets done, and properly
3052 static void smack_release_secctx(char *secdata, u32 seclen)
3056 static int smack_inode_notifysecctx(struct inode *inode, void *ctx, u32 ctxlen)
3058 return smack_inode_setsecurity(inode, XATTR_SMACK_SUFFIX, ctx, ctxlen, 0);
3061 static int smack_inode_setsecctx(struct dentry *dentry, void *ctx, u32 ctxlen)
3063 return __vfs_setxattr_noperm(dentry, XATTR_NAME_SMACK, ctx, ctxlen, 0);
3066 static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
3069 len = smack_inode_getsecurity(inode, XATTR_SMACK_SUFFIX, ctx, true);
3077 struct security_operations smack_ops = {
3080 .ptrace_access_check = smack_ptrace_access_check,
3081 .ptrace_traceme = smack_ptrace_traceme,
3082 .syslog = smack_syslog,
3084 .sb_alloc_security = smack_sb_alloc_security,
3085 .sb_free_security = smack_sb_free_security,
3086 .sb_copy_data = smack_sb_copy_data,
3087 .sb_kern_mount = smack_sb_kern_mount,
3088 .sb_statfs = smack_sb_statfs,
3089 .sb_mount = smack_sb_mount,
3090 .sb_umount = smack_sb_umount,
3092 .inode_alloc_security = smack_inode_alloc_security,
3093 .inode_free_security = smack_inode_free_security,
3094 .inode_init_security = smack_inode_init_security,
3095 .inode_link = smack_inode_link,
3096 .inode_unlink = smack_inode_unlink,
3097 .inode_rmdir = smack_inode_rmdir,
3098 .inode_rename = smack_inode_rename,
3099 .inode_permission = smack_inode_permission,
3100 .inode_setattr = smack_inode_setattr,
3101 .inode_getattr = smack_inode_getattr,
3102 .inode_setxattr = smack_inode_setxattr,
3103 .inode_post_setxattr = smack_inode_post_setxattr,
3104 .inode_getxattr = smack_inode_getxattr,
3105 .inode_removexattr = smack_inode_removexattr,
3106 .inode_getsecurity = smack_inode_getsecurity,
3107 .inode_setsecurity = smack_inode_setsecurity,
3108 .inode_listsecurity = smack_inode_listsecurity,
3109 .inode_getsecid = smack_inode_getsecid,
3111 .file_permission = smack_file_permission,
3112 .file_alloc_security = smack_file_alloc_security,
3113 .file_free_security = smack_file_free_security,
3114 .file_ioctl = smack_file_ioctl,
3115 .file_lock = smack_file_lock,
3116 .file_fcntl = smack_file_fcntl,
3117 .file_set_fowner = smack_file_set_fowner,
3118 .file_send_sigiotask = smack_file_send_sigiotask,
3119 .file_receive = smack_file_receive,
3121 .cred_alloc_blank = smack_cred_alloc_blank,
3122 .cred_free = smack_cred_free,
3123 .cred_prepare = smack_cred_prepare,
3124 .cred_commit = smack_cred_commit,
3125 .cred_transfer = smack_cred_transfer,
3126 .kernel_act_as = smack_kernel_act_as,
3127 .kernel_create_files_as = smack_kernel_create_files_as,
3128 .task_setpgid = smack_task_setpgid,
3129 .task_getpgid = smack_task_getpgid,
3130 .task_getsid = smack_task_getsid,
3131 .task_getsecid = smack_task_getsecid,
3132 .task_setnice = smack_task_setnice,
3133 .task_setioprio = smack_task_setioprio,
3134 .task_getioprio = smack_task_getioprio,
3135 .task_setscheduler = smack_task_setscheduler,
3136 .task_getscheduler = smack_task_getscheduler,
3137 .task_movememory = smack_task_movememory,
3138 .task_kill = smack_task_kill,
3139 .task_wait = smack_task_wait,
3140 .task_to_inode = smack_task_to_inode,
3142 .ipc_permission = smack_ipc_permission,
3143 .ipc_getsecid = smack_ipc_getsecid,
3145 .msg_msg_alloc_security = smack_msg_msg_alloc_security,
3146 .msg_msg_free_security = smack_msg_msg_free_security,
3148 .msg_queue_alloc_security = smack_msg_queue_alloc_security,
3149 .msg_queue_free_security = smack_msg_queue_free_security,
3150 .msg_queue_associate = smack_msg_queue_associate,
3151 .msg_queue_msgctl = smack_msg_queue_msgctl,
3152 .msg_queue_msgsnd = smack_msg_queue_msgsnd,
3153 .msg_queue_msgrcv = smack_msg_queue_msgrcv,
3155 .shm_alloc_security = smack_shm_alloc_security,
3156 .shm_free_security = smack_shm_free_security,
3157 .shm_associate = smack_shm_associate,
3158 .shm_shmctl = smack_shm_shmctl,
3159 .shm_shmat = smack_shm_shmat,
3161 .sem_alloc_security = smack_sem_alloc_security,
3162 .sem_free_security = smack_sem_free_security,
3163 .sem_associate = smack_sem_associate,
3164 .sem_semctl = smack_sem_semctl,
3165 .sem_semop = smack_sem_semop,
3167 .d_instantiate = smack_d_instantiate,
3169 .getprocattr = smack_getprocattr,
3170 .setprocattr = smack_setprocattr,
3172 .unix_stream_connect = smack_unix_stream_connect,
3173 .unix_may_send = smack_unix_may_send,
3175 .socket_post_create = smack_socket_post_create,
3176 .socket_connect = smack_socket_connect,
3177 .socket_sendmsg = smack_socket_sendmsg,
3178 .socket_sock_rcv_skb = smack_socket_sock_rcv_skb,
3179 .socket_getpeersec_stream = smack_socket_getpeersec_stream,
3180 .socket_getpeersec_dgram = smack_socket_getpeersec_dgram,
3181 .sk_alloc_security = smack_sk_alloc_security,
3182 .sk_free_security = smack_sk_free_security,
3183 .sock_graft = smack_sock_graft,
3184 .inet_conn_request = smack_inet_conn_request,
3185 .inet_csk_clone = smack_inet_csk_clone,
3187 /* key management security hooks */
3189 .key_alloc = smack_key_alloc,
3190 .key_free = smack_key_free,
3191 .key_permission = smack_key_permission,
3192 #endif /* CONFIG_KEYS */
3196 .audit_rule_init = smack_audit_rule_init,
3197 .audit_rule_known = smack_audit_rule_known,
3198 .audit_rule_match = smack_audit_rule_match,
3199 .audit_rule_free = smack_audit_rule_free,
3200 #endif /* CONFIG_AUDIT */
3202 .secid_to_secctx = smack_secid_to_secctx,
3203 .secctx_to_secid = smack_secctx_to_secid,
3204 .release_secctx = smack_release_secctx,
3205 .inode_notifysecctx = smack_inode_notifysecctx,
3206 .inode_setsecctx = smack_inode_setsecctx,
3207 .inode_getsecctx = smack_inode_getsecctx,
3211 static __init void init_smack_know_list(void)
3213 list_add(&smack_known_huh.list, &smack_known_list);
3214 list_add(&smack_known_hat.list, &smack_known_list);
3215 list_add(&smack_known_star.list, &smack_known_list);
3216 list_add(&smack_known_floor.list, &smack_known_list);
3217 list_add(&smack_known_invalid.list, &smack_known_list);
3218 list_add(&smack_known_web.list, &smack_known_list);
3222 * smack_init - initialize the smack system
3226 static __init int smack_init(void)
3230 if (!security_module_enable(&smack_ops))
3233 printk(KERN_INFO "Smack: Initializing.\n");
3236 * Set the security state for the initial task.
3238 cred = (struct cred *) current->cred;
3239 cred->security = &smack_known_floor.smk_known;
3241 /* initilize the smack_know_list */
3242 init_smack_know_list();
3246 spin_lock_init(&smack_known_huh.smk_cipsolock);
3247 spin_lock_init(&smack_known_hat.smk_cipsolock);
3248 spin_lock_init(&smack_known_star.smk_cipsolock);
3249 spin_lock_init(&smack_known_floor.smk_cipsolock);
3250 spin_lock_init(&smack_known_invalid.smk_cipsolock);
3255 if (register_security(&smack_ops))
3256 panic("smack: Unable to register with kernel.\n");
3262 * Smack requires early initialization in order to label
3263 * all processes and objects when they are created.
3265 security_initcall(smack_init);