* Race condition: calling remove_proc_entry in cleanup_module (module_exit) while someone's using procfile
@ 2007-09-04 16:39 anon... anon.al
2007-09-04 16:45 ` anon... anon.al
2007-09-04 16:56 ` Alexey Dobriyan
0 siblings, 2 replies; 4+ messages in thread
From: anon... anon.al @ 2007-09-04 16:39 UTC (permalink / raw)
To: linux-kernel
Hi!
There is a race condition if an instance is executing "__exit
device_exit" and calls remove_proc_entry, while someone is still using
the procfile, right?.
static void __exit device_exit(void)
{
// what if the procfile is still in use?
remove_proc_entry(PROC_FILE_NAME, &proc_root);
}
To remove this race condition, the code in "__exit device_exit" must
a) be sure that no other instance is in procfile functions
b) call remove_proc_entry before any other instance accesses the procfile
*** Is this at all possible if a race-condition is to be avoided?
If yes: which mechanism can be used?
Thanks -Albert
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: Race condition: calling remove_proc_entry in cleanup_module (module_exit) while someone's using procfile 2007-09-04 16:39 Race condition: calling remove_proc_entry in cleanup_module (module_exit) while someone's using procfile anon... anon.al @ 2007-09-04 16:45 ` anon... anon.al 2007-09-04 16:56 ` Alexey Dobriyan 1 sibling, 0 replies; 4+ messages in thread From: anon... anon.al @ 2007-09-04 16:45 UTC (permalink / raw) To: albert.neu; +Cc: linux-kernel On 9/4/07, anon... anon.al <anon.asdf@gmail.com> wrote: <snip> > If yes: which mechanism can be used? I was thinking about using an atomic counter in procfile_write proc_f = create_proc_entry(PROC_FILE_NAME, 0644, NULL); //... proc_f->write_proc = procfile_write; int procfile_write(struct file *filp, const char *buffer, \ unsigned long len, void *data) { //"StackXXX" atomic_inc(&cnt_procfile_users); printk(KERN_ALERT "Hi there!\n"); atomic_dec(&cnt_procfile_users); wake_up_interruptible(&queue); return len; } and then in cleanup_module using: wait_event_interruptible(queue, \ ( \ spin_lock_irqsave(&lock, flags), \ cnt = atomic_read(&cnt_procfile_users), \ ((cnt == 0) \ ? 1 \ : (spin_unlock_irqrestore(&lock, flags), 0))\ )); remove_proc_entry(PROC_FILE_NAME, &proc_root); spin_unlock_irqrestore(&lock, flags); But: x1) Could it happen that code is already in function procfile_write at "StackXXX" (before atomic_inc(&cnt_procfile_users)) when the scheduler switches to another task?? ((Or is the "entering into a function, up to the function's first statement" atomic??)) x2) Could it happen that the scheduler switches, after atomic_dev(&cnt_procfile_users) but before return len?? If so, then it could happen that we're in spin_lock_irqsave, while someone else is still using the procfile; and then this code still fails miserably. ? Regards -Albert ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Race condition: calling remove_proc_entry in cleanup_module (module_exit) while someone's using procfile 2007-09-04 16:39 Race condition: calling remove_proc_entry in cleanup_module (module_exit) while someone's using procfile anon... anon.al 2007-09-04 16:45 ` anon... anon.al @ 2007-09-04 16:56 ` Alexey Dobriyan 2007-09-04 17:35 ` anon... anon.al 1 sibling, 1 reply; 4+ messages in thread From: Alexey Dobriyan @ 2007-09-04 16:56 UTC (permalink / raw) To: anon... anon.al; +Cc: linux-kernel On Tue, Sep 04, 2007 at 06:39:33PM +0200, anon... anon.al wrote: > There is a race condition if an instance is executing "__exit > device_exit" and calls remove_proc_entry, while someone is still using > the procfile, right?. > > static void __exit device_exit(void) > { > // what if the procfile is still in use? > remove_proc_entry(PROC_FILE_NAME, &proc_root); > } For regular proc files, this is fixed in 2.6.23-rc1 and later. ^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Race condition: calling remove_proc_entry in cleanup_module (module_exit) while someone's using procfile 2007-09-04 16:56 ` Alexey Dobriyan @ 2007-09-04 17:35 ` anon... anon.al 0 siblings, 0 replies; 4+ messages in thread From: anon... anon.al @ 2007-09-04 17:35 UTC (permalink / raw) To: Alexey Dobriyan; +Cc: linux-kernel On 9/4/07, Alexey Dobriyan <adobriyan@gmail.com> wrote: > For regular proc files, this is fixed in 2.6.23-rc1 and later. Thanks! I see you've been working on it: fix-rmmod-read-write-races-in-proc-entries... http://www.kernel.org/pub/linux/kernel/people/akpm/patches/2.6/2.6.22-rc6/2.6.22-rc6-mm1/broken-out/ (( older relevant posts: http://groups.google.com/group/linux.kernel/browse_thread/thread/4c74bbea17727e6e/809c15bd0e6fa8f9? http://groups.google.com/group/fa.linux.kernel/browse_thread/thread/fb03e1a500fcb258/563a7f11acdec992? )) Thanks, Albert ^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2007-09-04 17:35 UTC | newest] Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2007-09-04 16:39 Race condition: calling remove_proc_entry in cleanup_module (module_exit) while someone's using procfile anon... anon.al 2007-09-04 16:45 ` anon... anon.al 2007-09-04 16:56 ` Alexey Dobriyan 2007-09-04 17:35 ` anon... anon.al
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®