Skip to contentSkip to conversation

drm/i915: Sanity check DP AUX message buffer and size

PATCH In review Imre Deak 4 participants 13 messages Jan 29, 2016 – Feb 2, 2016

Subsystems (2)
lore
Share & tools
lore

Imre Deak

author
#0 lore raw

PATCH 1/4 drm/i915: Sanity check DP AUX message buffer and size

While we are calling intel_dp_aux_transfer() with msg->size=0 whenever msg->buffer is NULL, passing NULL to memcpy() is undefined according to the ISO C standard. I haven't found any notes about this in the GNU C's or the kernel's documentation of the function and can't imagine what it would do with the NULL ptr. To better document this use of the parameters it still make sense to add an explicit check for this to the code.

Caught by Coverity.

---
 drivers/gpu/drm/i915/intel_dp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_dp.c +4 -1
index e2bea710..2aed36e 100644
@@ -979,7 +979,10 @@ intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
 		if (WARN_ON(txsize > 20))
 			return -E2BIG;
 
-		memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
+		if (msg->buffer)
+			memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
+		else
+			WARN_ON(msg->size);
 
 		ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
 		if (ret > 0) {
Signature · 6 lines
2.5.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
author
#1 lore raw

PATCH 2/4 drm/i915/chv: Fix error path in GPU freq helpers

Atm we wouldn't catch these errors or on the error path we would end up with a division-by-zero, fix this up.

Caught by Coverity.

---
 drivers/gpu/drm/i915/intel_pm.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_pm.c +4 -2
index 20bf854..740a0e3 100644
@@ -7189,9 +7189,10 @@ static int chv_gpu_freq(struct drm_i915_private *dev_priv, int val)
 {
 	int div, czclk_freq = DIV_ROUND_CLOSEST(dev_priv->czclk_freq, 1000);
 
-	div = vlv_gpu_freq_div(czclk_freq) / 2;
+	div = vlv_gpu_freq_div(czclk_freq);
 	if (div < 0)
 		return div;
+	div /= 2;
 
 	return DIV_ROUND_CLOSEST(czclk_freq * val, 2 * div) / 2;
 }
@@ -7200,9 +7201,10 @@ static int chv_freq_opcode(struct drm_i915_private *dev_priv, int val)
 {
 	int mul, czclk_freq = DIV_ROUND_CLOSEST(dev_priv->czclk_freq, 1000);
 
-	mul = vlv_gpu_freq_div(czclk_freq) / 2;
+	mul = vlv_gpu_freq_div(czclk_freq);
 	if (mul < 0)
 		return mul;
+	mul /= 2;
 
 	/* CHV needs even values */
 	return DIV_ROUND_CLOSEST(val * 2 * mul, czclk_freq) * 2;
Signature · 6 lines
2.5.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 2/4
#2 lore raw

Re: [PATCH 2/4] drm/i915/chv: Fix error path in GPU freq helpers

Quoted 6 lines · Imre Deak

Atm we wouldn't catch these errors or on the error path we would end up with a division-by-zero, fix this up.

Caught by Coverity.

Quoted 35 lines
---
 drivers/gpu/drm/i915/intel_pm.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/intel_pm.c +4 -2
index 20bf854..740a0e3 100644
@@ -7189,9 +7189,10 @@ static int chv_gpu_freq(struct drm_i915_private *dev_priv, int val)
 {
 	int div, czclk_freq = DIV_ROUND_CLOSEST(dev_priv->czclk_freq, 1000);
 
-	div = vlv_gpu_freq_div(czclk_freq) / 2;
+	div = vlv_gpu_freq_div(czclk_freq);
 	if (div < 0)
 		return div;
+	div /= 2;
 
 	return DIV_ROUND_CLOSEST(czclk_freq * val, 2 * div) / 2;
 }
@@ -7200,9 +7201,10 @@ static int chv_freq_opcode(struct drm_i915_private *dev_priv, int val)
 {
 	int mul, czclk_freq = DIV_ROUND_CLOSEST(dev_priv->czclk_freq, 1000);
 
-	mul = vlv_gpu_freq_div(czclk_freq) / 2;
+	mul = vlv_gpu_freq_div(czclk_freq);
 	if (mul < 0)
 		return mul;
+	mul /= 2;
 
 	/* CHV needs even values */
 	return DIV_ROUND_CLOSEST(val * 2 * mul, czclk_freq) * 2;
Signature · 1 line
2.5.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

author
#3 lore raw

PATCH 3/4 drm/i915: Add debug info for failed MSI enabling

In reply to Imre Deak

While not being able to enable MSI interrupts may be a normal circumstance, for debugging it may still be a useful information, so emit an info about this.

Caught by Coverity.

---
 drivers/gpu/drm/i915/i915_dma.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +4 -2
index db9b0c6..fd3a6d2 100644
@@ -1078,8 +1078,10 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
 	 * be lost or delayed, but we use them anyways to avoid
 	 * stuck interrupts on some machines.
 	 */
-	if (!IS_I945G(dev) && !IS_I945GM(dev))
-		pci_enable_msi(dev->pdev);
+	if (!IS_I945G(dev) && !IS_I945GM(dev)) {
+		if (pci_enable_msi(dev->pdev) < 0)
+			DRM_DEBUG_DRIVER("can't enable MSI");
+	}
 
 	intel_device_info_runtime_init(dev);
 
Signature · 6 lines
2.5.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 3/4
#4 lore raw

Re: [PATCH 3/4] drm/i915: Add debug info for failed MSI enabling

Quoted 7 lines · Imre Deak

While not being able to enable MSI interrupts may be a normal circumstance, for debugging it may still be a useful information, so emit an info about this.

Caught by Coverity.

Quoted 24 lines
---
 drivers/gpu/drm/i915/i915_dma.c | 6 ++++--
 1 file changed, 4 insertions(+), 2 deletions(-)
drivers/gpu/drm/i915/i915_dma.c +4 -2
index db9b0c6..fd3a6d2 100644
@@ -1078,8 +1078,10 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags)
 	 * be lost or delayed, but we use them anyways to avoid
 	 * stuck interrupts on some machines.
 	 */
-	if (!IS_I945G(dev) && !IS_I945GM(dev))
-		pci_enable_msi(dev->pdev);
+	if (!IS_I945G(dev) && !IS_I945GM(dev)) {
+		if (pci_enable_msi(dev->pdev) < 0)
+			DRM_DEBUG_DRIVER("can't enable MSI");
+	}
 
 	intel_device_info_runtime_init(dev);
 
Signature · 1 line
2.5.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

author
#5 lore raw

PATCH 4/4 drm/i915: Properly terminate KMS mode name string during tv init

In reply to Imre Deak

Caught by Coverity.

---
 drivers/gpu/drm/i915/intel_tv.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/i915/intel_tv.c +1 -0
index 948cbff..5034b00 100644
@@ -1420,6 +1420,7 @@ intel_tv_get_modes(struct drm_connector *connector)
 		if (!mode_ptr)
 			continue;
 		strncpy(mode_ptr->name, input->name, DRM_DISPLAY_MODE_LEN);
+		mode_ptr->name[DRM_DISPLAY_MODE_LEN - 1] = '\0';
 
 		mode_ptr->hdisplay = hactive_s;
 		mode_ptr->hsync_start = hactive_s + 1;
Signature · 6 lines
2.5.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx
Reviewed-by on v1 4/4
#6 lore raw

Re: [PATCH 4/4] drm/i915: Properly terminate KMS mode name string during tv init

Quoted 3 lines · Imre Deak

Caught by Coverity.

Quoted 19 lines
---
 drivers/gpu/drm/i915/intel_tv.c | 1 +
 1 file changed, 1 insertion(+)
drivers/gpu/drm/i915/intel_tv.c +1 -0
index 948cbff..5034b00 100644
@@ -1420,6 +1420,7 @@ intel_tv_get_modes(struct drm_connector *connector)
 		if (!mode_ptr)
 			continue;
 		strncpy(mode_ptr->name, input->name, DRM_DISPLAY_MODE_LEN);
+		mode_ptr->name[DRM_DISPLAY_MODE_LEN - 1] = '\0';
 
 		mode_ptr->hdisplay = hactive_s;
 		mode_ptr->hsync_start = hactive_s + 1;
Signature · 1 line
2.5.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#8 lore raw

✓ Fi.CI.BAT: success for series starting with [1/4] drm/i915: Sanity check DP AUX message buffer and size

In reply to Imre Deak
== Summary ==

== Summary ==

Series 2922v1 Series without cover letter
http://patchwork.freedesktop.org/api/1.0/series/2922/revisions/1/mbox/

bdw-nuci7        total:156  pass:147  dwarn:0   dfail:0   fail:0   skip:9  
bdw-ultra        total:159  pass:147  dwarn:0   dfail:0   fail:0   skip:12 
bsw-nuc-2        total:159  pass:129  dwarn:0   dfail:0   fail:0   skip:30 
hsw-brixbox      total:159  pass:146  dwarn:0   dfail:0   fail:0   skip:13 
hsw-gt2          total:159  pass:149  dwarn:0   dfail:0   fail:0   skip:10 
ilk-hp8440p      total:159  pass:111  dwarn:0   dfail:0   fail:0   skip:48 
ivb-t430s        total:159  pass:145  dwarn:0   dfail:0   fail:0   skip:14 
skl-i5k-2        total:159  pass:144  dwarn:1   dfail:0   fail:0   skip:14 
snb-dellxps      total:159  pass:137  dwarn:0   dfail:0   fail:0   skip:22 
snb-x220t        total:159  pass:137  dwarn:0   dfail:0   fail:1   skip:21 

Results at /archive/results/CI_IGT_test/Patchwork_1320/

5de97b25e5f3c5a63ee243a9d3b22d30792f7d3e drm-intel-nightly: 2016y-01m-29d-07h-32m-09s UTC integration manifest 57b87311f5051584bdfc69424b99e4db48c1872f drm/i915: Properly terminate KMS mode name string during tv init 54e3ae2b95671fb9e613a3bb7bdf598c456382d6 drm/i915: Add debug info for failed MSI enabling 1beca05c239fe210a28fb40d62f9ada1446d1376 drm/i915/chv: Fix error path in GPU freq helpers 39e351cc5d9bd16e84dd896445878a57b90b3ce1 drm/i915: Sanity check DP AUX message buffer and size

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

author
#9 lore raw

Re: ✓ Fi.CI.BAT: success for series starting with [1/4] drm/i915: Sanity check DP AUX message buffer and size

Quoted 5 lines · Patchwork

== Summary ==

Series 2922v1 Series without cover letter
http://patchwork.freedesktop.org/api/1.0/series/2922/revisions/1/mbox
/

Thanks for the review, I pushed the patchset to dinq.

--Imre

Quoted 33 lines

bdw-
nuci7        total:156  pass:147  dwarn:0   dfail:0   fail:0   skip:9
bdw-
ultra        total:159  pass:147  dwarn:0   dfail:0   fail:0   skip:1 2
bsw-nuc-
2        total:159  pass:129  dwarn:0   dfail:0   fail:0   skip:30 hsw-
brixbox      total:159  pass:146  dwarn:0   dfail:0   fail:0   skip:1 3
hsw-
gt2          total:159  pass:149  dwarn:0   dfail:0   fail:0   skip:1 0
ilk-
hp8440p      total:159  pass:111  dwarn:0   dfail:0   fail:0   skip:4 8
ivb-
t430s        total:159  pass:145  dwarn:0   dfail:0   fail:0   skip:1 4
skl-i5k-
2        total:159  pass:144  dwarn:1   dfail:0   fail:0   skip:14 snb-
dellxps      total:159  pass:137  dwarn:0   dfail:0   fail:0   skip:2 2
snb-
x220t        total:159  pass:137  dwarn:0   dfail:0   fail:1   skip:2 1

Results at /archive/results/CI_IGT_test/Patchwork_1320/

Quoted 11 lines

5de97b25e5f3c5a63ee243a9d3b22d30792f7d3e drm-intel-nightly: 2016y- 01m-29d-07h-32m-09s UTC integration manifest 57b87311f5051584bdfc69424b99e4db48c1872f drm/i915: Properly terminate KMS mode name string during tv init 54e3ae2b95671fb9e613a3bb7bdf598c456382d6 drm/i915: Add debug info for failed MSI enabling 1beca05c239fe210a28fb40d62f9ada1446d1376 drm/i915/chv: Fix error path in GPU freq helpers 39e351cc5d9bd16e84dd896445878a57b90b3ce1 drm/i915: Sanity check DP AUX message buffer and size

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

Reviewed-by on v1 1/4
#10 lore raw
In reply to Imre Deak
Quoted 11 lines · Imre Deak

While we are calling intel_dp_aux_transfer() with msg->size=0 whenever msg->buffer is NULL, passing NULL to memcpy() is undefined according to the ISO C standard. I haven't found any notes about this in the GNU C's or the kernel's documentation of the function and can't imagine what it would do with the NULL ptr. To better document this use of the parameters it still make sense to add an explicit check for this to the code.

Caught by Coverity.

Quoted 23 lines
---
 drivers/gpu/drm/i915/intel_dp.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_dp.c +4 -1
index e2bea710..2aed36e 100644
@@ -979,7 +979,10 @@ intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
 		if (WARN_ON(txsize > 20))
 			return -E2BIG;
 
-		memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
+		if (msg->buffer)
+			memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
+		else
+			WARN_ON(msg->size);
 
 		ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
 		if (ret > 0) {
Signature · 1 line
2.5.0

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

#11 lore raw
In reply to Imre Deak
Quoted 9 lines · Imre Deak

While we are calling intel_dp_aux_transfer() with msg->size=0 whenever msg->buffer is NULL, passing NULL to memcpy() is undefined according to the ISO C standard. I haven't found any notes about this in the GNU C's or the kernel's documentation of the function and can't imagine what it would do with the NULL ptr. To better document this use of the parameters it still make sense to add an explicit check for this to the code.

Caught by Coverity.

can you share more info on when is this scenario triggered ?

Quoted 11 lines
---
  drivers/gpu/drm/i915/intel_dp.c | 5 ++++-
  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_dp.c +0 -0
index e2bea710..2aed36e 100644
@@ -979,7 +979,10 @@ intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg)
  		if (WARN_ON(txsize > 20))

drivers/gpu/drm/i915/intel_dp.c intel_dp_aux_transfer(struct drm_dp_aux *aux, struct drm_dp_aux_msg *msg) · line 988

Quoted 10 lines
drivers/gpu/drm/i915/intel_dp.c +4 -1
  			return -E2BIG;
 
-		memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
+		if (msg->buffer)
+			memcpy(txbuf + HEADER_SIZE, msg->buffer, msg->size);
+		else
+			WARN_ON(msg->size);
 
  		ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
  		if (ret > 0) {

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx

author
#12 lore raw
Quoted 15 lines · Sivakumar
Quoted 13 lines · Imre Deak

While we are calling intel_dp_aux_transfer() with msg->size=0 whenever
msg->buffer is NULL, passing NULL to memcpy() is undefined according to
the ISO C standard. I haven't found any notes about this in the GNU C's
or the kernel's documentation of the function and can't imagine what it
would do with the NULL ptr. To better document this use of the parameters it still make sense to add an explicit check for this to the
code.

Quoted 2 lines
Quoted 1 line

Caught by Coverity.

can you share more info on when is this scenario triggered ?

When sending a bare address packet at the start and end of the I2c over AUX transfer. See drm_dp_i2c_xfer().

Quoted 17 lines
Quoted 17 lines

---
  drivers/gpu/drm/i915/intel_dp.c | 5 ++++-

  1 file changed, 4 insertions(+), 1 deletion(-)
drivers/gpu/drm/i915/intel_dp.c +0 -0
index e2bea710..2aed36e 100644
@@ -979,7 +979,10 @@ intel_dp_aux_transfer(struct drm_dp_aux *aux,
 struct drm_dp_aux_msg *msg)
   		if (WARN_ON(txsize > 20))
   			return -E2BIG;

drivers/gpu/drm/i915/intel_dp.c +0 -1
-		memcpy(txbuf + HEADER_SIZE, msg->buffer, msg-
Quoted 1 line

size);

Quoted 10 lines
Quoted 9 lines
drivers/gpu/drm/i915/intel_dp.c +2 -0
+		if (msg->buffer)
+			memcpy(txbuf + HEADER_SIZE, msg->buffer,

msg->size);

drivers/gpu/drm/i915/intel_dp.c +2 -0
+		else
+			WARN_ON(msg->size);


   ret = intel_dp_aux_ch(intel_dp, txbuf, txsize, rxbuf, rxsize);
   if (ret > 0) {

_______________________________________________
Intel-gfx mailing list
[email protected]
http://lists.freedesktop.org/mailman/listinfo/intel-gfx