mbox series

[v14,0/7] Fixes integer overflow or integer truncation issues in page lookups, ttm place configuration and scatterlist creation

Message ID 20221102145402.617336-1-gwan-gyeong.mun@intel.com (mailing list archive)
Headers show
Series Fixes integer overflow or integer truncation issues in page lookups, ttm place configuration and scatterlist creation | expand

Message

Gwan-gyeong Mun Nov. 2, 2022, 2:53 p.m. UTC
This patch series fixes integer overflow or integer truncation issues in
page lookups, ttm place configuration and scatterlist creation, etc.
We need to check that we avoid integer overflows when looking up a page,
and so fix all the instances where we have mistakenly used a plain integer
instead of a more suitable long.
And there is an impedance mismatch between the scatterlist API using
unsigned int and our memory/page accounting in unsigned long. That is we
may try to create a scatterlist for a large object that overflows returning
a small table into which we try to fit very many pages. As the object size
is under the control of userspace, we have to be prudent and catch the
conversion errors. To catch the implicit truncation as we switch from
unsigned long into the scatterlist's unsigned int, we use improved
overflows_type check and report E2BIG prior to the operation. This is
already used in our create ioctls to indicate if the uABI request is simply
too large for the backing store. 
And ttm place also has the same problem with scatterlist creation,
and we fix the integer truncation problem with the way approached by
scatterlist creation.
And It corrects the error code to return -E2BIG when creating gem objects
using ttm or shmem, if the size is too large in each case.

This series includes a patch [1][2] merged into the hardening tree. (it
added for testing of Intel-gfx CI and it should appear in -next shortly.)
This version fixes and updates the comments and discussions left in the v13
patch [3][4]. 
 - do not shadow sg_alloc_table() and sg_alloc_table_from_pages_segment()
   (Jani)
 - drop check_assign() and check_assign_user_ptr() macros (Linus)

[1] https://lore.kernel.org/lkml/202211011605.2D8C927C2@keescook/
[2] https://git.kernel.org/pub/scm/linux/kernel/git/kees/linux.git/commit/?h=for-next/hardening&id=5904fcb776d0b518be96bca43f258db90f26ba9a
[3] https://patchwork.freedesktop.org/patch/505092/?series=109169&rev=1
[4] https://lore.kernel.org/all/20220928081300.101516-6-gwan-gyeong.mun@intel.com/

Chris Wilson (3):
  drm/i915/gem: Typecheck page lookups
  drm/i915: Check for integer truncation on scatterlist creation
  drm/i915: Remove truncation warning for large objects

Gwan-gyeong Mun (3):
  drm/i915: Check for integer truncation on the configuration of ttm
    place
  drm/i915: Check if the size is too big while creating shmem file
  drm/i915: Use error code as -E2BIG when the size of gem ttm object is
    too large

Kees Cook (1):
  overflow: Introduce overflows_type() and castable_to_type()

 drivers/gpu/drm/i915/gem/i915_gem_internal.c  |   7 +-
 drivers/gpu/drm/i915/gem/i915_gem_object.c    |   7 +-
 drivers/gpu/drm/i915/gem/i915_gem_object.h    | 303 ++++++++++++--
 drivers/gpu/drm/i915/gem/i915_gem_pages.c     |  27 +-
 drivers/gpu/drm/i915/gem/i915_gem_phys.c      |   4 +
 drivers/gpu/drm/i915/gem/i915_gem_shmem.c     |  23 +-
 drivers/gpu/drm/i915/gem/i915_gem_ttm.c       |  20 +-
 drivers/gpu/drm/i915/gem/i915_gem_userptr.c   |   6 +-
 .../drm/i915/gem/selftests/huge_gem_object.c  |   6 +-
 .../gpu/drm/i915/gem/selftests/huge_pages.c   |   8 +
 .../drm/i915/gem/selftests/i915_gem_context.c |  12 +-
 .../drm/i915/gem/selftests/i915_gem_mman.c    |   8 +-
 .../drm/i915/gem/selftests/i915_gem_object.c  |   8 +-
 drivers/gpu/drm/i915/gvt/dmabuf.c             |  10 +-
 drivers/gpu/drm/i915/i915_gem.c               |  18 +-
 drivers/gpu/drm/i915/i915_scatterlist.c       |   5 +
 drivers/gpu/drm/i915/i915_user_extensions.c   |   2 +-
 drivers/gpu/drm/i915/i915_utils.h             |   4 -
 drivers/gpu/drm/i915/i915_vma.c               |   8 +-
 drivers/gpu/drm/i915/intel_region_ttm.c       |  14 +
 drivers/gpu/drm/i915/selftests/i915_gem_gtt.c |   4 +
 drivers/gpu/drm/i915/selftests/scatterlist.c  |   4 +
 include/linux/compiler.h                      |   1 +
 include/linux/overflow.h                      |  48 +++
 lib/Makefile                                  |   1 +
 lib/overflow_kunit.c                          | 381 ++++++++++++++++++
 26 files changed, 848 insertions(+), 91 deletions(-)

