Skip to content

Commit be9afb4

Browse files
committed
x86/iopl: Fixup misleading comment
The comment for the sys_iopl() implementation is outdated and actively misleading in some parts. Fix it up. Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: Andy Lutomirski <[email protected]>
1 parent 0907a09 commit be9afb4

File tree

1 file changed

+27
-8
lines changed

1 file changed

+27
-8
lines changed

arch/x86/kernel/ioport.c

Lines changed: 27 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ void io_bitmap_exit(void)
4141
}
4242

4343
/*
44-
* this changes the io permissions bitmap in the current task.
44+
* This changes the io permissions bitmap in the current task.
4545
*/
4646
long ksys_ioperm(unsigned long from, unsigned long num, int turn_on)
4747
{
@@ -136,14 +136,24 @@ SYSCALL_DEFINE3(ioperm, unsigned long, from, unsigned long, num, int, turn_on)
136136
}
137137

138138
/*
139-
* sys_iopl has to be used when you want to access the IO ports
140-
* beyond the 0x3ff range: to get the full 65536 ports bitmapped
141-
* you'd need 8kB of bitmaps/process, which is a bit excessive.
139+
* The sys_iopl functionality depends on the level argument, which if
140+
* granted for the task is used by the CPU to check I/O instruction and
141+
* CLI/STI against the current priviledge level (CPL). If CPL is less than
142+
* or equal the tasks IOPL level the instructions take effect. If not a #GP
143+
* is raised. The default IOPL is 0, i.e. no permissions.
142144
*
143-
* Here we just change the flags value on the stack: we allow
144-
* only the super-user to do it. This depends on the stack-layout
145-
* on system-call entry - see also fork() and the signal handling
146-
* code.
145+
* Setting IOPL to level 0-2 is disabling the userspace access. Only level
146+
* 3 enables it. If set it allows the user space thread:
147+
*
148+
* - Unrestricted access to all 65535 I/O ports
149+
* - The usage of CLI/STI instructions
150+
*
151+
* The advantage over ioperm is that the context switch does not require to
152+
* update the I/O bitmap which is especially true when a large number of
153+
* ports is accessed. But the allowance of CLI/STI in userspace is
154+
* considered a major problem.
155+
*
156+
* IOPL is strictly per thread and inherited on fork.
147157
*/
148158
SYSCALL_DEFINE1(iopl, unsigned int, level)
149159
{
@@ -164,9 +174,18 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
164174
security_locked_down(LOCKDOWN_IOPORT))
165175
return -EPERM;
166176
}
177+
/*
178+
* Change the flags value on the return stack, which has been set
179+
* up on system-call entry. See also the fork and signal handling
180+
* code how this is handled.
181+
*/
167182
regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) |
168183
(level << X86_EFLAGS_IOPL_BIT);
184+
/* Store the new level in the thread struct */
169185
t->iopl = level << X86_EFLAGS_IOPL_BIT;
186+
/*
187+
* X86_32 switches immediately and XEN handles it via emulation.
188+
*/
170189
set_iopl_mask(t->iopl);
171190

172191
return 0;

0 commit comments

Comments
 (0)