• Daniel Vetter's avatar
    dma-buf: Add debug option · 84335675
    Daniel Vetter authored
    We have too many people abusing the struct page they can get at but
    really shouldn't in importers. Aside from that the backing page might
    simply not exist (for dynamic p2p mappings) looking at it and using it
    e.g. for mmap can also wreak the page handling of the exporter
    completely. Importers really must go through the proper interface like
    dma_buf_mmap for everything.
    
    I'm semi-tempted to enforce this for dynamic importers since those
    really have no excuse at all to break the rules.
    
    Unfortuantely we can't store the right pointers somewhere safe to make
    sure we oops on something recognizable, so best is to just wrangle
    them a bit by flipping all the bits. At least on x86 kernel addresses
    have all their high bits sets and the struct page array is fairly low
    in the kernel mapping, so flipping all the bits gives us a very high
    pointer in userspace and hence excellent chances for an invalid
    dereference.
    
    v2: Add a note to the @map_dma_buf hook that exporters shouldn't do
    fancy caching tricks, which would blow up with this address scrambling
    trick here (Chris)
    
    Enable by default when CONFIG_DMA_API_DEBUG is enabled.
    
    v3: Only one copy of the mangle/unmangle code (Christian)
    
    v4: #ifdef, not #if (0day)
    
    v5: sg_table can also be an ERR_PTR (Chris, Christian)
    Reviewed-by: default avatarChris Wilson <chris@chris-wilson.co.uk>
    Reviewed-by: default avatarChristian König <christian.koenig@amd.com>
    Signed-off-by: default avatarDaniel Vetter <daniel.vetter@intel.com>
    Cc: Chris Wilson <chris@chris-wilson.co.uk>
    Cc: Sumit Semwal <sumit.semwal@linaro.org>
    Cc: "Christian König" <christian.koenig@amd.com>
    Cc: David Stevens <stevensd@chromium.org>
    Cc: linux-media@vger.kernel.org
    Cc: linaro-mm-sig@lists.linaro.org
    Link: https://patchwork.freedesktop.org/patch/msgid/20210115164739.3958206-1-daniel.vetter@ffwll.ch
    84335675
dma-buf.c 40.5 KB