~ecryptfs/ecryptfs/trunk

« back to all changes in this revision

Viewing changes to src/jprobes/jprobe-create.c

  • Committer: mhalcrow@us.ibm.com
  • Date: 2007-11-06 22:56:01 UTC
  • Revision ID: git-v1:f8357de9d554b274497b5cce9db4347254b7e7eb
Initial import of eCryptfs filesystem userspace utilities (mount helper, daemon component,
etc.)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * jprobe module for debugging eCryptfs file create operations
 
3
 */
 
4
 
 
5
#include <linux/module.h>
 
6
#include <linux/init.h>
 
7
#include <linux/kprobes.h>
 
8
#include <linux/kallsyms.h>
 
9
#include <linux/fs.h>
 
10
#include <linux/mm.h>
 
11
#include <linux/namei.h>
 
12
 
 
13
struct jprobe_mapping_elem {
 
14
        struct jprobe *jp;
 
15
        char *symbol;
 
16
        void *fp;
 
17
};
 
18
 
 
19
int jp_ecryptfs_create(struct inode *directory_inode,
 
20
                       struct dentry *ecryptfs_dentry,
 
21
                       int mode, struct nameidata *nd)
 
22
{
 
23
        printk(KERN_INFO "%s: directory_inode = [0x%p]; ecryptfs_dentry = [0x%p]; mode = [%.8x]; nd = [0x%p]\n", __FUNCTION__, directory_inode, ecryptfs_dentry, mode, nd);
 
24
        jprobe_return();
 
25
        return 0;
 
26
}
 
27
 
 
28
int jp_ecryptfs_do_create(struct inode *directory_inode,
 
29
                          struct dentry *ecryptfs_dentry, int mode,
 
30
                          struct nameidata *nd)
 
31
{
 
32
        printk(KERN_INFO "%s: directory_inode = [0x%p]; ecryptfs_dentry = [0x%p]; mode = [%.4x]; nd = [0x%p]\n", __FUNCTION__, directory_inode, ecryptfs_dentry, mode, nd);
 
33
        jprobe_return();
 
34
        return 0;
 
35
}
 
36
 
 
37
int jp_ecryptfs_create_underlying_file(struct inode *lower_dir_inode,
 
38
                                       struct dentry *lower_dentry,
 
39
                                       struct dentry *ecryptfs_dentry, int mode,
 
40
                                       struct nameidata *nd)
 
41
{
 
42
        printk(KERN_INFO "%s: lower_dir_inode = [0x%p]; lower_dentry = [0x%p]; ecryptfs_dentry = [0x%p]; mode = [%.8x]; nd = [0x%p]\n", __FUNCTION__, lower_dir_inode, lower_dentry, ecryptfs_dentry, mode, nd);
 
43
        printk(KERN_INFO "%s: Calling vfs_create()\n", __FUNCTION__);
 
44
        jprobe_return();
 
45
        return 0;
 
46
}
 
47
 
 
48
int jp_ecryptfs_interpose(struct dentry *lower_dentry, struct dentry *dentry,
 
49
                          struct super_block *sb, int flag)
 
50
{
 
51
        printk(KERN_INFO "%s: lower_dentry = [0x%p]; dentry = [0x%p]; sb = [0x%p]; flag = [0x%.8x]\n", __FUNCTION__, lower_dentry, dentry, sb, flag);
 
52
        jprobe_return();
 
53
        return 0;
 
54
}
 
55
 
 
56
int jp_ecryptfs_initialize_file(struct dentry *ecryptfs_dentry)
 
57
{
 
58
        printk(KERN_INFO "%s: ecryptfs_dentry = [0x%p]\n", __FUNCTION__, ecryptfs_dentry);
 
59
        jprobe_return();
 
60
        return 0;
 
61
}
 
62
 
 
63
int jp_ecryptfs_new_file_context(struct dentry *ecryptfs_dentry)
 
64
{
 
65
        printk(KERN_INFO "%s: ecryptfs_dentry = [0x%p]\n", __FUNCTION__, ecryptfs_dentry);
 
66
        jprobe_return();
 
67
        return 0;
 
68
}
 
69
 
 
70
/* ecryptfs_set_default_crypt_stat_vals */
 
71
/* ecryptfs_generate_new_key */
 
72
/* ecryptfs_init_crypt_ctx */
 
73
 
 
74
int jp_ecryptfs_write_headers(struct dentry *ecryptfs_dentry,
 
75
                              struct file *lower_file)
 
