From c9f3f962f560ea00c1058fa12c80023be63a79ba Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Fri, 20 Jan 2023 16:08:13 -0300 Subject: [PATCH 01/10] build,tools: add test-ubsan ci Signed-off-by: RafaelGSS Co-Authored-By: Santiago Gimeno --- .github/workflows/test-ubsan.yml | 61 ++++++++++++++++++++++ common.gypi | 24 +++++++++ configure.py | 7 +++ src/spawn_sync.cc | 2 +- suppressions.supp | 6 +++ test/parallel/test-node-output-console.mjs | 6 ++- 6 files changed, 104 insertions(+), 2 deletions(-) create mode 100644 .github/workflows/test-ubsan.yml create mode 100644 suppressions.supp diff --git a/.github/workflows/test-ubsan.yml b/.github/workflows/test-ubsan.yml new file mode 100644 index 00000000000000..fe97f2bd5c9233 --- /dev/null +++ b/.github/workflows/test-ubsan.yml @@ -0,0 +1,61 @@ +name: Test UBSan + +on: + pull_request: + types: [opened, synchronize, reopened, ready_for_review] + paths-ignore: + - .mailmap + - '**.md' + - AUTHORS + - doc/** + - .github/** + - '!.github/workflows/ubsan-asan.yml' + push: + branches: + - main + - canary + - v[0-9]+.x-staging + - v[0-9]+.x + paths-ignore: + - .mailmap + - '**.md' + - AUTHORS + - doc/** + - .github/** + - '!.github/workflows/ubsan-asan.yml' + +concurrency: + group: ${{ github.workflow }}-${{ github.head_ref || github.run_id }} + cancel-in-progress: true + +env: + PYTHON_VERSION: '3.11' + FLAKY_TESTS: keep_retrying + +permissions: + contents: read + +jobs: + test-ubsan: + if: github.event.pull_request.draft == false + runs-on: ubuntu-20.04 + env: + CC: gcc + CXX: g++ + LINK: g++ + CONFIG_FLAGS: --enable-ubsan + UBSAN_OPTIONS: suppressions=../../suppressions.supp:print_stacktrace=1 + steps: + - uses: actions/checkout@v3 + with: + persist-credentials: false + - name: Set up Python ${{ env.PYTHON_VERSION }} + uses: actions/setup-python@v4 + with: + python-version: ${{ env.PYTHON_VERSION }} + - name: Environment Information + run: npx envinfo + - name: Build + run: make build-ci -j2 V=1 + - name: Test + run: make run-ci -j2 V=1 TEST_CI_ARGS="-p actions -t 300 --measure-flakiness 9" diff --git a/common.gypi b/common.gypi index 876b0f14566b5d..def792f4062271 100644 --- a/common.gypi +++ b/common.gypi @@ -2,6 +2,7 @@ 'variables': { 'configuring_node%': 0, 'asan%': 0, + 'ubsan%': 0, 'werror': '', # Turn off -Werror in V8 build. 'visibility%': 'hidden', # V8's visibility setting 'target_arch%': 'ia32', # set v8's target architecture @@ -374,6 +375,29 @@ }], ], }], + ['ubsan == 1 and OS != "mac" and OS != "zos"', { + 'cflags+': [ + '-fno-omit-frame-pointer', + '-fsanitize=undefined', + ], + 'defines': [ 'UNDEFINED_SANITIZER'], + 'cflags!': [ '-fno-omit-frame-pointer' ], + 'ldflags': [ '-fsanitize=undefined' ], + }], + ['ubsan == 1 and OS == "mac"', { + 'xcode_settings': { + 'OTHER_CFLAGS+': [ + '-fno-omit-frame-pointer', + '-fsanitize=undefined', + '-DUNDEFINED_SANITIZER' + ], + }, + 'target_conditions': [ + ['_type!="static_library"', { + 'xcode_settings': {'OTHER_LDFLAGS': ['-fsanitize=undefined']}, + }], + ], + }], # The defines bellow must include all things from the external_v8_defines # list in v8/BUILD.gn. ['v8_enable_v8_checks == 1', { diff --git a/configure.py b/configure.py index be49cd5cd20cd5..1d7c095d03dbc2 100755 --- a/configure.py +++ b/configure.py @@ -725,6 +725,12 @@ default=None, help='compile for Address Sanitizer to find memory bugs') +parser.add_argument('--enable-ubsan', + action='store_true', + dest='enable_ubsan', + default=None, + help='compile for Undefined Behavior Sanitizer') + parser.add_argument('--enable-static', action='store_true', dest='enable_static', @@ -1440,6 +1446,7 @@ def configure_node(o): o['variables']['linked_module_files'] = options.linked_module o['variables']['asan'] = int(options.enable_asan or 0) + o['variables']['ubsan'] = int(options.enable_ubsan or 0) if options.coverage: o['variables']['coverage'] = 'true' diff --git a/src/spawn_sync.cc b/src/spawn_sync.cc index 3b73dc4a614b9a..0d5235274fb73f 100644 --- a/src/spawn_sync.cc +++ b/src/spawn_sync.cc @@ -68,7 +68,7 @@ void SyncProcessOutputBuffer::OnRead(const uv_buf_t* buf, size_t nread) { size_t SyncProcessOutputBuffer::Copy(char* dest) const { - memcpy(dest, data_, used()); + if (dest != nullptr) memcpy(dest, data_, used()); return used(); } diff --git a/suppressions.supp b/suppressions.supp new file mode 100644 index 00000000000000..9dc89fb83df5b4 --- /dev/null +++ b/suppressions.supp @@ -0,0 +1,6 @@ +vptr:deps/icu-small/source/common/uloc_tag.cpp +vptr:deps/icu-small/source/common/unistr.cpp +shift-base:deps/v8/src/wasm/decoder.h +vptr:deps/icu-small/source/common/sharedobject.cpp +vptr:deps/icu-small/source/i18n/coll.cpp +nonnull-attribute:deps/v8/src/snapshot/snapshot-source-sink.h diff --git a/test/parallel/test-node-output-console.mjs b/test/parallel/test-node-output-console.mjs index 5a1b9feb6c8bed..f995c170540ffa 100644 --- a/test/parallel/test-node-output-console.mjs +++ b/test/parallel/test-node-output-console.mjs @@ -31,7 +31,11 @@ describe('console output', { concurrency: true }, () => { .transform(snapshot.replaceWindowsLineEndings, snapshot.replaceWindowsPaths, replaceStackTrace); for (const { name, transform, env } of tests) { it(name, async () => { - await snapshot.spawnAndAssert(fixtures.path(name), transform ?? defaultTransform, { env }); + await snapshot.spawnAndAssert( + fixtures.path(name), + transform ?? defaultTransform, + { env: { ...env, ...process.env } }, + ); }); } }); From 682e426dbd9c1fdcb0e72fc51c119f6d80c80fc0 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Wed, 28 Feb 2024 11:09:55 -0300 Subject: [PATCH 02/10] fixup! attempt to use absolute suppressions path --- .github/workflows/test-ubsan.yml | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/.github/workflows/test-ubsan.yml b/.github/workflows/test-ubsan.yml index fe97f2bd5c9233..acdc15b59a82b7 100644 --- a/.github/workflows/test-ubsan.yml +++ b/.github/workflows/test-ubsan.yml @@ -44,11 +44,13 @@ jobs: CXX: g++ LINK: g++ CONFIG_FLAGS: --enable-ubsan - UBSAN_OPTIONS: suppressions=../../suppressions.supp:print_stacktrace=1 steps: - uses: actions/checkout@v3 with: persist-credentials: false + - name: Store suppressions path + run: | + echo "::set-env name=UBSAN_OPTIONS=$GITHUB_WORKSPACE/suppressions.supp:print_stacktrace=1" - name: Set up Python ${{ env.PYTHON_VERSION }} uses: actions/setup-python@v4 with: From fc20e84db8190e904e47a9d0e0bed125d8db46dc Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Wed, 28 Feb 2024 15:31:05 -0300 Subject: [PATCH 03/10] fixup! fixup! attempt to use absolute suppressions path --- suppressions.supp | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/suppressions.supp b/suppressions.supp index 9dc89fb83df5b4..a84ab83271a5f3 100644 --- a/suppressions.supp +++ b/suppressions.supp @@ -1,6 +1,3 @@ -vptr:deps/icu-small/source/common/uloc_tag.cpp -vptr:deps/icu-small/source/common/unistr.cpp +vptr:deps/icu-small/* shift-base:deps/v8/src/wasm/decoder.h -vptr:deps/icu-small/source/common/sharedobject.cpp -vptr:deps/icu-small/source/i18n/coll.cpp nonnull-attribute:deps/v8/src/snapshot/snapshot-source-sink.h From cf767543ec60be047803d86e4d5d5e2840f1bf10 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Wed, 28 Feb 2024 20:15:09 -0300 Subject: [PATCH 04/10] fixup! attempt to fix suppressions --- suppressions.supp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/suppressions.supp b/suppressions.supp index a84ab83271a5f3..9894b352e643d5 100644 --- a/suppressions.supp +++ b/suppressions.supp @@ -1,3 +1,7 @@ -vptr:deps/icu-small/* +deps/icu-small/* +vptr:deps/icu-small/source/common/uloc_tag.cpp +vptr:deps/icu-small/source/common/unistr.cpp shift-base:deps/v8/src/wasm/decoder.h +vptr:deps/icu-small/source/common/sharedobject.cpp +vptr:deps/icu-small/source/i18n/coll.cpp nonnull-attribute:deps/v8/src/snapshot/snapshot-source-sink.h From 71804c3a24605d78f9da848b1b8768494e3442e7 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Fri, 1 Mar 2024 10:00:41 -0300 Subject: [PATCH 05/10] debug --- .github/workflows/test-ubsan.yml | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/.github/workflows/test-ubsan.yml b/.github/workflows/test-ubsan.yml index acdc15b59a82b7..060d56407c88be 100644 --- a/.github/workflows/test-ubsan.yml +++ b/.github/workflows/test-ubsan.yml @@ -55,9 +55,12 @@ jobs: uses: actions/setup-python@v4 with: python-version: ${{ env.PYTHON_VERSION }} - - name: Environment Information - run: npx envinfo - - name: Build - run: make build-ci -j2 V=1 - - name: Test - run: make run-ci -j2 V=1 TEST_CI_ARGS="-p actions -t 300 --measure-flakiness 9" + - name: Check UBSAN_OPTIONS + run: | + echo $UBSAN_OPTIONS + # - name: Environment Information + # run: npx envinfo + # - name: Build + # run: make build-ci -j2 V=1 + # - name: Test + # run: make run-ci -j2 V=1 TEST_CI_ARGS="-p actions -t 300 --measure-flakiness 9" From c803294a6e92697e243f8eaab461f8eb72a1dc67 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Fri, 1 Mar 2024 10:06:35 -0300 Subject: [PATCH 06/10] fixup! debug --- .github/workflows/test-ubsan.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/test-ubsan.yml b/.github/workflows/test-ubsan.yml index 060d56407c88be..ec7468e2d37e05 100644 --- a/.github/workflows/test-ubsan.yml +++ b/.github/workflows/test-ubsan.yml @@ -50,7 +50,7 @@ jobs: persist-credentials: false - name: Store suppressions path run: | - echo "::set-env name=UBSAN_OPTIONS=$GITHUB_WORKSPACE/suppressions.supp:print_stacktrace=1" + echo "UBSAN_OPTIONS=$GITHUB_WORKSPACE/suppressions.supp:print_stacktrace=1" >> $GITHUB_ENV - name: Set up Python ${{ env.PYTHON_VERSION }} uses: actions/setup-python@v4 with: From f989175b800fa21dddfef907f9a7a0f4e218ba6b Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Fri, 1 Mar 2024 10:09:37 -0300 Subject: [PATCH 07/10] workflow: adjust github env for ubsan options --- .github/workflows/test-ubsan.yml | 20 +++++++++----------- suppressions.supp | 1 - 2 files changed, 9 insertions(+), 12 deletions(-) diff --git a/.github/workflows/test-ubsan.yml b/.github/workflows/test-ubsan.yml index ec7468e2d37e05..af34faff4cb5c4 100644 --- a/.github/workflows/test-ubsan.yml +++ b/.github/workflows/test-ubsan.yml @@ -44,23 +44,21 @@ jobs: CXX: g++ LINK: g++ CONFIG_FLAGS: --enable-ubsan + UBSAN_OPTIONS: "$GITHUB_WORKSPACE/suppressions.supp:print_stacktrace=1" steps: - uses: actions/checkout@v3 with: persist-credentials: false - - name: Store suppressions path + - name: Debug run: | - echo "UBSAN_OPTIONS=$GITHUB_WORKSPACE/suppressions.supp:print_stacktrace=1" >> $GITHUB_ENV + echo "$UBSAN_OPTIONS" - name: Set up Python ${{ env.PYTHON_VERSION }} uses: actions/setup-python@v4 with: python-version: ${{ env.PYTHON_VERSION }} - - name: Check UBSAN_OPTIONS - run: | - echo $UBSAN_OPTIONS - # - name: Environment Information - # run: npx envinfo - # - name: Build - # run: make build-ci -j2 V=1 - # - name: Test - # run: make run-ci -j2 V=1 TEST_CI_ARGS="-p actions -t 300 --measure-flakiness 9" + - name: Environment Information + run: npx envinfo + - name: Build + run: make build-ci -j2 V=1 + - name: Test + run: make run-ci -j2 V=1 TEST_CI_ARGS="-p actions -t 300 --measure-flakiness 9" diff --git a/suppressions.supp b/suppressions.supp index 9894b352e643d5..9dc89fb83df5b4 100644 --- a/suppressions.supp +++ b/suppressions.supp @@ -1,4 +1,3 @@ -deps/icu-small/* vptr:deps/icu-small/source/common/uloc_tag.cpp vptr:deps/icu-small/source/common/unistr.cpp shift-base:deps/v8/src/wasm/decoder.h From f4bbe7bf3028215dece3583e523c365741d08b43 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Tue, 5 Mar 2024 15:54:24 -0300 Subject: [PATCH 08/10] fixup! workflow: adjust github env for ubsan options --- .github/workflows/test-ubsan.yml | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/.github/workflows/test-ubsan.yml b/.github/workflows/test-ubsan.yml index af34faff4cb5c4..0af93f17ffdc5f 100644 --- a/.github/workflows/test-ubsan.yml +++ b/.github/workflows/test-ubsan.yml @@ -44,20 +44,22 @@ jobs: CXX: g++ LINK: g++ CONFIG_FLAGS: --enable-ubsan - UBSAN_OPTIONS: "$GITHUB_WORKSPACE/suppressions.supp:print_stacktrace=1" steps: - uses: actions/checkout@v3 with: persist-credentials: false - - name: Debug + - name: Store suppressions path run: | - echo "$UBSAN_OPTIONS" + echo "UBSAN_OPTIONS=$GITHUB_WORKSPACE/suppressions.supp" >> $GITHUB_ENV - name: Set up Python ${{ env.PYTHON_VERSION }} uses: actions/setup-python@v4 with: python-version: ${{ env.PYTHON_VERSION }} - name: Environment Information run: npx envinfo + - name: Debug + run: | + echo "$UBSAN_OPTIONS" - name: Build run: make build-ci -j2 V=1 - name: Test From 6cb690929aa632d0eb77803540574d9061e716f5 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Tue, 12 Mar 2024 17:10:57 -0300 Subject: [PATCH 09/10] fixup! fixup! workflow: adjust github env for ubsan options --- .github/workflows/test-ubsan.yml | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/.github/workflows/test-ubsan.yml b/.github/workflows/test-ubsan.yml index 0af93f17ffdc5f..25f2481720021c 100644 --- a/.github/workflows/test-ubsan.yml +++ b/.github/workflows/test-ubsan.yml @@ -50,16 +50,13 @@ jobs: persist-credentials: false - name: Store suppressions path run: | - echo "UBSAN_OPTIONS=$GITHUB_WORKSPACE/suppressions.supp" >> $GITHUB_ENV + echo "UBSAN_OPTIONS=suppressions=$GITHUB_WORKSPACE/suppressions.supp" >> $GITHUB_ENV - name: Set up Python ${{ env.PYTHON_VERSION }} uses: actions/setup-python@v4 with: python-version: ${{ env.PYTHON_VERSION }} - name: Environment Information run: npx envinfo - - name: Debug - run: | - echo "$UBSAN_OPTIONS" - name: Build run: make build-ci -j2 V=1 - name: Test From 03a8b7f0498587e5537be0a5b048bad28bd65d45 Mon Sep 17 00:00:00 2001 From: RafaelGSS Date: Thu, 14 Mar 2024 10:54:40 -0300 Subject: [PATCH 10/10] test: skip sea tests when ubsan=1 --- test/common/sea.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/test/common/sea.js b/test/common/sea.js index d57c9e4238d867..a700895e455217 100644 --- a/test/common/sea.js +++ b/test/common/sea.js @@ -45,6 +45,10 @@ function skipIfSingleExecutableIsNotSupported() { } } + if (process.config.variables.ubsan) { + common.skip('UndefinedBehavior Sanitizer is not supported'); + } + tmpdir.refresh(); // The SEA tests involve making a copy of the executable and writing some fixtures