*BSD News Article 85868


Return to BSD News archive

Path: euryale.cc.adfa.oz.au!newshost.carno.net.au!harbinger.cc.monash.edu.au!munnari.OZ.AU!uunet!in3.uu.net!144.212.100.12!news.mathworks.com!fu-berlin.de!irz401!orion.sax.de!uriah.heep!news
From: j@uriah.heep.sax.de (J Wunsch)
Newsgroups: comp.unix.bsd.freebsd.misc
Subject: Re: Accessing i/o-ports from user-code ?
Date: 30 Dec 1996 22:12:38 GMT
Organization: Private BSD site, Dresden
Lines: 31
Message-ID: <5a9eom$huj@uriah.heep.sax.de>
References: <87g20rbmk6.fsf@acme1.ruhr.de>
Reply-To: joerg_wunsch@uriah.heep.sax.de (Joerg Wunsch)
NNTP-Posting-Host: localhost.heep.sax.de
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 8bit
X-Newsreader: knews 0.9.6
X-Phone: +49-351-2012 669
X-PGP-Fingerprint: DC 47 E6 E4 FF A6 E9 8F  93 21 E0 7D F9 12 D6 4E
Xref: euryale.cc.adfa.oz.au comp.unix.bsd.freebsd.misc:33325

Christoph Haas <chris@acme1.ruhr.de> wrote:

> I need to access i/o-ports from within my application. I wanted to use
> inb() and outb() to send  bytes to a certain  port that is used by  an
> isa  card, but I got  a bus error.  Do I  need  special permissions to
> access the ports...

Yes.  You need to keep a filedescriptor open on /dev/io for this.  If
you're going to make your binary setuid root for this purpose, be
careful to drop permissions as soon as possible.  The safest way is
probably to:


int
main(void)
{
	int dummyfd;

	if ((dummyfd = open("/dev/io", O_RDWR)) == -1)
		err(EX_NOPERM, "Can't get IO privs.");

	(void)setuid(getuid());
	...


-- 
cheers, J"org

joerg_wunsch@uriah.heep.sax.de -- http://www.sax.de/~joerg/ -- NIC: JW11-RIPE
Never trust an operating system you don't have sources for. ;-)