[libc-commits] [libc] 701e6f7 - [libc][fix] Fix buffer overrun in initialization of GPU return value

Joseph Huber via libc-commits libc-commits at lists.llvm.org
Sat Sep 2 15:59:36 PDT 2023


Author: Joseph Huber
Date: 2023-09-02T17:59:01-05:00
New Revision: 701e6f7630474b637e0bc45d009bf2ec47f2d3fd

URL: https://github.com/llvm/llvm-project/commit/701e6f7630474b637e0bc45d009bf2ec47f2d3fd
DIFF: https://github.com/llvm/llvm-project/commit/701e6f7630474b637e0bc45d009bf2ec47f2d3fd.diff

LOG: [libc][fix] Fix buffer overrun in initialization of GPU return value

Summary:
The HSA API explicitly states that the size is a count of uint32_t's not
a byte count. This was erroneously being used as a simple memcpy,
causing some weird behaviour. Fix this by correctly passing `1` to
initialize a single integer to zero.

Added: 
    

Modified: 
    libc/utils/gpu/loader/amdgpu/Loader.cpp

Removed: 
    


################################################################################
diff  --git a/libc/utils/gpu/loader/amdgpu/Loader.cpp b/libc/utils/gpu/loader/amdgpu/Loader.cpp
index 2243d1974f77b11..9d732fe987da40a 100644
--- a/libc/utils/gpu/loader/amdgpu/Loader.cpp
+++ b/libc/utils/gpu/loader/amdgpu/Loader.cpp
@@ -397,7 +397,7 @@ int load(int argc, char **argv, char **envp, void *image, size_t size,
           hsa_amd_memory_pool_allocate(coarsegrained_pool, sizeof(int),
                                        /*flags=*/0, &dev_ret))
     handle_error(err);
-  hsa_amd_memory_fill(dev_ret, 0, sizeof(int));
+  hsa_amd_memory_fill(dev_ret, 0, /*count=*/1);
 
   // Allocate finegrained memory for the RPC server and client to share.
   uint32_t wavefront_size = 0;


        


More information about the libc-commits mailing list