Kernel
Also called Operating system kernel
A kernel is the program at the center of an operating system that controls the hardware and decides what every other program may do with it. It is the first program to start after the firmware and the last to stop. Every other program runs on top of it and depends on it. A crash in the kernel therefore takes down the whole machine, not one program.
The kernel runs at the highest ordinary privilege level of the CPU and owns the page tables and devices of the machine. Ordinary programs reach the hardware only through the interfaces it offers. That gives every program the same view of the hardware, whatever the make of its disk or network card. Drivers inside the kernel hide those differences from the programs above.
Between requests, the kernel keeps the machine running. It schedules processes onto cores and hands out memory, so that many programs can share one machine without knowing about each other. The scheduler switches between processes many times a second, so each seems to have a processor to itself. Memory works the same way, since the kernel maps each private address space onto shared physical memory.
Kernel mode and user mode
Kernel mode and user mode are the two modes that the processor enforces. Kernel mode can do anything, while user mode cannot touch devices or the memory of other programs. On x86 these modes are called rings, with the kernel in ring 0 and applications in ring 3. Arm processors call them exception levels instead.
Applications run in user mode. When one needs to open a file or start another program, it makes a system call that switches into the kernel, which checks the request and carries it out. The check is the point of the design. The kernel knows who is asking and can refuse, while a program that tries a privileged instruction directly gets a fault instead.
Hardware interrupts, such as a packet arriving or a timer firing, also pull the processor into kernel mode whenever they happen. The kernel handles each one in its device drivers and then returns to the interrupted program. A timer interrupt is how the kernel takes the processor back from a program that never yields. Without it, one busy loop could hold a core forever.
Monolithic kernels and microkernels
Monolithic kernels and microkernels are the two main designs of kernel, told apart by how much runs in kernel mode. A monolithic kernel runs drivers and file systems in kernel mode, in one address space. Everything in that space shares the same privileges, with no wall between its parts. Most kernels in wide use today follow this design.
Linux and the Windows NT kernel are mostly built this way. They are fast because their parts call each other directly, but a bug in any driver can crash or compromise the whole system. Linux eases this with loadable modules, which add drivers at run time but still run with full privileges. Drivers make up most of the code of such a kernel, and most of its bugs are found there.
A microkernel keeps only the minimum in kernel mode and runs the rest as separate programs, as seL4 and QNX do. That shrinks what has to be trusted, at some cost in speed. The cost comes from messages, because parts that a monolithic kernel calls directly must talk through the kernel instead. A crashed driver can be restarted like any other program, and seL4 has a formal proof that its code matches its specification.
Kernel sharing
Kernel sharing is the running of several workloads on one kernel, and it decides how strongly they are isolated. Containers are processes on one shared kernel, kept apart by namespaces and other kernel features. They start fast and use little memory because there is only one kernel to run. The price is that every container depends on that kernel enforcing the separation correctly.
Every system call a container makes runs host kernel code, so a single kernel bug can let it escape. The interface of the Linux kernel is large, so it offers many places for such a bug. Such escapes happen in practice. Flaws such as Dirty COW and Dirty Pipe let unprivileged code gain root on the host, and filtering system calls narrows that exposure without removing it.
A virtual machine runs its own kernel, so the boundary to the host is the hypervisor rather than a shared kernel. To reach the host, an attacker has to break the hypervisor, through the virtual devices and other interfaces it exposes to the guest. Platforms that run untrusted code therefore put a virtual machine, or a user-space kernel such as gVisor, in front of the host kernel. The guest kernel can crash or be compromised without touching its neighbors. The extra layer costs memory and start time, which lightweight virtual machines work to keep small.