Uh oh!
There was an error while loading. Please reload this page.
Free req.file.pathw in fs::ReadFileUtf8(). - #57811
Conversation
nodejs-github-bot
commented
Apr 10, 2025
bc9df87 to
25bb174CompareJustin-Nietzel
commented
Apr 10, 2025
I updated the commit comments after the first CI failure with module names in the title. I think it was mistaking some variable names as modules? I moved the original title into the description. Will that description also get flagged. Is there a safe way to format the variable name without triggering the module name CI check? |
tniessen
left a comment
There was a problem hiding this comment.
@Justin-Nietzel You need to force-push to your branch issue-57800 with an amended commit message. Since req.file.pathw is an implementation detail in an external dependency, I'd suggest a commit message title such as fs: add missing call to uv_fs_req_cleanup or something like that.
Is it safe to also unconditionally call us_fs_req_cleanup(&req) in defer_close? It seems very odd to me that defer_close will always call uv_fs_req_cleanup(&req) while conditionally reusing &req for uv_fs_close. Before #49691, there was a seperate uv_fs_t for the close operation (cc @anonrig).
Always call uv_fs_req_cleanup after calling uv_fs_open instead of just when uv_fs_open returns a negative result. I referenced ReadFileSync from node:js2c when making this change. https://github.com/bnoordhuis made the same suggestion based on the PR nodejs#49691. Fixes: nodejs#57800
Justin-Nietzel
commented
Apr 10, 2025
ReadFileSync in js2c.cc follows a very similar workflow to ReadFileUTF8 when using opening a file by file path. It re-uses the |
25bb174 to
a00fc51CompareCodecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@## main #57811 +/- ##
==========================================
- Coverage 90.23% 90.23% -0.01%
==========================================
Files 630 630 Lines 185465 185471 +6 Branches 36368 36374 +6 ==========================================
- Hits 167362 167353 -9 + Misses 10999 10996 -3 - Partials 7104 7122 +18
🚀 New features to boost your workflow:
|
mcollina
commented
Apr 11, 2025
@Justin-Nietzel do you think you'd be able to add a test that verify the memory leak is fixed? |
nodejs-github-bot
commented
Apr 11, 2025
I probably could add a unit test. I would reference the readFileSync test and this worker thread memory test. I just had a few questions.
|
Added a unit test for testing the memory usage of readFileSync. Test is looking specifically for the the issue caused by failing to free the filepath buffer in fs::ReadFileUtf8(), but it will also catch other significant memory leaks in readFileSync() as well. Refs: nodejs#57800
Justin-Nietzel
commented
Apr 11, 2025
@mcollina I added a unit test for this fix and did my best to follow all the documentation I could find on style and testing. Let me know if you need me to make any adjustments. |
Always call uv_fs_req_cleanup after calling uv_fs_open instead of just when uv_fs_open returns a negative result. I referenced ReadFileSync from node:js2c when making this change. https://github.com/bnoordhuis made the same suggestion based on the PR #49691. Fixes: #57800 PR-URL: #57811 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Added a unit test for testing the memory usage of readFileSync. Test is looking specifically for the the issue caused by failing to free the filepath buffer in fs::ReadFileUtf8(), but it will also catch other significant memory leaks in readFileSync() as well. Refs: #57800 PR-URL: #57811Fixes: #57800 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
jasnell
commented
Apr 12, 2025
Landed in d0a5bd6...09ecd2e |
tniessen
commented
Apr 12, 2025
On a side note for future PRs, the second commit technically does not satisfy our requirements for commit messages since the leading verb is not imperative ( |
Always call uv_fs_req_cleanup after calling uv_fs_open instead of just when uv_fs_open returns a negative result. I referenced ReadFileSync from node:js2c when making this change. https://github.com/bnoordhuis made the same suggestion based on the PR #49691. Fixes: #57800 PR-URL: #57811 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Added a unit test for testing the memory usage of readFileSync. Test is looking specifically for the the issue caused by failing to free the filepath buffer in fs::ReadFileUtf8(), but it will also catch other significant memory leaks in readFileSync() as well. Refs: #57800 PR-URL: #57811Fixes: #57800 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Always call uv_fs_req_cleanup after calling uv_fs_open instead of just when uv_fs_open returns a negative result. I referenced ReadFileSync from node:js2c when making this change. https://github.com/bnoordhuis made the same suggestion based on the PR #49691. Fixes: #57800 PR-URL: #57811 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Added a unit test for testing the memory usage of readFileSync. Test is looking specifically for the the issue caused by failing to free the filepath buffer in fs::ReadFileUtf8(), but it will also catch other significant memory leaks in readFileSync() as well. Refs: #57800 PR-URL: #57811Fixes: #57800 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Always call uv_fs_req_cleanup after calling uv_fs_open instead of just when uv_fs_open returns a negative result. I referenced ReadFileSync from node:js2c when making this change. https://github.com/bnoordhuis made the same suggestion based on the PR #49691. Fixes: #57800 PR-URL: #57811 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Added a unit test for testing the memory usage of readFileSync. Test is looking specifically for the the issue caused by failing to free the filepath buffer in fs::ReadFileUtf8(), but it will also catch other significant memory leaks in readFileSync() as well. Refs: #57800 PR-URL: #57811Fixes: #57800 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Always call uv_fs_req_cleanup after calling uv_fs_open instead of just when uv_fs_open returns a negative result. I referenced ReadFileSync from node:js2c when making this change. https://github.com/bnoordhuis made the same suggestion based on the PR #49691. Fixes: #57800 PR-URL: #57811 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Added a unit test for testing the memory usage of readFileSync. Test is looking specifically for the the issue caused by failing to free the filepath buffer in fs::ReadFileUtf8(), but it will also catch other significant memory leaks in readFileSync() as well. Refs: #57800 PR-URL: #57811Fixes: #57800 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Always call uv_fs_req_cleanup after calling uv_fs_open instead of just when uv_fs_open returns a negative result. I referenced ReadFileSync from node:js2c when making this change. https://github.com/bnoordhuis made the same suggestion based on the PR #49691. Fixes: #57800 PR-URL: #57811 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> CVE-ID: CVE-2025-23165
Added a unit test for testing the memory usage of readFileSync. Test is looking specifically for the the issue caused by failing to free the filepath buffer in fs::ReadFileUtf8(), but it will also catch other significant memory leaks in readFileSync() as well. Refs: #57800 PR-URL: #57811Fixes: #57800 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Always call uv_fs_req_cleanup after calling uv_fs_open instead of just when uv_fs_open returns a negative result. I referenced ReadFileSync from node:js2c when making this change. https://github.com/bnoordhuis made the same suggestion based on the PR #49691. Fixes: #57800 PR-URL: #57811 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> CVE-ID: CVE-2025-23165
Added a unit test for testing the memory usage of readFileSync. Test is looking specifically for the the issue caused by failing to free the filepath buffer in fs::ReadFileUtf8(), but it will also catch other significant memory leaks in readFileSync() as well. Refs: #57800 PR-URL: #57811Fixes: #57800 Reviewed-By: Matteo Collina <matteo.collina@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
I think there is something wrong with the test for this fix. Same thing for all release lines, you can try running the test with a pre-security release version. |
Justin-Nietzel
commented
May 15, 2025
Pummel tests are not ran as part of the CI tests.
Here's the commit we think may have introduced the bug: Here the code used for formatting the memory usage in the original bug report. functionformatBytes(bytes){constmegaBytes=(Math.round(bytes/1024/1024*100)/100);return`${megaBytes} MB`.padStart(12,' ');}exportfunctionprintMemoryUsage(){consttimeStamp=newDate().toISOString().replace('T',' ').slice(0,-5);const{ rss, heapTotal, heapUsed, external }=process.memoryUsage();console.log('')console.log(`${timeStamp}: rss -${formatBytes(rss)}`);console.log(`${timeStamp}: heapTotal -${formatBytes(heapTotal)}`);console.log(`${timeStamp}: heapUsed -${formatBytes(heapUsed)}`);console.log(`${timeStamp}: external -${formatBytes(external)}`);console.log('')}Let me know if there's anything else I can help with. |
I'm compiling node on my machine and testing on the release branches ( I'm going to test this on windows x64, unfortunately I don't have a linux x64 machine |
Justin-Nietzel
commented
May 15, 2025
I took a peek at libuv and the struct that originally enabled this pointer corruption is Windows specific.
|
Ok so knowing this is windows specific helps a lot. It would have been good to specify it in the release notes or CVE text. |
Sure, what would the best way to do this be? The original issue was Windows only, but the unit test would catch the issue if it was ever introduced to any other operating systems too. Should we add some more background info to the original issue report? I don't think anyone knew this was Windows only issue until just now. |
Always call uv_fs_req_cleanup after calling uv_fs_open instead of just when uv_fs_open returns a negative result. I referenced ReadFileSync from node:js2c when making this change.
https://github.com/bnoordhuis made the same suggestion based on the PR #49691.
Fixes: #57800