Comments

Gwan-gyeong Mun Nov. 3, 2022, 10:22 a.m. UTC | #1
On 11/3/22 9:07 AM, Patchwork wrote:
> *Patch Details*
> *Series:*	Fixes integer overflow or integer truncation issues in page 
> lookups, ttm place configuration and scatterlist creation (rev2)
> *URL:*	https://patchwork.freedesktop.org/series/110413/ 
> <https://patchwork.freedesktop.org/series/110413/>
> *State:*	failure
> *Details:* 
> https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110413v2/index.html 
> <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110413v2/index.html>
> 
> 
>   CI Bug Log - changes from CI_DRM_12333 -> Patchwork_110413v2
> 
> 
>     Summary
> 
> *FAILURE*
> 
> Serious unknown changes coming with Patchwork_110413v2 absolutely need to be
> verified manually.
> 
> If you think the reported changes have nothing to do with the changes
> introduced in Patchwork_110413v2, please notify your bug team to allow them
> to document this new failure mode, which will reduce false positives in CI.
> 
> External URL: 
> https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110413v2/index.html
> 
> 
>     Participating hosts (38 -> 27)
> 
> Missing (11): fi-tgl-dsi bat-dg2-8 bat-dg2-9 bat-adlp-6 bat-adlp-4 
> bat-adln-1 bat-rplp-1 bat-rpls-1 bat-rpls-2 bat-dg2-11 bat-jsl-1
> 
> 
>     Possible new issues
> 
> Here are the unknown changes that may have been introduced in 
> Patchwork_110413v2:
> 
> 
>       IGT changes
> 
This patch series does not affect the code flow of issues reported as 
regression.
So the problem reported as regression seems to be the effect of code 
other than this patch.

