Skip to content

Memory-safety fixes: uninitialized reads and a realloc leak - #613

Open
matejk wants to merge 2 commits into
LinearTapeFileSystem:release/v2.4.9.2from
matejk:fix/memory-safety
Open

matejk wants to merge 2 commits into
LinearTapeFileSystem:release/v2.4.9.2from
matejk:fix/memory-safety

Conversation

@matejk

@matejk matejk commented Jun 12, 2026 •

Copy link
Copy Markdown
Contributor

Two commits:

  • Reads of uninitialized values on error paths (4 sites): tape_get_pews leaves *pews unset on -LTFS_UNSUPPORTED while the caller computes pews + 10; ltfs_profiler_set tested an unset ret when the volume had neither an iosched nor a device handle; _get_dump derived a transfer length from cap_buf without checking the READ BUFFER result; the ICU normalize callers compared the output pointer against the input before checking the return code, reading uninitialized memory and potentially leaking the input buffer.
  • Key-list leak in the simple KMI: realloc was assigned straight back to priv.dk_list, so a failure overwrote the only pointer to the existing buffer with NULL and leaked it; the original pointer is now kept and freed on the error path.

@vandelvan
vandelvan requested review from XV02, madjesc and syaoraang June 12, 2026 20:55
@matejk
matejk force-pushed the fix/memory-safety branch from 1c27543 to 418c898 Compare June 17, 2026 20:35

@XV02 XV02 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for all your work, just some correctness comments :DD

Comment thread src/kmi/simple.c Resolved
Comment thread src/libltfs/ltfs.c Resolved
Comment thread src/libltfs/pathname.c Resolved
Comment thread src/libltfs/pathname.c Resolved
Comment thread src/libltfs/tape.c Resolved
Comment thread src/tape_drivers/linux/sg/sg_tape.c Resolved
@matejk
matejk force-pushed the fix/memory-safety branch from 418c898 to fcd7a4c Compare August 17, 2026 20:10
@matejk
matejk changed the base branch from main to release/v2.4.9.0 August 17, 2026 20:10
@matejk
matejk changed the base branch from release/v2.4.9.0 to main August 17, 2026 20:11
@matejk
matejk force-pushed the fix/memory-safety branch 3 times, most recently from 8040315 to 18cb1e6 Compare August 17, 2026 20:28
@matejk

matejk commented Aug 17, 2026

Copy link
Copy Markdown
Contributor Author

Thanks — addressed:

  • The comments on the initializations and NULL checks are removed.
  • simple.c: back to the single error path; the original pointer is kept in previous and freed there. free(NULL) is a no-op on the calloc branch, so no extra condition is needed.

make check 14/14.

@matejk
matejk requested a review from XV02 August 17, 2026 20:31

@XV02 XV02 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for addressing all my comments, LGTM! :DD

@matejk
matejk force-pushed the fix/memory-safety branch from 18cb1e6 to a495638 Compare October 13, 2026 08:34
@rangelmx
rangelmx changed the base branch from main to release/v2.4.9.2 November 17, 2026 20:48
@rangelmx

Copy link
Copy Markdown
Contributor

Hi @matejk ! We agreed that this change can be merged into our next release, 2.4.9.2. Since for the previous release process some PRs got squashed, git might be marking some changes incorrectly in this PR when we switched the base branch, if this happened please merge your branch with the release/2.4.9.2 and please confirm there are no conflicts so we can merge it with the new release branch. Thank you for your contribution!

pews, ret in ltfs_profiler_set, cap_buf after a failed READ BUFFER, and the
ICU normalize output pointer compared before its return code was checked.
@matejk

matejk commented Nov 26, 2026

Copy link
Copy Markdown
Contributor Author

Rebased on release/v2.4.9.2 (41b843f). Both commits apply without conflicts and are unchanged; the diff is the same five files. The CMake build on Linux passes, and the integration suite from #611 run on top of the branch passes (16 passed, 12-readdirplus skipped on FUSE 2).

I recommend including #611 in the same release. The suite uses the file tape backend, needs no tape drive and runs in a few seconds, so it gives a quick check that basic functionality is not broken.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants