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

Allow debugging of native addons on macOS #34340

Closed
ggreco opened this issue Jul 13, 2020 · 4 comments
Closed

Allow debugging of native addons on macOS #34340

ggreco opened this issue Jul 13, 2020 · 4 comments
Labels
macos Issues and PRs related to the macOS platform / OSX.

Comments

@ggreco
Copy link
Contributor

ggreco commented Jul 13, 2020

  • Version: v12.18 v14.5
  • Platform: macOS Catalina ( Darwin iMac-2.local 19.5.0 Darwin Kernel Version 19.5.0 )
  • Subsystem: main

What steps will reproduce the bug?

  • Open a terminal window

  • launch LLDB (the clang debugger) with the node executable (the official 14.3 and 12.x versions have the same problem

    lldb /usr/local/bin/node
    run -v

  • the result is:

    error: process exited with status -1 (Error 1)

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

It's 100% reproductable on catalina if the SIP (system integrity protection) is active.

What is the expected behavior?

The node binary should dump the version and quit, ie:

(lldb) r -v
Process 21451 launched: '/usr/local/bin/node' (x86_64)
v12.18.2
Process 21451 exited with status = 0 (0x00000000) 
(lldb)

What do you see instead?

The node binary cannot be debugged:

(lldb) r -v
error: process exited with status -1 (Error 1)
(lldb)

Additional information

The node binary miss the DEBUG entitlement, com.apple.security.get-task-allow , so lldb cannot attach to it nor launch it in debug mode.

The following command show the list of entitlements in the binary signature.

  codesign -d --entitlements :- /usr/local/bin/node

Here is the output of the command (in the pkg archive, or in the tar.gz, both for 12.x and 14.x):

Executable=/usr/local/bin/node
  <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.cs.allow-jit</key>
    <true/>
    <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
    <true/>
    <key>com.apple.security.cs.disable-executable-page-protection</key>
    <true/>
    <key>com.apple.security.cs.allow-dyld-environment-variables</key>
    <true/>
    <key>com.apple.security.cs.disable-library-validation</key>
    <true/>
</dict>
</plist>

Without debugging entitlements it's not possible to debug native modules with the official node binaries from nodejs.org. Entitlements can be added only when signing the binary.

Workarounds

  • Disable "hardened runtime" system-wide on osx (not suggested)

  • Use a self-built node executable (not suggested)

  • REPLACE node signature with your own (suggested):

    codesign --entitlements entitlements.txt -f -s "Developer ID Application: XXXXXXXX" /usr/local/bin/node
    

    Here is the contents of an entitlements.txt with the missing entitlement added:

  <?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
    <key>com.apple.security.cs.allow-jit</key>
    <true/>
    <key>com.apple.security.cs.allow-unsigned-executable-memory</key>
    <true/>
    <key>com.apple.security.cs.disable-executable-page-protection</key>
    <true/>
    <key>com.apple.security.cs.allow-dyld-environment-variables</key>
    <true/>
    <key>com.apple.security.cs.disable-library-validation</key>
    <true/>
    <key>com.apple.security.get-task-allow</key>
    <true/>
</dict>
</plist>
@addaleax addaleax added the macos Issues and PRs related to the macOS platform / OSX. label Jul 13, 2020
@addaleax
Copy link
Member

@nodejs/platform-macos

@richardlau
Copy link
Member

@ggreco If you want to open a pull request, the entitlements used by our build process are in https://github.com/nodejs/node/blob/master/tools/osx-entitlements.plist.

@devsnek
Copy link
Member

devsnek commented Jul 13, 2020

see also nodejs/help#2817

ggreco added a commit to ggreco/node that referenced this issue Jul 15, 2020
To debug native modules node should be a debuggable process, that will require the **com.apple.security.get-task-allow** entitlement.

This will solve the issue:

nodejs#34340
ggreco added a commit to ggreco/node that referenced this issue Jul 15, 2020
To debug native modules node should be a debuggable process, that will require the **com.apple.security.get-task-allow** entitlement to be added to the codesign procedure.

Fixes: nodejs#34340

nodejs#34340
@ggreco
Copy link
Contributor Author

ggreco commented Jul 15, 2020

I created a pull request to fix this issue:

#34378

@lpinca lpinca closed this as completed in b0e4970 Aug 10, 2020
MylesBorins pushed a commit that referenced this issue Aug 17, 2020
To debug native modules node should be a debuggable process, that will
require the **com.apple.security.get-task-allow** entitlement to be
added to the codesign procedure.

PR-URL: #34378
Fixes: #34340
Reviewed-By: Rod Vagg <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
BethGriggs pushed a commit that referenced this issue Aug 20, 2020
To debug native modules node should be a debuggable process, that will
require the **com.apple.security.get-task-allow** entitlement to be
added to the codesign procedure.

PR-URL: #34378
Fixes: #34340
Reviewed-By: Rod Vagg <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
addaleax pushed a commit that referenced this issue Sep 22, 2020
To debug native modules node should be a debuggable process, that will
require the **com.apple.security.get-task-allow** entitlement to be
added to the codesign procedure.

PR-URL: #34378
Fixes: #34340
Reviewed-By: Rod Vagg <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
addaleax pushed a commit that referenced this issue Sep 22, 2020
To debug native modules node should be a debuggable process, that will
require the **com.apple.security.get-task-allow** entitlement to be
added to the codesign procedure.

PR-URL: #34378
Fixes: #34340
Reviewed-By: Rod Vagg <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
richardlau pushed a commit that referenced this issue Oct 7, 2020
To debug native modules node should be a debuggable process, that will
require the **com.apple.security.get-task-allow** entitlement to be
added to the codesign procedure.

PR-URL: #34378
Fixes: #34340
Reviewed-By: Rod Vagg <[email protected]>
Reviewed-By: Michael Dawson <[email protected]>
Reviewed-By: Evan Lucas <[email protected]>
Reviewed-By: Matteo Collina <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
macos Issues and PRs related to the macOS platform / OSX.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants