Are the out
and in
instructions privileged instructions? I assume they are because if they were not, then any process running in user mode can access port mapped I/O hardware. But I can't find anything online that confirms that.
Asked
Active
Viewed 540 times
1

Cody Gray - on strike
- 239,200
- 50
- 490
- 574

user247763
- 191
- 5
- 15
-
2yes they are or can be. What did you find when you read the documentation? – old_timer Jun 15 '17 at 20:40
-
which is oneline... – old_timer Jun 15 '17 at 20:42
1 Answers
3
They are tied to the I/O privilege level (IOPL), as documented here for OUT
and here for IN
. The IOPL is bits 12-13 of the (R|E)FLAGS
register. If the current privilege level is greater than (i.e. has less privilege than) the value in the IOPL, IN
and OUT
will not work.
This obviously applies to operating modes other than real mode, which doesn't have any concept of privilege levels.

Govind Parmar
- 20,656
- 7
- 53
- 85
-
3
-
@fuz Yes, but this question was specifically about the instructions. – Govind Parmar Jun 15 '17 at 21:01
-
1Right, but the point is that an operating system can configure things so that `outb 0x60` is allowed in a user-space process, but `outb 0x50` faults, right? OTOH, Linux uses a larger bitmap in software, presumably catching the exception from `in`/`out` and checking (in software) if it should have been allowed. See http://man7.org/linux/man-pages/man2/ioperm.2.html – Peter Cordes Jun 28 '17 at 05:13