From 39731363a8e00f110f6557aafd0d31dd7ea75bad Mon Sep 17 00:00:00 2001 From: "Neil R. Spruit" Date: Tue, 17 Dec 2024 08:11:31 -0800 Subject: [PATCH] [L0] Fix use after free with Module build strings - Address Sanitizer HASAN fails with temporary strings even after last use after free patch. This change resolves all use after free of these strings satifsying the address sanitzer checks with HASAN. Signed-off-by: Neil R. Spruit --- source/adapters/level_zero/program.cpp | 6 ++---- source/adapters/level_zero/program.hpp | 2 +- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/source/adapters/level_zero/program.cpp b/source/adapters/level_zero/program.cpp index be8c366d6b..b5a64c3eda 100644 --- a/source/adapters/level_zero/program.cpp +++ b/source/adapters/level_zero/program.cpp @@ -452,11 +452,9 @@ ur_result_t urProgramLinkExp( // Build flags may be different for different devices, so handle them // here. Clear values of the previous device first. BuildFlagPtrs.clear(); - std::vector TemporaryOptionsStrings; for (uint32_t I = 0; I < count; I++) { - TemporaryOptionsStrings.push_back( - phPrograms[I]->getBuildOptions(ZeDevice)); - BuildFlagPtrs.push_back(TemporaryOptionsStrings.back().c_str()); + BuildFlagPtrs.push_back( + phPrograms[I]->getBuildOptions(ZeDevice).c_str()); } ZeExtModuleDesc.pBuildFlags = BuildFlagPtrs.data(); if (count == 1) diff --git a/source/adapters/level_zero/program.hpp b/source/adapters/level_zero/program.hpp index 4fe8c24acd..90b297fa40 100644 --- a/source/adapters/level_zero/program.hpp +++ b/source/adapters/level_zero/program.hpp @@ -169,7 +169,7 @@ struct ur_program_handle_t_ : _ur_object { DeviceDataMap[ZeDevice].BuildFlags += Options; } - std::string getBuildOptions(ze_device_handle_t ZeDevice) { + std::string &getBuildOptions(ze_device_handle_t ZeDevice) { return DeviceDataMap[ZeDevice].BuildFlags; }