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

EnvironmentTest crashes when /proc is unavailable #45901

Closed
awilfox opened this issue Dec 18, 2022 · 1 comment · Fixed by #45902
Closed

EnvironmentTest crashes when /proc is unavailable #45901

awilfox opened this issue Dec 18, 2022 · 1 comment · Fixed by #45902

Comments

@awilfox
Copy link
Contributor

awilfox commented Dec 18, 2022

Version

16.15.0, but able to produce with Git head as well

Platform

Linux ember.foxkit.us 5.15.44-mc2-easy #1 SMP Wed Aug 17 20:37:04 UTC 2022 i686 GNU/Linux

Subsystem

env

What steps will reproduce the bug?

  1. Ensure /proc/self/exe does not exist.
  2. Run cctest / make test-only on a Linux host.

How often does it reproduce? Is there a required condition?

Always reproducible when /proc is not mounted (i.e. in a container) or when /proc/self/exe does not exist.

What is the expected behavior?

Test passing.

What do you see instead?

Core was generated by `out/Release/cctest --gtest_filter=*'.
Program terminated with signal SIGSEGV, Segmentation fault.
#0  0xf7524644 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /usr/lib/libstdc++.so.6
[Current thread is 1 (LWP 4574)]
(gdb) bt
#0  0xf7524644 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::_M_assign(std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> > const&) () from /usr/lib/libstdc++.so.6
#1  0x56da0c64 in std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::assign (__str=..., 
    this=0xf2d7d424) at /usr/include/c++/8.5.0/bits/basic_string.h:1370
#2  std::__cxx11::basic_string<char, std::char_traits<char>, std::allocator<char> >::operator= (__str=..., this=0xf2d7d424)
    at /usr/include/c++/8.5.0/bits/basic_string.h:699
#3  node::GetExecPath (argv=...) at ../../src/env.cc:313
#4  0x56dab741 in node::Environment::Environment (this=<optimized out>, isolate_data=<optimized out>, isolate=<optimized out>, 
    args=..., exec_args=..., env_info=<optimized out>, flags=<optimized out>, thread_id=...) at ../../src/env.cc:359
#5  0x56dad8ac in node::Environment::Environment (this=0xf2d7d020, isolate_data=0xf569e9c0, context=..., args=..., 
    exec_args=..., env_info=0x0, flags=node::EnvironmentFlags::kDefaultFlags, thread_id=...) at ../../src/env.cc:436
#6  0x56d5e2da in node::CreateEnvironment (isolate_data=isolate_data@entry=0xf569e9c0, context=context@entry=..., args=..., 
    exec_args=..., flags=node::EnvironmentFlags::kDefaultFlags, thread_id=..., inspector_parent_handle=...)
    at ../../src/api/environment.cc:345
#7  0x56d101b9 in EnvironmentTest_NestedMicrotaskQueue_Test::TestBody (this=0xf2e8a370)
    at ../../test/cctest/test_environment.cc:677

This is because argv is accessed in node::GetExecPath without checking the length first.

Additional information

I'm not sure if Node tests are meant to pass without /proc mounted on Linux systems, but it seems good to avoid a nullptr dereference when possible.

@cjihrig
Copy link
Contributor

cjihrig commented Dec 18, 2022

I'm not sure if Node tests are meant to pass without /proc mounted on Linux systems, but it seems good to avoid a nullptr dereference when possible.

We should fix this if possible. Would you like to send a patch?

awilfox added a commit to awilfox/node that referenced this issue Dec 18, 2022
If we are in an artifically created Environment that has no args set,
and uv_exepath returns an error (for instance, if /proc is not mounted
on a Linux system), then we crash with a nullptr deref attempting to
use argv[0].

Fixes: nodejs#45901
awilfox added a commit to awilfox/node that referenced this issue Dec 18, 2022
If we are in an artifically created Environment that has no args set,
and uv_exepath returns an error (for instance, if /proc is not mounted
on a Linux system), then we crash with a nullptr deref attempting to
use argv[0].

Fixes: nodejs#45901
nodejs-github-bot pushed a commit that referenced this issue Dec 20, 2022
If we are in an artifically created Environment that has no args set,
and uv_exepath returns an error (for instance, if /proc is not mounted
on a Linux system), then we crash with a nullptr deref attempting to
use argv[0].

Fixes: #45901
PR-URL: #45902
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
targos pushed a commit that referenced this issue Jan 1, 2023
If we are in an artifically created Environment that has no args set,
and uv_exepath returns an error (for instance, if /proc is not mounted
on a Linux system), then we crash with a nullptr deref attempting to
use argv[0].

Fixes: #45901
PR-URL: #45902
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
RafaelGSS pushed a commit that referenced this issue Jan 4, 2023
If we are in an artifically created Environment that has no args set,
and uv_exepath returns an error (for instance, if /proc is not mounted
on a Linux system), then we crash with a nullptr deref attempting to
use argv[0].

Fixes: #45901
PR-URL: #45902
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
RafaelGSS pushed a commit that referenced this issue Jan 5, 2023
If we are in an artifically created Environment that has no args set,
and uv_exepath returns an error (for instance, if /proc is not mounted
on a Linux system), then we crash with a nullptr deref attempting to
use argv[0].

Fixes: #45901
PR-URL: #45902
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
juanarbol pushed a commit that referenced this issue Jan 26, 2023
If we are in an artifically created Environment that has no args set,
and uv_exepath returns an error (for instance, if /proc is not mounted
on a Linux system), then we crash with a nullptr deref attempting to
use argv[0].

Fixes: #45901
PR-URL: #45902
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
juanarbol pushed a commit that referenced this issue Jan 31, 2023
If we are in an artifically created Environment that has no args set,
and uv_exepath returns an error (for instance, if /proc is not mounted
on a Linux system), then we crash with a nullptr deref attempting to
use argv[0].

Fixes: #45901
PR-URL: #45902
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
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.

2 participants