]> git.ipfire.org Git - thirdparty/kernel/linux.git/commit
fbdev: udlfb: add vm_ops to dlfb_ops_mmap to prevent use-after-free
authorRajat Gupta <rajgupt@qti.qualcomm.com>
Mon, 4 May 2026 03:51:10 +0000 (20:51 -0700)
committerHelge Deller <deller@gmx.de>
Mon, 4 May 2026 08:35:55 +0000 (10:35 +0200)
commit8de779dc40d35d39fa07387b6f921eb11df0f511
tree64d27f6247ea175f235d2a99666711b06c916251
parentd237f719b2726c0e6d62bfa1543f53b624471929
fbdev: udlfb: add vm_ops to dlfb_ops_mmap to prevent use-after-free

dlfb_ops_mmap() uses remap_pfn_range() to map vmalloc framebuffer pages
to userspace but sets no vm_ops on the VMA. This means the kernel cannot
track active mmaps. When dlfb_realloc_framebuffer() replaces the backing
buffer via FBIOPUT_VSCREENINFO, existing mmap PTEs are not invalidated.
On USB disconnect, dlfb_ops_destroy() calls vfree() on the old pages
while userspace PTEs still reference them, resulting in a use-after-free:
the process retains read/write access to freed kernel pages.

Add vm_operations_struct with open/close callbacks that maintain an
atomic mmap_count on struct dlfb_data. In dlfb_realloc_framebuffer(),
check mmap_count and return -EBUSY if the buffer is currently mapped,
preventing buffer replacement while userspace holds stale PTEs.

Tested with PoC using dummy_hcd + raw_gadget USB device emulation.

Signed-off-by: Rajat Gupta <rajgupt@qti.qualcomm.com>
Acked-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
Cc: stable@vger.kernel.org
Signed-off-by: Helge Deller <deller@gmx.de>
drivers/video/fbdev/udlfb.c
include/video/udlfb.h