Lines 17-32
Link Here
|
17 |
#include <asm/uaccess.h> |
17 |
#include <asm/uaccess.h> |
18 |
#include <linux/list.h> |
18 |
#include <linux/list.h> |
19 |
#include <linux/mount.h> |
19 |
#include <linux/mount.h> |
|
|
20 |
|
21 |
#include "subfs.h" |
22 |
|
23 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,30) |
24 |
#include <linux/spinlock_types.h> |
25 |
#include <linux/fs_struct.h> |
26 |
#endif |
27 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,22) |
28 |
#include <linux/nsproxy.h> |
29 |
#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,20) |
30 |
#include <linux/mnt_namespace.h> |
31 |
#else |
20 |
#include <linux/namespace.h> |
32 |
#include <linux/namespace.h> |
|
|
33 |
#endif |
21 |
#include <linux/namei.h> |
34 |
#include <linux/namei.h> |
22 |
#include <linux/dcache.h> |
35 |
#include <linux/dcache.h> |
23 |
#include <linux/sysfs.h> |
36 |
#include <linux/sysfs.h> |
|
|
37 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,27) |
38 |
#include <linux/semaphore.h> |
39 |
#else |
24 |
#include <asm/semaphore.h> |
40 |
#include <asm/semaphore.h> |
|
|
41 |
#endif |
25 |
#include <asm/signal.h> |
42 |
#include <asm/signal.h> |
26 |
#include <linux/signal.h> |
43 |
#include <linux/signal.h> |
27 |
#include <linux/sched.h> |
44 |
#include <linux/sched.h> |
|
|
45 |
#include <linux/rcupdate.h> |
28 |
|
46 |
|
29 |
#include "subfs.h" |
|
|
30 |
|
47 |
|
31 |
MODULE_LICENSE("GPL"); |
48 |
MODULE_LICENSE("GPL"); |
32 |
MODULE_AUTHOR("Eugene S. Weiss"); |
49 |
MODULE_AUTHOR("Eugene S. Weiss"); |
Lines 47-53
Link Here
|
47 |
/* Get the head of the global mount list from the init process. */ |
64 |
/* Get the head of the global mount list from the init process. */ |
48 |
/* Is there a better way? */ |
65 |
/* Is there a better way? */ |
49 |
init_fs = init_task.fs; |
66 |
init_fs = init_task.fs; |
|
|
67 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25) |
68 |
head = &init_fs->root.mnt->mnt_list; |
69 |
#else |
50 |
head = &init_fs->rootmnt->mnt_list; |
70 |
head = &init_fs->rootmnt->mnt_list; |
|
|
71 |
#endif |
51 |
|
72 |
|
52 |
/* Go through the list and look for a superblock pointer match. */ |
73 |
/* Go through the list and look for a superblock pointer match. */ |
53 |
list_for_each_safe(entry, lh, head) { |
74 |
list_for_each_safe(entry, lh, head) { |
Lines 72-81
Link Here
|
72 |
struct vfsmount *old_pwdmnt; |
93 |
struct vfsmount *old_pwdmnt; |
73 |
|
94 |
|
74 |
write_lock(&fs->lock); |
95 |
write_lock(&fs->lock); |
|
|
96 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25) |
97 |
old_pwd = fs->pwd.dentry; |
98 |
old_pwdmnt = fs->pwd.mnt; |
99 |
fs->pwd.mnt = mntget(mnt); |
100 |
fs->pwd.dentry = dget(dentry); |
101 |
#else |
75 |
old_pwd = fs->pwd; |
102 |
old_pwd = fs->pwd; |
76 |
old_pwdmnt = fs->pwdmnt; |
103 |
old_pwdmnt = fs->pwdmnt; |
77 |
fs->pwdmnt = mntget(mnt); |
104 |
fs->pwdmnt = mntget(mnt); |
78 |
fs->pwd = dget(dentry); |
105 |
fs->pwd = dget(dentry); |
|
|
106 |
#endif |
79 |
write_unlock(&fs->lock); |
107 |
write_unlock(&fs->lock); |
80 |
|
108 |
|
81 |
if (old_pwd) { |
109 |
if (old_pwd) { |
Lines 94-104
Link Here
|
94 |
struct task_struct *task = current; |
122 |
struct task_struct *task = current; |
95 |
int signal = SIGCONT; |
123 |
int signal = SIGCONT; |
96 |
|
124 |
|
97 |
read_lock(&tasklist_lock); |
125 |
rcu_read_lock(); |
98 |
spin_lock_irq(&task->sighand->siglock); |
126 |
spin_lock_irq(&task->sighand->siglock); |
99 |
sigaddset(&task->pending.signal, signal); |
127 |
sigaddset(&task->pending.signal, signal); |
100 |
spin_unlock_irq(&task->sighand->siglock); |
128 |
spin_unlock_irq(&task->sighand->siglock); |
101 |
read_unlock(&tasklist_lock); |
129 |
rcu_read_unlock(); |
102 |
set_tsk_thread_flag(task, TIF_SIGPENDING); |
130 |
set_tsk_thread_flag(task, TIF_SIGPENDING); |
103 |
return; |
131 |
return; |
104 |
} |
132 |
} |
Lines 111-124
Link Here
|
111 |
*/ |
139 |
*/ |
112 |
static void add_procuid(struct subfs_mount *sfs_mnt) |
140 |
static void add_procuid(struct subfs_mount *sfs_mnt) |
113 |
{ |
141 |
{ |
114 |
struct task_struct *task = current; |
142 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,29) |
|
|
143 |
uid_t uid = current->cred->uid; |
144 |
gid_t gid = current->cred->gid; |
145 |
#else |
146 |
uid_t uid = current->uid; |
147 |
gid_t gid = current->gid; |
148 |
#endif |
115 |
|
149 |
|
116 |
char *o = kmalloc(strlen(sfs_mnt->options) + 1 + 32 + 1, GFP_KERNEL); |
150 |
char *o = kmalloc(strlen(sfs_mnt->options) + 1 + 32 + 1, GFP_KERNEL); |
117 |
|
151 |
|
118 |
if (sfs_mnt->options[0] == '\0') |
152 |
if (sfs_mnt->options[0] == '\0') |
119 |
sprintf(o, "uid=%d,gid=%d", task->uid, task->gid); |
153 |
sprintf(o, "uid=%d,gid=%d", uid, gid); |
120 |
else |
154 |
else |
121 |
sprintf(o, "%s,uid=%d,gid=%d", sfs_mnt->options, task->uid, task->gid); |
155 |
sprintf(o, "%s,uid=%d,gid=%d", sfs_mnt->options, uid, gid); |
122 |
|
156 |
|
123 |
kfree(sfs_mnt->options); |
157 |
kfree(sfs_mnt->options); |
124 |
sfs_mnt->options = o; |
158 |
sfs_mnt->options = o; |
Lines 137-150
Link Here
|
137 |
char *envp[2] = { "HOME=/", NULL }; |
171 |
char *envp[2] = { "HOME=/", NULL }; |
138 |
char *path_buf; |
172 |
char *path_buf; |
139 |
int result, len = 0; |
173 |
int result, len = 0; |
|
|
174 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25) |
175 |
struct path p; |
176 |
#endif |
140 |
|
177 |
|
141 |
argv[1] = sfs_mnt->device; |
178 |
argv[1] = sfs_mnt->device; |
142 |
path_buf = (char *) __get_free_page(GFP_KERNEL); |
179 |
path_buf = (char *) __get_free_page(GFP_KERNEL); |
143 |
if (!path_buf) |
180 |
if (!path_buf) |
144 |
return -ENOMEM; |
181 |
return -ENOMEM; |
145 |
argv[2] = |
182 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25) |
146 |
d_path(sfs_mnt->mount->mnt_mountpoint, |
183 |
p.mnt = sfs_mnt->mount; |
147 |
sfs_mnt->mount->mnt_parent, path_buf, PAGE_SIZE); |
184 |
p.dentry = p.mnt->mnt_root; |
|
|
185 |
argv[2] = d_path(&p, path_buf, PAGE_SIZE); |
186 |
#else |
187 |
argv[2] = d_path(sfs_mnt->mount->mnt_mountpoint, sfs_mnt->mount->mnt_parent, path_buf, PAGE_SIZE); |
188 |
#endif |
148 |
argv[3] = sfs_mnt->req_fs; |
189 |
argv[3] = sfs_mnt->req_fs; |
149 |
if (!(argv[4] = kmalloc(17, GFP_KERNEL))) { |
190 |
if (!(argv[4] = kmalloc(17, GFP_KERNEL))) { |
150 |
free_page((unsigned long) path_buf); |
191 |
free_page((unsigned long) path_buf); |
Lines 221-238
Link Here
|
221 |
struct vfsmount *child; |
262 |
struct vfsmount *child; |
222 |
|
263 |
|
223 |
/* This is ugly, but prevents a lockup during mount. */ |
264 |
/* This is ugly, but prevents a lockup during mount. */ |
|
|
265 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) |
266 |
mutex_unlock(&dir->i_mutex); |
267 |
#else |
224 |
up(&dir->i_sem); |
268 |
up(&dir->i_sem); |
|
|
269 |
#endif |
225 |
if (down_interruptible(&sfs_mnt->sem)) { |
270 |
if (down_interruptible(&sfs_mnt->sem)) { |
226 |
down(&dir->i_sem);/*put the dir sem back down if interrupted*/ |
271 |
/*put the dir sem back down if interrupted*/ |
|
|
272 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) |
273 |
mutex_lock(&dir->i_mutex); |
274 |
#else |
275 |
down(&dir->i_sem); |
276 |
#endif |
227 |
return ERR_PTR(-ERESTARTSYS); |
277 |
return ERR_PTR(-ERESTARTSYS); |
228 |
} |
278 |
} |
229 |
child = get_child_mount(sfs_mnt); |
279 |
child = get_child_mount(sfs_mnt); |
230 |
up(&sfs_mnt->sem); |
280 |
up(&sfs_mnt->sem); |
|
|
281 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,16) |
282 |
mutex_lock(&dir->i_mutex); |
283 |
#else |
231 |
down(&dir->i_sem); |
284 |
down(&dir->i_sem); |
|
|
285 |
#endif |
232 |
if (IS_ERR(child)) |
286 |
if (IS_ERR(child)) |
233 |
return (void *) child; |
287 |
return (void *) child; |
234 |
subfs_send_signal(); |
288 |
subfs_send_signal(); |
|
|
289 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25) |
290 |
if (sfs_mnt->mount == current->fs->pwd.mnt) |
291 |
#else |
235 |
if (sfs_mnt->mount == current->fs->pwdmnt) |
292 |
if (sfs_mnt->mount == current->fs->pwdmnt) |
|
|
293 |
#endif |
236 |
subfs_set_fs_pwd(current->fs, child, child->mnt_root); |
294 |
subfs_set_fs_pwd(current->fs, child, child->mnt_root); |
237 |
return ERR_PTR(-ERESTARTSYS); |
295 |
return ERR_PTR(-ERESTARTSYS); |
238 |
} |
296 |
} |
Lines 254-260
Link Here
|
254 |
if (IS_ERR(child)) |
312 |
if (IS_ERR(child)) |
255 |
return PTR_ERR(child); |
313 |
return PTR_ERR(child); |
256 |
subfs_send_signal(); |
314 |
subfs_send_signal(); |
|
|
315 |
#if LINUX_VERSION_CODE >= KERNEL_VERSION(2,6,25) |
316 |
if (sfs_mnt->mount == current->fs->pwd.mnt) |
317 |
#else |
257 |
if (sfs_mnt->mount == current->fs->pwdmnt) |
318 |
if (sfs_mnt->mount == current->fs->pwdmnt) |
|
|
319 |
#endif |
258 |
subfs_set_fs_pwd(current->fs, child, child->mnt_root); |
320 |
subfs_set_fs_pwd(current->fs, child, child->mnt_root); |
259 |
return -ERESTARTSYS; |
321 |
return -ERESTARTSYS; |
260 |
} |
322 |
} |
Lines 262-270
Link Here
|
262 |
|
324 |
|
263 |
/* Implements the statfs method so df and such will work on the mountpoint. |
325 |
/* Implements the statfs method so df and such will work on the mountpoint. |
264 |
*/ |
326 |
*/ |
|
|
327 |
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17) |
328 |
static int subfs_statfs(struct dentry *dentry, struct kstatfs *buf) |
329 |
{ |
330 |
struct subfs_mount *sfs_mnt = dentry->d_sb->s_fs_info; |
331 |
#else |
265 |
static int subfs_statfs(struct super_block *sb, struct kstatfs *buf) |
332 |
static int subfs_statfs(struct super_block *sb, struct kstatfs *buf) |
266 |
{ |
333 |
{ |
267 |
struct subfs_mount *sfs_mnt = sb->s_fs_info; |
334 |
struct subfs_mount *sfs_mnt = sb->s_fs_info; |
|
|
335 |
#endif |
268 |
struct vfsmount *child; |
336 |
struct vfsmount *child; |
269 |
if (down_interruptible(&sfs_mnt->sem)) |
337 |
if (down_interruptible(&sfs_mnt->sem)) |
270 |
return -ERESTARTSYS; |
338 |
return -ERESTARTSYS; |
Lines 286-292
Link Here
|
286 |
if (ret) { |
354 |
if (ret) { |
287 |
ret->i_mode = mode; |
355 |
ret->i_mode = mode; |
288 |
ret->i_uid = ret->i_gid = 0; |
356 |
ret->i_uid = ret->i_gid = 0; |
|
|
357 |
#if LINUX_VERSION_CODE < KERNEL_VERSION(2,6,19) |
289 |
ret->i_blksize = PAGE_CACHE_SIZE; |
358 |
ret->i_blksize = PAGE_CACHE_SIZE; |
|
|
359 |
#endif |
290 |
ret->i_blocks = 0; |
360 |
ret->i_blocks = 0; |
291 |
ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME; |
361 |
ret->i_atime = ret->i_mtime = ret->i_ctime = CURRENT_TIME; |
292 |
ret->i_fop = &subfs_file_ops; |
362 |
ret->i_fop = &subfs_file_ops; |
Lines 382-414
Link Here
|
382 |
* subfs_mount structure is pointed to by the s_fs_info field of the |
452 |
* subfs_mount structure is pointed to by the s_fs_info field of the |
383 |
* superblock structure. |
453 |
* superblock structure. |
384 |
*/ |
454 |
*/ |
|
|
455 |
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17) |
456 |
static int subfs_get_super(struct file_system_type *fst, |
457 |
int flags, const char *devname, void *data, |
458 |
struct vfsmount *mnt) |
459 |
#else |
385 |
static struct super_block *subfs_get_super(struct file_system_type *fst, |
460 |
static struct super_block *subfs_get_super(struct file_system_type *fst, |
386 |
int flags, const char *devname, void *data) |
461 |
int flags, const char *devname, void *data) |
|
|
462 |
#endif |
387 |
{ |
463 |
{ |
388 |
char *device; |
464 |
char *device; |
389 |
struct subfs_mount *newmount; |
465 |
struct subfs_mount *newmount; |
390 |
int ret; |
466 |
int ret; |
391 |
|
467 |
|
392 |
if (!(newmount = kmalloc(sizeof(struct subfs_mount), GFP_KERNEL))) |
468 |
if (!(newmount = kmalloc(sizeof(struct subfs_mount), GFP_KERNEL))) { |
393 |
return ERR_PTR(-ENOMEM); |
469 |
ret = -ENOMEM; |
|
|
470 |
goto err; |
471 |
} |
394 |
newmount->req_fs = NULL; |
472 |
newmount->req_fs = NULL; |
395 |
newmount->sb = NULL; |
473 |
newmount->sb = NULL; |
396 |
newmount->mount = NULL; |
474 |
newmount->mount = NULL; |
397 |
newmount->procuid = 0; |
475 |
newmount->procuid = 0; |
398 |
sema_init(&newmount->sem, 1); |
476 |
sema_init(&newmount->sem, 1); |
399 |
if (!(device = kmalloc((strlen(devname) + 1), GFP_KERNEL))) |
477 |
if (!(device = kmalloc((strlen(devname) + 1), GFP_KERNEL))) { |
400 |
return ERR_PTR(-ENOMEM); |
478 |
ret = -ENOMEM; |
|
|
479 |
goto err; |
480 |
} |
401 |
strcpy(device, devname); |
481 |
strcpy(device, devname); |
402 |
newmount->device = device; |
482 |
newmount->device = device; |
403 |
if (!(newmount->helper_prog = |
483 |
if (!(newmount->helper_prog = |
404 |
kmalloc(sizeof(SUBMOUNTD_PATH), GFP_KERNEL))) |
484 |
kmalloc(sizeof(SUBMOUNTD_PATH), GFP_KERNEL))) { |
405 |
return ERR_PTR(-ENOMEM); |
485 |
ret = -ENOMEM; |
|
|
486 |
goto err; |
487 |
} |
406 |
strcpy(newmount->helper_prog, SUBMOUNTD_PATH); |
488 |
strcpy(newmount->helper_prog, SUBMOUNTD_PATH); |
407 |
if ((ret = proc_opts(newmount, data))) |
489 |
if ((ret = proc_opts(newmount, data))) |
408 |
return ERR_PTR(ret); |
490 |
goto err; |
|
|
491 |
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17) |
492 |
ret = get_sb_nodev(fst, flags, data, subfs_fill_super, mnt); |
493 |
if (ret) |
494 |
goto err; |
495 |
newmount->sb = mnt->mnt_sb; |
496 |
newmount->sb->s_fs_info = newmount; |
497 |
return ret; |
498 |
#else |
409 |
newmount->sb = get_sb_nodev(fst, flags, data, subfs_fill_super); |
499 |
newmount->sb = get_sb_nodev(fst, flags, data, subfs_fill_super); |
410 |
newmount->sb->s_fs_info = newmount; |
500 |
newmount->sb->s_fs_info = newmount; |
411 |
return newmount->sb; |
501 |
return newmount->sb; |
|
|
502 |
#endif |
503 |
|
504 |
err: |
505 |
#if LINUX_VERSION_CODE > KERNEL_VERSION(2,6,17) |
506 |
return ret; |
507 |
#else |
508 |
return ERR_PTR(ret); |
509 |
#endif |
412 |
} |
510 |
} |
413 |
|
511 |
|
414 |
|
512 |
|