diff options
author | Ted Unangst <tedu@cvs.openbsd.org> | 2014-10-09 03:43:35 +0000 |
---|---|---|
committer | Ted Unangst <tedu@cvs.openbsd.org> | 2014-10-09 03:43:35 +0000 |
commit | 4412ac1c73c799d3fa808c6c2d91b189bfa64fbb (patch) | |
tree | 8e70f8fdd82c2668ee4cbed4052d52af8698f0bc | |
parent | 7c46beb83f454d0fb483e79183c1c45f4b6f0c06 (diff) |
no more modules
-rw-r--r-- | sbin/modload/Makefile | 9 | ||||
-rw-r--r-- | sbin/modload/elf.c | 481 | ||||
-rw-r--r-- | sbin/modload/modload.8 | 143 | ||||
-rw-r--r-- | sbin/modload/modload.c | 454 | ||||
-rw-r--r-- | sbin/modload/modload.h | 58 | ||||
-rw-r--r-- | sbin/modload/pathnames.h | 6 | ||||
-rw-r--r-- | sbin/modunload/Makefile | 40 | ||||
-rw-r--r-- | sbin/modunload/modunload.8 | 80 | ||||
-rw-r--r-- | sbin/modunload/modunload.c | 129 | ||||
-rw-r--r-- | sbin/modunload/pathnames.h | 6 |
10 files changed, 0 insertions, 1406 deletions
diff --git a/sbin/modload/Makefile b/sbin/modload/Makefile deleted file mode 100644 index 5c83f4572f2..00000000000 --- a/sbin/modload/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# $OpenBSD: Makefile,v 1.5 2013/07/05 21:29:51 miod Exp $ - -PROG= modload -MAN= modload.8 - -SRCS= modload.c -SRCS+= elf.c - -.include <bsd.prog.mk> diff --git a/sbin/modload/elf.c b/sbin/modload/elf.c deleted file mode 100644 index e4c6ae3bfab..00000000000 --- a/sbin/modload/elf.c +++ /dev/null @@ -1,481 +0,0 @@ -/* $OpenBSD: elf.c,v 1.9 2012/08/31 23:26:47 matthew Exp $ */ -/* $NetBSD: elf.c,v 1.8 2002/01/03 21:45:58 jdolecek Exp $ */ - -/* - * Copyright (c) 1998 Johan Danielsson <joda@pdc.kth.se> - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR - * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES - * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. - * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, - * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, - * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED - * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, - * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/param.h> - -#if defined(__LP64__) -#define ELFSIZE 64 -#else -#define ELFSIZE 32 -#endif -#include <sys/exec_elf.h> -#ifndef ELF_HDR_SIZE -#define ELF_HDR_SIZE sizeof(Elf_Ehdr) -#endif - -#include <sys/types.h> -#include <sys/stat.h> -#include <sys/lkm.h> - -#include <err.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <fcntl.h> - -#include "modload.h" - -char *strtab; - -static void -read_section_header(int fd, Elf_Ehdr *ehdr, int num, Elf_Shdr *shdr) -{ - - if (lseek(fd, ehdr->e_shoff + num * ehdr->e_shentsize, SEEK_SET) < 0) - err(1, "lseek"); - if (read(fd, shdr, sizeof(*shdr)) != sizeof(*shdr)) - err(1, "read"); -} - -struct elf_section { - char *name; /* name of section; points into string table */ - unsigned long type; /* type of section */ - void *addr; /* load address of section */ - off_t offset; /* offset in file */ - size_t size; /* size of section */ - size_t align; - struct elf_section *next; -}; - -/* adds the section `s' at the correct (sorted by address) place in - the list ponted to by head; *head may be NULL */ -static void -add_section(struct elf_section **head, struct elf_section *s) -{ - struct elf_section *p, **q; - q = head; - p = *head; - - while (1) { - if (p == NULL || p->addr > s->addr) { - s->next = p; - *q = s; - return; - } - q = &p->next; - p = p->next; - } -} - -/* make a linked list of all sections containing ALLOCatable data */ -static void -read_sections(int fd, Elf_Ehdr *ehdr, char *shstrtab, struct elf_section **head) -{ - int i; - Elf_Shdr shdr; - - *head = NULL; - /* scan through section headers */ - for (i = 0; i < ehdr->e_shnum; i++) { - struct elf_section *s; - read_section_header(fd, ehdr, i, &shdr); - if ((shdr.sh_flags & SHF_ALLOC) == 0 && - shdr.sh_type != SHT_STRTAB && - shdr.sh_type != SHT_SYMTAB && - shdr.sh_type != SHT_DYNSYM) { - /* skip non-ALLOC sections */ - continue; - } - s = malloc(sizeof(*s)); - if (s == NULL) - errx(1, "failed to allocate %lu bytes", - (u_long)sizeof(*s)); - s->name = shstrtab + shdr.sh_name; - s->type = shdr.sh_type; - s->addr = (void *)shdr.sh_addr; - s->offset = shdr.sh_offset; - s->size = shdr.sh_size; - s->align = shdr.sh_addralign; - add_section(head, s); - } -} - -/* get the symbol table sections and free the rest of them */ -static void -get_symtab(struct elf_section **stab) -{ - struct elf_section *head, *cur, *prev; - - head = NULL; - prev = NULL; - cur = *stab; - while (cur) { - if ((cur->type == SHT_SYMTAB) || (cur->type == SHT_DYNSYM)) { - if (head == NULL) - head = cur; - if (prev != NULL) - prev->next = cur; - prev = cur; - cur = cur->next; - } else { - struct elf_section *p = cur; - cur = cur->next; - p->next = NULL; - free(p); - } - } - - if (prev) - prev->next = NULL; - *stab = head; -} - -/* free a list of section headers */ -static void -free_sections(struct elf_section *head) -{ - - while (head) { - struct elf_section *p = head; - head = head->next; - free(p); - } -} - -/* read section header's string table */ -static char * -read_shstring_table(int fd, Elf_Ehdr *ehdr) -{ - Elf_Shdr shdr; - char *shstrtab; - - read_section_header(fd, ehdr, ehdr->e_shstrndx, &shdr); - - shstrtab = malloc(shdr.sh_size); - if (shstrtab == NULL) - errx(1, "failed to allocate %lu bytes", (u_long)shdr.sh_size); - if (lseek(fd, shdr.sh_offset, SEEK_SET) < 0) - err(1, "lseek"); - if (read(fd, shstrtab, shdr.sh_size) != shdr.sh_size) - err(1, "read"); - return shstrtab; -} - -/* read string table */ -static char * -read_string_table(int fd, struct elf_section *head, int *strtablen) -{ - char *string_table=NULL; - - while (head) { - if (strcmp(head->name, ".strtab") == 0 && - head->type == SHT_STRTAB) { - string_table = malloc(head->size); - if (string_table == NULL) - errx(1, "failed to allocate %lu bytes", - (u_long)head->size); - if (lseek(fd, head->offset, SEEK_SET) < 0) - err(1, "lseek"); - if (read(fd, string_table, head->size) != head->size) - err(1, "read"); - *strtablen = head->size; - break; - } else - head = head->next; - } - return string_table; -} - -static int -read_elf_header(int fd, Elf_Ehdr *ehdr) -{ - ssize_t n; - - n = read(fd, ehdr, sizeof(*ehdr)); - if (n < 0) - err(1, "failed reading %lu bytes", (u_long)sizeof(*ehdr)); - if (n != sizeof(*ehdr)) { - if (debug) - warnx("failed to read %lu bytes", (u_long)sizeof(*ehdr)); - return -1; - } - if (memcmp(ehdr->e_ident, ELFMAG, SELFMAG) != 0 || - ehdr->e_ident[EI_CLASS] != ELFCLASS) - errx(4, "not in ELF%u format", ELFSIZE); - if (ehdr->e_ehsize != ELF_HDR_SIZE) - errx(4, "file has ELF%u identity, but wrong header size", - ELFSIZE); - return 0; -} - -/* offset of data segment; this is horrible, but keeps the size of the - module to a minimum */ -static ssize_t data_offset; - -/* return size needed by the module */ -int -elf_mod_sizes(int fd, size_t *modsize, int *strtablen, - struct lmc_resrv *resrvp, struct stat *sp) -{ - Elf_Ehdr ehdr; - ssize_t off = 0; - size_t data_hole = 0; - char *shstrtab, *strtab; - struct elf_section *head, *s, *stab; - - if (read_elf_header(fd, &ehdr) < 0) - return -1; - shstrtab = read_shstring_table(fd, &ehdr); - read_sections(fd, &ehdr, shstrtab, &head); - - for (s = head; s; s = s->next) { - /* XXX impossible! */ - if (s->type == SHT_STRTAB && s->type == SHT_SYMTAB && - s->type == SHT_DYNSYM) - continue; - if (debug) - fprintf(stderr, - "%s: addr = %p size = %#lx align = %#lx\n", - s->name, s->addr, (u_long)s->size, (u_long)s->align); - /* - * XXX try to get rid of the hole before the data - * section that GNU-ld likes to put there - */ - if (strcmp(s->name, ".data") == 0 && s->addr > (void *)off) { - data_offset = roundup(off, s->align); - if (debug) - fprintf(stderr, ".data section forced to " - "offset %p (was %p)\n", - (void *)data_offset, s->addr); - /* later remove size of compressed hole from off */ - data_hole = (ssize_t)s->addr - data_offset; - } - off = (ssize_t)s->addr + s->size; - } - off -= data_hole; - - /* XXX round to pagesize? */ - *modsize = roundup(off, sysconf(_SC_PAGESIZE)); - - /* get string table length */ - strtab = read_string_table(fd, head, strtablen); - free(shstrtab); - free(strtab); - - /* get symbol table sections */ - get_symtab(&head); - stab = head; - resrvp->sym_symsize = 0; - while (stab) { - resrvp->sym_symsize += stab->size; - stab = stab->next; - } - resrvp->sym_size = resrvp->sym_symsize + *strtablen; - free_sections(head); - - return (0); -} - -/* - * Expected linker options: - * - * -R executable to link against - * -e entry point - * -o output file - * -Ttext address to link text segment to in hex (assumes it's - * a page boundry) - * -Tdata address to link data segment to in hex - * <target> object file */ - -#define LINKCMD "ld -nopie -Z -R %s -e %s -o %s -Ttext %p %s" -#define LINKCMD2 "ld -nopie -Z -R %s -e %s -o %s -Ttext %p -Tdata %p %s" - -/* make a link command; XXX if data_offset above is non-zero, force - data address to be at start of text + offset */ -void -elf_linkcmd(char *buf, size_t len, const char *kernel, - const char *entry, const char *outfile, const void *address, - const char *object) -{ - ssize_t n; - - if (data_offset == 0) - n = snprintf(buf, len, LINKCMD, kernel, entry, - outfile, address, object); - else - n = snprintf(buf, len, LINKCMD2, kernel, entry, - outfile, address, - (const char*)address + data_offset, object); - if (n < 0 || n >= len) - errx(1, "link command longer than %lu bytes", (u_long)len); -} - -/* load a prelinked module; returns entry point */ -void * -elf_mod_load(int fd) -{ - Elf_Ehdr ehdr; - size_t zero_size = 0; - size_t b; - ssize_t n; - char *shstrtab; - struct elf_section *head, *s; - char buf[10 * BUFSIZ]; - void *addr = NULL; - - if (read_elf_header(fd, &ehdr) < 0) - return NULL; - - shstrtab = read_shstring_table(fd, &ehdr); - read_sections(fd, &ehdr, shstrtab, &head); - - for (s = head; s; s = s->next) { - if (s->type != SHT_STRTAB && s->type != SHT_SYMTAB && - s->type != SHT_DYNSYM) { - if (debug) - fprintf(stderr, "loading `%s': addr = %p, " - "size = %#lx\n", - s->name, s->addr, (u_long)s->size); - if (s->type == SHT_NOBITS) { - /* skip some space */ - zero_size += s->size; - } else { - if (addr != NULL) { - /* - * if there is a gap in the prelinked - * module, transfer some empty space. - */ - zero_size += (char*)s->addr - - (char*)addr; - } - if (zero_size) { - loadspace(zero_size); - zero_size = 0; - } - b = s->size; - if (lseek(fd, s->offset, SEEK_SET) == -1) - err(1, "lseek"); - while (b) { - n = read(fd, buf, MIN(b, sizeof(buf))); - if (n == 0) - errx(1, "unexpected EOF"); - if (n < 0) - err(1, "read"); - loadbuf(buf, n); - b -= n; - } - addr = (char*)s->addr + s->size; - } - } - } - if (zero_size) - loadspace(zero_size); - - free_sections(head); - free(shstrtab); - return (void *)ehdr.e_entry; -} - -extern int devfd, modfd; - -void -elf_mod_symload(int strtablen) -{ - Elf_Ehdr ehdr; - char *shstrtab; - struct elf_section *head, *s; - char *symbuf, *strbuf; - - /* - * Seek to the text offset to start loading... - */ - if (lseek(modfd, 0, SEEK_SET) == -1) - err(12, "lseek"); - if (read_elf_header(modfd, &ehdr) < 0) - return; - - shstrtab = read_shstring_table(modfd, &ehdr); - read_sections(modfd, &ehdr, shstrtab, &head); - - for (s = head; s; s = s->next) { - struct elf_section *p = s; - - if ((p->type == SHT_SYMTAB) || (p->type == SHT_DYNSYM)) { - if (debug) - fprintf(stderr, "loading `%s': addr = %p, " - "size = %#lx\n", - s->name, s->addr, (u_long)s->size); - /* - * Seek to the file offset to start loading it... - */ - if (lseek(modfd, p->offset, SEEK_SET) == -1) - err(12, "lseek"); - symbuf = malloc(p->size); - if (symbuf == 0) - err(13, "malloc"); - if (read(modfd, symbuf, p->size) != p->size) - err(14, "read"); - - loadsym(symbuf, p->size); - free(symbuf); - } - } - - for (s = head; s; s = s->next) { - struct elf_section *p = s; - - if ((p->type == SHT_STRTAB) && - (strcmp(p->name, ".strtab") == 0 )) { - if (debug) - fprintf(stderr, "loading `%s': addr = %p, " - "size = %#lx\n", - s->name, s->addr, (u_long)s->size); - /* - * Seek to the file offset to start loading it... - */ - if (lseek(modfd, p->offset, SEEK_SET) == -1) - err(12, "lseek"); - strbuf = malloc(p->size); - if (strbuf == 0) - err(13, "malloc"); - if (read(modfd, strbuf, p->size) != p->size) - err(14, "read"); - - loadsym(strbuf, p->size); - free(strbuf); - } - } - - free(shstrtab); - free_sections(head); - return; -} diff --git a/sbin/modload/modload.8 b/sbin/modload/modload.8 deleted file mode 100644 index 92f4496d79d..00000000000 --- a/sbin/modload/modload.8 +++ /dev/null @@ -1,143 +0,0 @@ -.\" $OpenBSD: modload.8,v 1.27 2013/07/16 09:45:28 schwarze Exp $ -.\" $NetBSD: modload.8,v 1.17 2001/11/16 11:57:16 wiz Exp $ -.\" -.\" Copyright (c) 1993 Christopher G. Demetriou -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed for the -.\" NetBSD Project. See http://www.netbsd.org/ for -.\" information about NetBSD. -.\" 4. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.\" <<Id: LICENSE,v 1.2 2000/06/14 15:57:33 cgd Exp>> -.\" -.Dd $Mdocdate: July 16 2013 $ -.Dt MODLOAD 8 -.Os -.Sh NAME -.Nm modload -.Nd load a kernel module -.Sh SYNOPSIS -.Nm modload -.Op Fl dnSsv -.Op Fl A Ar kernel -.Op Fl e Ar entry -.Op Fl o Ar output_file -.Op Fl p Ar postinstall -.Ar input_file -.Sh DESCRIPTION -The -.Nm -utility loads a loadable kernel module into a running system. -The input file is an object file (.o file). -.Pp -The options to -.Nm -are as follows: -.Bl -tag -width Ds -.It Fl A Ar kernel -Specify the file that is passed to the linker -to resolve module references to external symbols. -The symbol file must be for the currently running -kernel or the module is likely to crash the system. -.It Fl d -Debug. -Used to debug -.Nm -itself. -.It Fl e Ar entry -Specify the module entry point. -This is passed by -.Nm -to -.Xr ld 1 -when the module is linked. -The default module entry point name is `xxxinit'. -If `xxxinit' cannot be found, an attempt to use `<module_name>_lkmentry' -will be made, where <module_name> is the filename being loaded without -the `.o'. -.It Fl n -Do everything, except calling the module entry point (and any -post-install program). -.It Fl o Ar output_file -Specify the name of the output file that is produced by -the linker. -.It Fl p Ar postinstall -Specify the name of a shell script or program that will -be executed if the module is successfully loaded. -It is always passed the module id (in decimal) and module -type (in hexadecimal) as the first two arguments. -For loadable drivers, the third argument is -the block or character major device number. -For a loadable system call, the third argument is the system -call number. -.It Fl S -Do not remove the temporary object file. -By default, the -.Xr ld 1 -output is removed after being loaded into the kernel. -.It Fl s -Do not load symbols from the kernel module. -.It Fl v -Print comments about the loading process. -.El -.Sh FILES -.Bl -tag -width "/usr/include/sys/lkm.hXXX" -compact -.It Pa /dev/ksyms -Default file passed to the linker to resolve external -references in the module. -.It Pa /usr/include/sys/lkm.h -File containing definitions of module types. -.El -.Sh EXIT STATUS -The -.Nm -utility exits with a status of 0 on success -and with a nonzero status if an error occurs. -.Sh SEE ALSO -.Xr ld 1 , -.Xr lkm 4 , -.Xr securelevel 7 , -.Xr modstat 8 , -.Xr modunload 8 -.Sh HISTORY -The -.Nm -command was designed to be similar in functionality -to the corresponding command in -.Tn "SunOS 4.1.3" . -.Sh AUTHORS -.An Terrence R. Lambert Aq Mt terry@cs.weber.edu -.Sh BUGS -.Bl -bullet -.It -The loadable device driver framework can -only reserve either a character or block device entry, not both. -.It -Loading the symbol table is expensive in terms of space: -it presently duplicates all the kernel symbols for each lkm loaded -with -.Fl s . -.El diff --git a/sbin/modload/modload.c b/sbin/modload/modload.c deleted file mode 100644 index 588e39009f0..00000000000 --- a/sbin/modload/modload.c +++ /dev/null @@ -1,454 +0,0 @@ -/* $OpenBSD: modload.c,v 1.45 2013/10/15 02:46:31 deraadt Exp $ */ -/* $NetBSD: modload.c,v 1.30 2001/11/08 15:33:15 christos Exp $ */ - -/* - * Copyright (c) 1993 Terrence R. Lambert. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Terrence R. Lambert. - * 4. The name Terrence R. Lambert may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY TERRENCE R. LAMBERT ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/param.h> -#include <sys/ioctl.h> -#include <sys/conf.h> -#include <sys/mount.h> -#include <sys/lkm.h> -#include <sys/stat.h> -#include <sys/file.h> - -#include <err.h> -#include <errno.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> -#include <nlist.h> - -#include "modload.h" -#include "pathnames.h" - -#define TRUE 1 -#define FALSE 0 - -#ifndef DFLT_ENTRY -#define DFLT_ENTRY "xxxinit" -#endif /* !DFLT_ENTRY */ -#ifndef DFLT_ENTRYEXT -#define DFLT_ENTRYEXT "_lkmentry" -#endif /* !DFLT_ENTRYEXT */ - -int debug = 0; -int verbose = 0; -char *out = NULL; -int symtab = 1; -int Sflag; - -extern char *__progname; - -static void cleanup(void); - -/* prelink the module */ -static int -prelink(const char *kernel, const char *entry, const char *outfile, - const void *address, const char *object) -{ - char cmdbuf[1024]; - int fd; - - linkcmd(cmdbuf, sizeof(cmdbuf), - kernel, entry, outfile, address, object); - - if (debug) - fprintf(stderr, "%s\n", cmdbuf); - - if ((fd = open(kernel, O_RDONLY)) == -1) - errx(1, "can't open %s\n%s: please specify alternative kernel " - "executable with -A option", kernel, __progname); - else - close(fd); - - if (system(cmdbuf) != 0) - return (1); - - return (0); -} - -static void -usage(void) -{ - - fprintf(stderr, "usage: %s [-dnSsv] [-A kernel] [-e entry]\n", - __progname); - fprintf(stderr, "\t[-o output_file] [-p postinstall] input_file\n"); - exit(1); -} - -int fileopen = 0; -#define DEV_OPEN 0x01 -#define MOD_OPEN 0x02 -#define PART_RESRV 0x04 -#define OUTFILE_CREAT 0x08 - -int devfd, modfd; -struct lmc_resrv resrv; - -static void -cleanup(void) -{ - - if (fileopen & PART_RESRV) { - /* - * Free up kernel memory - */ - if (ioctl(devfd, LMUNRESRV, 0) == -1) - warn("can't release slot 0x%08x memory", resrv.slot); - } - - if (fileopen & OUTFILE_CREAT) - unlink(out); -} - -static int -verify_entry(const char *entry, char *filename) -{ - struct nlist names[2]; - int n; - char *s; - - memset(names, 0, sizeof(names)); - if (asprintf(&s, "_%s", entry) == -1) - err(1, "malloc"); - names[0].n_name = s; - - n = nlist(filename, names); - if (n == -1) - err(1, "nlist %s", filename); - free(s); - return n; -} - -/* - * Transfer data to kernel memory in chunks - * of MODIOBUF size at a time. - */ -void -loadbuf(void *buf, size_t len) -{ - struct lmc_loadbuf ldbuf; - size_t n; - char *p = buf; - - while (len) { - n = MIN(len, MODIOBUF); - ldbuf.cnt = n; - ldbuf.data = p; - if (ioctl(devfd, LMLOADBUF, &ldbuf) == -1) - err(11, "error loading buffer"); - len -= n; - p += n; - } -} - -/* Transfer some empty space. */ -void -loadspace(size_t len) -{ - char buf[MODIOBUF]; - size_t n; - - memset(buf, 0, sizeof(buf)); - while (len) { - n = MIN(len, sizeof(buf)); - loadbuf(buf, n); - len -= n; - } -} - -/* - * Transfer symbol table to kernel memory in chunks - * of MODIOBUF size at a time. - */ -void -loadsym(void *buf, size_t len) -{ - struct lmc_loadbuf ldbuf; - size_t n; - char *p = buf; - - while (len) { - n = MIN(len, MODIOBUF); - ldbuf.cnt = n; - ldbuf.data = p; - if (ioctl(devfd, LMLOADSYMS, &ldbuf) == -1) - err(11, "error loading buffer"); - len -= n; - p += n; - } -} - -/* Transfer some empty space. */ -int -main(int argc, char *argv[]) -{ - int strtablen, c, noready = 0, old = 0; - const char *kname = _PATH_KSYMS; - char *entry = DFLT_ENTRY; - char *post = NULL; - char *modobj; - char modout[80], *p; - struct stat stb; - size_t modsize; /* XXX */ - void* modentry; /* XXX */ - - while ((c = getopt(argc, argv, "dnvsA:Se:p:o:")) != -1) { - switch (c) { - case 'd': - debug = 1; - break; /* debug */ - case 'v': - verbose = 1; - break; /* verbose */ - case 'A': - kname = optarg; - break; /* kernel */ - case 'e': - entry = optarg; - break; /* entry point */ - case 'p': - post = optarg; - break; /* postinstall */ - case 'o': - out = optarg; - break; /* output file */ - case 'n': - noready = 1; - break; - case 's': - symtab = 0; - break; - case 'S': - Sflag = 1; - break; - default: - usage(); - } - } - argc -= optind; - argv += optind; - - if (argc != 1) - usage(); - - modobj = argv[0]; - - atexit(cleanup); - - /* - * Open the virtual device device driver for exclusive use (needed - * to write the new module to it as our means of getting it in the - * kernel). - */ - if ((devfd = open(_PATH_LKM, O_RDWR, 0)) == -1) - err(3, "%s", _PATH_LKM); - fileopen |= DEV_OPEN; - - strncpy(modout, modobj, sizeof(modout) - 1); - modout[sizeof(modout) - 1] = '\0'; - - p = strrchr(modout, '.'); - if (!p || strcmp(p, ".o")) - errx(2, "module object must end in .o"); - *p = '\0'; - if (out == NULL) - out = modout; - - /* - * Verify that the entry point for the module exists. - */ - if (verify_entry(entry, modobj)) { - /* - * Try <modobj>_init if entry is DFLT_ENTRY. - */ - if (strcmp(entry, DFLT_ENTRY) == 0) { - if ((p = strrchr(modout, '/'))) - p++; - else - p = modout; - if (asprintf(&entry, "%s%s", p, DFLT_ENTRYEXT) == -1) - err(1, "asprintf"); - if (verify_entry(entry, modobj)) - errx(1, "entry point _%s not found in %s", - entry, modobj); - } else - errx(1, "entry point _%s not found in %s", entry, - modobj); - } - - /* - * Prelink to get file size - */ - if (prelink(kname, entry, out, 0, modobj)) - errx(1, "can't prelink `%s' creating `%s'", modobj, out); - if (Sflag == 0) - fileopen |= OUTFILE_CREAT; - - /* - * Pre-open the 0-linked module to get the size information - */ - if ((modfd = open(out, O_RDONLY, 0)) == -1) - err(4, "%s", out); - fileopen |= MOD_OPEN; - - /* - * stat for filesize to figure out string table size - */ - if (fstat(modfd, &stb) == -1) - err(3, "fstat `%s'", out); - - /* - * work out various sizes and fill in resrv bits - */ - if (mod_sizes(modfd, &modsize, &strtablen, &resrv, &stb) != 0) - err(1, "can't get module sizes"); - - /* - * Close the dummy module -- we have our sizing information. - */ - close(modfd); - fileopen &= ~MOD_OPEN; - - /* - * Reserve the required amount of kernel memory -- this may fail - * to be successful. - */ - resrv.size = modsize; /* size in bytes */ - resrv.name = modout; /* objname w/o ".o" */ - resrv.slot = -1; /* returned */ - resrv.addr = 0; /* returned */ - - if (verbose) - warnx("reserving %lu bytes of memory", (unsigned long)modsize); - - if (ioctl(devfd, LMRESERV, &resrv) == -1) { - if (symtab) { - warn("not loading symbols: kernel does not support " - "symbol table loading"); - } - doold: - symtab = 0; - if (ioctl(devfd, LMRESERV_O, &resrv) == -1) - err(9, "can't reserve memory"); - old = TRUE; - } - fileopen |= PART_RESRV; - - /* - * Relink at kernel load address - */ - if (prelink(kname, entry, out, (void*)resrv.addr, modobj)) - errx(1, "can't link `%s' creating `%s' bound to %p", - modobj, out, (void*)resrv.addr); - - /* - * Open the relinked module to load it... - */ - if ((modfd = open(out, O_RDONLY, 0)) == -1) - err(4, "%s", out); - fileopen |= MOD_OPEN; - - modentry = mod_load(modfd); - if (debug) - (void)fprintf(stderr, "modentry = %p\n", modentry); - - if (symtab) - mod_symload(strtablen); - - /* - * Save ourselves before disaster (potentitally) strikes... - */ - sync(); - - if (noready) - return 0; - - /* - * Trigger the module as loaded by calling the entry procedure; - * this will do all necessary table fixup to ensure that state - * is maintained on success, or blow everything back to ground - * zero on failure. - */ - if (ioctl(devfd, LMREADY, &modentry) == -1) { - if (errno == EINVAL && !old) { - if (fileopen & MOD_OPEN) - close(modfd); - /* - * PART_RESRV is not true since the kernel cleans - * up after a failed LMREADY. - */ - fileopen &= ~(MOD_OPEN|PART_RESRV); - /* try using oldstyle */ - warn("module failed to load using new version; " - "trying old version"); - goto doold; - } else - err(14, "error initializing module"); - } - - /* - * Success! - */ - fileopen &= ~PART_RESRV; /* loaded */ - printf("Module loaded as ID %d\n", resrv.slot); - - /* - * Execute the post-install program, if specified. - */ - if (post) { - struct lmc_stat sbuf; - char name[MAXLKMNAME] = ""; - char id[16], type[32], offset[32]; - - sbuf.id = resrv.slot; - sbuf.name = name; - if (ioctl(devfd, LMSTAT, &sbuf) == -1) - err(15, "error fetching module stats for post-install"); - (void)snprintf(id, sizeof(id), "%d", sbuf.id); - (void)snprintf(type, sizeof(type), "0x%x", sbuf.type); - (void)snprintf(offset, sizeof(offset), "%ld", - (long)sbuf.offset); - /* - * XXX - * The modload docs say that drivers can install bdevsw & - * cdevsw, but the interface only supports one at a time. - */ - execl(post, post, id, type, offset, (char *)NULL); - err(16, "can't exec `%s'", post); - } - - exit (0); -} diff --git a/sbin/modload/modload.h b/sbin/modload/modload.h deleted file mode 100644 index 53a62fc0e99..00000000000 --- a/sbin/modload/modload.h +++ /dev/null @@ -1,58 +0,0 @@ -/* $OpenBSD: modload.h,v 1.5 2013/10/15 02:46:31 deraadt Exp $ */ -/* $NetBSD: modload.h,v 1.2 2001/11/08 15:33:15 christos Exp $ */ - -/* - * Copyright (c) 1993 Terrence R. Lambert. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Terrence R. Lambert. - * 4. The name Terrence R. Lambert may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY TERRENCE R. LAMBERT ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef __modload_h__ -#define __modload_h__ - -int elf_mod_sizes(int, size_t *, int *, struct lmc_resrv *, - struct stat *); -void *elf_mod_load(int); -void elf_linkcmd(char *, size_t, const char *, const char *, - const char *, const void *, const char *); -void elf_mod_symload(int); - -#define mod_sizes elf_mod_sizes -#define mod_load elf_mod_load -#define mod_symload elf_mod_symload -#define linkcmd elf_linkcmd - -void loadbuf(void *, size_t); -void loadspace(size_t); -void loadsym(void *, size_t); - -extern int debug; -extern int verbose; - -#endif /* __modload_h__ */ diff --git a/sbin/modload/pathnames.h b/sbin/modload/pathnames.h deleted file mode 100644 index be006c41653..00000000000 --- a/sbin/modload/pathnames.h +++ /dev/null @@ -1,6 +0,0 @@ -/* $OpenBSD: pathnames.h,v 1.4 2002/01/08 21:28:38 ericj Exp $ */ -/* $NetBSD: pathnames.h,v 1.2 1995/03/18 14:56:46 cgd Exp $ */ - -#include <paths.h> - -#define _PATH_LKM "/dev/lkm" diff --git a/sbin/modunload/Makefile b/sbin/modunload/Makefile deleted file mode 100644 index 3bbfe270d15..00000000000 --- a/sbin/modunload/Makefile +++ /dev/null @@ -1,40 +0,0 @@ -# $OpenBSD: Makefile,v 1.3 1997/09/21 11:37:01 deraadt Exp $ -# -# Makefile for modunload -# -# 25 May 93 Terry Lambert Original -# -# Copyright (c) 1993 Terrence R. Lambert. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in the -# documentation and/or other materials provided with the distribution. -# 3. All advertising materials mentioning features or use of this software -# must display the following acknowledgement: -# This product includes software developed by Terrence R. Lambert. -# 4. The name Terrence R. Lambert may not be used to endorse or promote -# products derived from this software without specific prior written -# permission. -# -# THIS SOFTWARE IS PROVIDED BY TERRENCE R. LAMBERT ``AS IS'' AND ANY -# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -# IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -# ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE -# FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -# DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -# OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -# HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -# LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -# OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -# SUCH DAMAGE. - -PROG= modunload -MAN= modunload.8 - -.include <bsd.prog.mk> diff --git a/sbin/modunload/modunload.8 b/sbin/modunload/modunload.8 deleted file mode 100644 index bb3371ff6ca..00000000000 --- a/sbin/modunload/modunload.8 +++ /dev/null @@ -1,80 +0,0 @@ -.\" $OpenBSD: modunload.8,v 1.16 2013/08/14 12:40:12 jmc Exp $ -.\" $NetBSD: modunload.8,v 1.3 1995/03/18 14:56:49 cgd Exp $ -.\" -.\" Copyright (c) 1993 Christopher G. Demetriou -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. The name of the author may not be used to endorse or promote products -.\" derived from this software without specific prior written permission -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR -.\" IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES -.\" OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. -.\" IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, -.\" INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT -.\" NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, -.\" DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY -.\" THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT -.\" (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF -.\" THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. -.\" -.Dd $Mdocdate: August 14 2013 $ -.Dt MODUNLOAD 8 -.Os -.Sh NAME -.Nm modunload -.Nd unload a kernel module -.Sh SYNOPSIS -.Nm modunload -.Op Fl i Ar id -.Op Fl n Ar name -.Op Fl p Ar postunload -.Sh DESCRIPTION -The -.Nm -utility unloads a loadable kernel module from a running system. -The -.Ar id -or -.Ar name -is the ID or name of the module as shown by -.Xr modstat 8 . -.Pp -One of the following options must be specified: -.Bl -tag -width indent -.It Fl i Ar id -Unload the module with the ID -.Ar id . -.It Fl n Ar name -Unload the module with the name -.Ar name . -.It Fl p Ar postunload -Specify the name of a shell script or program that will be executed if the -module is successfully unloaded. -This program is passed no arguments. -.El -.Sh EXIT STATUS -The -.Nm -utility exits 0 on success or with a non-zero status if an error occurred. -.Sh SEE ALSO -.Xr lkm 4 , -.Xr securelevel 7 , -.Xr modload 8 , -.Xr modstat 8 -.Sh HISTORY -The -.Nm -command was designed to be similar in functionality -to the corresponding command in -.Tn "SunOS 4.1.3" . -.Sh AUTHORS -.An Terrence R. Lambert Aq Mt terry@cs.weber.edu diff --git a/sbin/modunload/modunload.c b/sbin/modunload/modunload.c deleted file mode 100644 index 7b8b84cc692..00000000000 --- a/sbin/modunload/modunload.c +++ /dev/null @@ -1,129 +0,0 @@ -/* $OpenBSD: modunload.c,v 1.14 2003/09/19 17:36:03 deraadt Exp $ */ -/* $NetBSD: modunload.c,v 1.9 1995/05/28 05:23:05 jtc Exp $ */ - -/* - * Copyright (c) 1993 Terrence R. Lambert. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by Terrence R. Lambert. - * 4. The name Terrence R. Lambert may not be used to endorse or promote - * products derived from this software without specific prior written - * permission. - * - * THIS SOFTWARE IS PROVIDED BY TERRENCE R. LAMBERT ``AS IS'' AND ANY - * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE TERRENCE R. LAMBERT BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#include <sys/param.h> -#include <sys/ioctl.h> -#include <sys/conf.h> -#include <sys/mount.h> -#include <sys/lkm.h> - -#include <a.out.h> -#include <err.h> -#include <errno.h> -#include <fcntl.h> -#include <stdio.h> -#include <stdlib.h> -#include <string.h> -#include <unistd.h> - -#include "pathnames.h" - -static void -usage(void) -{ - extern char *__progname; - - (void)fprintf(stderr, "usage: %s [-i id] [-n name] [-p postunload]\n", - __progname); - exit(1); -} - -int -main(int argc, char *argv[]) -{ - int c, devfd; - long modnum = -1; - char *modname = NULL; - char *endptr, *post = NULL; - struct lmc_unload ulbuf; - - while ((c = getopt(argc, argv, "i:n:p:")) != -1) { - switch (c) { - case 'i': - modnum = strtol(optarg, &endptr, 0); - if (modnum < 0 || modnum > INT_MAX || *endptr != '\0') - errx(1, "not a valid number"); - break; - case 'n': - modname = optarg; - break; - case 'p': - post = optarg; - break; - default: - usage(); - break; - } - } - argc -= optind; - argv += optind; - - if (argc != 0 || (modnum == -1 && modname == NULL)) - usage(); - - - /* - * Open the virtual device device driver for exclusive use (needed - * to ioctl() to retrive the loaded module(s) status). - */ - if ((devfd = open(_PATH_LKM, O_RDWR, 0)) == -1) - err(2, "%s", _PATH_LKM); - - /* - * Unload the requested module. - */ - ulbuf.name = modname; - ulbuf.id = (int)modnum; - - if (ioctl(devfd, LMUNLOAD, &ulbuf) == -1) { - switch (errno) { - case EINVAL: - errx(3, "id out of range"); - case ENOENT: - errx(3, "no such module"); - default: - err(5, "LMUNLOAD"); - } - } - - /* - * Execute the post-unload program. - */ - if (post) { - execl(post, post, (char *)NULL); - err(16, "can't exec `%s'", post); - } - exit(0); -} diff --git a/sbin/modunload/pathnames.h b/sbin/modunload/pathnames.h deleted file mode 100644 index c9fcbdb27b0..00000000000 --- a/sbin/modunload/pathnames.h +++ /dev/null @@ -1,6 +0,0 @@ -/* $OpenBSD: pathnames.h,v 1.2 1996/06/23 14:31:08 deraadt Exp $ */ -/* $NetBSD: pathnames.h,v 1.2 1995/03/18 14:56:51 cgd Exp $ */ - -#include <paths.h> - -#define _PATH_LKM "/dev/lkm" |