From owner-freebsd-hackers@FreeBSD.ORG Wed Jun 22 22:53:39 2005 Return-Path: X-Original-To: freebsd-hackers@freebsd.org Delivered-To: freebsd-hackers@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 964BE16A41C for ; Wed, 22 Jun 2005 22:53:39 +0000 (GMT) (envelope-from mauser@poczta.fm) Received: from smtp.poczta.interia.pl (smtp2.poczta.interia.pl [213.25.80.232]) by mx1.FreeBSD.org (Postfix) with ESMTP id 4FAA943D4C for ; Wed, 22 Jun 2005 22:53:39 +0000 (GMT) (envelope-from mauser@poczta.fm) Received: by smtp.poczta.interia.pl (INTERIA.PL, from userid 502) id B7D84D1D0B; Thu, 23 Jun 2005 00:53:37 +0200 (CEST) Received: from poczta.interia.pl (mi04.poczta.interia.pl [10.217.12.4]) by smtp.poczta.interia.pl (INTERIA.PL) with ESMTP id 0C870D1BBB; Thu, 23 Jun 2005 00:53:37 +0200 (CEST) Received: by poczta.interia.pl (INTERIA.PL, from userid 502) id 0305E142B21; Thu, 23 Jun 2005 00:53:36 +0200 (CEST) Received: from acer.local (pj162.katowice.sdi.tpnet.pl [217.96.213.162]) by www.poczta.fm (INTERIA.PL) with ESMTP id 68491142B1F; Thu, 23 Jun 2005 00:53:35 +0200 (CEST) Date: Thu, 23 Jun 2005 00:53:37 +0200 From: Mauser To: Dan Nelson Message-Id: <20050623005337.6fccc5e7.mauser@poczta.fm> In-Reply-To: <20050622215258.GE49171@dan.emsphone.com> References: <20050622192127.05bff1b8.mauser@poczta.fm> <20050622215258.GE49171@dan.emsphone.com> X-Mailer: Sylpheed version 1.0.4 (GTK+ 1.2.10; i386-portbld-freebsd5.4) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit X-EMID: 4875e138 Cc: freebsd-hackers@freebsd.org Subject: Re: kld problem X-BeenThere: freebsd-hackers@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Technical Discussions relating to FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 22 Jun 2005 22:53:39 -0000 On Wed, 22 Jun 2005 16:52:58 -0500 Dan Nelson wrote: > In the last episode (Jun 22), Mauser said: > > 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 > ... > > 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_load(struct module *mod, int cmd, void *arg) { > > if(cmd != MOD_LOAD && cmd != MOD_UNLOAD) > > return EOPNOTSUPP; > > return 0; > > > > In test_load, you can return a nonzero value on MOD_UNLOAD to abort an > unload request. See the module(9) manpage for more details. You may > need to increment a counter or hold a mutex while in the syscall to > make it easy for test_load to determine whether it's safe to unload or > not. > Yes, I know, I rtfm ;) This issue occured to me while writing own security-related kld which modify some syscalls and perform authorization (something like rexec,cerb). I think that holding a mutex on each of syscalls would be a bit inefficient. Furthermore I'll need to unset MP_SAFE flags in modified syscalls to be 100% certain that nobody unload the module while executing syscall (mutex _after_ calling syscall won't be enough if i'm not mistaken). Maciek ---------------------------------------------------------------------- OMNIXMAIL! Jesli masz telefon w sieci Era i dostep do WAP, to mozesz na komorce odbierac poczte ze wszystkich swoich kont poczty e-mail! OMNIXMAIL jest w Era Omnix: http://link.interia.pl/f1896