76
{
 
77
        printk(KERN_INFO "%s: ecryptfs_dentry = [0x%p]; lower_file = [0x%p]\n", __FUNCTION__, ecryptfs_dentry, lower_file);
 
78
        jprobe_return();
 
79
        return 0;
 
80
}
 
81
 
 
82
struct ecryptfs_crypt_stat;
 
83
 
 
84
int jp_ecryptfs_write_headers_virt(char *page_virt,
 
85
                                   struct ecryptfs_crypt_stat *crypt_stat,
 
86
                                   struct dentry *ecryptfs_dentry)
 
87
{
 
88
        printk(KERN_INFO "%s: page_virt = [0x%p]; crypt_stat = [0x%p]; ecryptfs_dentry = [0x%p]\n", __FUNCTION__, page_virt, crypt_stat, ecryptfs_dentry);
 
89
        jprobe_return();
 
90
        return 0;
 
91
}
 
92
 
 
93
int jp_grow_file(struct dentry *ecryptfs_dentry, struct file *lower_file,
 
94
                 struct inode *inode, struct inode *lower_inode)
 
95
{
 
96
        printk(KERN_INFO "%s: ecryptfs_dentry = [0x%p]; lower_file = [0x%p]; inode = [0x%p]; lower_inode = [0x%p]\n", __FUNCTION__, ecryptfs_dentry, lower_file, inode, lower_inode);
 
97
        jprobe_return();
 
98
        return 0;
 
99
}
 
100
 
 
101
int jp_ecryptfs_fill_zeros(struct file *file, loff_t new_length)
 
102
{
 
103
        printk(KERN_INFO "%s: file = [0x%p]; new_length = [%llu]\n", __FUNCTION__, file, new_length);
 
104
        jprobe_return();
 
105
        return 0;
 
106
}
 
107
 
 
108
/* write_zeros */
 
109
 
 
110
int
 
111
jp_ecryptfs_write_inode_size_to_header(struct file *lower_file,
 
112
                                       struct inode *lower_inode,
 
113
                                       struct inode *inode)
 
114
{
 
115
        printk(KERN_INFO "%s: lower_file = [0x%p]; lower_inode = [0x%p]; inode = [0x%p]\n", __FUNCTION__, lower_file, lower_inode, inode);
 
116
        dump_stack();
 
117
        jprobe_return();
 
118
        return 0;
 
119
}
 
120
 
 
121
int jp_ecryptfs_grab_and_map_lower_page(struct page **lower_page,
 
122
                                        char **lower_virt,
 
123
                                        struct inode *lower_inode,
 
124
                                        unsigned long lower_page_index)
 
125
{
 
126
        printk(KERN_INFO "%s: lower_page = [0x%p]; lower_virt = [0x%p]; lower_inode = [0x%p]; lower_page_index = [%lu]\n", __FUNCTION__, lower_page, lower_virt, lower_inode, lower_page_index);
 
127
        jprobe_return();
 
128
        return 0;
 
129
}
 
130
 
 
131
void jp_ecryptfs_unmap_and_release_lower_page(struct page *lower_page)
 
132
{
 
133
        printk(KERN_INFO "%s: lower_page = [0x%p]\n", __FUNCTION__, lower_page);
 
134
        jprobe_return();
 
135
        return;
 
136
}
 
137
 
 
138
int jp_ecryptfs_commit_write(struct file *file, struct page *page,
 
139
                             unsigned from, unsigned to)
 
140
{
 
141
        printk(KERN_INFO "%s: file = [0x%p]; page = [0x%p]; page->mapping = [0x%p]\n", __FUNCTION__, file, page, page->mapping);
 
142
        jprobe_return();
 
143
        return 0;
 
144
}
 
145
 
 
146
int
 
147
jp_ecryptfs_permission(struct inode *inode, int mask, struct nameidata *nd)
 
148
{
 
149
        printk(KERN_INFO "%s: inode = [0x%p]; mask = [0x%.8x]; nd = [0x%p]\n", __FUNCTION__, inode, mask, nd);
 
150
        if (nd) {
 
151
                printk(KERN_INFO "%s: nd->dentry = [0x%p]\n", __FUNCTION__,
 
152
                       nd->dentry);
 
153
                if (nd->dentry)
 
154
                        printk(KERN_INFO "%s: nd->dentry->d_fsdata = [0x%p]\n",
 
155
                               __FUNCTION__, nd->dentry->d_fsdata);
 
156
        }
 
157
        jprobe_return();
 
158
        return 0;
 
159
}
 
