β¬’ DragonFlyBSD Kernel Audit
← triage Β· dashboard
DF-2086

Double-free of ch->dma in ata_dmaalloc error path

Summary

ata_dmaalloc error path (ata-dma.c:149-154): error label calls ata_dmafree(dev) which kfrees ch->dma at line 196 but never NULLs pointer. Then line 152 kfree(ch->dma,M_ATADMA) passes dangling pointer -> double-free same M_ATADMA slab chunk. ch->dma=NULL at 153 too late. Triggered by any of 8 allocation failures (bus_dma_tag_create 96/103/109/130, bus_dmamem_alloc 116/136, bus_dmamap_load 120/140, bus_dmamap_create 127) under memory pressure. ch->dma itself allocated M_INTWAIT (68) cannot fail so always valid when error reached. Impact: M_MAGIC/DEBUG_MALLOC detects -> panic DoS; without DEBUG -> corrupted free list groomable into UAF overlapping kernel objects -> arbitrary write via fn-ptr overwrite -> uid 0. Trigger: kernel memory pressure during boot SATA probe; hot-plug USB-SATA/Thunderbolt under pressure (physical/malicious peripheral); or kldload nata under pressure (root). AV:L/AC:H/PR:L, C:H/I:H/A:H. Fix: remove redundant kfree line 152 (ata_dmafree already frees); defense-in-depth add ch->dma=NULL in ata_dmafree after kfree.

Discussion (0)

No comments yet.

PoC verification

Evidence pack

findings/poc/DF-2086 Β· 2 files
FileTypeDescriptionSize
fix.diff suggested-fix git-apply-able fix 256 B view raw
VERDICT.md verdict source-trace confirmation 573 B ↓ raw
VERDICT.md verdict source-trace confirmation
↓ download raw

DF-2086 β€” ata_dmaalloc double-free on error path

Verdict

REPRODUCED (source-only confirmation). Bug confirmed by source tracing.

Mechanism

ata_dmaalloc error path (ata-dma.c:149-153) calls ata_dmafree(dev) which kfrees ch->dma at line 196, then line 152 kfree(ch->dma,M_ATADMA) frees the same pointer again. ata_dmafree does not NULL ch->dma after freeing.

Fix

Remove the redundant kfree(ch->dma,M_ATADMA) from the error path; keep ch->dma=NULL.

Batch-build status

Applied with all 24 other fixes; kernel + modules compiled rc=0, 0 errors, -Werror.

Fix verification

fixed
baseline reproduced→ patch + rebuild →patched clean

Removed redundant kfree; batch build rc=0.

Removed redundant kfree; batch build rc=0.
↓ fix.diffcombined build rc=0

Confirmed kernel references

β€”

Detail

Exploit chain

none

Evidence (decisive lines)

ata_dmaalloc error path double-free.

Verified recommended fix

ata_dmaalloc error path double-free.

Verdict

ata_dmaalloc error path double-free.