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?


#include <stdio.h>
#include <unistd.h>

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

if (execvp(argv[1], &argv[1]) == -1)
return 1;

return 0;

#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");
__asm__("inb $0x61, %al\n"
"andb $0xFC, %al\n"
"outb %al, $0x61\n");
return 0;
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
Please read the FAQ at