diff options
-rw-r--r-- | lkm/ap/Makefile | 8 | ||||
-rw-r--r-- | lkm/ap/README | 84 | ||||
-rw-r--r-- | lkm/ap/aperture.c | 74 | ||||
-rw-r--r-- | lkm/ap/apinstall | 16 | ||||
-rw-r--r-- | lkm/ap/aptest/Makefile | 6 | ||||
-rw-r--r-- | lkm/ap/aptest/aptest.c | 122 | ||||
-rw-r--r-- | lkm/ap/lkm.c | 43 | ||||
-rw-r--r-- | lkm/ap/version.c | 8 | ||||
-rw-r--r-- | lkm/ap/version.h | 8 |
9 files changed, 369 insertions, 0 deletions
diff --git a/lkm/ap/Makefile b/lkm/ap/Makefile new file mode 100644 index 00000000000..f2ac7ec97ec --- /dev/null +++ b/lkm/ap/Makefile @@ -0,0 +1,8 @@ +# $OpenBSD: Makefile,v 1.1 1996/03/05 11:25:24 mickey Exp $ + +LKM= ap +SRCS+= aperture.c lkm.c version.c +NOMAN= noman +SUBDIR= aptest + +.include <bsd.lkm.mk> diff --git a/lkm/ap/README b/lkm/ap/README new file mode 100644 index 00000000000..3103f1204c5 --- /dev/null +++ b/lkm/ap/README @@ -0,0 +1,84 @@ +# $OpenBSD: README,v 1.1 1996/03/05 11:25:27 mickey Exp $ + + XFree86 Framebuffer aperture driver for NetBSD. + ----------------------------------------------- + +This module was written to help work around the security feature of +NetBSD 0.9C and later that prevents read/write access to /dev/mem. + +XFree86 can take advantage of having direct access to video +memory (especially with VLB and PCI cards) and even requires it for +the P9000 server. + +This driver works like the standard /dev/mem driver. It just allows +mapping of the VGA framebuffer even if kernel security level is > 0. +The driver only implements the open(), close() and mmap() calls. In +order not to defeat kernel security, only one open() at a time is +allowed and only a process with effective user id of 0 can perform +it. So while you're running XFree86, no other process will be allowed +to open /dev/xf86. + +This work is heavily inspired from the Solaris x86 aperture driver by +Doug Anson (danson@lgc.com) and David Holland (davidh@use.com). + + +Installation: +------------- + +1. Edit the Makefile if you want to modify the default installation + directory. + +2. run make depend && make; then as root, run make install. + +3. add these lines somehere at the end of /etc/rc.local (before the + sysctl that raises the security level): + + KERNDIR=/usr/X11R6/lib/X11/kernel + if [ -f ${KERNDIR}/ap.o ]; then + modload -o ${KERNDIR}/ap -e ap -p ${KERNDIR}/apinstall ${KERNDIR}/ap.o + fi + + to load the driver at bootime. + +4. Reboot your system. + +5. If you're running a version prior to NetBSD 1.0, modload does not + execute post-install scripts. So you have to create the device manually. + If you're running NetBSD 1.0 or later, skip this. + + WARNING: be sure to understand what you'll do before proceeding + + a) find out what major device number will be allocated to you by + modload. Modload allocates major numbers beginning at 29. So if + 'ap' is your only device driver module, it will have major + number 29. If it's the third, it will be 31... + + b) goto the /dev directory and type ``mknod xf86 c 29 0'' (replace + 29 by the appropriate value if you load more than one device + driver module. + + Make sure that rc.local loads the module every time at the same + position as it did now. + +6. Test the module by running 'aptest' as root. The outpout will look like: + +# ./aptest +NOTICE: VGA mapped [0xa0000 ,size=4096) to addr=0x10073000... + +DONE displaying memory contents (80 bytes) +UNMAPPING [0xa0000 ,size=4096) to addr=0x10073000... and closing...DONE. +Exiting successful... + +7. If you're running XFree86 3.1 or higher, just make sure that + HasNetBSDApertureDriver is set to YES in xf86site.def before building + your server. The netBSD binary distribution has the aperture driver + code enabled. + +Bug reports, comments, suggestions can be sent to matthieu@laas.fr + +--Matthieu Herrb + +---------------------------------------------------------------------- + + Copyright (c) 1994 The XFree86 Project Inc. + diff --git a/lkm/ap/aperture.c b/lkm/ap/aperture.c new file mode 100644 index 00000000000..09de3223ffb --- /dev/null +++ b/lkm/ap/aperture.c @@ -0,0 +1,74 @@ +/* $OpenBSD: aperture.c,v 1.1 1996/03/05 11:25:29 mickey Exp $ */ + +/* + * Copyright 1994 the XFree86 Project Inc. + */ + +/* + * linear framebuffer aperture driver for NetBSD + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/proc.h> +#include <sys/errno.h> + +#define VGA_START 0xA0000 +#define VGA_END 0xBFFFF + +/* open counter */ +static int ap_open_count = 0; + +/* + * Open the device + */ +int +apopen(dev_t dev, int oflags, int devtype, struct proc *p) +{ + struct pcred *pc = p->p_cred; + + if (suser(p->p_ucred, &p->p_acflag) != 0) { + return(EPERM); + } + /* authorize only one simultaneous open() */ + if (ap_open_count > 0) { + return(EPERM); + } + ap_open_count++; + + return(0); +} + +/* + * Close the device + */ +int +apclose(dev_t dev, int cflags, int devtype, struct proc *p) +{ + + ap_open_count--; + return(0); +} + +/* + * mmap() physical memory sections + * + * allow only section in the vga framebuffer and above main memory + * to be mapped + */ +int +apmmap(dev_t dev, int offset, int length) +{ + +#ifdef AP_DEBUG + printf("apmmap: addr 0x%x\n", offset); +#endif + if ((minor(dev) == 0) + && (offset >= VGA_START && offset <= VGA_END + || (unsigned)offset > (unsigned)ctob(physmem))) { + return i386_btop(offset); + } else { + return(-1); + } +} + diff --git a/lkm/ap/apinstall b/lkm/ap/apinstall new file mode 100644 index 00000000000..eef9f931350 --- /dev/null +++ b/lkm/ap/apinstall @@ -0,0 +1,16 @@ +#! /bin/sh +# $OpenBSD: apinstall,v 1.1 1996/03/05 11:25:31 mickey Exp $ +# +# Postinstall script for NetBSD Aperture Driver +# +# Copyright (C) 1994 The XFree86 Project Inc. +# +if [ $# -ne 3 ]; then + echo "$0: should be called by modload(8) with 3 arguments" + exit 1 +fi + +echo "Major device number: $3" +rm -f /dev/xf86 +mknod /dev/xf86 c $3 0 +exit 0 diff --git a/lkm/ap/aptest/Makefile b/lkm/ap/aptest/Makefile new file mode 100644 index 00000000000..2b63c0a111c --- /dev/null +++ b/lkm/ap/aptest/Makefile @@ -0,0 +1,6 @@ +# $OpenBSD: Makefile,v 1.1 1996/03/05 11:25:42 mickey Exp $ + +PROG= aptest +NOMAN= noman + +.include <bsd.prog.mk> diff --git a/lkm/ap/aptest/aptest.c b/lkm/ap/aptest/aptest.c new file mode 100644 index 00000000000..ed73cdd28ab --- /dev/null +++ b/lkm/ap/aptest/aptest.c @@ -0,0 +1,122 @@ +/* $OpenBSD: aptest.c,v 1.1 1996/03/05 11:25:46 mickey Exp $ */ +/* + * Copyright 1994 Doug Anson, danson@lgc.com & David Holland, davidh@use.com + * + * Author: Doug Anson (danson@lgc.com) + * Date : 2/21/94 + * Modifed: David Holland (davidh@use.com) + * Log: + * DWH - Changed names/added comments 2/23/94 + * DWH - Removed annoying delays. 2/23/94 + * + * This program test the fb aperture driver by 'cheating' + * it uses the aperture driver to access/read the main + * system BIOS header + * + * Copyright notice: + * Permission to use, copy, modify, distribute, and sell this software and its + * documentation for any purpose is hereby granted without fee, provided that + * the above copyright notice appear in all copies and that both that + * copyright notice and this permission notice appear in supporting + * documentation, and that the name of Doug Anson, and David Holland be used in + * advertising or publicity pertaining to distribution of the software + * Doug Anson, and David Holland make no * representations about the + * suitability of this software for any purpose. + * It is provided "as is" without express or implied warranty. + * + * Disclaimer: + * DOUG ANSON, AND DAVID HOLLAND DISCLAIMS ALL WARRIENTS WITH REGARD TO THIS + * SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY, AND FITNESS, + * IN NO EVENT SHALL DOUG ANSON, OR DAVID HOLLAND BE LIABLE FOR ANY SPECIAL, + * INDIRECT, OR CONSEQUENTIAL DAMAGES, OR ANY DAMAGES WHATSOEVER RESULTING FROM + * USAGE OF THIS SOFTWARE. + */ + +/* + * linear framebuffer aperture driver test program + */ + +/* + * Id + */ + + +#include <stdio.h> +#include <sys/types.h> +#include <sys/mman.h> +#include <sys/stat.h> +#include <fcntl.h> +#include <errno.h> + +#if !defined(sun) +extern void exit(int); +extern caddr_t mmap(); +extern int close(); +extern int munmap(); +#endif + +/* framebuffer access defines */ +#define AP_DEV "/dev/xf86" /* framebuffer apperture device */ +#define PADDR 0xa0000 /* offset from fbmem base */ +#define BUF_LENGTH 0x1000 /* length in bytes -- ignored */ + +/* debug testing defines */ +#define START_INDEX 0 /* display starting index(>=0)*/ +#define STOP_INDEX 80 /* display stopping index */ +#define INCR 1 /* display increment */ + +/* main program */ +int main(int argc,char **argv) +{ + caddr_t addr = (caddr_t)0; + int fb_dev; + long start = START_INDEX; + long stop = STOP_INDEX; + int i; + + /* open the framebuffer device */ + fb_dev = open (AP_DEV,O_RDWR); + if (fb_dev < 0) + { + /* failed to open framebuffer driver */ + printf("ERROR: failed to open %s\n",AP_DEV); + perror("ERROR: open()"); + exit(1); + } + + /* memory map the framebuffer */ + addr = (caddr_t)mmap((caddr_t)0,BUF_LENGTH,PROT_READ|PROT_WRITE,MAP_SHARED, + fb_dev,(off_t)PADDR); + if (addr == (caddr_t)-1) + { + /* failed to memory map framebuffer driver */ + printf("ERROR: failed to mmap [0x%x ,size=%d bytes)\n", + PADDR,BUF_LENGTH); + perror("ERROR: mmap()"); + close(fb_dev); + exit(1); + } + else + { + /* frame buffer mapped */ + close(fb_dev); + printf("NOTICE: BIOS mapped [0x%x ,size=%d) to addr=0x%x...\n", + PADDR,BUF_LENGTH,(int)addr); + + /* display the buffer */ + for(i=start;i<stop;i=i+INCR) + printf("%c",addr[i]); + /* printf("addr[%d]=%c\n",i,addr[i]); + */ + printf("\nDONE displaying memory contents (%d bytes)\n",stop); + + /* unmap and close */ + printf("UNMAPPING [0x%x ,size=%d) to addr=0x%x... and closing...", + PADDR,BUF_LENGTH,(int)addr); + munmap(addr,BUF_LENGTH); + printf("DONE.\n"); + printf("Exiting successful...\n"); + exit(0); + } + return 1; +} diff --git a/lkm/ap/lkm.c b/lkm/ap/lkm.c new file mode 100644 index 00000000000..a0dcedae6c3 --- /dev/null +++ b/lkm/ap/lkm.c @@ -0,0 +1,43 @@ +/* $OpenBSD: lkm.c,v 1.1 1996/03/05 11:25:34 mickey Exp $ */ +/* + * Copyright (c) 1994 The XFree86 Project Inc. + */ + +#include <sys/param.h> +#include <sys/systm.h> +#include <sys/conf.h> +#include <sys/uio.h> +#include <sys/exec.h> +#include <sys/lkm.h> +#include <errno.h> +#include "version.h" + +extern int apopen(dev_t dev, int oflags, int devtype, struct proc *p); +extern int apclose(dev_t dev, int fflags, int devtype, struct proc *p); +extern int apmmap(dev_t dev, int offset, int length); + +static struct cdevsw newdev = { + apopen, apclose, + (dev_type_read((*))) enodev, (dev_type_write((*))) enodev, + (dev_type_ioctl((*))) enodev, + (dev_type_stop((*))) enodev, + 0, seltrue, (dev_type_mmap((*))) apmmap, 0}; + +MOD_DEV("ap", LM_DT_CHAR, -1, &newdev) + +static int +ap_load(struct lkm_table *lkmtp, int cmd) +{ + if (cmd == LKM_E_LOAD) { + printf("\n Aperture driver for XFree86 version %s.%s\n", + ap_major_version, ap_minor_version); + } + return(0); +} + +int +ap(struct lkm_table *lkmtp, int cmd, int ver) +{ + DISPATCH(lkmtp, cmd, ver, ap_load, lkm_nofunc, lkm_nofunc) +} + diff --git a/lkm/ap/version.c b/lkm/ap/version.c new file mode 100644 index 00000000000..b545be13898 --- /dev/null +++ b/lkm/ap/version.c @@ -0,0 +1,8 @@ +/* $OpenBSD: version.c,v 1.1 1996/03/05 11:25:36 mickey Exp $ */ +/* + * Loadable Kernel Module for XFree86 Aperture driver + * + * Copyright (c) 1994 The XFree86 Project Inc. + */ +char *ap_major_version = "1"; +char *ap_minor_version = "4"; diff --git a/lkm/ap/version.h b/lkm/ap/version.h new file mode 100644 index 00000000000..d71bb41ed3f --- /dev/null +++ b/lkm/ap/version.h @@ -0,0 +1,8 @@ +/* $OpenBSD: version.h,v 1.1 1996/03/05 11:25:38 mickey Exp $ */ +/* + * Loadable Kernel Module for XFree86 Aperture driver + * + * Copyright (c) 1994 Matthieu Herrb + */ +extern char *ap_major_version; +extern char *ap_minor_version; |