drm/i915/gem: Fix a NULL pointer dereference in igt_request_rewind()
authorZhou Qingyang <zhou1615@umn.edu>
Tue, 30 Nov 2021 14:15:44 +0000 (22:15 +0800)
committerTvrtko Ursulin <tvrtko.ursulin@intel.com>
Wed, 1 Dec 2021 09:22:15 +0000 (09:22 +0000)
commit49a8bf50caa2fb0fb2eb1c89923ea61192227c32
treeb5348fecdd086ef61eff3093f99784d220072c61
parentcca084692394ad2733995241866fbb4b1b8668bc
drm/i915/gem: Fix a NULL pointer dereference in igt_request_rewind()

In igt_request_rewind(), mock_context(i915, "A") is assigned to ctx[0]
and used in i915_gem_context_get_engine(). There is a dereference
of ctx[0] in i915_gem_context_get_engine(), which could lead to a NULL
pointer dereference on failure of mock_context(i915, "A") .

So as mock_context(i915, "B").

Although this bug is not serious for it belongs to testing code, it is
better to be fixed to avoid unexpected failure in testing.

Fix this bugs by adding checks about ctx[0] and ctx[1].

This bug was found by a static analyzer. The analysis employs
differential checking to identify inconsistent security operations
(e.g., checks or kfrees) between two code paths and confirms that the
inconsistent operations are not recovered in the current function or
the callers, so they constitute bugs.

Note that, as a bug found by static analysis, it can be a false
positive or hard to trigger. Multiple researchers have cross-reviewed
the bug.

Builds with CONFIG_DRM_I915_SELFTEST=y show no new warnings,
and our static analyzer no longer warns about this code.

References: 591c0fb85d1c ("drm/i915: Exercise request cancellation using a mock selftest")
[tursulin: Replaced fixes with references to avoid.]
Signed-off-by: Zhou Qingyang <zhou1615@umn.edu>
Reviewed-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Signed-off-by: Tvrtko Ursulin <tvrtko.ursulin@intel.com>
Link: https://patchwork.freedesktop.org/patch/msgid/20211130141545.153899-1-zhou1615@umn.edu
drivers/gpu/drm/i915/selftests/i915_request.c