iopl not preserved across execve on x64

From: Alex Henrie
Date: Mon Jul 02 2012 - 17:46:13 EST


Dear Linux kernel developers,

I have a question about how iopl works with execve. Essentially, I
want to set iopl to 3 with one program, then call execve to change to
another program that writes to the system speaker. This works fine on
x86 kernels, but segfaults on x64 kernels. Why is this?

-Alex

---iopl3.c---
#include <stdio.h>
#include <unistd.h>

int main(int argc, char* argv[])
{
if (iopl(3) == -1)
{
perror("iopl");
return 1;
}

if (execvp(argv[1], &argv[1]) == -1)
{
perror("execvp");
return 1;
}

return 0;
}

---beep.c---
#include <stdio.h>

int main()
{
__asm__("movb $0xB6, %al\n"
"outb %al, $0x43\n"
"inb $0x61, %al\n"
"orb $0x03, %al\n"
"outb %al, $0x61\n"
"movb $0x64, %al\n"
"outb %al, $0x42\n"
"movb $0x01, %al\n"
"outb %al, $0x42\n");
sleep(1);
__asm__("inb $0x61, %al\n"
"andb $0xFC, %al\n"
"outb %al, $0x61\n");
return 0;
}

---test.sh---
gcc iopl3.c -o iopl3
gcc beep.c -o beep
sudo setcap cap_sys_rawio+eip ./iopl3
./iopl3 ./beep
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/