svgalib program is setuid root but still can't seem to allocate graphics console

Chris Pressey cpressey at catseye.mine.nu
Thu Sep 18 13:21:21 PDT 2003


On Thu, 18 Sep 2003 12:04:53 -0700
Chris Pressey <cpressey at catseye.mine.nu> wrote:

> On Thu, 18 Sep 2003 11:00:25 -0700
> Chris Pressey <cpressey at catseye.mine.nu> wrote:
> 
> > Hi,
> > 
> > I'm trying to write some code that uses /usr/ports/graphics/svgalib.
> > 
> > I've started off with the first example program on:
> > 
> >   http://www.svgalib.org/jay/beginners_guide/beginners_guide.html
> > 
> > As root, I can compile and run it fine, and I get the message:
> > 
> >   [svgalib: allocated virtual console #10]
> > 
> > And if I try to run it as a normal user, I get:
> > 
> >   svgalib: Cannot get I/O permissions.
> > 
> > This is expected, because the program is not setuid root.  So as
> > root I chmod u+s it, but then when I run it as a normal user I get:
> > 
> >   You must be the owner of the current console to use svgalib.
> >   Not running in a graphics capable console,
> >   and unable to find one.
> >   Using RAGE driver, 8192KB.   ChipID:35 MemType:6
> >   Rage: BIOS reports base frequency=28.636MHz  Denominator= 31
> >   svgalib 1.4.3
> >   You must be the owner of the current console to use svgalib.
> >   Not running in a graphics capable console,
> >   and unable to find one.
> >   Not running in a graphics capable console,
> >   and unable to find one.
> > 
> > This is on ttyv0, btw.  I'm running X on ttyv9.
> 
> Followup: this is happening not just with my own program, but with
> programs in the ports tree like /usr/ports/graphics/acidwarp and
> /usr/ports/graphics/seejpeg, on both of my FreeBSD machines:
> 
> FreeBSD foo 4.9-PRERELEASE FreeBSD 4.9-PRERELEASE #0: Thu Aug 28
> 11:26:32 CDT 2003     root at foo:/usr/obj/usr/src/sys/FOO  i386
> 
> FreeBSD bar 4.9-PRERELEASE FreeBSD 4.9-PRERELEASE #3: Tue Sep  9
> 11:35:09 CDT 2003     root at bar:/usr/obj/usr/src/sys/BAR  i386
> 
> Both machines contain this in their dmesg:
> 
> vga0: <Generic ISA VGA> at port 0x3c0-0x3df iomem 0xa0000-0xbffff on
> isa0
> 
> But in short this doesn't feel like a video problem, it feels like a
> setuid-bit/svgalib/both problem.
> 
> Is anyone else experiencing these sorts of problems?  Was there some
> recent STABLE change regarding setuid/svgalib that I missed?
> 
> -Chris

Oho, I found something!

If I (as a normal user) happen to be logged in on ttyv1 as well as
ttyv0, I *can* run seejpeg from ttyv0.  Likewise, if I'm logged in on
ttyv2, I can run it on ttyv1...

It looks like there's an off-by-one error in vga.c:
The function check_owner() takes an argument which is the number of the
current virtual console.  This number is retrieved by a call to
ioctl(..., VT_GETACTIVE, &vts)

Has perhaps this ioctl changed lately, where it's returning 1 instead of
0, for ttyv0?

It would be simple enough to prepare a patch and a PR for this, but it
would be nice to know if this is affecting other people, and why its
happening, first.

-Chris


More information about the freebsd-questions mailing list