G.G.
> 
>         Possible regressions
> 
>   * igt@i915_selftest@live@hangcheck:
>       o fi-rkl-guc: PASS
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12333/fi-rkl-guc/igt@i915_selftest@live@hangcheck.html>
>         -> INCOMPLETE
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110413v2/fi-rkl-guc/igt@i915_selftest@live@hangcheck.html>
> 
> 
>     Known issues
> 
> Here are the changes found in Patchwork_110413v2 that come from known 
> issues:
> 
> 
>       IGT changes
> 
> 
>         Issues hit
> 
>   *
> 
>     igt@gem_lmem_swapping@basic:
> 
>       o fi-apl-guc: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110413v2/fi-apl-guc/igt@gem_lmem_swapping@basic.html>
>         (fdo#109271
>         <https://bugs.freedesktop.org/show_bug.cgi?id=109271> /
>         i915#4613
>         <https://gitlab.freedesktop.org/drm/intel/issues/4613>) +3
>         similar issues
>   *
> 
>     igt@i915_selftest@live@hangcheck:
> 
>       o fi-hsw-g3258: PASS
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12333/fi-hsw-g3258/igt@i915_selftest@live@hangcheck.html>
>         -> INCOMPLETE
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110413v2/fi-hsw-g3258/igt@i915_selftest@live@hangcheck.html>
>         (i915#3303
>         <https://gitlab.freedesktop.org/drm/intel/issues/3303> /
>         i915#4785 <https://gitlab.freedesktop.org/drm/intel/issues/4785>)
>   *
> 
>     igt@i915_suspend@basic-s3-without-i915:
> 
>       o fi-bdw-5557u: PASS
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12333/fi-bdw-5557u/igt@i915_suspend@basic-s3-without-i915.html>
>         -> INCOMPLETE
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110413v2/fi-bdw-5557u/igt@i915_suspend@basic-s3-without-i915.html>
>         (i915#146 <https://gitlab.freedesktop.org/drm/intel/issues/146>)
>   *
> 
>     igt@kms_chamelium@hdmi-crc-fast:
> 
>       o fi-apl-guc: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110413v2/fi-apl-guc/igt@kms_chamelium@hdmi-crc-fast.html>
>         (fdo#109271
>         <https://bugs.freedesktop.org/show_bug.cgi?id=109271> /
>         fdo#111827
>         <https://bugs.freedesktop.org/show_bug.cgi?id=111827>) +8
>         similar issues
>   *
> 
>     igt@kms_force_connector_basic@force-connector-state:
> 
>       o fi-apl-guc: NOTRUN -> SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110413v2/fi-apl-guc/igt@kms_force_connector_basic@force-connector-state.html>
>         (fdo#109271
>         <https://bugs.freedesktop.org/show_bug.cgi?id=109271>) +11
>         similar issues
>   *
> 
>     igt@runner@aborted:
> 
>       o fi-hsw-g3258: NOTRUN -> FAIL
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110413v2/fi-hsw-g3258/igt@runner@aborted.html>
>         (fdo#109271
>         <https://bugs.freedesktop.org/show_bug.cgi?id=109271> /
>         i915#4312 <https://gitlab.freedesktop.org/drm/intel/issues/4312>
>         / i915#4991 <https://gitlab.freedesktop.org/drm/intel/issues/4991>)
> 
> 
>         Possible fixes
> 
>   *
> 
>     igt@gem_ctx_create@basic-files:
> 
>       o {fi-tgl-mst}: DMESG-WARN
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12333/fi-tgl-mst/igt@gem_ctx_create@basic-files.html>
>         (i915#6434
>         <https://gitlab.freedesktop.org/drm/intel/issues/6434>) -> PASS
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110413v2/fi-tgl-mst/igt@gem_ctx_create@basic-files.html>
>   *
> 
>     igt@gem_exec_gttfill@basic:
> 
>       o fi-pnv-d510: FAIL
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12333/fi-pnv-d510/igt@gem_exec_gttfill@basic.html>
>         (i915#7229
>         <https://gitlab.freedesktop.org/drm/intel/issues/7229>) -> PASS
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110413v2/fi-pnv-d510/igt@gem_exec_gttfill@basic.html>
>   *
> 
>     igt@gem_render_tiled_blits@basic:
> 
>       o fi-apl-guc: INCOMPLETE
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12333/fi-apl-guc/igt@gem_render_tiled_blits@basic.html>
>         -> PASS
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110413v2/fi-apl-guc/igt@gem_render_tiled_blits@basic.html>
>   *
> 
>     igt@gem_tiled_blits@basic:
> 
>       o fi-pnv-d510: SKIP
>         <https://intel-gfx-ci.01.org/tree/drm-tip/CI_DRM_12333/fi-pnv-d510/igt@gem_tiled_blits@basic.html>
>         (fdo#109271
>         <https://bugs.freedesktop.org/show_bug.cgi?id=109271>) -> PASS
>         <https://intel-gfx-ci.01.org/tree/drm-tip/Patchwork_110413v2/fi-pnv-d510/igt@gem_tiled_blits@basic.html>
>         +1 similar issue
> 
> {name}: This element is suppressed. This means it is ignored when computing
> the status of the difference (SUCCESS, WARNING, or FAILURE).
> 
> 
>     Build changes
> 
>   * Linux: CI_DRM_12333 -> Patchwork_110413v2
> 
> CI-20190529: 20190529
> CI_DRM_12333: e7d1d39c197e7f06cf4d1ee19cfd467d6b68e10e @ 
> git://anongit.freedesktop.org/gfx-ci/linux
> IGT_7038: 5389b3f3b9b75df6bd8506e4aa3da357fd0c0ab1 @ 
> https://gitlab.freedesktop.org/drm/igt-gpu-tools.git
> Patchwork_110413v2: e7d1d39c197e7f06cf4d1ee19cfd467d6b68e10e @ 
> git://anongit.freedesktop.org/gfx-ci/linux
> 
> 
>       Linux commits
> 
> c92843681a18 drm/i915: Remove truncation warning for large objects
> ab7b18a9855f drm/i915: Use error code as -E2BIG when the size of gem ttm 
> object is too large
> 4389e2689bd6 drm/i915: Check if the size is too big while creating shmem 
> file
> 084bc23a10c9 drm/i915: Check for integer truncation on the configuration 
> of ttm place
> fbf0071038b2 drm/i915: Check for integer truncation on scatterlist creation
> fbae424b451f drm/i915/gem: Typecheck page lookups
> 86dffbe22669 overflow: Introduce overflows_type() and castable_to_type()
>