Skip to content

drm: Sanitize DRM_IOCTL_MODE_CREATE_DUMB input

Thierry Reding dri-devel 2 versions – In review

Get series with b4
b4 am [email protected]

Versions newest first · linked by author and title

  1. v2 Latest8 patches 4 repliesIn review
  2. v17 patches 16 repliesSuperseded

Patches in v2 No applies recorded yet

#Subject and filesSizeRepliesApplied
1/8drm/gem: Fix a few kerneldoc typosdrivers/gpu/drm/drm_gem.c+5 -60 replies
2/8drm/doc: mm: Fix indentationDocumentation/DocBook/drm.tmpl+134 -1340 replies
3/8drm/doc: Add GEM/CMA helpers to kerneldocDocumentation/DocBook/drm.tmpl drivers/gpu/drm/drm_gem_cma_helper.c include/drm/drm_gem_cma_helper.h+203 -481 reply
4/8drm/cma: Introduce drm_gem_cma_dumb_create_internal()drivers/gpu/drm/drm_gem_cma_helper.c drivers/gpu/drm/rcar-du/rcar_du_kms.c include/drm/drm_gem_cma_helper.h+45 -70 replies
5/8drm/omap: gem: dumb: pitch is an outputdrivers/gpu/drm/omapdrm/omap_gem.c+1 -12 replies
6/8drm/rcar: gem: dumb: pitch is an outputdrivers/gpu/drm/rcar-du/rcar_du_kms.c+1 -10 replies
7/8drm: Sanitize DRM_IOCTL_MODE_CREATE_DUMB inputdrivers/gpu/drm/drm_crtc.c+10 -00 replies
8/8drm/cma: Remove call to drm_gem_free_mmap_offset()drivers/gpu/drm/drm_gem_cma_helper.c+0 -21 reply

Reviews trailers per patch

7 of 8 patches have a Reviewed-by or Acked-by.

PatchDaniel VetterRob ClarkTomi Valkeinen
1/8R-b
2/8A-b
3/8
4/8R-b
5/8R-b R-b A-b
6/8R-b
7/8R-b
8/8R-b

Trailers given in replies are filled; those carried in the patches from earlier versions are outlined with dashes. Scroll the table sideways for all 3 reviewers.

Read the v2 thread

Cover letter [PATCH v2 0/8] drm: Sanitize DRM_IOCTL_MODE_CREATE_DUMB input

From: Thierry Reding <[email protected]>

This second version addresses review comments from before. A new patch is added that removes a redundant call to drm_gem_free_mmap_offset() in the CMA GEM helpers.

Below is the cover letter from the first version for more background in case anybody missed it the last time:

Drivers currently treat the IOCTL data for DRM_IOCTL_MODE_CREATE_DUMB inconsistently. While the documentation clearly states that the handle, pitch and size fields are outputs, some drivers use their values as a minimum hint from userspace, presumably to allow userspace to over- allocate buffers on purpose (for example after negotiating pitch alignment requirements with other devices).

Most of userspace is well-behaved in that in zeros out the output fields which works well with drivers that use them as minima. However, some userspace (like Mesa's GBM DRI backend) only initializes the inputs, so that the driver will end up using uninitialized data from the stack in the computations. This can cause the driver to attempt very large allocations, resulting in failure, or silently use excessively large buffers.

This series tries to fix this by sanitizing the IOCTL data (setting the output fields to 0 in the kernel) so that drivers can no longer use uninitialized data. While at it, it also fixes existing drivers to not treat output fields as input/output for consistency.

Note that this is technically breaking ABI since overallocating will no longer be possible after this series is applied. However, the public DRM headers have always documented the fields as being outputs, so any application relying on them being inputs could be considered buggy. The hope is that no such applications exist in the wild.

Discussion on IRC lead to the conclusion that new IOCTLs should have input validation and require userspace to zero out output parameters to avoid this kind of mess in the future. In order to help avoid this kind of ambiguity it would be a good idea to start documenting IOCTLs more officially (e.g. in the DRM DocBook).

I'm adding a bunch of people on Cc to get feedback about what userspace people know might be relying on the current behaviour. Drivers that are impacted are OMAP, R-Car and any that use GEM CMA helpers.

This series also contains a couple of preparatory patches that add the GEM CMA helpers to our DocBook.

Thierry

Thierry Reding (8):
drm/gem: Fix a few kerneldoc typos
drm/doc: mm: Fix indentation
drm/doc: Add GEM/CMA helpers to kerneldoc drm/cma: Introduce drm_gem_cma_dumb_create_internal() drm/omap: gem: dumb: pitch is an output drm/rcar: gem: dumb: pitch is an output
drm: Sanitize DRM_IOCTL_MODE_CREATE_DUMB input drm/cma: Remove call to drm_gem_free_mmap_offset()

 Documentation/DocBook/drm.tmpl        | 274 +++++++++++++++++-----------------
 drivers/gpu/drm/drm_crtc.c            |  10 ++
 drivers/gpu/drm/drm_gem.c             |  11 +-
 drivers/gpu/drm/drm_gem_cma_helper.c  | 259 ++++++++++++++++++++++++++------
 drivers/gpu/drm/omapdrm/omap_gem.c    |   2 +-
 drivers/gpu/drm/rcar-du/rcar_du_kms.c |   4 +-
 include/drm/drm_gem_cma_helper.h      |  30 +++-
 7 files changed, 395 insertions(+), 195 deletions(-)
Signature · 6 lines
2.1.3

_______________________________________________
dri-devel mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/dri-devel