[PATCH i-g-t v3] Fix memory access issue due to variable block scope

Peter Senna Tschudin me at petersenna.com
Tue Mar 26 21:39:36 UTC 2024


This patch fixes the tests many-4k-incremental and many-4k-zero from
gem_exec_capture that are currently failing with an invalid file
descriptor error.

tests/intel/gem_exec_capture.c
    many(), userptr(), capture_invisible()
        find_first_available_engine()
            for_each_ctx_engine()
                for_each_ctx_cfg_engine()

find_first_available_engine() expects a struct intel_execution_engine2
*e as parameter. for_each_ctx_cfg_engine() allocates a struct
intel_engine_data ed inside a for loop and then update e to point to an
element of ed.

The problem is that ed has the block scope of the for loop, and trying
to access its content through e after the for loop has ended creates
undefined behavior.

This patch updates e to point to the same content at a different memory
region, to avoid the block scope of ed.

Signed-off-by: Peter Senna Tschudin <me at petersenna.com>
---
 tests/intel/gem_exec_capture.c | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/tests/intel/gem_exec_capture.c b/tests/intel/gem_exec_capture.c
index 57b178f3e..0f78bdc22 100644
--- a/tests/intel/gem_exec_capture.c
+++ b/tests/intel/gem_exec_capture.c
@@ -667,8 +667,9 @@ static bool needs_recoverable_ctx(int fd)
 		for_each_ctx_engine(fd, ctx, e) \
 			for_each_if(gem_class_can_store_dword(fd, e->class)) \
 				break; \
-		igt_assert(e); \
 		saved = configure_hangs(fd, e, ctx->id); \
+		e = &saved.engine; \
+		igt_assert(e); \
 	} while(0)
 
 static void many(int fd, int dir, uint64_t size, unsigned int flags)
-- 
2.44.0



More information about the igt-dev mailing list