Release 4.10 arch/x86/kernel/ioport.c
/*
* This contains the io-permission bitmap code - written by obz, with changes
* by Linus. 32/64 bits code unification by Miguel Botón.
*/
#include <linux/sched.h>
#include <linux/kernel.h>
#include <linux/capability.h>
#include <linux/errno.h>
#include <linux/types.h>
#include <linux/ioport.h>
#include <linux/smp.h>
#include <linux/stddef.h>
#include <linux/slab.h>
#include <linux/thread_info.h>
#include <linux/syscalls.h>
#include <linux/bitmap.h>
#include <asm/syscalls.h>
/*
* this changes the io permissions bitmap in the current task.
*/
asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
{
struct thread_struct *t = ¤t->thread;
struct tss_struct *tss;
unsigned int i, max_long, bytes, bytes_updated;
if ((from + num <= from) || (from + num > IO_BITMAP_BITS))
return -EINVAL;
if (turn_on && !capable(CAP_SYS_RAWIO))
return -EPERM;
/*
* If it's the first ioperm() call in this thread's lifetime, set the
* IO bitmap up. ioperm() is much less timing critical than clone(),
* this is why we delay this operation until now:
*/
if (!t->io_bitmap_ptr) {
unsigned long *bitmap = kmalloc(IO_BITMAP_BYTES, GFP_KERNEL);
if (!bitmap)
return -ENOMEM;
memset(bitmap, 0xff, IO_BITMAP_BYTES);
t->io_bitmap_ptr = bitmap;
set_thread_flag(TIF_IO_BITMAP);
}
/*
* do it in the per-thread copy and in the TSS ...
*
* Disable preemption via get_cpu() - we must not switch away
* because the ->io_bitmap_max value must match the bitmap
* contents:
*/
tss = &per_cpu(cpu_tss, get_cpu());
if (turn_on)
bitmap_clear(t->io_bitmap_ptr, from, num);
else
bitmap_set(t->io_bitmap_ptr, from, num);
/*
* Search for a (possibly new) maximum. This is simple and stupid,
* to keep it obviously correct:
*/
max_long = 0;
for (i = 0; i < IO_BITMAP_LONGS; i++)
if (t->io_bitmap_ptr[i] != ~0UL)
max_long = i;
bytes = (max_long + 1) * sizeof(unsigned long);
bytes_updated = max(bytes, t->io_bitmap_max);
t->io_bitmap_max = bytes;
/* Update the TSS: */
memcpy(tss->io_bitmap, t->io_bitmap_ptr, bytes_updated);
put_cpu();
return 0;
}
Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 88 | 34.78% | 8 | 38.10% |
ingo molnar | ingo molnar | 43 | 17.00% | 1 | 4.76% |
miguel boton | miguel boton | 37 | 14.62% | 1 | 4.76% |
benjamin lahaise | benjamin lahaise | 17 | 6.72% | 1 | 4.76% |
akinobu mita | akinobu mita | 16 | 6.32% | 1 | 4.76% |
thomas gleixner | thomas gleixner | 12 | 4.74% | 1 | 4.76% |
brian gerst | brian gerst | 11 | 4.35% | 1 | 4.76% |
albert cahalan | albert cahalan | 8 | 3.16% | 2 | 9.52% |
andrew morton | andrew morton | 6 | 2.37% | 1 | 4.76% |
stephane eranian | stephane eranian | 5 | 1.98% | 1 | 4.76% |
shai fultheim | shai fultheim | 5 | 1.98% | 1 | 4.76% |
robert love | robert love | 4 | 1.58% | 1 | 4.76% |
andy lutomirski | andy lutomirski | 1 | 0.40% | 1 | 4.76% |
| Total | 253 | 100.00% | 21 | 100.00% |
/*
* sys_iopl has to be used when you want to access the IO ports
* beyond the 0x3ff range: to get the full 65536 ports bitmapped
* you'd need 8kB of bitmaps/process, which is a bit excessive.
*
* Here we just change the flags value on the stack: we allow
* only the super-user to do it. This depends on the stack-layout
* on system-call entry - see also fork() and the signal handling
* code.
*/
SYSCALL_DEFINE1(iopl, unsigned int, level)
{
struct pt_regs *regs = current_pt_regs();
struct thread_struct *t = ¤t->thread;
/*
* Careful: the IOPL bits in regs->flags are undefined under Xen PV
* and changing them has no effect.
*/
unsigned int old = t->iopl >> X86_EFLAGS_IOPL_BIT;
if (level > 3)
return -EINVAL;
/* Trying to gain more privileges? */
if (level > old) {
if (!capable(CAP_SYS_RAWIO))
return -EPERM;
}
regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) |
(level << X86_EFLAGS_IOPL_BIT);
t->iopl = level << X86_EFLAGS_IOPL_BIT;
set_iopl_mask(t->iopl);
return 0;
}
Overall Contributors
| Person | Tokens | Prop | Commits | CommitProp |
pre-git | pre-git | 149 | 37.06% | 11 | 32.35% |
miguel boton | miguel boton | 53 | 13.18% | 1 | 2.94% |
ingo molnar | ingo molnar | 43 | 10.70% | 1 | 2.94% |
brian gerst | brian gerst | 22 | 5.47% | 2 | 5.88% |
benjamin lahaise | benjamin lahaise | 20 | 4.98% | 1 | 2.94% |
akinobu mita | akinobu mita | 19 | 4.73% | 1 | 2.94% |
andy lutomirski | andy lutomirski | 14 | 3.48% | 2 | 5.88% |
al viro | al viro | 13 | 3.23% | 1 | 2.94% |
thomas gleixner | thomas gleixner | 12 | 2.99% | 1 | 2.94% |
chris wright | chris wright | 10 | 2.49% | 1 | 2.94% |
albert cahalan | albert cahalan | 8 | 1.99% | 2 | 5.88% |
andrew morton | andrew morton | 6 | 1.49% | 1 | 2.94% |
stephane eranian | stephane eranian | 5 | 1.24% | 1 | 2.94% |
shai fultheim | shai fultheim | 5 | 1.24% | 1 | 2.94% |
zachary amsden | zachary amsden | 5 | 1.24% | 1 | 2.94% |
linus torvalds | linus torvalds | 4 | 1.00% | 1 | 2.94% |
robert love | robert love | 4 | 1.00% | 1 | 2.94% |
randy dunlap | randy dunlap | 3 | 0.75% | 1 | 2.94% |
jaswinder singh rajput | jaswinder singh rajput | 3 | 0.75% | 1 | 2.94% |
adrian bunk | adrian bunk | 3 | 0.75% | 1 | 2.94% |
h. peter anvin | h. peter anvin | 1 | 0.25% | 1 | 2.94% |
| Total | 402 | 100.00% | 34 | 100.00% |
Information contained on this website is for historical information purposes only and does not indicate or represent copyright ownership.