@@ -41,7 +41,7 @@ void io_bitmap_exit(void)
41
41
}
42
42
43
43
/*
44
- * this changes the io permissions bitmap in the current task.
44
+ * This changes the io permissions bitmap in the current task.
45
45
*/
46
46
long ksys_ioperm (unsigned long from , unsigned long num , int turn_on )
47
47
{
@@ -136,14 +136,24 @@ SYSCALL_DEFINE3(ioperm, unsigned long, from, unsigned long, num, int, turn_on)
136
136
}
137
137
138
138
/*
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.
142
144
*
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.
147
157
*/
148
158
SYSCALL_DEFINE1 (iopl , unsigned int , level )
149
159
{
@@ -164,9 +174,18 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
164
174
security_locked_down (LOCKDOWN_IOPORT ))
165
175
return - EPERM ;
166
176
}
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
+ */
167
182
regs -> flags = (regs -> flags & ~X86_EFLAGS_IOPL ) |
168
183
(level << X86_EFLAGS_IOPL_BIT );
184
+ /* Store the new level in the thread struct */
169
185
t -> iopl = level << X86_EFLAGS_IOPL_BIT ;
186
+ /*
187
+ * X86_32 switches immediately and XEN handles it via emulation.
188
+ */
170
189
set_iopl_mask (t -> iopl );
171
190
172
191
return 0 ;
0 commit comments