nodejs / postject

Easily inject arbitrary read-only resources into executable formats (Mach-O, PE, ELF) and use it at runtime.
Other
177 stars 12 forks source link

RuntimeError: Aborted when injecting into debug build of Node.js on Linux, Windows and macOS #46

Open RaisinTen opened 1 year ago

RaisinTen commented 1 year ago

System info

Linux

$ uname -a
Linux darshan-NUC11PAHi7 5.15.0-47-generic #51-Ubuntu SMP Thu Aug 11 07:51:15 UTC 2022 x86_64 x86_64 x86_64 GNU/Linux

Windows

 uname -a
MINGW64_NT-10.0-22000 DESKTOP-MDFU6BO 3.1.7-340.x86_64 2021-10-12 16:29 UTC x86_64 Msys

macOS

$ uname -a
Darwin Darshans-MacBook-Pro.local 21.6.0 Darwin Kernel Version 21.6.0: Mon Aug 22 20:17:10 PDT 2022; root:xnu-8020.140.49~2/RELEASE_X86_64 x86_64

Versions

Node.js: v16.15.0 (debug build) Postject: Built from https://github.com/postmanlabs/postject/pull/45

Repro

echo "Hello, world!" > file.txt
postject ./node lol ./file.txt

./node is a debug build of Node.js v16.15.0 and it has a size of 1.4G on Linux, 105M on Windows and 76M on Intel macOS.

Error logs

Linux

Aborted()   
/home/darshan/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9
var Module=typeof Module!="undefined"?Module:{}; ... more unreadable code ...

RuntimeError: Aborted(). Build with -sASSERTIONS for more info.
    at abort (/home/darshan/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:7843)
    at _abort (/home/darshan/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:92618)
    at wasm://wasm/00d4368e:wasm-function[114]:0x3da3
    at invoke_ii (/home/darshan/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:113924)
    at wasm://wasm/00d4368e:wasm-function[3887]:0x2afb02
    at invoke_ii (/home/darshan/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:113924)
    at wasm://wasm/00d4368e:wasm-function[2955]:0x1b1552
    at wasm://wasm/00d4368e:wasm-function[2346]:0x135036
    at Object.injectIntoELF (eval at new_ (/home/darshan/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:73676), <anonymous>:11:10)
    at Command.main (/home/darshan/Desktop/git/starship/node_modules/@raisinten/postject/dist/main.js:89:38)

Windows

Aborted()   
C:\Users\admin\Desktop\git\starship\node_modules\@raisinten\postject\dist\postject.js:9
var Module=typeof Module!="undefined"?Module:{}; ... more unreadable code ...

RuntimeError: Aborted(). Build with -sASSERTIONS for more info.
    at abort (C:\Users\admin\Desktop\git\starship\node_modules\@raisinten\postject\dist\postject.js:9:7843)
    at _abort (C:\Users\admin\Desktop\git\starship\node_modules\@raisinten\postject\dist\postject.js:9:92618)
    at wasm://wasm/00d4368e:wasm-function[114]:0x3da3
    at wasm://wasm/00d4368e:wasm-function[419]:0x1b6b1
    at wasm://wasm/00d4368e:wasm-function[1559]:0xc64b4
    at invoke_vii (C:\Users\admin\Desktop\git\starship\node_modules\@raisinten\postject\dist\postject.js:9:113453)
    at wasm://wasm/00d4368e:wasm-function[1010]:0x5a689
    at wasm://wasm/00d4368e:wasm-function[2815]:0x1860f4
    at wasm://wasm/00d4368e:wasm-function[2346]:0x135036
    at Object.injectIntoPE (eval at new_ (C:\Users\admin\Desktop\git\starship\node_modules\@raisinten\postject\dist\postject.js:1:1), <anonymous>:11:10)

macOS

Aborted()   
/home/raisinten/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9
var Module=typeof Module!="undefined"?Module:{}; ... more unreadable code ...

RuntimeError: Aborted(). Build with -sASSERTIONS for more info.
    at abort (/Users/raisinten/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:7918)
    at _abort (/Users/raisinten/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:92964)
    at wasm://wasm/00d4368e:wasm-function[114]:0x3da3
    at invoke_ii (/Users/raisinten/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:114307)
    at wasm://wasm/00d4368e:wasm-function[2643]:0x149f63
    at invoke_iii (/Users/raisinten/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:114155)
    at wasm://wasm/00d4368e:wasm-function[1427]:0x9c6d3
    at invoke_iii (/Users/raisinten/Desktop/git/starship/node_modules/@raisinten/postject/dist/postject.js:9:114155)
    at wasm://wasm/00d4368e:wasm-function[2633]:0x149287
    at wasm://wasm/00d4368e:wasm-function[1507]:0xb624e

after building with -sASSERTIONS. the error looks like this:

Linux

Aborted(native code called abort())
/home/darshan/Desktop/git/postject/dist/postject.js:9
var Module=typeof Module!="undefined"?Module:{};... more unreadable code ...

RuntimeError: Aborted(native code called abort())
    at abort (/home/darshan/Desktop/git/postject/dist/postject.js:9:17627)
    at _abort (/home/darshan/Desktop/git/postject/dist/postject.js:9:111887)
    at <anonymous>:wasm-function[3619]:0x2af151
    at <anonymous>:wasm-function[877]:0x7ab90
    at invoke_iiiii (/home/darshan/Desktop/git/postject/dist/postject.js:9:136355)
    at <anonymous>:wasm-function[1269]:0xd8ca8
    at <anonymous>:wasm-function[532]:0x4c919
    at <anonymous>:wasm-function[554]:0x55102
    at dynCall_iiij (<anonymous>:wasm-function[3917]:0x2befaf)
    at /home/darshan/Desktop/git/postject/dist/postject.js:9:18225

Additional info

It works when I inject data into an official release build of the same version of Node.js which is 72M in size on Linux.

Handcrafted stack trace for Linux -

KCGD commented 4 months ago

Strange, im having a similar issue on node v21.7.3 for linux. I'm using the node-sea platform to generate an executable blob and inject it into the node executable with postject:

yarn run postject [NODE EXECUTABLE PATH] NODE_SEA_BLOB [EXECUTABLE BLOB PATH] --sentinel-fuse NODE_SEA_FUSE_fce680ab2cc467b6e072b8b5df1996b2

I believe this bug has something to do with the size of the blob being injected, as it only occurs for me when large files are packaged in the blob. I ran some tests where I injected different size binary blobs that I generated with dd if=/dev/urandom of=./bin bs=1M count=[Size in MB]. I found that different node platforms have different file size limits regarding what can be injected before crashing. I found these numbers where upper limit is the largest possible blob that can be injected without crashing (+1Mb will cause a crash at this point):

Where x is the size of the blob:
Linux: x < 290 | upper limit = 298Mb
Windows is 493 < x < 494 | upper limit = 493Mb
Darwin is 527 < x < 528 | upper limit = 527Mb

Keep in mind these were all generated on linux. Again if the injected blob is below these specified sizes, no error occurs and the executable works as it should.

Errors:

Linux:

image

Windows:

image

Darwin/Mac:

image

System Info

uname -a:
Linux [my hostname] 6.8.7-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed, 17 Apr 2024 15:20:28 +0000 x86_64 GNU/Linux
free -h:
               total        used        free      shared  buff/cache   available
Mem:            15Gi       5.7Gi       5.4Gi       1.1Gi       5.7Gi       9.7Gi
Swap:          4.0Gi       155Mi       3.8Gi