Hey folks,
We recently migrated to a Dmabuf-based rendering model in Ghostty. We’ve been working through the issues that have came up since, but I’ve encountered one with my own older Pascal GPU here that seems like one that we can’t particularly work around, basically hitting a UAF while releasing SGT/GEM resources; almost looks like it’s trying to release it twice, even though it’s manifesting itself as a UAF on the KFENCEd memory.
The GPU in question via lspci: NVIDIA Corporation GP104 [GeForce GTX 1080] (rev a1)
I use a NixOS machine being built off the latest kernel (linuxPackages_latest) and the latest driver from unstable (580.178.04, see here).
I’ve reviewed most of the code in the Dmabuf stack, particularly to the buffer sharing lifecycle and can’t see anything particularly wrong.
Reproduction is not super stable. Best thing I can say is build Ghostty off of main (GH link) using as close to the defined setup as possible, and just run frames until you get zapped by the fence. ;) Should happen sooner rather than later, famous last words though.
Any help is appreciated!
PS: I noticed that the UAF is hit in nv_dma_release_sgt, which from what I’ve seen is part of the open stack, but I haven’t really tried messing with it all (just reading to see if I could see possibly see what might have been getting accessed). Obviously it’s a bit of a lift to try and mess around/test with editing any of that but it would possibly be beneficial and there’s an easy way to iterate on open components with the proprietary driver I’d be happy to give it a shot.
PPS: older drivers seem to have the issue too, namely trying on 6.18 w/580.173.02 hits it at the same offsets AFAIK. Didn’t try any others.
kernel: ==================================================================
kernel: BUG: KFENCE: use-after-free read in nv_dma_release_sgt+0x2c/0x80 [nvidia]
kernel: Use-after-free read at 0x0000000023f05280 (in kfence-#158):
kernel: nv_dma_release_sgt+0x2c/0x80 [nvidia]
kernel: _nv049607rm+0x68/0xd0 [nvidia]
kernel: _nv043700rm+0x8a/0x3c0 [nvidia]
kernel: _nv043662rm+0x65/0x130 [nvidia]
kernel: _nv004992rm+0xd/0x20 [nvidia]
kernel: _nv006815rm+0x27/0xc0 [nvidia]
kernel: _nv019537rm+0x627/0x730 [nvidia]
kernel: _nv054359rm+0xb3/0xd5 [nvidia]
kernel: _nv056327rm+0xbe/0x190 [nvidia]
kernel: _nv056325rm+0x6c5/0x730 [nvidia]
kernel: _nv054234rm+0xda/0x1a0 [nvidia]
kernel: _nv054235rm+0x41/0x70 [nvidia]
kernel: _nv000641rm+0x4d/0x60 [nvidia]
kernel: _nv000800rm+0x21a/0xe30 [nvidia]
kernel: rm_ioctl+0x7f/0x3d0 [nvidia]
kernel: nvidia_unlocked_ioctl+0x758/0xae0 [nvidia]
kernel: __x64_sys_ioctl+0x97/0xe0
kernel: do_syscall_64+0x134/0x6b0
kernel: entry_SYSCALL_64_after_hwframe+0x77/0x7f
kernel:
kernel: kfence-#158: 0x000000003aa470ea-0x00000000d863fdcc, size=400, cache=kmalloc-part-06-512
kernel: allocated by task 36175 on cpu 7 at 50904.516698s (0.029247s ago):
kernel: nv_drm_calloc+0x43/0x80 [nvidia_drm]
kernel: nv_drm_gem_prime_import_sg_table+0x2d/0xb0 [nvidia_drm]
kernel: drm_gem_prime_import_dev+0x9b/0x160
kernel: drm_gem_prime_fd_to_handle+0xdf/0x230
kernel: drm_ioctl_kernel+0xae/0x100
kernel: drm_ioctl+0x27e/0x5b0
kernel: __x64_sys_ioctl+0x97/0xe0
kernel: do_syscall_64+0x134/0x6b0
kernel: entry_SYSCALL_64_after_hwframe+0x77/0x7f
kernel:
kernel: freed by task 36175 on cpu 3 at 50904.542249s (0.003725s ago):
kernel: nv_dma_release_sgt+0x53/0x80 [nvidia]
kernel: _nv049607rm+0x68/0xd0 [nvidia]
kernel: _nv043700rm+0x8a/0x3c0 [nvidia]
kernel: _nv043662rm+0x65/0x130 [nvidia]
kernel: _nv004992rm+0xd/0x20 [nvidia]
kernel: _nv006815rm+0x27/0xc0 [nvidia]
kernel: _nv019537rm+0x627/0x730 [nvidia]
kernel: _nv054359rm+0xb3/0xd5 [nvidia]
kernel: _nv056327rm+0xbe/0x190 [nvidia]
kernel: _nv056325rm+0x6c5/0x730 [nvidia]
kernel: _nv054234rm+0xda/0x1a0 [nvidia]
kernel: _nv054235rm+0x41/0x70 [nvidia]
kernel: _nv000641rm+0x4d/0x60 [nvidia]
kernel: _nv000800rm+0x21a/0xe30 [nvidia]
kernel: rm_ioctl+0x7f/0x3d0 [nvidia]
kernel: nvidia_unlocked_ioctl+0x758/0xae0 [nvidia]
kernel: __x64_sys_ioctl+0x97/0xe0
kernel: do_syscall_64+0x134/0x6b0
kernel: entry_SYSCALL_64_after_hwframe+0x77/0x7f
kernel:
kernel: CPU: 3 UID: 1000 PID: 36175 Comm: .ghostty-wrappe Tainted: P B O 7.2.6 #1-NixOS PREEMPT(lazy)
kernel: Tainted: [P]=PROPRIETARY_MODULE, [B]=BAD_PAGE, [O]=OOT_MODULE