Skip to contentSkip to conversation

lib/igt_kms: Fix memory corruption

PATCH Superseded Vignesh Raman 5 participants 8 messages Nov 8, 2023 – Nov 9, 2023 Library code

v3 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

PATCH v3 1/1 lib/igt_kms: Fix memory corruption

In crosvm, the kernel reports 16 for count_crtcs, which exceeds IGT_MAX_PIPES set to 8. The function igt_display_require allocates memory for IGT_MAX_PIPES members of igt_pipe_t structures, but then writes into it based on the count_crtcs reported by the kernel, resulting in memory corruption.

# malloc(): corrupted top size
# Received signal SIGABRT.
# Stack trace:

 #  #0 [fatal_sig_handler+0x17b]
 #  #1 [__sigaction+0x40]
 #  #2 [pthread_key_delete+0x14c]
 #  #3 [gsignal+0x12]
 #  #4 [abort+0xd3]
 #  #5 [__fsetlocking+0x290]
 #  #6 [timer_settime+0x37a]
 #  #7 [__default_morecore+0x1f1b]
 #  #8 [__libc_calloc+0x161]
 #  #9 [drmModeGetPlaneResources+0x44]
 #  #10 [igt_display_require+0x194]
 #  #11 [__igt_unique____real_main1356+0x93c]
 #  #12 [main+0x3f]
 #  #13 [__libc_init_first+0x8a]
 #  #14 [__libc_start_main+0x85]
 #  #15 [_start+0x21]

Increase IGT_MAX_PIPES to 16 to fix this memory corruption issue. igt_display_require initializes display and allocate resources as a prerequisite for the tests. Fail the test if count_crtcs exceeds IGT_MAX_PIPES with debug information.

This fix is required for drm-ci to run igt tests on virtio-gpu.

---

v2:
- Rework the fix to increase IGT_MAX_PIPES to 16

v3:
- Fail the test if count_crtcs exceeds IGT_MAX_PIPES with debug information

---
 lib/igt_kms.c |  6 +++++-
 lib/igt_kms.h | 20 +++++++++++++++++++-
 2 files changed, 24 insertions(+), 2 deletions(-)
