drm/i915/gvt/scheduler: fix potential NULL pointer dereference
PATCH 1/1 drm/i915/gvt/scheduler: fix potential NULL pointer dereference
_workload_ is being dereferenced before it is null checked, hence there is a potential null pointer dereference.
Fix this by moving the pointer dereference after _workload_ has been null checked.
Addresses-Coverity-ID: 1430136 ("Dereference before null check")
--- drivers/gpu/drm/i915/gvt/scheduler.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-)
drivers/gpu/drm/i915/gvt/scheduler.c +7 -3
@@ -60,9 +60,9 @@ static void set_context_pdp_root_pointer(static void sr_oa_regs (struct intel_vgpu_workload *workload,u32 *reg_state,bool save) { -struct drm_i915_private *dev_priv = workload->vgpu->gvt->dev_priv; -u32 ctx_oactxctrl = dev_priv->perf.oa.ctx_oactxctrl_offset; -u32 ctx_flexeu0 = dev_priv->perf.oa.ctx_flexeu0_offset; +struct drm_i915_private *dev_priv; +u32 ctx_oactxctrl; +u32 ctx_flexeu0;int i =0 ;u32 flex_mmio[] = {i915_mmio_reg_offset (EU_PERF_CNTL0 ),
@@ -77,6 +77,10 @@ static void sr_oa_regs(struct intel_vgpu_workload *workload,if (!workload || !reg_state || workload->ring_id !=RCS )return ; + dev_priv = workload->vgpu->gvt->dev_priv; + ctx_oactxctrl = dev_priv->perf.oa.ctx_oactxctrl_offset; + ctx_flexeu0 = dev_priv->perf.oa.ctx_flexeu0_offset; +if (save) { workload->oactxctrl = reg_state[ctx_oactxctrl +1 ];
Signature · 1 line
2.7.4
Quoting Gustavo A. R. Silva (2018-03-19 19:30:53)
Quoted 5 lines
_workload_ is being dereferenced before it is null checked, hence there is a potential null pointer dereference.
Fix this by moving the pointer dereference after _workload_ has been null checked.
The checks are misleading and not required.
-Chris
_______________________________________________
dri-devel mailing list
[email protected]
https://lists.freedesktop.org/mailman/listinfo/dri-devel
Hi Chris,
Quoted 8 lines · Chris Wilson
Quoting Gustavo A. R. Silva (2018-03-19 19:30:53)
Quoted 5 lines
_workload_ is being dereferenced before it is null checked, hence there is a potential null pointer dereference.
Fix this by moving the pointer dereference after _workload_ has been null checked.
The checks are misleading and not required.
All of them?
if (!workload || !reg_state || workload->ring_id != RCS)
return;
or just the null check on workload ?
Thanks for the feedback.
--
Gustavo
Quoting Gustavo A. R. Silva (2018-03-19 20:50:12)
Quoted 10 lines
Hi Chris,
Quoted 7 lines · Chris Wilson
Quoting Gustavo A. R. Silva (2018-03-19 19:30:53)
Quoted 5 lines
_workload_ is being dereferenced before it is null checked, hence there is a potential null pointer dereference.
Fix this by moving the pointer dereference after _workload_ has been null checked.
Quoted 6 lines
Quoted 1 line
The checks are misleading and not required.
All of them?
if (!workload || !reg_state ||
workload->ring_id!= RCS)return;
workload can not be NULL (dereference in caller), reg_state can not be NULL (by construct from kmap()).
It may be not an RCS ring through.
-Chris
Quoted 15 lines · Chris Wilson
Quoting Gustavo A. R. Silva (2018-03-19 20:50:12)
Quoted 14 lines
Hi Chris,
Quoted 8 lines · Chris Wilson
Quoting Gustavo A. R. Silva (2018-03-19 19:30:53)
Quoted 5 lines
_workload_ is being dereferenced before it is null checked, hence there is a potential null pointer dereference.
Fix this by moving the pointer dereference after _workload_ has been null checked.
The checks are misleading and not required.
All of them?
Quoted 7 lines
Quoted 2 lines
if (!workload || !reg_state ||
workload->ring_id!= RCS)return;workload can not be NULL (dereference in caller),
reg_statecan not be NULL (by construct fromkmap()).It may be not an RCS ring through
I got it.
I'll send the following patch then:
drivers/gpu/drm/i915/gvt/scheduler.c +1 -1
@@ -74,7 +74,7 @@ static void sr_oa_regs(struct intel_vgpu_workload *workload, i915_mmio_reg_offset(EU_PERF_CNTL6), }; -if (!workload || !reg_state || workload->ring_id !=RCS ) +if (workload->ring_id !=RCS )return ;if (save) {
Thanks
--
Gustavo