Skip to content

[Issue]: SIGSEGV during HIP initialization if environ is clearenv-ed #164

Open
@dusan-exostellar

Description

@dusan-exostellar

Problem Description

If environ variable is NULL (e.g. after executing clearenv), SIGSEGV is raised.

The NULL dereference of environ happens in rocclr/utils/flags.cpp:

for (const char** p = const_cast<const char**>(environ); *p != NULL; ++p) {

Operating System

Ubuntu 22.04.5 LTS (Jammy Jellyfish)

CPU

AMD EPYC 9654 96-Core Processor

GPU

AMD Instinct MI300X

ROCm Version

ROCm 6.4.0

ROCm Component

No response

Steps to Reproduce

Reproducing steps:

git clone https://github.com/ROCm/hip-tests.git
cd hip-tests/samples/1_Utils/hipInfo/
git checkout rocm-6.4.0
git rev-parse HEAD
sed -i 's/printCompilerInfo();/clearenv();\n    printCompilerInfo();/' ./hipInfo.cpp
cmake .
make
./hipInfo

Causes:

dusan@SharkMi300X-2:~$ git clone https://github.com/ROCm/hip-tests.git
Cloning into 'hip-tests'...
remote: Enumerating objects: 18488, done.
remote: Counting objects: 100% (3577/3577), done.
remote: Compressing objects: 100% (647/647), done.
remote: Total 18488 (delta 3276), reused 2963 (delta 2928), pack-reused 14911 (from 3)
Receiving objects: 100% (18488/18488), 7.14 MiB | 28.77 MiB/s, done.
Resolving deltas: 100% (13063/13063), done.
dusan@SharkMi300X-2:~$ cd hip-tests/samples/1_Utils/hipInfo/
dusan@SharkMi300X-2:~/hip-tests/samples/1_Utils/hipInfo$ git checkout rocm-6.4.0
Note: switching to 'rocm-6.4.0'.

You are in 'detached HEAD' state. You can look around, make experimental
changes and commit them, and you can discard any commits you make in this
state without impacting any branches by switching back to a branch.

If you want to create a new branch to retain commits you create, you may
do so (now or later) by using -c with the switch command. Example:

  git switch -c <new-branch-name>

Or undo this operation with:

  git switch -

Turn off this advice by setting config variable advice.detachedHead to false

HEAD is now at 3573bde0 SWDEV-489106 - Hip Tests for Linker APIs
dusan@SharkMi300X-2:~/hip-tests/samples/1_Utils/hipInfo$ git rev-parse HEAD
3573bde0c29113ea53c72df986ffdd97763f37ed
dusan@SharkMi300X-2:~/hip-tests/samples/1_Utils/hipInfo$ sed -i 's/printCompilerInfo();/clearenv();\n    printCompilerInfo();/' ./hipInfo.cpp
dusan@SharkMi300X-2:~/hip-tests/samples/1_Utils/hipInfo$ cmake .
-- The C compiler identification is GNU 11.4.0
-- The CXX compiler identification is GNU 11.4.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: /usr/bin/cc - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: /usr/bin/c++ - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD
-- Performing Test CMAKE_HAVE_LIBC_PTHREAD - Success
-- Found Threads: TRUE  
-- Configuring done
-- Generating done
-- Build files have been written to: /home/dusan/hip-tests/samples/1_Utils/hipInfo
dusan@SharkMi300X-2:~/hip-tests/samples/1_Utils/hipInfo$ make
[ 50%] Building CXX object CMakeFiles/hipInfo.dir/hipInfo.cpp.o
[100%] Linking CXX executable hipInfo
[100%] Built target hipInfo
dusan@SharkMi300X-2:~/hip-tests/samples/1_Utils/hipInfo$ ./hipInfo

Segmentation fault (core dumped)

(Optional for Linux users) Output of /opt/rocm/bin/rocminfo --support

No response

Additional Information

I can file a fixing PR, but I would need write access rights.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions