Skip to content

Conversation

@tmplt
Copy link

@tmplt tmplt commented May 5, 2025

This patch was written before I noticed the legal notice: feel free to discard (but please do apply explicit O_CREAT params to the client remoting code; it would simplify the packaging effort for NixOS: NixOS/nixpkgs#397658).

Note: I have not tested the remoting functionality with this patch, only that it builds.

Cheers.


This fixes the compilation error below, which is triggered in hardened build environments (e.g. NixOS):

   > In file included from /nix/store/aaaaaaaa-glibc-2.40-66-dev/include/fcntl.h:341,
   >                  from /build/source/native/remoting/client_tcp.cpp:12:
   > In function ‘int open(const char*, int, ...)’,
   >     inlined from ‘void* fmi2Instantiate(fmi2String, fmi2Type, fmi2String, fmi2String, const fmi2CallbackFunctions*, fmi2Boolean, fmi2Boolean)’ at /build/source/native/remoting/client_tcp.cpp:217:28:
   > /nix/store/aaaaaaaa-glibc-2.40-66-dev/include/bits/fcntl2.h:52:31: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT or O_TMPFILE in second argument needs 3 arguments
   >    52 |           __open_missing_mode ();
   >       |           ~~~~~~~~~~~~~~~~~~~~^~

In short: O_CREAT without explicit mode params may generate a file with suid/sgid. Error triggered by _FORTIFY_SOURCE. This commit explicitly creates the file with read/write permissions for the file owner.

Adopted from facebook/hhvm#168

For legal reasons we're currently not accepting pull requests.

Please create an issue if you have suggestions for improvements.

This fixes the compilation error below, which is triggered in hardened
build environments (e.g. NixOS):

       > In file included from /nix/store/aaaaaaaa-glibc-2.40-66-dev/include/fcntl.h:341,
       >                  from /build/source/native/remoting/client_tcp.cpp:12:
       > In function ‘int open(const char*, int, ...)’,
       >     inlined from ‘void* fmi2Instantiate(fmi2String, fmi2Type, fmi2String, fmi2String, const fmi2CallbackFunctions*, fmi2Boolean, fmi2Boolean)’ at /build/source/native/remoting/client_tcp.cpp:217:28:
       > /nix/store/aaaaaaaa-glibc-2.40-66-dev/include/bits/fcntl2.h:52:31: error: call to ‘__open_missing_mode’ declared with attribute error: open with O_CREAT or O_TMPFILE in second argument needs 3 arguments
       >    52 |           __open_missing_mode ();
       >       |           ~~~~~~~~~~~~~~~~~~~~^~

In short: O_CREAT without explicit mode params may generate a file
with suid/sgid. Error triggered by _FORTIFY_SOURCE. This commit
explicitly creates the file with read/write permissions for the file
owner.

Adopted from facebook/hhvm#168
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant