Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Jun 2005 23:58:22 +0300
From:      Maslan <maslanbsd@gmail.com>
To:        Mauser <mauser@poczta.fm>
Cc:        freebsd-hackers@freebsd.org
Subject:   Re: kld problem
Message-ID:  <319cceca05062213587952cd42@mail.gmail.com>
In-Reply-To: <20050622192127.05bff1b8.mauser@poczta.fm>
References:  <20050622192127.05bff1b8.mauser@poczta.fm>

next in thread | previous in thread | raw e-mail | index | archive | help
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@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:
>=20
> $ cat kldtest.c
>=20
> #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>
>=20
> static int test_nw;
>=20
> static int test_syscall(struct thread *td, void *arg) {
>     struct timeval tv;
>     tv.tv_sec =3D 15;
>     tv.tv_usec =3D 0;
>     tsleep(&test_nw,PWAIT,"test",tvtohz(&tv));
>     return 0;
> }
>=20
> static int test_offset =3D NO_SYSCALL;
>=20
> static struct sysent test_sysent =3D {
>     0, test_syscall
> };
>=20
> static int test_load(struct module *mod, int cmd, void *arg) {
>     if(cmd !=3D MOD_LOAD && cmd !=3D MOD_UNLOAD)
>         return EOPNOTSUPP;
>     return 0;
> }
>=20
> SYSCALL_MODULE(test,&test_offset,&test_sysent,test_load,NULL);
>=20
> $ cat calltest.c
>=20
> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/module.h>
> #include <sys/syscall.h>
>=20
> int main() {
>         struct module_stat stat;
>         stat.version =3D sizeof(stat);
>         modstat(modfind("test"),&stat);
>         return syscall(stat.data.intval);
> }
>=20
> 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.
>=20
> Currently I don't have any idea how to fix it, but it would be nice to
> inform about this issue in manual.
>=20
> Maciek
>=20
> ------------------------------------------------------------------
> Kwiaty dla Taty..
> Wyslij bukiet na Dzien Ojca.. >> http://link.interia.pl/f1897 <<
>=20
> _______________________________________________
> freebsd-hackers@freebsd.org mailing list
> http://lists.freebsd.org/mailman/listinfo/freebsd-hackers
> To unsubscribe, send any mail to "freebsd-hackers-unsubscribe@freebsd.org=
"
>=20


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



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?319cceca05062213587952cd42>