160
 
 
161
struct dentry *jp_ecryptfs_lookup(struct inode *dir, struct dentry *dentry,
 
162
                               struct nameidata *nd)
 
163
{
 
164
        printk(KERN_INFO "%s: dir = [0x%p]; dentry = [0x%p]; nd = [0x%p]\n",
 
165
               __FUNCTION__, dir, dentry, nd);
 
166
        printk(KERN_INFO "%s: dentry->d_name.name = [%s]\n",
 
167
               __FUNCTION__, dentry->d_name.name);
 
168
        jprobe_return();
 
169
        return NULL;
 
170
}
 
171
 
 
172
struct jprobe_mapping_elem jprobe_mapping[] = {
 
173
        {NULL, "ecryptfs_create", jp_ecryptfs_create},
 
174
        {NULL, "ecryptfs_do_create", jp_ecryptfs_do_create},
 
175
        {NULL, "ecryptfs_create_underlying_file", jp_ecryptfs_create_underlying_file},
 
176
        {NULL, "ecryptfs_interpose", jp_ecryptfs_interpose},
 
177
        {NULL, "ecryptfs_initialize_file", jp_ecryptfs_initialize_file},
 
178
        {NULL, "ecryptfs_new_file_context", jp_ecryptfs_new_file_context},
 
179
        {NULL, "ecryptfs_write_headers", jp_ecryptfs_write_headers},
 
180
        {NULL, "ecryptfs_write_headers_virt", jp_ecryptfs_write_headers_virt},
 
181
        {NULL, "grow_file", jp_grow_file},
 
182
        {NULL, "ecryptfs_fill_zeros", jp_ecryptfs_fill_zeros},
 
183
        {NULL, "ecryptfs_write_inode_size_to_header", jp_ecryptfs_write_inode_size_to_header},
 
184
        {NULL, "ecryptfs_grab_and_map_lower_page", jp_ecryptfs_grab_and_map_lower_page},
 
185
        {NULL, "ecryptfs_unmap_and_release_lower_page", jp_ecryptfs_unmap_and_release_lower_page},
 
186
        {NULL, "ecryptfs_commit_write", jp_ecryptfs_commit_write},
 
187
        {NULL, "ecryptfs_permission", jp_ecryptfs_permission},
 
188
        {NULL, "ecryptfs_lookup", jp_ecryptfs_lookup}
 
189
};
 
190
 
 
191
static int __init jprobe_create_init(void)
 
192
{
 
193
        int i;
 
194
 
 
195
        for (i = 0; i < ARRAY_SIZE(jprobe_mapping); i++) {
 
196
                jprobe_mapping[i].jp = kmalloc(sizeof(struct jprobe),
 
197
                                               GFP_KERNEL);
 
198
                jprobe_mapping[i].jp->entry = jprobe_mapping[i].fp;
 
199
                jprobe_mapping[i].jp->kp.addr = (kprobe_opcode_t *)
 
200
                        kallsyms_lookup_name(jprobe_mapping[i].symbol);
 
201
                if (jprobe_mapping[i].jp->kp.addr == NULL) {
 
202
                        int j;
 
203
 
 
204
                        printk(KERN_NOTICE "Unable to find symbol [%s]\n",
 
205
                               jprobe_mapping[i].symbol);
 
206
                        for (j = 0; j < i; j++) {
 
207
                                unregister_jprobe(jprobe_mapping[j].jp);
 
208
                                kfree(jprobe_mapping[j].jp);
 
209
                        }
 
210
                        return -EINVAL;
 
211
                }
 
212
                register_jprobe(jprobe_mapping[i].jp);
 
213
        }
 
214
        return 0;
 
215
}
 
216
 
 
217
static void __exit jprobe_create_exit(void)
 
218
{
 
219
        int i;
 
220
 
 
221
        for (i = 0; i < ARRAY_SIZE(jprobe_mapping); i++) {
 
222
                unregister_jprobe(jprobe_mapping[i].jp);
 
223
                kfree(jprobe_mapping[i].jp);
 
224
        }
 
225
}
 
226
 
 
227
module_init(jprobe_create_init);
 
228
module_exit(jprobe_create_exit);
 
229
MODULE_LICENSE("GPL");