Skip to contentSkip to conversation

tools/intel_vbt_decode: fix division by zero child device size

PATCH In review Jani Nikula 3 participants 5 messages Feb 28, 2023 – Mar 1, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 tools/intel_vbt_decode: fix division by zero child device size

Real world VBTs keep fuzzing our decoder, this time with a legacy child devices block #11 that has child_dev_size 0, leading to division by zero. Check for it, and bail out early, both for legacy and current child device blocks.

---
 tools/intel_vbt_decode.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
tools/intel_vbt_decode.c +10 -4
index 8f707c1f822a..3294f74c2e7c 100644
@@ -1118,8 +1118,6 @@ static void dump_general_definitions(struct context *context,
 	const struct bdb_general_definitions *defs = block_data(block);
 	int child_dev_num;
 
-	child_dev_num = (block->size - sizeof(*defs)) / defs->child_dev_size;
-
 	printf("\tCRT DDC GMBUS addr: 0x%02x\n", defs->crt_ddc_gmbus_pin);
 	printf("\tUse DPMS on AIM devices: %s\n", YESNO(defs->dpms_aim));
 	printf("\tSkip CRT detect at boot: %s\n",
@@ -1129,6 +1127,11 @@ static void dump_general_definitions(struct context *context,
 	printf("\tBoot display type: 0x%02x%02x\n", defs->boot_display[1],
 	       defs->boot_display[0]);
 	printf("\tChild device size: %d\n", defs->child_dev_size);
+
+	if (!defs->child_dev_size)
+		return;
+
+	child_dev_num = (block->size - sizeof(*defs)) / defs->child_dev_size;
 	printf("\tChild device count: %d\n", child_dev_num);
 
 	dump_child_devices(context, defs->devices,
@@ -1141,9 +1144,12 @@ static void dump_legacy_child_devices(struct context *context,
 	const struct bdb_legacy_child_devices *defs = block_data(block);
 	int child_dev_num;
 
-	child_dev_num = (block->size - sizeof(*defs)) / defs->child_dev_size;
-
 	printf("\tChild device size: %d\n", defs->child_dev_size);
+
+	if (!defs->child_dev_size)
+		return;
+
+	child_dev_num = (block->size - sizeof(*defs)) / defs->child_dev_size;
 	printf("\tChild device count: %d\n", child_dev_num);
 
 	dump_child_devices(context, defs->devices,
Signature · 1 line
2.39.1
#1 lore raw

[igt-dev] ✓ Fi.CI.BAT: success for tools/intel_vbt_decode: fix division by zero child device size

== Series Details ==

== Series Details ==

Series: tools/intel_vbt_decode: fix division by zero child device size
URL : https://patchwork.freedesktop.org/series/114467/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_12790 -> IGTPW_8538
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/index.html

Participating hosts (2 -> 1)
------------------------------

Missing (1): fi-snb-2520m

Changes
-------

No changes found

Build changes
-------------

* CI: CI-20190529 -> None
* IGT: IGT_7175 -> IGTPW_8538

CI-20190529: 20190529
CI_DRM_12790: 92b7ba2b502495a393b6db904061b6938a09db17 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_8538: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/index.html
IGT_7175: e825eb183729902489365e56bd99f15af2aa3316 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/index.html

#2 lore raw

[igt-dev] ✓ Fi.CI.IGT: success for tools/intel_vbt_decode: fix division by zero child device size

In reply to Jani Nikula
== Series Details ==

== Series Details ==

Series: tools/intel_vbt_decode: fix division by zero child device size
URL : https://patchwork.freedesktop.org/series/114467/
State : success

== Summary ==

CI Bug Log - changes from CI_DRM_12790_full -> IGTPW_8538_full
====================================================

Summary
-------

**SUCCESS**

No regressions found.

External URL: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/index.html

Participating hosts (9 -> 9)
------------------------------

No changes in participating hosts

Known issues
------------

Here are the changes found in IGTPW_8538_full that come from known issues:

### IGT changes ###

#### Issues hit ####

* igt@fbdev@write:
- shard-tglu-9: NOTRUN -> [SKIP][1] ([i915#2582])
[1]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/shard-tglu-9/igt@[email protected]

* igt@gem_ctx_sseu@engines:
- shard-tglu-9: NOTRUN -> [SKIP][2] ([i915#280])
[2]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/shard-tglu-9/igt@[email protected]

* igt@gem_exec_fence@syncobj-signal:
- shard-tglu-9: NOTRUN -> [ABORT][3] ([i915#8233]) +1 similar issue
[3]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/shard-tglu-9/igt@[email protected]

* igt@gem_lmem_swapping@heavy-verify-random-ccs:
- shard-tglu-9: NOTRUN -> [SKIP][4] ([i915#4613])
[4]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/shard-tglu-9/igt@[email protected]

* igt@gen9_exec_parse@valid-registers:
- shard-tglu-9: NOTRUN -> [SKIP][5] ([i915#2527] / [i915#2856])
[5]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/shard-tglu-9/igt@[email protected]

* igt@i915_pm_backlight@bad-brightness:
- shard-tglu-9: NOTRUN -> [SKIP][6] ([i915#7561])
[6]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/shard-tglu-9/igt@[email protected]

* igt@i915_pm_rc6_residency@rc6-idle@rcs0:
- shard-tglu-9: NOTRUN -> [WARN][7] ([i915#2681]) +3 similar issues
[7]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/shard-tglu-9/igt@i915_pm_rc6_residency@[email protected]

* igt@kms_chamelium_hpd@vga-hpd:
- shard-tglu-9: NOTRUN -> [SKIP][8] ([i915#7828])
[8]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/shard-tglu-9/igt@[email protected]

* igt@kms_cursor_legacy@cursora-vs-flipa-varying-size:
- shard-tglu-9: NOTRUN -> [SKIP][9] ([i915#1845]) +1 similar issue
[9]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/shard-tglu-9/igt@[email protected]

* igt@kms_flip@2x-plain-flip-fb-recreate-interruptible:
- shard-tglu-9: NOTRUN -> [SKIP][10] ([fdo#109274] / [i915#3637]) +1 similar issue
[10]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/shard-tglu-9/igt@[email protected]

* igt@kms_flip_scaled_crc@flip-32bpp-4tile-to-32bpp-4tiledg2rcccs-upscaling:
- shard-tglu-9: NOTRUN -> [SKIP][11] ([i915#3555]) +2 similar issues
[11]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/shard-tglu-9/igt@kms_flip_scaled_crc@flip-32bpp-4tile-to-32bpp-4tiledg2rcccs-upscaling.html

* igt@kms_frontbuffer_tracking@fbcpsr-2p-primscrn-pri-indfb-draw-blt:
- shard-tglu-9: NOTRUN -> [SKIP][12] ([i915#1849]) +9 similar issues
[12]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/shard-tglu-9/igt@kms_frontbuffer_tracking@fbcpsr-2p-primscrn-pri-indfb-draw-blt.html

* igt@kms_psr@psr2_dpms:
- shard-tglu-9: NOTRUN -> [SKIP][13] ([fdo#110189]) +2 similar issues
[13]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/shard-tglu-9/igt@kms_psr@psr2_dpms.html

* igt@kms_rotation_crc@primary-yf-tiled-reflect-x-0:
- shard-tglu-9: NOTRUN -> [SKIP][14] ([fdo#111615] / [i915#1845])
[14]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/shard-tglu-9/igt@[email protected]

* igt@kms_rotation_crc@sprite-rotation-270:
- shard-tglu-9: NOTRUN -> [SKIP][15] ([i915#1845] / [i915#7651]) +16 similar issues
[15]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/shard-tglu-9/igt@[email protected]

* igt@v3d/v3d_mmap@mmap-bad-flags:
- shard-tglu-9: NOTRUN -> [SKIP][16] ([fdo#109315] / [i915#2575])
[16]: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/shard-tglu-9/igt@v3d/[email protected]

{name}: This element is suppressed. This means it is ignored when computing
the status of the difference (SUCCESS, WARNING, or FAILURE).

[fdo#109274]: https://bugs.freedesktop.org/show_bug.cgi?id=109274
[fdo#109280]: https://bugs.freedesktop.org/show_bug.cgi?id=109280
[fdo#109289]: https://bugs.freedesktop.org/show_bug.cgi?id=109289
[fdo#109295]: https://bugs.freedesktop.org/show_bug.cgi?id=109295
[fdo#109315]: https://bugs.freedesktop.org/show_bug.cgi?id=109315
[fdo#109506]: https://bugs.freedesktop.org/show_bug.cgi?id=109506
[fdo#109642]: https://bugs.freedesktop.org/show_bug.cgi?id=109642
[fdo#110189]: https://bugs.freedesktop.org/show_bug.cgi?id=110189
[fdo#111068]: https://bugs.freedesktop.org/show_bug.cgi?id=111068
[fdo#111614]: https://bugs.freedesktop.org/show_bug.cgi?id=111614
[fdo#111615]: https://bugs.freedesktop.org/show_bug.cgi?id=111615
[fdo#111825]: https://bugs.freedesktop.org/show_bug.cgi?id=111825
[fdo#111827]: https://bugs.freedesktop.org/show_bug.cgi?id=111827
[i915#1072]: https://gitlab.freedesktop.org/drm/intel/issues/1072
[i915#1845]: https://gitlab.freedesktop.org/drm/intel/issues/1845
[i915#1849]: https://gitlab.freedesktop.org/drm/intel/issues/1849
[i915#2527]: https://gitlab.freedesktop.org/drm/intel/issues/2527
[i915#2575]: https://gitlab.freedesktop.org/drm/intel/issues/2575
[i915#2582]: https://gitlab.freedesktop.org/drm/intel/issues/2582
[i915#2587]: https://gitlab.freedesktop.org/drm/intel/issues/2587
[i915#2672]: https://gitlab.freedesktop.org/drm/intel/issues/2672
[i915#2681]: https://gitlab.freedesktop.org/drm/intel/issues/2681
[i915#280]: https://gitlab.freedesktop.org/drm/intel/issues/280
[i915#2856]: https://gitlab.freedesktop.org/drm/intel/issues/2856
[i915#3281]: https://gitlab.freedesktop.org/drm/intel/issues/3281
[i915#3282]: https://gitlab.freedesktop.org/drm/intel/issues/3282
[i915#3297]: https://gitlab.freedesktop.org/drm/intel/issues/3297
[i915#3301]: https://gitlab.freedesktop.org/drm/intel/issues/3301
[i915#3458]: https://gitlab.freedesktop.org/drm/intel/issues/3458
[i915#3555]: https://gitlab.freedesktop.org/drm/intel/issues/3555
[i915#3591]: https://gitlab.freedesktop.org/drm/intel/issues/3591
[i915#3637]: https://gitlab.freedesktop.org/drm/intel/issues/3637
[i915#3638]: https://gitlab.freedesktop.org/drm/intel/issues/3638
[i915#3689]: https://gitlab.freedesktop.org/drm/intel/issues/3689
[i915#3708]: https://gitlab.freedesktop.org/drm/intel/issues/3708
[i915#3886]: https://gitlab.freedesktop.org/drm/intel/issues/3886
[i915#404]: https://gitlab.freedesktop.org/drm/intel/issues/404
[i915#4077]: https://gitlab.freedesktop.org/drm/intel/issues/4077
[i915#4083]: https://gitlab.freedesktop.org/drm/intel/issues/4083
[i915#4270]: https://gitlab.freedesktop.org/drm/intel/issues/4270
[i915#4349]: https://gitlab.freedesktop.org/drm/intel/issues/4349
[i915#4538]: https://gitlab.freedesktop.org/drm/intel/issues/4538
[i915#4565]: https://gitlab.freedesktop.org/drm/intel/issues/4565
[i915#4613]: https://gitlab.freedesktop.org/drm/intel/issues/4613
[i915#4812]: https://gitlab.freedesktop.org/drm/intel/issues/4812
[i915#4833]: https://gitlab.freedesktop.org/drm/intel/issues/4833
[i915#4854]: https://gitlab.freedesktop.org/drm/intel/issues/4854
[i915#4860]: https://gitlab.freedesktop.org/drm/intel/issues/4860
[i915#4881]: https://gitlab.freedesktop.org/drm/intel/issues/4881
[i915#5286]: https://gitlab.freedesktop.org/drm/intel/issues/5286
[i915#5289]: https://gitlab.freedesktop.org/drm/intel/issues/5289
[i915#5431]: https://gitlab.freedesktop.org/drm/intel/issues/5431
[i915#5563]: https://gitlab.freedesktop.org/drm/intel/issues/5563
[i915#6095]: https://gitlab.freedesktop.org/drm/intel/issues/6095
[i915#6334]: https://gitlab.freedesktop.org/drm/intel/issues/6334
[i915#6433]: https://gitlab.freedesktop.org/drm/intel/issues/6433
[i915#6524]: https://gitlab.freedesktop.org/drm/intel/issues/6524
[i915#658]: https://gitlab.freedesktop.org/drm/intel/issues/658
[i915#6768]: https://gitlab.freedesktop.org/drm/intel/issues/6768
[i915#7456]: https://gitlab.freedesktop.org/drm/intel/issues/7456
[i915#7561]: https://gitlab.freedesktop.org/drm/intel/issues/7561
[i915#7651]: https://gitlab.freedesktop.org/drm/intel/issues/7651
[i915#7711]: https://gitlab.freedesktop.org/drm/intel/issues/7711
[i915#7828]: https://gitlab.freedesktop.org/drm/intel/issues/7828
[i915#8152]: https://gitlab.freedesktop.org/drm/intel/issues/8152
[i915#8233]: https://gitlab.freedesktop.org/drm/intel/issues/8233

Build changes
-------------

* CI: CI-20190529 -> None
* IGT: IGT_7175 -> IGTPW_8538

CI-20190529: 20190529
CI_DRM_12790: 92b7ba2b502495a393b6db904061b6938a09db17 @ git://anongit.freedesktop.org/gfx-ci/linux
IGTPW_8538: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/index.html
IGT_7175: e825eb183729902489365e56bd99f15af2aa3316 @ https://gitlab.freedesktop.org/drm/igt-gpu-tools.git

== Logs ==

For more details see: https://intel-gfx-ci.01.org/tree/drm-tip/IGTPW_8538/index.html

Reviewed-by on v1 1/1
#3 lore raw
In reply to Jani Nikula
Quoted 6 lines · Jani Nikula

Real world VBTs keep fuzzing our decoder, this time with a legacy child devices block #11 that has child_dev_size 0, leading to division by zero. Check for it, and bail out early, both for legacy and current child device blocks.

lgtm,

--
Kamil

Quoted 47 lines
---
 tools/intel_vbt_decode.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
tools/intel_vbt_decode.c +10 -4
index 8f707c1f822a..3294f74c2e7c 100644
@@ -1118,8 +1118,6 @@ static void dump_general_definitions(struct context *context,
 	const struct bdb_general_definitions *defs = block_data(block);
 	int child_dev_num;
 
-	child_dev_num = (block->size - sizeof(*defs)) / defs->child_dev_size;
-
 	printf("\tCRT DDC GMBUS addr: 0x%02x\n", defs->crt_ddc_gmbus_pin);
 	printf("\tUse DPMS on AIM devices: %s\n", YESNO(defs->dpms_aim));
 	printf("\tSkip CRT detect at boot: %s\n",
@@ -1129,6 +1127,11 @@ static void dump_general_definitions(struct context *context,
 	printf("\tBoot display type: 0x%02x%02x\n", defs->boot_display[1],
 	       defs->boot_display[0]);
 	printf("\tChild device size: %d\n", defs->child_dev_size);
+
+	if (!defs->child_dev_size)
+		return;
+
+	child_dev_num = (block->size - sizeof(*defs)) / defs->child_dev_size;
 	printf("\tChild device count: %d\n", child_dev_num);
 
 	dump_child_devices(context, defs->devices,
@@ -1141,9 +1144,12 @@ static void dump_legacy_child_devices(struct context *context,
 	const struct bdb_legacy_child_devices *defs = block_data(block);
 	int child_dev_num;
 
-	child_dev_num = (block->size - sizeof(*defs)) / defs->child_dev_size;
-
 	printf("\tChild device size: %d\n", defs->child_dev_size);
+
+	if (!defs->child_dev_size)
+		return;
+
+	child_dev_num = (block->size - sizeof(*defs)) / defs->child_dev_size;
 	printf("\tChild device count: %d\n", child_dev_num);
 
 	dump_child_devices(context, defs->devices,
Signature · 1 line
2.39.1
#4 lore raw
Quoted 10 lines · Kamil Konieczny
Quoted 6 lines · Jani Nikula

Real world VBTs keep fuzzing our decoder, this time with a legacy child devices block #11 that has child_dev_size 0, leading to division by zero. Check for it, and bail out early, both for legacy and current child device blocks.

lgtm,

Pushed, thanks for the review.

BR,
Jani.

Quoted 51 lines

--
Kamil

Quoted 47 lines
---
 tools/intel_vbt_decode.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)
tools/intel_vbt_decode.c +10 -4
index 8f707c1f822a..3294f74c2e7c 100644
@@ -1118,8 +1118,6 @@ static void dump_general_definitions(struct context *context,
 	const struct bdb_general_definitions *defs = block_data(block);
 	int child_dev_num;
 
-	child_dev_num = (block->size - sizeof(*defs)) / defs->child_dev_size;
-
 	printf("\tCRT DDC GMBUS addr: 0x%02x\n", defs->crt_ddc_gmbus_pin);
 	printf("\tUse DPMS on AIM devices: %s\n", YESNO(defs->dpms_aim));
 	printf("\tSkip CRT detect at boot: %s\n",
@@ -1129,6 +1127,11 @@ static void dump_general_definitions(struct context *context,
 	printf("\tBoot display type: 0x%02x%02x\n", defs->boot_display[1],
 	       defs->boot_display[0]);
 	printf("\tChild device size: %d\n", defs->child_dev_size);
+
+	if (!defs->child_dev_size)
+		return;
+
+	child_dev_num = (block->size - sizeof(*defs)) / defs->child_dev_size;
 	printf("\tChild device count: %d\n", child_dev_num);
 
 	dump_child_devices(context, defs->devices,
@@ -1141,9 +1144,12 @@ static void dump_legacy_child_devices(struct context *context,
 	const struct bdb_legacy_child_devices *defs = block_data(block);
 	int child_dev_num;
 
-	child_dev_num = (block->size - sizeof(*defs)) / defs->child_dev_size;
-
 	printf("\tChild device size: %d\n", defs->child_dev_size);
+
+	if (!defs->child_dev_size)
+		return;
+
+	child_dev_num = (block->size - sizeof(*defs)) / defs->child_dev_size;
 	printf("\tChild device count: %d\n", child_dev_num);
 
 	dump_child_devices(context, defs->devices,
Signature · 1 line
2.39.1
Signature · 1 line
Jani Nikula, Intel Open Source Graphics Center