lib/igt_kms.c +5 -1
index 453103f90..6ad7cc127 100644
@@ -906,7 +906,7 @@ static igt_plane_t *igt_get_assigned_primary(igt_output_t *output, igt_pipe_t *p
  */
 const char *kmstest_pipe_name(enum pipe pipe)
 {
-	static const char str[] = "A\0B\0C\0D\0E\0F\0G\0H";
+	static const char str[] = "A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P";
 
 	_Static_assert(sizeof(str) == IGT_MAX_PIPES * 2,
 		       "Missing pipe name");
@@ -2770,6 +2770,10 @@ void igt_display_require(igt_display_t *display, int drm_fd)
 	}
 #endif
 
+	igt_assert_f(resources->count_crtcs <= IGT_MAX_PIPES,
+		     "count_crtcs exceeds IGT_MAX_PIPES, resources->count_crtcs=%d, IGT_MAX_PIPES=%d\n",
+		     resources->count_crtcs, IGT_MAX_PIPES);
+
 	display->n_pipes = IGT_MAX_PIPES;
 	display->pipes = calloc(sizeof(igt_pipe_t), display->n_pipes);
 	igt_assert_f(display->pipes, "Failed to allocate memory for %d pipes\n", display->n_pipes);
lib/igt_kms.h +19 -1
index 9028ab9be..5c705b585 100644
@@ -57,6 +57,16 @@
  * @PIPE_D: Fourth crtc.
  * @PIPE_E: Fifth crtc.
  * @PIPE_F: Sixth crtc.
+ * @PIPE_G: Seventh crtc.
+ * @PIPE_H: Eighth crtc.
+ * @PIPE_I: Ninth crtc.
+ * @PIPE_J: Tenth crtc.
+ * @PIPE_K: Eleventh crtc.
+ * @PIPE_L: Twelfth crtc.
+ * @PIPE_M: Thirteenth crtc.
+ * @PIPE_N: Fourteenth crtc.
+ * @PIPE_O: Fifteenth crtc.
+ * @PIPE_P: Sixteenth crtc.
  * @IGT_MAX_PIPES: Max number of pipes allowed.
  */
 enum pipe {
@@ -70,7 +80,15 @@ enum pipe {
         PIPE_F,
 	PIPE_G,
 	PIPE_H,
-        IGT_MAX_PIPES
+	PIPE_I,
+	PIPE_J,
+	PIPE_K,
+	PIPE_L,
+	PIPE_M,
+	PIPE_N,
+	PIPE_O,
+	PIPE_P,
+	IGT_MAX_PIPES
 };
 const char *kmstest_pipe_name(enum pipe pipe);
 int kmstest_pipe_to_index(char pipe);
Signature · 1 line
2.40.1
#1 lore raw

[igt-dev] ✗ Fi.CI.BUILD: failure for lib/igt_kms: Fix memory corruption (rev3)

== Series Details ==

== Series Details ==

Series: lib/igt_kms: Fix memory corruption (rev3)
URL : https://patchwork.freedesktop.org/series/125599/
State : failure

== Summary ==

IGT patchset build failed on latest successful build 6edf8b6808de2bde968415926d2b55817f7ea1de tests/amd_security: add secure write test for gfx

Tail of build.log:
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-primary-basic-y-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-primary-basic-y-tiled-gen12-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-primary-basic-y-tiled-gen12-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-primary-basic-y-tiled-gen12-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-primary-basic-yf-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-primary-rotation-180-4-tiled-dg2-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-primary-rotation-180-4-tiled-dg2-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-primary-rotation-180-4-tiled-dg2-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-primary-rotation-180-4-tiled-mtl-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-primary-rotation-180-4-tiled-mtl-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-primary-rotation-180-4-tiled-mtl-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-primary-rotation-180-y-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-primary-rotation-180-y-tiled-gen12-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-primary-rotation-180-y-tiled-gen12-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-primary-rotation-180-y-tiled-gen12-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-primary-rotation-180-yf-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-sprite-planes-basic-4-tiled-dg2-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-sprite-planes-basic-4-tiled-dg2-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-sprite-planes-basic-4-tiled-dg2-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-sprite-planes-basic-4-tiled-mtl-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-sprite-planes-basic-4-tiled-mtl-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-sprite-planes-basic-4-tiled-mtl-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-sprite-planes-basic-y-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-sprite-planes-basic-y-tiled-gen12-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-sprite-planes-basic-y-tiled-gen12-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-sprite-planes-basic-y-tiled-gen12-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-crc-sprite-planes-basic-yf-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-missing-ccs-buffer-4-tiled-mtl-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-missing-ccs-buffer-4-tiled-mtl-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-missing-ccs-buffer-4-tiled-mtl-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-missing-ccs-buffer-y-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-missing-ccs-buffer-y-tiled-gen12-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-missing-ccs-buffer-y-tiled-gen12-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-missing-ccs-buffer-y-tiled-gen12-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-missing-ccs-buffer-yf-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-yf-tiled-ccs Please refer: docs/test_documentation.md for more details
[1651/1654] Generating xe_tests.html with a custom command.
[1652/1654] Generating i915_tests.html with a custom command.
ninja: build stopped: subcommand failed.

#2 lore raw

[igt-dev] ✗ GitLab.Pipeline: warning for lib/igt_kms: Fix memory corruption (rev3)

In reply to Vignesh Raman
== Series Details ==

== Series Details ==

Series: lib/igt_kms: Fix memory corruption (rev3)
URL : https://patchwork.freedesktop.org/series/125599/
State : warning

== Summary ==

Pipeline status: FAILED.

see https://gitlab.freedesktop.org/gfx-ci/igt-ci-tags/-/pipelines/1029126 for the overview.

build:tests-debian-meson has failed (https://gitlab.freedesktop.org/gfx-ci/igt-ci-tags/-/jobs/51327672):
Warning: Missing documentation for igt@kms_ccs@pipe-P-missing-ccs-buffer-yf-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-yf-tiled-ccs Please refer: docs/test_documentation.md for more details
ninja: build stopped: subcommand failed.
section_end:1699425801:step_script
section_start:1699425801:cleanup_file_variables
Cleaning up project directory and file based variables section_end:1699425802:cleanup_file_variables
ERROR: Job failed: exit code 1

build:tests-fedora has failed (https://gitlab.freedesktop.org/gfx-ci/igt-ci-tags/-/jobs/51327667):
Warning: Missing documentation for igt@kms_ccs@pipe-P-missing-ccs-buffer-yf-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-yf-tiled-ccs Please refer: docs/test_documentation.md for more details
ninja: build stopped: subcommand failed.
section_end:1699425811:step_script section_start:1699425811:cleanup_file_variables
Cleaning up project directory and file based variables section_end:1699425811:cleanup_file_variables
ERROR: Job failed: exit code 1

build:tests-fedora-clang has failed (https://gitlab.freedesktop.org/gfx-ci/igt-ci-tags/-/jobs/51327671):
Warning: Missing documentation for igt@kms_ccs@pipe-P-missing-ccs-buffer-yf-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-yf-tiled-ccs Please refer: docs/test_documentation.md for more details
ninja: build stopped: subcommand failed.
section_end:1699425829:step_script
section_start:1699425829:cleanup_file_variables
Cleaning up project directory and file based variables section_end:1699425831:cleanup_file_variables
ERROR: Job failed: exit code 1

build:tests-fedora-no-libdrm-nouveau has failed (https://gitlab.freedesktop.org/gfx-ci/igt-ci-tags/-/jobs/51327670):
Warning: Missing documentation for igt@kms_ccs@pipe-P-missing-ccs-buffer-yf-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-yf-tiled-ccs
Please refer: docs/test_documentation.md for more details
ninja: build stopped: subcommand failed.
section_end:1699425804:step_script
section_start:1699425804:cleanup_file_variables
Cleaning up project directory and file based variables section_end:1699425805:cleanup_file_variables
ERROR: Job failed: exit code 1

build:tests-fedora-no-libunwind has failed (https://gitlab.freedesktop.org/gfx-ci/igt-ci-tags/-/jobs/51327668):
Warning: Missing documentation for igt@kms_ccs@pipe-P-missing-ccs-buffer-yf-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-yf-tiled-ccs
Please refer: docs/test_documentation.md for more details
ninja: build stopped: subcommand failed.
section_end:1699425812:step_script
section_start:1699425812:cleanup_file_variables
Cleaning up project directory and file based variables section_end:1699425812:cleanup_file_variables
ERROR: Job failed: exit code 1

build:tests-fedora-oldest-meson has failed (https://gitlab.freedesktop.org/gfx-ci/igt-ci-tags/-/jobs/51327669):
Warning: Missing documentation for igt@kms_ccs@pipe-P-missing-ccs-buffer-yf-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-dg2-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-4-tiled-mtl-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-mc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-rc-ccs
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-y-tiled-gen12-rc-ccs-cc
Warning: Missing documentation for igt@kms_ccs@pipe-P-random-ccs-data-yf-tiled-ccs
Please refer: docs/test_documentation.md for more details
ninja: build stopped: subcommand failed.
section_end:1699425809:step_script
section_start:1699425809:cleanup_file_variables
Cleaning up project directory and file based variables section_end:1699425810:cleanup_file_variables
ERROR: Job failed: exit code 1

== Logs ==

For more details see: https://gitlab.freedesktop.org/gfx-ci/igt-ci-tags/-/pipelines/1029126

Acked-by on v3 1/1
#3 lore raw
In reply to Vignesh Raman
Quoted 31 lines · Vignesh Raman

In crosvm, the kernel reports 16 for count_crtcs, which exceeds IGT_MAX_PIPES set to 8. The function igt_display_require allocates memory for IGT_MAX_PIPES members of igt_pipe_t structures, but then writes into it based on the count_crtcs reported by the kernel, resulting in memory corruption.

# malloc(): corrupted top size
# Received signal SIGABRT.
# Stack trace:

  #  #0 [fatal_sig_handler+0x17b]
  #  #1 [__sigaction+0x40]
  #  #2 [pthread_key_delete+0x14c]
  #  #3 [gsignal+0x12]
  #  #4 [abort+0xd3]
  #  #5 [__fsetlocking+0x290]
  #  #6 [timer_settime+0x37a]
  #  #7 [__default_morecore+0x1f1b]
  #  #8 [__libc_calloc+0x161]
  #  #9 [drmModeGetPlaneResources+0x44]
  #  #10 [igt_display_require+0x194]
  #  #11 [__igt_unique____real_main1356+0x93c]
  #  #12 [main+0x3f]
  #  #13 [__libc_init_first+0x8a]
  #  #14 [__libc_start_main+0x85]
  #  #15 [_start+0x21]

Increase IGT_MAX_PIPES to 16 to fix this memory corruption issue. igt_display_require initializes display and allocate resources as a prerequisite for the tests. Fail the test if count_crtcs exceeds IGT_MAX_PIPES with debug information.

Quoted 5 lines

This fix is required for drm-ci to run igt tests on virtio-gpu.

lgtm

Thanks
Helen

Quoted 75 lines

---

v2:
- Rework the fix to increase IGT_MAX_PIPES to 16

v3:
- Fail the test if count_crtcs exceeds IGT_MAX_PIPES with debug information

---
  lib/igt_kms.c |  6 +++++-
  lib/igt_kms.h | 20 +++++++++++++++++++-
  2 files changed, 24 insertions(+), 2 deletions(-)
lib/igt_kms.c +5 -1
index 453103f90..6ad7cc127 100644
@@ -906,7 +906,7 @@ static igt_plane_t *igt_get_assigned_primary(igt_output_t *output, igt_pipe_t *p
   */
  const char *kmstest_pipe_name(enum pipe pipe)
  {
-	static const char str[] = "A\0B\0C\0D\0E\0F\0G\0H";
+	static const char str[] = "A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P";
 
  	_Static_assert(sizeof(str) == IGT_MAX_PIPES * 2,
  		       "Missing pipe name");
@@ -2770,6 +2770,10 @@ void igt_display_require(igt_display_t *display, int drm_fd)
  	}
  #endif
 
+	igt_assert_f(resources->count_crtcs <= IGT_MAX_PIPES,
+		     "count_crtcs exceeds IGT_MAX_PIPES, resources->count_crtcs=%d, IGT_MAX_PIPES=%d\n",
+		     resources->count_crtcs, IGT_MAX_PIPES);
+
  	display->n_pipes = IGT_MAX_PIPES;
  	display->pipes = calloc(sizeof(igt_pipe_t), display->n_pipes);
  	igt_assert_f(display->pipes, "Failed to allocate memory for %d pipes\n", display->n_pipes);
lib/igt_kms.h +19 -1
index 9028ab9be..5c705b585 100644
@@ -57,6 +57,16 @@
   * @PIPE_D: Fourth crtc.
   * @PIPE_E: Fifth crtc.
   * @PIPE_F: Sixth crtc.
+ * @PIPE_G: Seventh crtc.
+ * @PIPE_H: Eighth crtc.
+ * @PIPE_I: Ninth crtc.
+ * @PIPE_J: Tenth crtc.
+ * @PIPE_K: Eleventh crtc.
+ * @PIPE_L: Twelfth crtc.
+ * @PIPE_M: Thirteenth crtc.
+ * @PIPE_N: Fourteenth crtc.
+ * @PIPE_O: Fifteenth crtc.
+ * @PIPE_P: Sixteenth crtc.
   * @IGT_MAX_PIPES: Max number of pipes allowed.
   */
  enum pipe {
@@ -70,7 +80,15 @@ enum pipe {
          PIPE_F,
  	PIPE_G,
  	PIPE_H,
-        IGT_MAX_PIPES
+	PIPE_I,
+	PIPE_J,
+	PIPE_K,
+	PIPE_L,
+	PIPE_M,
+	PIPE_N,
+	PIPE_O,
+	PIPE_P,
+	IGT_MAX_PIPES
  };
  const char *kmstest_pipe_name(enum pipe pipe);
  int kmstest_pipe_to_index(char pipe);
Reviewed-by on v3 1/1
#4 lore raw
In reply to Vignesh Raman

Hi Vignesh,

Quoted 1 line · Vignesh Raman

In crosvm

Strictly speaking, the change is in virtio-gpu (the kernel driver providing KMS), not crosvm (the KVM host for the kernel), but this is an unimportant detail.

Quoted 26 lines

, the kernel reports 16 for count_crtcs, which exceeds IGT_MAX_PIPES set to 8. The function igt_display_require allocates memory for IGT_MAX_PIPES members of igt_pipe_t structures, but then writes into it based on the count_crtcs reported by the kernel, resulting in memory corruption.

[...]
# Received signal SIGABRT.
# Stack trace:

  #  #0 [fatal_sig_handler+0x17b]
  #  #1 [__sigaction+0x40]
  #  #2 [pthread_key_delete+0x14c]
  #  #3 [gsignal+0x12]
  #  #4 [abort+0xd3]
  #  #5 [__fsetlocking+0x290]
  #  #6 [timer_settime+0x37a]
  #  #7 [__default_morecore+0x1f1b]
  #  #8 [__libc_calloc+0x161]
  #  #9 [drmModeGetPlaneResources+0x44]
  #  #10 [igt_display_require+0x194]
  #  #11 [__igt_unique____real_main1356+0x93c]
  #  #12 [main+0x3f]
  #  #13 [__libc_init_first+0x8a]
  #  #14 [__libc_start_main+0x85]
  #  #15 [_start+0x21]
Quoted 6 lines

Increase IGT_MAX_PIPES to 16 to fix this memory corruption issue. igt_display_require initializes display and allocate resources as a prerequisite for the tests. Fail the test if count_crtcs exceeds IGT_MAX_PIPES with debug information.

This fix is required for drm-ci to run igt tests on virtio-gpu.

The rest is all good though, so this change is:

Thanks,
Daniel

#5 lore raw
In reply to Vignesh Raman

Hi Vignesh,

As we introduced the IGT documentation[1] to generate the testlist, we need a fix in few kms tests to compile the IGT.

Also, needs few changes in intel-ci/ to avoid noise in the CI.

[1]: https://cgit.freedesktop.org/drm/igt-gpu-tools/tree/docs/test_documentation.md

- Bhanu

Quoted 111 lines · Vignesh Raman

In crosvm, the kernel reports 16 for count_crtcs, which exceeds IGT_MAX_PIPES set to 8. The function igt_display_require allocates memory for IGT_MAX_PIPES members of igt_pipe_t structures, but then writes into it based on the count_crtcs reported by the kernel, resulting in memory corruption.

# malloc(): corrupted top size
# Received signal SIGABRT.
# Stack trace:

  #  #0 [fatal_sig_handler+0x17b]
  #  #1 [__sigaction+0x40]
  #  #2 [pthread_key_delete+0x14c]
  #  #3 [gsignal+0x12]
  #  #4 [abort+0xd3]
  #  #5 [__fsetlocking+0x290]
  #  #6 [timer_settime+0x37a]
  #  #7 [__default_morecore+0x1f1b]
  #  #8 [__libc_calloc+0x161]
  #  #9 [drmModeGetPlaneResources+0x44]
  #  #10 [igt_display_require+0x194]
  #  #11 [__igt_unique____real_main1356+0x93c]
  #  #12 [main+0x3f]
  #  #13 [__libc_init_first+0x8a]
  #  #14 [__libc_start_main+0x85]
  #  #15 [_start+0x21]

Increase IGT_MAX_PIPES to 16 to fix this memory corruption issue. igt_display_require initializes display and allocate resources as a prerequisite for the tests. Fail the test if count_crtcs exceeds IGT_MAX_PIPES with debug information.

This fix is required for drm-ci to run igt tests on virtio-gpu.

---

v2:
- Rework the fix to increase IGT_MAX_PIPES to 16

v3:
- Fail the test if count_crtcs exceeds IGT_MAX_PIPES with debug information

---
  lib/igt_kms.c |  6 +++++-
  lib/igt_kms.h | 20 +++++++++++++++++++-
  2 files changed, 24 insertions(+), 2 deletions(-)
lib/igt_kms.c +5 -1
index 453103f90..6ad7cc127 100644
@@ -906,7 +906,7 @@ static igt_plane_t *igt_get_assigned_primary(igt_output_t *output, igt_pipe_t *p
   */
  const char *kmstest_pipe_name(enum pipe pipe)
  {
-	static const char str[] = "A\0B\0C\0D\0E\0F\0G\0H";
+	static const char str[] = "A\0B\0C\0D\0E\0F\0G\0H\0I\0J\0K\0L\0M\0N\0O\0P";
 
  	_Static_assert(sizeof(str) == IGT_MAX_PIPES * 2,
  		       "Missing pipe name");
@@ -2770,6 +2770,10 @@ void igt_display_require(igt_display_t *display, int drm_fd)
  	}
  #endif
 
+	igt_assert_f(resources->count_crtcs <= IGT_MAX_PIPES,
+		     "count_crtcs exceeds IGT_MAX_PIPES, resources->count_crtcs=%d, IGT_MAX_PIPES=%d\n",
+		     resources->count_crtcs, IGT_MAX_PIPES);
+
  	display->n_pipes = IGT_MAX_PIPES;
  	display->pipes = calloc(sizeof(igt_pipe_t), display->n_pipes);
  	igt_assert_f(display->pipes, "Failed to allocate memory for %d pipes\n", display->n_pipes);
lib/igt_kms.h +19 -1
index 9028ab9be..5c705b585 100644
@@ -57,6 +57,16 @@
   * @PIPE_D: Fourth crtc.
   * @PIPE_E: Fifth crtc.
   * @PIPE_F: Sixth crtc.
+ * @PIPE_G: Seventh crtc.
+ * @PIPE_H: Eighth crtc.
+ * @PIPE_I: Ninth crtc.
+ * @PIPE_J: Tenth crtc.
+ * @PIPE_K: Eleventh crtc.
+ * @PIPE_L: Twelfth crtc.
+ * @PIPE_M: Thirteenth crtc.
+ * @PIPE_N: Fourteenth crtc.
+ * @PIPE_O: Fifteenth crtc.
+ * @PIPE_P: Sixteenth crtc.
   * @IGT_MAX_PIPES: Max number of pipes allowed.
   */
  enum pipe {
@@ -70,7 +80,15 @@ enum pipe {
          PIPE_F,
  	PIPE_G,
  	PIPE_H,
-        IGT_MAX_PIPES
+	PIPE_I,
+	PIPE_J,
+	PIPE_K,
+	PIPE_L,
+	PIPE_M,
+	PIPE_N,
+	PIPE_O,
+	PIPE_P,
+	IGT_MAX_PIPES
  };
  const char *kmstest_pipe_name(enum pipe pipe);
  int kmstest_pipe_to_index(char pipe);
#6 lore raw

Hi Bhanu,

Quoted 7 lines · Bhanuprakash

Hi Vignesh,

As we introduced the IGT documentation[1] to generate the testlist, we need a fix in few kms tests to compile the IGT.

Also, needs few changes in intel-ci/ to avoid noise in the CI.

[1]: https://cgit.freedesktop.org/drm/igt-gpu-tools/tree/docs/test_documentation.md

Are you referring to the pipeline failures in https://gitlab.freedesktop.org/gfx-ci/igt-ci-tags/-/pipelines/1029126

In my forked branch the pipeline fails in containers stage,
https://gitlab.freedesktop.org/vigneshraman/igt-gpu-tools/-/pipelines/1030263

Is there a way to run the pipeline in my fork or should I locally build docs (build igt-gpu-tools-doc) with the patch and check the issue?

Regards,
Vignesh

#7 lore raw

Hi Bhanu,

Quoted 11 lines · Vignesh Raman

Hi Bhanu,

Quoted 7 lines · Bhanuprakash

Hi Vignesh,

As we introduced the IGT documentation[1] to generate the testlist, we need a fix in few kms tests to compile the IGT.

Also, needs few changes in intel-ci/ to avoid noise in the CI.

[1]: https://cgit.freedesktop.org/drm/igt-gpu-tools/tree/docs/test_documentation.md

Quoted 8 lines

Are you referring to the pipeline failures in https://gitlab.freedesktop.org/gfx-ci/igt-ci-tags/-/pipelines/1029126

In my forked branch the pipeline fails in containers stage,
https://gitlab.freedesktop.org/vigneshraman/igt-gpu-tools/-/pipelines/1030263

Is there a way to run the pipeline in my fork or should I locally build docs (build igt-gpu-tools-doc) with the patch and check the issue?

I can reproduce the error with,
scripts/igt_doc.py --config tests/intel/kms_test_config.json --rest docs/testplan/kms_tests.rst --check-testlist --igt-build-path build/

I will check these warnings.

Regards,
Vignesh