Skip to content
RCE Write-up Advanced

Linux Kernel Exploitation for Beginners: Arbitrary Function Point

A deliberately vulnerable Linux kernel module allows a user to set a function pointer via /proc/vuln_alloc and then call it via /proc/vuln_use, enabling arbitrary kernel code execution. The author demonstrates privilege escalation to root using the ret2user technique when kernel protections are disabled.

Antonius W1sdom Follow

Published on medium.com

In this example, exploitation is performed on Linux kernel 5.15 running on Lubuntu 20.04.5 with Linux kernel protections disabled. The technique we will use will cause a kernel panic on Linux kernel 6.2 and above.

Antonius W1sdom, on medium.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

The kernel module copies a user-supplied address into a function pointer without validation and later calls it, allowing execution of arbitrary code in kernel mode.

Impact

An attacker could execute arbitrary code in kernel mode and escalate privileges to root, but only if kernel protections such as SMEP, SMAP, KPTI, and KASLR are disabled.

What the attacker needed

Vulnerable kernel module loaded; kernel protections disabled; kptr_restrict set to 0; local user access

How it was found

  1. Compile and load the vulnerable kernel module.
  2. Disable kernel protections (SMEP, SMAP, KPTI, KASLR) and kptr_restrict.
  3. Save user-mode state (segment registers, stack pointer, flags) for later return.
  4. Read addresses of prepare_kernel_cred and commit_creds from /proc/kallsyms.
  5. Write the address of the payload function to /proc/vuln_alloc.
  6. Trigger the call by reading from /proc/vuln_use, causing the payload to run and spawn a root shell.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A kernel module is a piece of code that runs with the highest privileges inside the operating system. This module lets any user store a memory address that the kernel will later jump to and execute as if it were trusted kernel code. By pointing that address to their own code, an attacker can make the kernel run their program with full system rights.

What is RCE?

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.

More by Antonius W1sdom

View all

2 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Remote code execution

The lesson behind this report.

Running the attacker's code on the target's servers: through command or code injection, unsafe deserialisation or template injection.