• Chris Wilson's avatar
    drm/i915/gvt: Prevent use-after-free in ppgtt_free_all_spt() · 968a85b1
    Chris Wilson authored
    ppgtt_free_all_spt() iterates the radixtree as it is deleting it,
    forgoing all protection against the leaves being freed in the process
    (leaving the iter pointing into the void).
    
    A minimal fix seems to be to use the available post_shadow_list to
    decompose the tree into a list prior to destroying the radixtree.
    
    Alerted by the sparse warnings:
    
    drivers/gpu/drm/i915/gvt/gtt.c:757:9: warning: incorrect type in assignment (different address spaces)
    drivers/gpu/drm/i915/gvt/gtt.c:757:9:    expected void **slot
    drivers/gpu/drm/i915/gvt/gtt.c:757:9:    got void [noderef] <asn:4> **
    drivers/gpu/drm/i915/gvt/gtt.c:757:9: warning: incorrect type in assignment (different address spaces)
    drivers/gpu/drm/i915/gvt/gtt.c:757:9:    expected void **slot
    drivers/gpu/drm/i915/gvt/gtt.c:757:9:    got void [noderef] <asn:4> **
    drivers/gpu/drm/i915/gvt/gtt.c:758:45: warning: incorrect type in argument 1 (different address spaces)
    drivers/gpu/drm/i915/gvt/gtt.c:758:45:    expected void [noderef] <asn:4> **slot
    drivers/gpu/drm/i915/gvt/gtt.c:758:45:    got void **slot
    drivers/gpu/drm/i915/gvt/gtt.c:757:9: warning: incorrect type in argument 1 (different address spaces)
    drivers/gpu/drm/i915/gvt/gtt.c:757:9:    expected void [noderef] <asn:4> **slot
    drivers/gpu/drm/i915/gvt/gtt.c:757:9:    got void **slot
    drivers/gpu/drm/i915/gvt/gtt.c:757:9: warning: incorrect type in assignment (different address spaces)
    drivers/gpu/drm/i915/gvt/gtt.c:757:9:    expected void **slot
    drivers/gpu/drm/i915/gvt/gtt.c:757:9:    got void [noderef] <asn:4> **
    
    This would also have been loudly warning if run through CI for the
    invalid RCU dereferences.
    
    Fixes: b6c126a3 ("drm/i915/gvt: Manage shadow pages with radix tree")
    Reviewed-by: default avatarZhenyu Wang <zhenyuw@linux.intel.com>
    Signed-off-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
    Cc: Changbin Du <changbin.du@intel.com>
    Cc: Zhenyu Wang <zhenyuw@linux.intel.com>
    Cc: Zhi Wang <zhi.a.wang@intel.com>
    Signed-off-by: default avatarZhenyu Wang <zhenyuw@linux.intel.com>
    968a85b1
gtt.c 72.7 KB