drm_mode_create_dumb() already validates width * cpp * height before calling the driver. On 32-bit systems, however, multiplying the pitch after its 64-byte alignment by height can still overflow size_t.
Use drm_mode_size_dumb() for the aligned calculation and preserve the 64-byte pitch and page-aligned allocation. Signed-off-by: Gabriel Gama <[email protected]> --- diff --git a/drivers/gpu/drm/gma500/gem.c b/drivers/gpu/drm/gma500/gem.c index 2708e8c68f4c5bae592292c257de47bdef3e41e9..7250bf660abd204f72e4fc07ff3e95e614252f30 100644 --- a/drivers/gpu/drm/gma500/gem.c +++ b/drivers/gpu/drm/gma500/gem.c @@ -16,6 +16,7 @@ #include <asm/set_memory.h> #include <drm/drm.h> +#include <drm/drm_dumb_buffers.h> #include <drm/drm_print.h> #include <drm/drm_vma_manager.h> @@ -200,21 +201,16 @@ int psb_gem_dumb_create(struct drm_file *file, struct drm_device *dev, struct drm_mode_create_dumb *args) { - size_t pitch, size; struct psb_gem_object *pobj; struct drm_gem_object *obj; u32 handle; int ret; - pitch = args->width * DIV_ROUND_UP(args->bpp, 8); - pitch = ALIGN(pitch, 64); - - size = pitch * args->height; - size = roundup(size, PAGE_SIZE); - if (!size) - return -EINVAL; - - pobj = psb_gem_create(dev, size, "gem", false, PAGE_SIZE); + ret = drm_mode_size_dumb(dev, args, 64, 0); + if (ret) + return ret; + + pobj = psb_gem_create(dev, args->size, "gem", false, PAGE_SIZE); if (IS_ERR(pobj)) return PTR_ERR(pobj); obj = &pobj->base; @@ -225,8 +221,6 @@ drm_gem_object_put(obj); - args->pitch = pitch; - args->size = size; args->handle = handle; return 0; On Fri, 13 Nov 2026 12:17:54 -0800, Gabriel Gama <[email protected]> wrote: > Hi, > > This series fixes existing gma500 dumb-buffer, GEM and SGX page-table bugs > against Linux 7.4-rc2, 7475ea8b58616b33c04afb976cf0fbaad9dd63fb. It keeps > SGX535 support and the current driver selection. The series contains no > architectural migration, new rendering interface or accelerated admission. > > The existing DRM ioctl already checks width * cpp * height. The dumb-buffer > fix covers the product after 64-byte pitch alignment on 32-bit size_t. > The unpin fix uses drm_WARN_ON() and retains reservation-lock cleanup. > The cache fixes separately address a directory-entry flush after unmap > and the unconditional clflush_count division. The former is exposed by > 32-bit HIGHMEM with CONFIG_DEBUG_KMAP_LOCAL_FORCE_MAP. > > Following Joseph Telaak's review of the previous six-patch RFC, the MMU > changes are split into zero-page semantics, the incorrect stolen-range > unload address, removal of absent mappings, range validation, and a > transactional insertion/error-cleanup unit. The old inner do/while loops > executed once for zero-page requests; they become no-ops here. > > One deliberate exception to splitting every lock change is patch 9. The > write semaphore, prefix rollback and newly introduced GEM page-release > error paths form a single safety unit. A rollback prefix cannot remain > owned while another writer is allowed to change the range. Keeping these > changes together prevents selecting an error-propagation-only patch that > frees pages while stale PTEs reference them. The temporary host fault test > explicitly checks for PTE references before each put_pages call; removing > rollback triggers that assertion. > > For backports, take that entire transaction and its range-validation > prerequisite (patch 8). Do not separate err_put_pages or weaken writer > exclusion. A textual git-apply result alone does not establish safe > backporting. Fixes tags were checked against the original introducing > source: 8c8f1c958ab5 for MMU/cache behavior and ae012bdc5799 for the stolen > mapping and unchecked callers. The unload fix uses the load address, > gatt_start, rather than mmu_gatt_start (0xe0000000). > > Current validation: > - Native, UBSan and i386 CPU harnesses: ten MMU cases / 50 assertions, > twelve extra fault/cache checks, 48 GEM checks and eleven fixture > allocation budgets passed. Kernel services in these harnesses are > simulated; no device or GPU is involved. > - Actual original sizing arithmetic / DRM alignment-helper boundary > witness passed on native, UBSan and i386 CPU backends. > - i386 W=1 / HIGHMEM4G / forced-local-map gma500 objects compiled. > - Normal x86_64 W=1 gma500 driver objects/archive compiled successfully. > - Full i386 W=1 / HIGHMEM4G / forced-local-map guest-kernel link passed. > - The actual guest kernel passed all ten software MMU KUnit cases under > QEMU TCG; guest exit0 and parser exit0. This is software emulation, > without a physical SGX/device or hardware cache/TLB validation. > - Patch-prefix replay and source whitespace checks passed. Checkpatch > has zero errors; the new KUnit file gets the generic MAINTAINERS > advisory and is covered by the existing gma500 directory entry. > > Hardware display, GPU, suspend/resume and platform validation have not > been run for this candidate. No upstream-readiness or > hardware-validation claim is made. > > Patch list: > 1. Use the common dumb-buffer size helper. > 2. Prevent GEM unpin underflow with a device warning. > 3. Flush the directory entry within its local mapping lifetime. > 4. Calculate CLFLUSH count only on the path that uses it. > 5. Make zero-page MMU requests no-ops. > 6. Remove the stolen mapping at its load address. > 7. Skip absent mappings during removal. > 8. Validate MMU ranges and exclusive endpoints. > 9. Make failed MMU insertion safe for GEM error cleanup. > 10. Add software-only KUnit coverage. > > Thanks, > Gabriel Gama
