-
-
Notifications
You must be signed in to change notification settings - Fork 31.7k
test: include strace openat test #46150
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
'use strict'; | ||
|
||
const common = require('../common'); | ||
const { spawn, spawnSync } = require('node:child_process'); | ||
const { createInterface } = require('node:readline'); | ||
const assert = require('node:assert'); | ||
|
||
if (!common.hasCrypto) | ||
common.skip('missing crypto'); | ||
if (!common.isLinux) | ||
common.skip('linux only'); | ||
if (common.isAsan) | ||
common.skip('strace does not work well with address sanitizer builds'); | ||
if (spawnSync('strace').error !== undefined) { | ||
common.skip('missing strace'); | ||
} | ||
|
||
{ | ||
const allowedOpenCalls = new Set([ | ||
'/etc/ssl/openssl.cnf', | ||
]); | ||
const strace = spawn('strace', [ | ||
'-f', '-ff', | ||
'-e', 'trace=open,openat', | ||
'-s', '512', | ||
'-D', process.execPath, '-e', 'require("crypto")', | ||
]); | ||
|
||
// stderr is the default for strace | ||
const rl = createInterface({ input: strace.stderr }); | ||
rl.on('line', (line) => { | ||
if (!line.startsWith('open')) { | ||
return; | ||
} | ||
|
||
const file = line.match(/"(.*?)"/)[1]; | ||
// skip .so reading attempt | ||
if (file.match(/.+\.so(\.?)/) !== null) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It might actually not be that bad to assert these as well – if we added a new .so dependency on Linux, we might want to know about that? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. In my case, it's reading the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You could assert just the filename, ignoring the rest of the path, right? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not sure. That CVE mentioned in the PR description is really about it. Reading a file/library from an unexpected path. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Yeah, please don’t consider this a blocking comment. This would test something different, that’s true, but it does seem valuable to test it regardless. |
||
return; | ||
} | ||
// skip /proc/* | ||
if (file.match(/\/proc\/.+/) !== null) { | ||
return; | ||
} | ||
|
||
assert(allowedOpenCalls.delete(file), `${file} is not in the list of allowed openat calls`); | ||
}); | ||
const debugOutput = []; | ||
strace.stderr.setEncoding('utf8'); | ||
strace.stderr.on('data', (chunk) => { | ||
debugOutput.push(chunk.toString()); | ||
}); | ||
strace.on('error', common.mustNotCall()); | ||
strace.on('exit', common.mustCall((code) => { | ||
assert.strictEqual(code, 0, debugOutput); | ||
const missingKeys = Array.from(allowedOpenCalls.keys()); | ||
if (missingKeys.length) { | ||
assert.fail(`The following openat call are missing: ${missingKeys.join(',')}`); | ||
} | ||
})); | ||
} |
Uh oh!
There was an error while loading. Please reload this page.