diff options
author | Mimi Zohar <zohar@linux.vnet.ibm.com> | 2009-02-04 09:06:57 -0500 |
---|---|---|
committer | James Morris <jmorris@namei.org> | 2009-02-05 17:05:30 -0500 |
commit | 6146f0d5e47ca4047ffded0fb79b6c25359b386c (patch) | |
tree | edd792e52ad56d4a5d3ac6caa8437d3283fc157e /fs | |
parent | 659aaf2bb5496a425ba14036b5b5900f593e4484 (diff) |
integrity: IMA hooks
This patch replaces the generic integrity hooks, for which IMA registered
itself, with IMA integrity hooks in the appropriate places directly
in the fs directory.
Signed-off-by: Mimi Zohar <zohar@us.ibm.com>
Acked-by: Serge Hallyn <serue@us.ibm.com>
Signed-off-by: James Morris <jmorris@namei.org>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/exec.c | 10 | ||||
-rw-r--r-- | fs/file_table.c | 2 | ||||
-rw-r--r-- | fs/inode.c | 24 | ||||
-rw-r--r-- | fs/namei.c | 8 |
4 files changed, 37 insertions, 7 deletions
@@ -45,6 +45,7 @@ | |||
45 | #include <linux/proc_fs.h> | 45 | #include <linux/proc_fs.h> |
46 | #include <linux/mount.h> | 46 | #include <linux/mount.h> |
47 | #include <linux/security.h> | 47 | #include <linux/security.h> |
48 | #include <linux/ima.h> | ||
48 | #include <linux/syscalls.h> | 49 | #include <linux/syscalls.h> |
49 | #include <linux/tsacct_kern.h> | 50 | #include <linux/tsacct_kern.h> |
50 | #include <linux/cn_proc.h> | 51 | #include <linux/cn_proc.h> |
@@ -130,6 +131,9 @@ asmlinkage long sys_uselib(const char __user * library) | |||
130 | error = vfs_permission(&nd, MAY_READ | MAY_EXEC | MAY_OPEN); | 131 | error = vfs_permission(&nd, MAY_READ | MAY_EXEC | MAY_OPEN); |
131 | if (error) | 132 | if (error) |
132 | goto exit; | 133 | goto exit; |
134 | error = ima_path_check(&nd.path, MAY_READ | MAY_EXEC | MAY_OPEN); | ||
135 | if (error) | ||
136 | goto exit; | ||
133 | 137 | ||
134 | file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE); | 138 | file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE); |
135 | error = PTR_ERR(file); | 139 | error = PTR_ERR(file); |
@@ -683,6 +687,9 @@ struct file *open_exec(const char *name) | |||
683 | err = vfs_permission(&nd, MAY_EXEC | MAY_OPEN); | 687 | err = vfs_permission(&nd, MAY_EXEC | MAY_OPEN); |
684 | if (err) | 688 | if (err) |
685 | goto out_path_put; | 689 | goto out_path_put; |
690 | err = ima_path_check(&nd.path, MAY_EXEC | MAY_OPEN); | ||
691 | if (err) | ||
692 | goto out_path_put; | ||
686 | 693 | ||
687 | file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE); | 694 | file = nameidata_to_filp(&nd, O_RDONLY|O_LARGEFILE); |
688 | if (IS_ERR(file)) | 695 | if (IS_ERR(file)) |
@@ -1209,6 +1216,9 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs) | |||
1209 | retval = security_bprm_check(bprm); | 1216 | retval = security_bprm_check(bprm); |
1210 | if (retval) | 1217 | if (retval) |
1211 | return retval; | 1218 | return retval; |
1219 | retval = ima_bprm_check(bprm); | ||
1220 | if (retval) | ||
1221 | return retval; | ||
1212 | 1222 | ||
1213 | /* kernel module loader fixup */ | 1223 | /* kernel module loader fixup */ |
1214 | /* so we don't try to load run modprobe in kernel space. */ | 1224 | /* so we don't try to load run modprobe in kernel space. */ |
diff --git a/fs/file_table.c b/fs/file_table.c index 0fbcacc3ea75..55895ccc08c6 100644 --- a/fs/file_table.c +++ b/fs/file_table.c | |||
@@ -13,6 +13,7 @@ | |||
13 | #include <linux/module.h> | 13 | #include <linux/module.h> |
14 | #include <linux/fs.h> | 14 | #include <linux/fs.h> |
15 | #include <linux/security.h> | 15 | #include <linux/security.h> |
16 | #include <linux/ima.h> | ||
16 | #include <linux/eventpoll.h> | 17 | #include <linux/eventpoll.h> |
17 | #include <linux/rcupdate.h> | 18 | #include <linux/rcupdate.h> |
18 | #include <linux/mount.h> | 19 | #include <linux/mount.h> |
@@ -276,6 +277,7 @@ void __fput(struct file *file) | |||
276 | if (file->f_op && file->f_op->release) | 277 | if (file->f_op && file->f_op->release) |
277 | file->f_op->release(inode, file); | 278 | file->f_op->release(inode, file); |
278 | security_file_free(file); | 279 | security_file_free(file); |
280 | ima_file_free(file); | ||
279 | if (unlikely(S_ISCHR(inode->i_mode) && inode->i_cdev != NULL)) | 281 | if (unlikely(S_ISCHR(inode->i_mode) && inode->i_cdev != NULL)) |
280 | cdev_put(inode->i_cdev); | 282 | cdev_put(inode->i_cdev); |
281 | fops_put(file->f_op); | 283 | fops_put(file->f_op); |
diff --git a/fs/inode.c b/fs/inode.c index 098a2443196f..ed22b14f2202 100644 --- a/fs/inode.c +++ b/fs/inode.c | |||
@@ -17,6 +17,7 @@ | |||
17 | #include <linux/hash.h> | 17 | #include <linux/hash.h> |
18 | #include <linux/swap.h> | 18 | #include <linux/swap.h> |
19 | #include <linux/security.h> | 19 | #include <linux/security.h> |
20 | #include <linux/ima.h> | ||
20 | #include <linux/pagemap.h> | 21 | #include <linux/pagemap.h> |
21 | #include <linux/cdev.h> | 22 | #include <linux/cdev.h> |
22 | #include <linux/bootmem.h> | 23 | #include <linux/bootmem.h> |
@@ -144,13 +145,13 @@ struct inode *inode_init_always(struct super_block *sb, struct inode *inode) | |||
144 | inode->i_cdev = NULL; | 145 | inode->i_cdev = NULL; |
145 | inode->i_rdev = 0; | 146 | inode->i_rdev = 0; |
146 | inode->dirtied_when = 0; | 147 | inode->dirtied_when = 0; |
147 | if (security_inode_alloc(inode)) { | 148 | |
148 | if (inode->i_sb->s_op->destroy_inode) | 149 | if (security_inode_alloc(inode)) |
149 | inode->i_sb->s_op->destroy_inode(inode); | 150 | goto out_free_inode; |
150 | else | 151 | |
151 | kmem_cache_free(inode_cachep, (inode)); | 152 | /* allocate and initialize an i_integrity */ |
152 | return NULL; | 153 | if (ima_inode_alloc(inode)) |
153 | } | 154 | goto out_free_security; |
154 | 155 | ||
155 | spin_lock_init(&inode->i_lock); | 156 | spin_lock_init(&inode->i_lock); |
156 | lockdep_set_class(&inode->i_lock, &sb->s_type->i_lock_key); | 157 | lockdep_set_class(&inode->i_lock, &sb->s_type->i_lock_key); |
@@ -186,6 +187,15 @@ struct inode *inode_init_always(struct super_block *sb, struct inode *inode) | |||
186 | inode->i_mapping = mapping; | 187 | inode->i_mapping = mapping; |
187 | 188 | ||
188 | return inode; | 189 | return inode; |
190 | |||
191 | out_free_security: | ||
192 | security_inode_free(inode); | ||
193 | out_free_inode: | ||
194 | if (inode->i_sb->s_op->destroy_inode) | ||
195 | inode->i_sb->s_op->destroy_inode(inode); | ||
196 | else | ||
197 | kmem_cache_free(inode_cachep, (inode)); | ||
198 | return NULL; | ||
189 | } | 199 | } |
190 | EXPORT_SYMBOL(inode_init_always); | 200 | EXPORT_SYMBOL(inode_init_always); |
191 | 201 | ||
diff --git a/fs/namei.c b/fs/namei.c index af3783fff1de..734f2b5591bf 100644 --- a/fs/namei.c +++ b/fs/namei.c | |||
@@ -24,6 +24,7 @@ | |||
24 | #include <linux/fsnotify.h> | 24 | #include <linux/fsnotify.h> |
25 | #include <linux/personality.h> | 25 | #include <linux/personality.h> |
26 | #include <linux/security.h> | 26 | #include <linux/security.h> |
27 | #include <linux/ima.h> | ||
27 | #include <linux/syscalls.h> | 28 | #include <linux/syscalls.h> |
28 | #include <linux/mount.h> | 29 | #include <linux/mount.h> |
29 | #include <linux/audit.h> | 30 | #include <linux/audit.h> |
@@ -860,6 +861,8 @@ static int __link_path_walk(const char *name, struct nameidata *nd) | |||
860 | err = exec_permission_lite(inode); | 861 | err = exec_permission_lite(inode); |
861 | if (err == -EAGAIN) | 862 | if (err == -EAGAIN) |
862 | err = vfs_permission(nd, MAY_EXEC); | 863 | err = vfs_permission(nd, MAY_EXEC); |
864 | if (!err) | ||
865 | err = ima_path_check(&nd->path, MAY_EXEC); | ||
863 | if (err) | 866 | if (err) |
864 | break; | 867 | break; |
865 | 868 | ||
@@ -1525,6 +1528,11 @@ int may_open(struct nameidata *nd, int acc_mode, int flag) | |||
1525 | error = vfs_permission(nd, acc_mode); | 1528 | error = vfs_permission(nd, acc_mode); |
1526 | if (error) | 1529 | if (error) |
1527 | return error; | 1530 | return error; |
1531 | |||
1532 | error = ima_path_check(&nd->path, | ||
1533 | acc_mode & (MAY_READ | MAY_WRITE | MAY_EXEC)); | ||
1534 | if (error) | ||
1535 | return error; | ||
1528 | /* | 1536 | /* |
1529 | * An append-only file must be opened in append mode for writing. | 1537 | * An append-only file must be opened in append mode for writing. |
1530 | */ | 1538 | */ |