Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Buffer Overflow security vulnerability in ParModelica #4787

Closed
OpenModelica-TracImporter opened this issue Jun 27, 2020 · 5 comments · Fixed by #8367
Closed

Buffer Overflow security vulnerability in ParModelica #4787

OpenModelica-TracImporter opened this issue Jun 27, 2020 · 5 comments · Fixed by #8367
Assignees

Comments

@OpenModelica-TracImporter
Copy link
Member

No description provided.

@ijknabla
Copy link

Hi everyone!

In our organization, OpenModelica cannot be used because the following vulnerabilities exist in OpenModelica.

https://nvd.nist.gov/vuln/detail/CVE-2019-1010038

Is there any chance that this vulnerability will be fixed?

If not, I'd like to try to fix it, but are there any consideration?

@ijknabla
Copy link

The vulnerability is that the value of the environment variable OPENMODELICAHOME
is included in the data to be written to the fixed length (100 bytes) buffer.

A malicious user could give a long(>=100 bytes) environment variable that would cause a buffer overflow.

This issue imported from https://trac.openmodelica.org/OpenModelica/ticket/4787
@sjoelund mentioned in the above ticket:

This should naturally be fixed as soon as possible, but the impact is very low since ParModelica is rarely used.

I've confirmed that the pointed implementation still exists in the latest code.

// Build the program (OpenCL JIT compilation)
char options[100];
const char* flags = "-g -w -I\"";
const char* OMHOME = getenv("OPENMODELICAHOME");
const char* OMINCL = "/include/omc\"";
const char* OMBIN = "/bin\"";
if ( OMHOME != NULL )
{
strcpy(options, flags);
strcat(options, OMHOME);

However, in the latest code, CMakeLists.txt to build this vulnerable target is not referenced from the CMakeLists.txt in the parent directory.
# omc_add_subdirectory(ParModelica)

@ijknabla
Copy link

When I checked the build settings for the OpenModelica/OMCompiler/SimulationRuntime/ParModelica/explicit/openclrt/ itself, the referenced source was ocl_offcomp.cpp, not ocl_offcomp.c.

SET(PARMODELICA_OffCompiler_SRC ocl_offcomp.cpp)
INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR})
INCLUDE_DIRECTORIES(../../../c)
ADD_LIBRARY(ParModelicaExpl ${PARMODELICA_SRC})
ADD_EXECUTABLE(ParModelicaOCLOffCompiler ${PARMODELICA_OffCompiler_SRC})

ocloffc: omc_ocl_util.h libParModelicaExpl.a
$(CXX) -I. -o ocloffcomp$(EXEEXT) ocl_offcomp.cpp libParModelicaExpl.a $(OPENLC_LIB) $(CFLAGS)


Going back further in time, I found the following commit in the archived OpenModelica/OMCompiler repository when it was a submodule.

OpenModelica/OMCompiler@d8285af#diff-242370b48b4920f97b1e9430ae1d36a35cbd446915a89cc06b20eb334ef1154fR17

- $(CXX) -I. -o ocloffcomp$(EXEEXT) ocl_offcomp.c libOMOCLRuntime.a $(OPENLC_LIB) $(CFLAGS)
+ $(CXX) -I. -o ocloffcomp$(EXEEXT) ocl_offcomp.cpp libParModelicaExpl.a $(OPENLC_LIB) $(CFLAGS)

The commit time is 2015-09-11T19:39:08+02:00

Therefore, OpenModelica built after 2015-09-11T19:39:08+02:00 does not include this vulnerability.
Dear @mahge is this correct?

May I ask the maintainer for the following two things?

  • Remove uncompiled code containing vulnerabilities (s.t. ocl_offcomp.c) from future releases
  • Provide NIST with a list of versions that do not actually contain the vulnerabilities and have the database modified.

mahge added a commit to mahge/OpenModelica that referenced this issue Dec 28, 2021
  - Closes OpenModelica#4787.

  - This file is not used anymore since its target is never built.

  - It has a buffer overflow vulnerability due to usage of an env
    variable that is appended to a static buffer array.

  - It was an experiment at having an "offline" compiler for OpenCL code.
    It was used to compile OpenCL code ahead of time and save some time
    by avoiding JIT (runtime) compilation.
@mahge
Copy link
Contributor

mahge commented Dec 28, 2021

@ijknabla Thank you for tracking down and analyzing the issue.

As you said the code was not actually used or even built. So it has been removed in #8367. This should resolve the vulnerably. Please let us know if there is anything more that prevents you from using OpenModelica in your organization.

mahge added a commit that referenced this issue Dec 28, 2021
  - Closes #4787.

  - This file is not used anymore since its target is never built.

  - It has a buffer overflow vulnerability due to usage of an env
    variable that is appended to a static buffer array.

  - It was an experiment at having an "offline" compiler for OpenCL code.
    It was used to compile OpenCL code ahead of time and save some time
    by avoiding JIT (runtime) compilation.
@ijknabla
Copy link

ijknabla commented Dec 29, 2021

@mahge

anything more that prevents you from using OpenModelica in your organization.

I confirmed that the NIST page already had a list of versions.
I would like to report this list and this response to the leaders.

Thank you very much.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants