Bug 12454
Summary: | race between procfile opens and setting of pde->owner | ||
---|---|---|---|
Product: | File System | Reporter: | Jeff Layton (jlayton) |
Component: | Other | Assignee: | Alexey Dobriyan (adobriyan) |
Status: | RESOLVED CODE_FIX | ||
Severity: | normal | ||
Priority: | P1 | ||
Hardware: | All | ||
OS: | Linux | ||
Kernel Version: | 2.6.29-rc1 | Subsystem: | |
Regression: | No | Bisected commit-id: | |
Attachments: | test case: kernel module |
Description
Jeff Layton
2009-01-15 10:42:09 UTC
Created attachment 19816 [details]
test case: kernel module
Part of a reproducer. Kernel module that creates a dummy procfile and then sleeps for 10s before setting pde->owner.
To reproduce, build this and plug it in. After plugging it in, run a program to open the proctest procfile and just hold it open. After the owner is set, close the file. The module refcount will go to -1.
The race window is a lot smaller with most real-world procfiles, but almost all of them are racy.
Time to remove struct proc_dir_entry::owner, I guess. All surgery with proc_reg_file_ops and making remove_proc_entry() reliable made ->owner unnecessary. Final proofreading for races and into bitbucket it goes. That certainly sounds easier, but won't that take away the guarantee that you hold a reference to a module while holding one of its procfiles open? With the reproducer above, that'll just make sure that you never get a module reference at all. For a real-world example, I know that some NFS daemons hold open files under /proc and periodically poll them. What would prevent the module from being unplugged between polls? If we want to get rid of the ->owner field, I we'll still need to have some way to make sure that holding a procfile open gives you a module reference. Looks like ->read_proc, ->write_proc users still rely on ->owner being set. Well, we may shove under the carpet this fact. You care about one thing: module shouldn't be removed while one of callbacks is executed. For that, remove_proc_entry() waits while all users inside module stop executing module's code. After that generic proc code marks PDE as dead and starts returning -E for newcomers. This also fixes "cd into dir and module is pinned" annoyance. So, I'd like to leave this scheme (one may argue about suppying THIS_MODULE during registration, just like we do with ->proc_fops and ->data). But still "bogo-revoke" case #2 in commit 786d7e1612f0b0adb6046f19b906609e4fe8b1ba can't be fixed by this, proxy fops are required, and if we do proxy fops we might as well supply .owner in fops. Also removing ->owner fixes minor bug with subsystems flipping ->owner on live PDE (obvious refcount leak and refcount underleak), simply because it's so simple to assign new ->owner. With proc_fops being const, they might think about doing this better. I look what to do with ->read_proc/->write_proc, after that patch will be straightforward. commit 99b76233803beab302123d243eea9e41149804f3 in mainline |