kld problem

Maslan maslanbsd at gmail.com
Wed Jun 22 20:58:23 GMT 2005


i don't know if kld should check if the module is used or not before
unloading it.
but i should.


On 6/22/05, Mauser <mauser at poczta.fm> wrote:
> Unloading syscall kernel module can cause a system crash. It occurs when we
> unload the module while a process is executing our syscall. Example:
> 
> $ cat kldtest.c
> 
> #include <sys/types.h>
> #include <sys/param.h>
> #include <sys/proc.h>
> #include <sys/module.h>
> #include <sys/sysent.h>
> #include <sys/kernel.h>
> #include <sys/systm.h>
> #include <sys/time.h>
> #include <sys/timetc.h>
> 
> static int test_nw;
> 
> static int test_syscall(struct thread *td, void *arg) {
>     struct timeval tv;
>     tv.tv_sec = 15;
>     tv.tv_usec = 0;
>     tsleep(&test_nw,PWAIT,"test",tvtohz(&tv));
>     return 0;
> }
> 
> static int test_offset = NO_SYSCALL;
> 
> static struct sysent test_sysent = {
>     0, test_syscall
> };
> 
> static int test_load(struct module *mod, int cmd, void *arg) {
>     if(cmd != MOD_LOAD && cmd != MOD_UNLOAD)
>         return EOPNOTSUPP;
>     return 0;
> }
> 
> SYSCALL_MODULE(test,&test_offset,&test_sysent,test_load,NULL);
> 
> $ cat calltest.c
> 
> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/module.h>
> #include <sys/syscall.h>
> 
> int main() {
>         struct module_stat stat;
>         stat.version = sizeof(stat);
>         modstat(modfind("test"),&stat);
>         return syscall(stat.data.intval);
> }
> 
> We load the module, execute calltest, and within 15 seconds unload the
> module. We get a kernel panic, because we removed the memory where our
> test_syscall was located.
> 
> Currently I don't have any idea how to fix it, but it would be nice to
> inform about this issue in manual.
> 
> Maciek
> 
> ------------------------------------------------------------------
> Kwiaty dla Taty..
> Wyslij bukiet na Dzien Ojca.. >> http://link.interia.pl/f1897 <<
> 
> _______________________________________________
> freebsd-hackers at freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe at freebsd.org"
> 


-- 
I'm Searching For Perfection,
So Even If U Need Portability U've To Use Assembly ;-)
http://www.maslanlab.org


More information about the freebsd-hackers mailing list