[PATCH] qnx4: fix to avoid panic due to buffer overflow

2023-11-12 Thread Ronald Monthero
qnx4 dir name length can vary to be of maximum size QNX4_NAME_MAX or QNX4_SHORT_NAME_MAX depending on whether 'link info' entry is stored and the status byte is set. So to avoid buffer overflow check di_fname length fetched from (struct qnx4_inode_entry *) before use in strlen to avoid buffer overf

Re: [PATCH] qnx4: fix to avoid panic due to buffer overflow

2023-11-12 Thread Anders Larsen
On 2023-11-12 10:53 Ronald Monthero wrote: > qnx4 dir name length can vary to be of maximum size > QNX4_NAME_MAX or QNX4_SHORT_NAME_MAX depending on whether > 'link info' entry is stored and the status byte is set. > So to avoid buffer overflow check di_fname length > fetched from (struct qnx4_inod

[RFC PATCH v2 03/19] KVM: x86: Add notifications for Heki policy configuration and violation

2023-11-12 Thread Mickaël Salaün
Add an interface for user space to be notified about guests' Heki policy and related violations. Extend the KVM_ENABLE_CAP IOCTL with KVM_CAP_HEKI_CONFIGURE and KVM_CAP_HEKI_DENIAL. Each one takes a bitmask as first argument that can contains KVM_HEKI_EXIT_REASON_CR0 and KVM_HEKI_EXIT_REASON_CR4.

[RFC PATCH v2 01/19] virt: Introduce Hypervisor Enforced Kernel Integrity (Heki)

2023-11-12 Thread Mickaël Salaün
From: Madhavan T. Venkataraman Hypervisor Enforced Kernel Integrity (Heki) is a feature that will use the hypervisor to enhance guest virtual machine security. Implement minimal code to introduce Heki: - Define the config variables. - Define a kernel command line parameter "heki" to turn the f

[RFC PATCH v2 00/19] Hypervisor-Enforced Kernel Integrity

2023-11-12 Thread Mickaël Salaün
Hi, This patch series is a proof-of-concept that implements new KVM features (guest memory attributes, MBEC support, CR pinning) and defines a new API to protect guest VMs. You can find related resources, including the related commits here: https://github.com/heki-linux We'll talk about this work

[RFC PATCH v2 04/19] heki: Lock guest control registers at the end of guest kernel init

2023-11-12 Thread Mickaël Salaün
The hypervisor needs to provide some functions to support Heki. These form the Heki-Hypervisor API. Define a heki_hypervisor structure to house the API functions. A hypervisor that supports Heki must instantiate a heki_hypervisor structure and pass it to the Heki common code. This allows the commo

[RFC PATCH v2 02/19] KVM: x86: Add new hypercall to lock control registers

2023-11-12 Thread Mickaël Salaün
This enables guests to lock their CR0 and CR4 registers with a subset of X86_CR0_WP, X86_CR4_SMEP, X86_CR4_SMAP, X86_CR4_UMIP, X86_CR4_FSGSBASE and X86_CR4_CET flags. The new KVM_HC_LOCK_CR_UPDATE hypercall takes three arguments. The first is to identify the control register, the second is a bit

[RFC PATCH v2 08/19] KVM: x86: Extend kvm_vm_set_mem_attributes() with a mask

2023-11-12 Thread Mickaël Salaün
Enable to only update a subset of attributes. This is needed to be able to use the XArray for different use cases and make sure they don't interfere (see a following commit). Cc: Chao Peng Cc: Kees Cook Cc: Madhavan T. Venkataraman Cc: Sean Christopherson Cc: Yu Zhang Signed-off-by: Mickaël

[RFC PATCH v2 06/19] KVM: x86: Add kvm_x86_ops.fault_gva()

2023-11-12 Thread Mickaël Salaün
This function is needed for kvm_mmu_page_fault() to create synthetic page faults. Code originally written by Mihai Donțu and Nicușor Cîțu: https://lore.kernel.org/r/20211006173113.26445-18-ala...@bitdefender.com Renamed fault_gla() to fault_gva() and use the new EPT_VIOLATION_GVA_IS_VALID. Cc: Bo

[RFC PATCH v2 05/19] KVM: VMX: Add MBEC support

2023-11-12 Thread Mickaël Salaün
This changes add support for VMX_FEATURE_MODE_BASED_EPT_EXEC (named ept_mode_based_exec in /proc/cpuinfo and MBEC elsewhere), which enables to separate EPT execution bits for supervisor vs. user. It transforms the semantic of VMX_EPT_EXECUTABLE_MASK from a global execution to a kernel execution, a

[RFC PATCH v2 07/19] KVM: x86: Make memory attribute helpers more generic

2023-11-12 Thread Mickaël Salaün
To make it useful for other use cases such as Heki, remove the private memory optimizations. I guess we could try to infer the applied attributes to get back these optimizations when it makes sense, but let's keep this simple for now. Main changes: - Replace slots_lock with slots_arch_lock to ma

[RFC PATCH v2 09/19] KVM: x86: Extend kvm_range_has_memory_attributes() with match_all

2023-11-12 Thread Mickaël Salaün
This enables to check if an attribute is tied to any memory page in a range. This will be useful in a folling commit to check for KVM_MEMORY_ATTRIBUTE_HEKI_IMMUTABLE. Cc: Chao Peng Cc: Kees Cook Cc: Madhavan T. Venkataraman Cc: Sean Christopherson Cc: Yu Zhang Signed-off-by: Mickaël Salaün -

[RFC PATCH v2 11/19] KVM: x86: Add new hypercall to set EPT permissions

2023-11-12 Thread Mickaël Salaün
From: Madhavan T. Venkataraman Add a new KVM_HC_PROTECT_MEMORY hypercall that enables a guest to set EPT permissions for guest pages. Until now, all of the guest pages (except Page Tracked pages) are given RWX permissions in the EPT. In Heki, we want to restrict the permissions to what is strict

[RFC PATCH v2 10/19] KVM: x86: Implement per-guest-page permissions

2023-11-12 Thread Mickaël Salaün
Define memory attributes that can be associated with guest physical pages in KVM. To begin with, define permissions as memory attributes (READ, WRITE and EXECUTE), and the IMMUTABLE property. In the future, other attributes could be defined. Use the memory attribute feature to implement the follow

[RFC PATCH v2 12/19] x86: Implement the Memory Table feature to store arbitrary per-page data

2023-11-12 Thread Mickaël Salaün
From: Madhavan T. Venkataraman This feature can be used by a consumer to associate any arbitrary pointer with a physical page. The feature implements a page table format that mirrors the hardware page table. A leaf entry in the table points to consumer data for that page. The page table format h

[RFC PATCH v2 13/19] heki: Implement a kernel page table walker

2023-11-12 Thread Mickaël Salaün
From: Madhavan T. Venkataraman The Heki feature needs to do the following: - Find kernel mappings. - Determine the permissions associated with each mapping. - Determine the collective permissions for a guest physical page across all of its mappings. This way, a guest physical page can refle

[RFC PATCH v2 14/19] heki: x86: Initialize permissions counters for pages mapped into KVA

2023-11-12 Thread Mickaël Salaün
From: Madhavan T. Venkataraman Define a permissions counters structure that contains a counter for read, write and execute. Each mapped guest page will be allocated a permissions counters structure. During kernel boot, walk the kernel address space, locate all the mappings, create permissions co

[RFC PATCH v2 15/19] heki: x86: Initialize permissions counters for pages in vmap()/vunmap()

2023-11-12 Thread Mickaël Salaün
From: Madhavan T. Venkataraman When a page gets mapped, create permissions counters for it and initialize them based on the specified permissions. When a page gets unmapped, update the counters appropriately. Cc: Borislav Petkov Cc: Dave Hansen Cc: H. Peter Anvin Cc: Ingo Molnar Cc: Kees Co

[RFC PATCH v2 16/19] heki: x86: Update permissions counters when guest page permissions change

2023-11-12 Thread Mickaël Salaün
From: Madhavan T. Venkataraman When permissions are changed on an existing mapping, update the permissions counters. Cc: Borislav Petkov Cc: Dave Hansen Cc: H. Peter Anvin Cc: Ingo Molnar Cc: Kees Cook Cc: Madhavan T. Venkataraman Cc: Mickaël Salaün Cc: Paolo Bonzini Cc: Sean Christopher

[RFC PATCH v2 17/19] heki: x86: Update permissions counters during text patching

2023-11-12 Thread Mickaël Salaün
From: Madhavan T. Venkataraman X86 uses a function called __text_poke() to modify executable code. This patching function is used by many features such as KProbes and FTrace. Update the permissions counters for the text page so that write permissions can be temporarily established in the EPT to

[RFC PATCH v2 18/19] heki: x86: Protect guest kernel memory using the KVM hypervisor

2023-11-12 Thread Mickaël Salaün
From: Madhavan T. Venkataraman Implement a hypervisor function, kvm_protect_memory() that calls the KVM_HC_PROTECT_MEMORY hypercall to request the KVM hypervisor to set specified permissions on a list of guest pages. Using the protect_memory() function, set proper EPT permissions for all guest p

[RFC PATCH v2 19/19] virt: Add Heki KUnit tests

2023-11-12 Thread Mickaël Salaün
This adds a new CONFIG_HEKI_TEST option to run tests at boot. Because we use some symbols not exported to modules (e.g., kernel_set_to_readonly) this could not work as modules. To run these tests, we need to boot the kernel with the heki_test=N boot argument with N selecting a specific test: 1. he