On Mon, Jan 15, 2018 at 02:18:00PM -0800, Stephen Hemminger wrote: > On Tue, 16 Jan 2018 00:42:40 +0300 > Alexey Dobriyan <adobri...@gmail.com> wrote: > > > /proc has been ignoring struct file_operations::owner field for 10 years. > > Specifically, it started with commit > > 786d7e1612f0b0adb6046f19b906609e4fe8b1ba > > ("Fix rmmod/read/write races in /proc entries"). Notice the chunk where > > inode->i_fop is initialized with proxy struct file_operations for > > regular files: > > > > - if (de->proc_fops) > > - inode->i_fop = de->proc_fops; > > + if (de->proc_fops) { > > + if (S_ISREG(inode->i_mode)) > > + inode->i_fop = &proc_reg_file_ops; > > + else > > + inode->i_fop = de->proc_fops; > > + } > > > > VFS stopped pinning module at this point. > > > > Signed-off-by: Alexey Dobriyan <adobri...@gmail.com> > > What happens if /proc file for the module is open and the module is unloaded? > Just because it is old doesn't mean that it wasn't a bug.
/proc ensures that ->release hook is called for every file which has it set in its struct file_operations either at normal close() time or at rmmod time, see fs/proc/inode.c Normal filesystems don't have this problem because they pin module at mount time. This whole series was started to fix all the races wrt proc entries disappearing while they're being used. Here is likely incomplete list: commit 786d7e1612f0b0adb6046f19b906609e4fe8b1ba commit c2319540cd7330fa9066e5b9b84d357a2c8631a2 commit 5a622f2d0f86b316b07b55a4866ecb5518dd1cf7 commit 2d3a4e3666325a9709cc8ea2e88151394e8f20fc commit 59b7435149eab2dd06dd678742faff6049cb655f commit 881adb85358309ea9c6f707394002719982ec607 commit 300b994b74e75120dd1a48529552a44977e0a82a commit 3dec7f59c370c7b58184d63293c3dc984d475840 commit 99b76233803beab302123d243eea9e41149804f3 and more fixes by Al commit 866ad9a747bbf5461739fcae6d0a41c8971bbe1d commit ca469f35a8e9ef12571a4b80ac6d7fdc0260fb44 commit 05c0ae21c034a6f7c6f4c0c63a31167ebb4b061f commit 7e0e953bb0cf649f93277ac8fb67ecbb7f7b04a9