-
-
Notifications
You must be signed in to change notification settings - Fork 32.3k
Closed
Labels
fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.processIssues and PRs related to the process subsystem.Issues and PRs related to the process subsystem.workerIssues and PRs related to Worker support.Issues and PRs related to Worker support.
Description
This code is unsafe when worker threads are active:
node/src/node_process_methods.cc
Lines 248 to 249 in 40b559a
old = umask(0); | |
umask(static_cast<mode_t>(old)); |
The umask(0)
call temporarily changes the process-wide umask and races with fs operations from other threads.
Test case:
'use strict';
const { Worker, isMainThread } = require('worker_threads');
const { statSync, writeFileSync, unlinkSync } = require('fs');
function pummel() {
for (let i = 0; i < 1e4; i++) process.umask();
setImmediate(pummel);
}
if (isMainThread) {
process.umask(0o22);
new Worker(__filename);
pummel();
} else {
const file = 'x.txt';
for (;;) {
writeFileSync(file, 'ok', { mode: 0o666 });
const s = statSync(file);
s.mode &= 0o777;
if (0o644 !== s.mode) throw 'unexpected mode: ' + s.mode.toString(8);
unlinkSync(file);
}
}
Fails within a few iterations with unexpected mode: 666
process.umask()
(no arg) is allowed in workers so this test case works both ways.
This bug is potentially a security issue.
addaleax, ExE-Boss and bl-ue
Metadata
Metadata
Assignees
Labels
fsIssues and PRs related to the fs subsystem / file system.Issues and PRs related to the fs subsystem / file system.processIssues and PRs related to the process subsystem.Issues and PRs related to the process subsystem.workerIssues and PRs related to Worker support.Issues and PRs related to Worker support.