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

gcc-14: map_shadow_stack incorrect syscall number #263

Open
anarthal opened this issue Jul 8, 2024 · 3 comments · May be fixed by #270
Open

gcc-14: map_shadow_stack incorrect syscall number #263

anarthal opened this issue Jul 8, 2024 · 3 comments · May be fixed by #270

Comments

@anarthal
Copy link

anarthal commented Jul 8, 2024

System: Ubuntu 24.04 (as per the ubuntu:24.04 Docker image)
Compiler: g++-14 (as per apt install g++-14 in the aforementioned image)
uname -a: Linux 2b064e2a8785 6.5.0-41-generic #41~22.04.2-Ubuntu SMP PREEMPT_DYNAMIC Mon Jun 3 11:32:55 UTC 2 x86_64 x86_64 x86_64 GNU/Linux
glibc version: 2.39
Variant: release
Library version: Boost develop branch

I'm getting a warning about a redefinition of __NR_map_shadow_stack. It's not causing any issues, in part because I'm only indirectly including the file (via Asio's spawn.hpp). It looks like <boost/context/fiber.hpp> is defining __NR_map_shadow_stack to 451, but the actual syscall number seems to be 453. This only happens in C++23, where <memory> includes all the syscall numbers.

For me it's just an annoying warning, but it seems it may point to a real bug. I don't know enough to provide further diagnostics.

Please note that this doesn't happen in the Godbolt environment, which uses an older glibc version. The ubuntu 24.04 gcc-14 seems to have __CET__ defined by default.

Repro instructions:

$> cd $BOOST_ROOT
$> cat libs/mysql/repro/Jamfile
exe repro :
    repro.cpp
    /boost/context//boost_context ;

$> cat libs/mysql/repro/repro.cpp
#include <boost/context/fiber.hpp>

int main() {}

$> ./b2 toolset=gcc-14 cxxstd=23 libs/mysql/repro warnings-as-errors=on
Performing configuration checks

    - default address-model    : 64-bit (cached) [1]
    - default architecture     : x86 (cached) [1]
    - symlinks supported       : yes (cached)

[1] gcc-14
...patience...
...found 639 targets...
...updating 9 targets...
gcc.compile.c++ bin.v2/libs/mysql/repro/gcc-14/debug/x86_64/cxxstd-23-iso/threading-multi/visibility-hidden/repro.o
In file included from ./boost/context/fiber.hpp:12,
                 from libs/mysql/repro/repro.cpp:1:
./boost/context/fiber_fcontext.hpp:52:11: error: "__NR_map_shadow_stack" redefined [-Werror]
   52 | #  define __NR_map_shadow_stack 451
      |           ^~~~~~~~~~~~~~~~~~~~~
In file included from /usr/include/x86_64-linux-gnu/asm/unistd.h:20,
                 from /usr/include/x86_64-linux-gnu/sys/syscall.h:24,
                 from /usr/include/syscall.h:1,
                 from /usr/include/c++/14/bits/atomic_wait.h:47,
                 from /usr/include/c++/14/bits/atomic_base.h:42,
                 from /usr/include/c++/14/bits/shared_ptr_atomic.h:33,
                 from /usr/include/c++/14/memory:81,
                 from ./boost/context/fiber_fcontext.hpp:18:
/usr/include/x86_64-linux-gnu/asm/unistd_64.h:368:9: note: this is the location of the previous definition
  368 | #define __NR_map_shadow_stack 453
      |         ^~~~~~~~~~~~~~~~~~~~~
cc1plus: all warnings being treated as errors

    "g++"   -std=c++23 -fvisibility-inlines-hidden -fPIC -m64 -pthread -O0 -fno-inline -Wall -Werror -g -fvisibility=hidden  -DBOOST_ALL_NO_LIB=1 -DBOOST_CONTEXT_DYN_LINK=1   -I"."  -c -o "bin.v2/libs/mysql/repro/gcc-14/debug/x86_64/cxxstd-23-iso/threading-multi/visibility-hidden/repro.o" "libs/mysql/repro/repro.cpp"

...failed gcc.compile.c++ bin.v2/libs/mysql/repro/gcc-14/debug/x86_64/cxxstd-23-iso/threading-multi/visibility-hidden/repro.o...
...skipped <pbin.v2/libs/mysql/repro/gcc-14/debug/x86_64/cxxstd-23-iso/threading-multi/visibility-hidden>repro for lack of <pbin.v2/libs/mysql/repro/gcc-14/debug/x86_64/cxxstd-23-iso/threading-multi/visibility-hidden>repro.o...

...updated 7 targets...

...skipped 1 target...
   <pbin.v2/libs/mysql/repro/gcc-14/debug/x86_64/cxxstd-23-iso/threading-multi/visibility-hidden>repro

...failed updating 1 target...
   gcc.compile.c++ bin.v2/libs/mysql/repro/gcc-14/debug/x86_64/cxxstd-23-iso/threading-multi/visibility-hidden/repro.o
@olk
Copy link
Member

olk commented Aug 28, 2024

Might be fixed by PR 259 (#259). Could you test it?

@arnaud-lb
Copy link
Contributor

This is a separate issue.

The syscall number appears to have changed since the implementation of shadow stacks in boost/context.

The impact is that boost/context will fail to setup a shadow stack when SHSTK is enabled (which is unlikely currently), and will crash.

In https://github.com/php/php-src/pull/14027/files we define SYS_map_shadow_stack to 453, and only when it's not already defined.

@anarthal
Copy link
Author

anarthal commented Sep 1, 2024

Confirming that this still happens, and having read the source, I agree with @arnaud-lb on the diagnostics. I don't know the specifics on gcc-14 and why I'm encountering this without setting any flags, but this looks like a problem.

Lastique added a commit to Lastique/context that referenced this issue Sep 12, 2024
__NR_map_shadow_stack is defined to 453 (not 451) on Ubuntu 24.04 with
Linux kernel 6.8.0-44, gcc 13.2.0 and glibc 2.39. This causes warnings
about macro redefinition when Boost.Fiber is compiled.

Change the syscall number to 453 and only define the macro if it has
not been defined already. Also include unistd.h for syscall() and
__NR_* constants.

Fixes boostorg#263.
Fixes boostorg#269.
@Lastique Lastique linked a pull request Sep 12, 2024 that will close this issue
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 a pull request may close this issue.

3 participants