Microsoft Azure Sphere Kernel pwm_ioctl_apply_state kfree() code execution vulnerability
A kernel driver in Azure Sphere mishandles a failed copy_from_user, leaving an attacker-controlled pointer in a structure that is later freed with kfree. An attacker with local access can trigger an arbitrary kfree, potentially leading to code execution.
Originally disclosed on Cisco Talos
A code execution vulnerability exists in the kernel pwmioctlapplystate functionality of Microsoft Azure Sphere 21.01. A specially crafted ioctl can lead to arbitrary kfree.
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 report has not been written yet. The Original tab links to the source.
How it worked
Root cause
Likely the driver fails to initialise the extended_state pointer when copy_from_user fails, so kfree is called on an attacker-controlled value.
Impact
An attacker with local access could achieve arbitrary code execution in the kernel, though an information leak is needed to make exploitation reliable.
What the attacker needed
Local access to the device; userland code execution; access to /dev/pwm*
How it was found
- Obtain userland code execution on the device with access to /dev/pwm*.
- Craft an ioctl call to PWM_APPLY_STATE with a pwm_chardev_params buffer that is not 32-bit aligned and whose last three bytes are unreadable.
- The copy_from_user fails, leaving the extended_state pointer controlled by the attacker.
- The driver calls kfree on that pointer, causing an arbitrary free.
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 report has not been written yet. The Original tab links to the source.
This is a bug in a device driver that runs with high privileges. When the driver tries to copy data from a user program and that copy fails partway, it does not clear all the data it received. Later it frees a pointer that the attacker can control, which can crash the system or let the attacker run their own code.
What is Memory corruption?
Native code reads or writes memory it should not: overflows, use-after-free, type confusion. The core of browser, kernel and parser bugs.