diff options
author | Alexey Dobriyan <adobriyan@gmail.com> | 2009-03-25 15:48:06 -0400 |
---|---|---|
committer | Alexey Dobriyan <adobriyan@gmail.com> | 2009-03-30 17:14:44 -0400 |
commit | 99b76233803beab302123d243eea9e41149804f3 (patch) | |
tree | 398178210fe66845ccd6fa4258ba762a87e023ad /fs | |
parent | 3dec7f59c370c7b58184d63293c3dc984d475840 (diff) |
proc 2/2: remove struct proc_dir_entry::owner
Setting ->owner as done currently (pde->owner = THIS_MODULE) is racy
as correctly noted at bug #12454. Someone can lookup entry with NULL
->owner, thus not pinning enything, and release it later resulting
in module refcount underflow.
We can keep ->owner and supply it at registration time like ->proc_fops
and ->data.
But this leaves ->owner as easy-manipulative field (just one C assignment)
and somebody will forget to unpin previous/pin current module when
switching ->owner. ->proc_fops is declared as "const" which should give
some thoughts.
->read_proc/->write_proc were just fixed to not require ->owner for
protection.
rmmod'ed directories will be empty and return "." and ".." -- no harm.
And directories with tricky enough readdir and lookup shouldn't be modular.
We definitely don't want such modular code.
Removing ->owner will also make PDE smaller.
So, let's nuke it.
Kudos to Jeff Layton for reminding about this, let's say, oversight.
http://bugzilla.kernel.org/show_bug.cgi?id=12454
Signed-off-by: Alexey Dobriyan <adobriyan@gmail.com>
Diffstat (limited to 'fs')
-rw-r--r-- | fs/afs/proc.c | 1 | ||||
-rw-r--r-- | fs/cifs/cifs_debug.c | 1 | ||||
-rw-r--r-- | fs/jfs/jfs_debug.c | 1 | ||||
-rw-r--r-- | fs/nfs/client.c | 2 | ||||
-rw-r--r-- | fs/proc/inode.c | 19 | ||||
-rw-r--r-- | fs/proc/proc_tty.c | 1 | ||||
-rw-r--r-- | fs/reiserfs/procfs.c | 5 |
7 files changed, 4 insertions, 26 deletions
diff --git a/fs/afs/proc.c b/fs/afs/proc.c index 7578c1ab9e0b..8630615e57fe 100644 --- a/fs/afs/proc.c +++ b/fs/afs/proc.c | |||
@@ -146,7 +146,6 @@ int afs_proc_init(void) | |||
146 | proc_afs = proc_mkdir("fs/afs", NULL); | 146 | proc_afs = proc_mkdir("fs/afs", NULL); |
147 | if (!proc_afs) | 147 | if (!proc_afs) |
148 | goto error_dir; | 148 | goto error_dir; |
149 | proc_afs->owner = THIS_MODULE; | ||
150 | 149 | ||
151 | p = proc_create("cells", 0, proc_afs, &afs_proc_cells_fops); | 150 | p = proc_create("cells", 0, proc_afs, &afs_proc_cells_fops); |
152 | if (!p) | 151 | if (!p) |
diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c index 877e4d9a1159..7f19fefd3d45 100644 --- a/fs/cifs/cifs_debug.c +++ b/fs/cifs/cifs_debug.c | |||
@@ -404,7 +404,6 @@ cifs_proc_init(void) | |||
404 | if (proc_fs_cifs == NULL) | 404 | if (proc_fs_cifs == NULL) |
405 | return; | 405 | return; |
406 | 406 | ||
407 | proc_fs_cifs->owner = THIS_MODULE; | ||
408 | proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops); | 407 | proc_create("DebugData", 0, proc_fs_cifs, &cifs_debug_data_proc_fops); |
409 | 408 | ||
410 | #ifdef CONFIG_CIFS_STATS | 409 | #ifdef CONFIG_CIFS_STATS |
diff --git a/fs/jfs/jfs_debug.c b/fs/jfs/jfs_debug.c index 6a73de84bcef..dd824d9b0b1a 100644 --- a/fs/jfs/jfs_debug.c +++ b/fs/jfs/jfs_debug.c | |||
@@ -90,7 +90,6 @@ void jfs_proc_init(void) | |||
90 | 90 | ||
91 | if (!(base = proc_mkdir("fs/jfs", NULL))) | 91 | if (!(base = proc_mkdir("fs/jfs", NULL))) |
92 | return; | 92 | return; |
93 | base->owner = THIS_MODULE; | ||
94 | 93 | ||
95 | for (i = 0; i < NPROCENT; i++) | 94 | for (i = 0; i < NPROCENT; i++) |
96 | proc_create(Entries[i].name, 0, base, Entries[i].proc_fops); | 95 | proc_create(Entries[i].name, 0, base, Entries[i].proc_fops); |
diff --git a/fs/nfs/client.c b/fs/nfs/client.c index 574158ae2398..2277421656e7 100644 --- a/fs/nfs/client.c +++ b/fs/nfs/client.c | |||
@@ -1606,8 +1606,6 @@ int __init nfs_fs_proc_init(void) | |||
1606 | if (!proc_fs_nfs) | 1606 | if (!proc_fs_nfs) |
1607 | goto error_0; | 1607 | goto error_0; |
1608 | 1608 | ||
1609 | proc_fs_nfs->owner = THIS_MODULE; | ||
1610 | |||
1611 | /* a file of servers with which we're dealing */ | 1609 | /* a file of servers with which we're dealing */ |
1612 | p = proc_create("servers", S_IFREG|S_IRUGO, | 1610 | p = proc_create("servers", S_IFREG|S_IRUGO, |
1613 | proc_fs_nfs, &nfs_server_list_fops); | 1611 | proc_fs_nfs, &nfs_server_list_fops); |
diff --git a/fs/proc/inode.c b/fs/proc/inode.c index e11dc22c6511..d78ade305541 100644 --- a/fs/proc/inode.c +++ b/fs/proc/inode.c | |||
@@ -58,11 +58,8 @@ static void proc_delete_inode(struct inode *inode) | |||
58 | 58 | ||
59 | /* Let go of any associated proc directory entry */ | 59 | /* Let go of any associated proc directory entry */ |
60 | de = PROC_I(inode)->pde; | 60 | de = PROC_I(inode)->pde; |
61 | if (de) { | 61 | if (de) |
62 | if (de->owner) | ||
63 | module_put(de->owner); | ||
64 | de_put(de); | 62 | de_put(de); |
65 | } | ||
66 | if (PROC_I(inode)->sysctl) | 63 | if (PROC_I(inode)->sysctl) |
67 | sysctl_head_put(PROC_I(inode)->sysctl); | 64 | sysctl_head_put(PROC_I(inode)->sysctl); |
68 | clear_inode(inode); | 65 | clear_inode(inode); |
@@ -449,12 +446,9 @@ struct inode *proc_get_inode(struct super_block *sb, unsigned int ino, | |||
449 | { | 446 | { |
450 | struct inode * inode; | 447 | struct inode * inode; |
451 | 448 | ||
452 | if (!try_module_get(de->owner)) | ||
453 | goto out_mod; | ||
454 | |||
455 | inode = iget_locked(sb, ino); | 449 | inode = iget_locked(sb, ino); |
456 | if (!inode) | 450 | if (!inode) |
457 | goto out_ino; | 451 | return NULL; |
458 | if (inode->i_state & I_NEW) { | 452 | if (inode->i_state & I_NEW) { |
459 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; | 453 | inode->i_mtime = inode->i_atime = inode->i_ctime = CURRENT_TIME; |
460 | PROC_I(inode)->fd = 0; | 454 | PROC_I(inode)->fd = 0; |
@@ -485,16 +479,9 @@ struct inode *proc_get_inode(struct super_block *sb, unsigned int ino, | |||
485 | } | 479 | } |
486 | } | 480 | } |
487 | unlock_new_inode(inode); | 481 | unlock_new_inode(inode); |
488 | } else { | 482 | } else |
489 | module_put(de->owner); | ||
490 | de_put(de); | 483 | de_put(de); |
491 | } | ||
492 | return inode; | 484 | return inode; |
493 | |||
494 | out_ino: | ||
495 | module_put(de->owner); | ||
496 | out_mod: | ||
497 | return NULL; | ||
498 | } | 485 | } |
499 | 486 | ||
500 | int proc_fill_super(struct super_block *s) | 487 | int proc_fill_super(struct super_block *s) |
diff --git a/fs/proc/proc_tty.c b/fs/proc/proc_tty.c index d153946d6d15..4a9e0f65ae60 100644 --- a/fs/proc/proc_tty.c +++ b/fs/proc/proc_tty.c | |||
@@ -152,7 +152,6 @@ void proc_tty_register_driver(struct tty_driver *driver) | |||
152 | if (!ent) | 152 | if (!ent) |
153 | return; | 153 | return; |
154 | ent->read_proc = driver->ops->read_proc; | 154 | ent->read_proc = driver->ops->read_proc; |
155 | ent->owner = driver->owner; | ||
156 | ent->data = driver; | 155 | ent->data = driver; |
157 | 156 | ||
158 | driver->proc_entry = ent; | 157 | driver->proc_entry = ent; |
diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c index d5066400638a..9229e5514a4e 100644 --- a/fs/reiserfs/procfs.c +++ b/fs/reiserfs/procfs.c | |||
@@ -492,7 +492,6 @@ int reiserfs_proc_info_init(struct super_block *sb) | |||
492 | spin_lock_init(&__PINFO(sb).lock); | 492 | spin_lock_init(&__PINFO(sb).lock); |
493 | REISERFS_SB(sb)->procdir = proc_mkdir(b, proc_info_root); | 493 | REISERFS_SB(sb)->procdir = proc_mkdir(b, proc_info_root); |
494 | if (REISERFS_SB(sb)->procdir) { | 494 | if (REISERFS_SB(sb)->procdir) { |
495 | REISERFS_SB(sb)->procdir->owner = THIS_MODULE; | ||
496 | REISERFS_SB(sb)->procdir->data = sb; | 495 | REISERFS_SB(sb)->procdir->data = sb; |
497 | add_file(sb, "version", show_version); | 496 | add_file(sb, "version", show_version); |
498 | add_file(sb, "super", show_super); | 497 | add_file(sb, "super", show_super); |
@@ -556,9 +555,7 @@ int reiserfs_proc_info_global_init(void) | |||
556 | { | 555 | { |
557 | if (proc_info_root == NULL) { | 556 | if (proc_info_root == NULL) { |
558 | proc_info_root = proc_mkdir(proc_info_root_name, NULL); | 557 | proc_info_root = proc_mkdir(proc_info_root_name, NULL); |
559 | if (proc_info_root) { | 558 | if (!proc_info_root) { |
560 | proc_info_root->owner = THIS_MODULE; | ||
561 | } else { | ||
562 | reiserfs_warning(NULL, "cannot create /proc/%s", | 559 | reiserfs_warning(NULL, "cannot create /proc/%s", |
563 | proc_info_root_name); | 560 | proc_info_root_name); |
564 | return 1; | 561 | return 1; |