Re: [patch V3 17/20] x86/iopl: Restrict iopl() permission scope

From: Borislav Petkov
Date: Thu Nov 14 2019 - 13:13:27 EST


On Wed, Nov 13, 2019 at 09:42:57PM +0100, Thomas Gleixner wrote:
> From: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
>
> The access to the full I/O port range can be also provided by the TSS I/O
> bitmap, but that would require to copy 8k of data on scheduling in the
> task. As shown with the sched out optimization TSS.io_bitmap_base can be
> used to switch the incoming task to a preallocated I/O bitmap which has all
> bits zero, i.e. allows access to all I/O ports.
>
> Implementing this allows to provide an iopl() emulation mode which restricts
> the IOPL level 3 permissions to I/O port access but removes the STI/CLI
> permission which is coming with the hardware IOPL mechansim.
>
> Provide a config option to switch IOPL to emulation mode, make it the
> default and while at it also provide an option to disable IOPL completely.
>
> Signed-off-by: Thomas Gleixner <tglx@xxxxxxxxxxxxx>
> Acked-by: Andy Lutomirski <luto@xxxxxxxxxx>
> ---
> V3: Folded the missing NULL pointer check, reduced preempt disable
> scope (Ingo)
>
> V2: Fixed the 32bit build fail by increasing the cpu entry area size
> Move the TSS update out of the iopl() emulation code.
> ---
> arch/x86/Kconfig | 32 +++++++++++
> arch/x86/include/asm/pgtable_32_types.h | 2
> arch/x86/include/asm/processor.h | 28 +++++++---
> arch/x86/kernel/cpu/common.c | 5 +
> arch/x86/kernel/ioport.c | 87 ++++++++++++++++++++++----------
> arch/x86/kernel/process.c | 28 ++++++----
> 6 files changed, 137 insertions(+), 45 deletions(-)
>
> --- a/arch/x86/Kconfig
> +++ b/arch/x86/Kconfig
> @@ -1254,6 +1254,38 @@ config X86_VSYSCALL_EMULATION
> Disabling this option saves about 7K of kernel size and
> possibly 4K of additional runtime pagetable memory.
>
> +choice
> + prompt "IOPL"
> + default X86_IOPL_EMULATION
> +
> +config X86_IOPL_EMULATION
> + bool "IOPL Emulation"
> + ---help---
> + Legacy IOPL support is an overbroad mechanism which allows user
> + space aside of accessing all 65536 I/O ports also to disable
> + interrupts. To gain this access the caller needs CAP_SYS_RAWIO
> + capabilities and permission from eventually active security

I think you mean here: s/eventually/potentially/ or so. "eventually" is
one of the false friends. :)

--
Regards/Gruss,
Boris.

https://people.kernel.org/tglx/notes-about-netiquette