Skip to content

Commit 6146f0d

Browse files
Mimi ZoharJames Morris
authored andcommitted
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 <[email protected]> Acked-by: Serge Hallyn <[email protected]> Signed-off-by: James Morris <[email protected]>
1 parent 659aaf2 commit 6146f0d

File tree

7 files changed

+86
-7
lines changed

7 files changed

+86
-7
lines changed

Documentation/kernel-parameters.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ parameter is applicable:
4444
FB The frame buffer device is enabled.
4545
HW Appropriate hardware is enabled.
4646
IA-64 IA-64 architecture is enabled.
47+
IMA Integrity measurement architecture is enabled.
4748
IOSCHED More than one I/O scheduler is enabled.
4849
IP_PNP IP DHCP, BOOTP, or RARP is enabled.
4950
ISAPNP ISA PnP code is enabled.

fs/exec.c

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
#include <linux/proc_fs.h>
4646
#include <linux/mount.h>
4747
#include <linux/security.h>
48+
#include <linux/ima.h>
4849
#include <linux/syscalls.h>
4950
#include <linux/tsacct_kern.h>
5051
#include <linux/cn_proc.h>
@@ -128,6 +129,9 @@ asmlinkage long sys_uselib(const char __user * library)
128129
goto exit;
129130

130131
error = vfs_permission(&nd, MAY_READ | MAY_EXEC | MAY_OPEN);
132+
if (error)
133+
goto exit;
134+
error = ima_path_check(&nd.path, MAY_READ | MAY_EXEC | MAY_OPEN);
131135
if (error)
132136
goto exit;
133137

@@ -681,6 +685,9 @@ struct file *open_exec(const char *name)
681685
goto out_path_put;
682686

683687
err = vfs_permission(&nd, MAY_EXEC | MAY_OPEN);
688+
if (err)
689+
goto out_path_put;
690+
err = ima_path_check(&nd.path, MAY_EXEC | MAY_OPEN);
684691
if (err)
685692
goto out_path_put;
686693

@@ -1207,6 +1214,9 @@ int search_binary_handler(struct linux_binprm *bprm,struct pt_regs *regs)
12071214
}
12081215
#endif
12091216
retval = security_bprm_check(bprm);
1217+
if (retval)
1218+
return retval;
1219+
retval = ima_bprm_check(bprm);
12101220
if (retval)
12111221
return retval;
12121222

fs/file_table.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
#include <linux/module.h>
1414
#include <linux/fs.h>
1515
#include <linux/security.h>
16+
#include <linux/ima.h>
1617
#include <linux/eventpoll.h>
1718
#include <linux/rcupdate.h>
1819
#include <linux/mount.h>
@@ -276,6 +277,7 @@ void __fput(struct file *file)
276277
if (file->f_op && file->f_op->release)
277278
file->f_op->release(inode, file);
278279
security_file_free(file);
280+
ima_file_free(file);
279281
if (unlikely(S_ISCHR(inode->i_mode) && inode->i_cdev != NULL))
280282
cdev_put(inode->i_cdev);
281283
fops_put(file->f_op);

fs/inode.c

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@
1717
#include <linux/hash.h>
1818
#include <linux/swap.h>
1919
#include <linux/security.h>
20+
#include <linux/ima.h>
2021
#include <linux/pagemap.h>
2122
#include <linux/cdev.h>
2223
#include <linux/bootmem.h>
@@ -144,13 +145,13 @@ struct inode *inode_init_always(struct super_block *sb, struct inode *inode)
144145
inode->i_cdev = NULL;
145146
inode->i_rdev = 0;
146147
inode->dirtied_when = 0;
147-
if (security_inode_alloc(inode)) {
148-
if (inode->i_sb->s_op->destroy_inode)
149-
inode->i_sb->s_op->destroy_inode(inode);
150-
else
151-
kmem_cache_free(inode_cachep, (inode));
152-
return NULL;
153-
}
148+
149+
if (security_inode_alloc(inode))
150+
goto out_free_inode;
151+
152+
/* allocate and initialize an i_integrity */
153+
if (ima_inode_alloc(inode))
154+
goto out_free_security;
154155

155156
spin_lock_init(&inode->i_lock);
156157
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)
186187
inode->i_mapping = mapping;
187188

188189
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;
189199
}
190200
EXPORT_SYMBOL(inode_init_always);
191201

fs/namei.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include <linux/fsnotify.h>
2525
#include <linux/personality.h>
2626
#include <linux/security.h>
27+
#include <linux/ima.h>
2728
#include <linux/syscalls.h>
2829
#include <linux/mount.h>
2930
#include <linux/audit.h>
@@ -860,6 +861,8 @@ static int __link_path_walk(const char *name, struct nameidata *nd)
860861
err = exec_permission_lite(inode);
861862
if (err == -EAGAIN)
862863
err = vfs_permission(nd, MAY_EXEC);
864+
if (!err)
865+
err = ima_path_check(&nd->path, MAY_EXEC);
863866
if (err)
864867
break;
865868

@@ -1525,6 +1528,11 @@ int may_open(struct nameidata *nd, int acc_mode, int flag)
15251528
error = vfs_permission(nd, acc_mode);
15261529
if (error)
15271530
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;
15281536
/*
15291537
* An append-only file must be opened in append mode for writing.
15301538
*/

include/linux/ima.h

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
/*
2+
* Copyright (C) 2008 IBM Corporation
3+
* Author: Mimi Zohar <[email protected]>
4+
*
5+
* This program is free software; you can redistribute it and/or modify
6+
* it under the terms of the GNU General Public License as published by
7+
* the Free Software Foundation, version 2 of the License.
8+
*/
9+
10+
#include <linux/fs.h>
11+
12+
#ifndef _LINUX_IMA_H
13+
#define _LINUX_IMA_H
14+
15+
static inline int ima_bprm_check(struct linux_binprm *bprm)
16+
{
17+
return 0;
18+
}
19+
20+
static inline int ima_inode_alloc(struct inode *inode)
21+
{
22+
return 0;
23+
}
24+
25+
static inline void ima_inode_free(struct inode *inode)
26+
{
27+
return;
28+
}
29+
30+
static inline int ima_path_check(struct path *path, int mask)
31+
{
32+
return 0;
33+
}
34+
35+
static inline void ima_file_free(struct file *file)
36+
{
37+
return;
38+
}
39+
40+
static inline int ima_file_mmap(struct file *file, unsigned long prot)
41+
{
42+
return 0;
43+
}
44+
#endif /* _LINUX_IMA_H */

mm/mmap.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
#include <linux/fs.h>
2121
#include <linux/personality.h>
2222
#include <linux/security.h>
23+
#include <linux/ima.h>
2324
#include <linux/hugetlb.h>
2425
#include <linux/profile.h>
2526
#include <linux/module.h>
@@ -1048,6 +1049,9 @@ unsigned long do_mmap_pgoff(struct file * file, unsigned long addr,
10481049
}
10491050

10501051
error = security_file_mmap(file, reqprot, prot, flags, addr, 0);
1052+
if (error)
1053+
return error;
1054+
error = ima_file_mmap(file, prot);
10511055
if (error)
10521056
return error;
10531057

0 commit comments

Comments
 (0)