Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 22 Jun 2005 19:21:27 +0200
From:      Mauser <mauser@poczta.fm>
To:        freebsd-hackers@freebsd.org
Subject:   kld problem
Message-ID:  <20050622192127.05bff1b8.mauser@poczta.fm>

next in thread | raw e-mail | index | archive | help
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 <<




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