Skip to content

erasure-code/jerasure: do not free a system libJerasure's fields - #73726

Merged
ljflores merged 1 commit into
ceph:mainfrom
abrahamperz:wip-ec-jerasure-system-double-free
Nov 25, 2026
Merged

ljflores merged 1 commit into
ceph:mainfrom
abrahamperz:wip-ec-jerasure-system-double-free

Conversation

@abrahamperz

Copy link
Copy Markdown
Contributor

debian/rules builds with WITH_SYSTEM_JERASURE=ON, so the jerasure and shec plugins (and their legacy flavors) link the same shared libJerasure. They share galois.c's table of default Galois fields. Each plugin's jerasure_finish() destructor frees those fields at exit but does not clear the table, so the second plugin frees them again. A monitor that has loaded both plugins corrupts its heap during shutdown, and tcmalloc segfaults under gf_free(), as in the tracker.

This change frees the fields only when the vendored jerasure is linked into the plugin, where each plugin owns its own copy. With the system library, the fields are left to the library.

Fixes: https://tracker.ceph.com/issues/82975

How this was verified

  • Reproducer: a small program that dlopen()s libec_jerasure.so and libec_shec.so, calls jerasure_init() in each and exits. With both plugins linked against the system libJerasure/libgf_complete (as in the Ubuntu packages), glibc aborts with free(): double free detected in tcache 2, and valgrind reports invalid reads/frees in jerasure_finish(). With this change: exit 0, valgrind ERROR SUMMARY: 0 errors.
  • The vendored build is unchanged: the same reproducer is clean under valgrind before and after.
  • A configure with -DWITH_SYSTEM_JERASURE=ON passes -DWITH_SYSTEM_JERASURE to jerasure_init.cc.
  • unittest_erasure_code* (plugin, jerasure, shec, lrc; 12 tests) pass.

Contribution Guidelines

  • To sign and title your commits, please refer to Submitting Patches to Ceph.

  • If you are submitting a fix for a stable branch (e.g. "quincy"), please refer to Submitting Patches to Ceph - Backports for the proper workflow.

  • When filling out the below checklist, you may click boxes directly in the GitHub web UI. When entering or editing the entire PR message in the GitHub web UI editor, you may also select a checklist item by adding an x between the brackets: [x]. Spaces and capitalization matter when checking off items this way.

Checklist

  • Tracker (select at least one)
    • References tracker ticket
    • Very recent bug; references commit where it was introduced
    • New feature (ticket optional)
    • Doc update (no ticket needed)
    • Code cleanup (no ticket needed)
  • Component impact
    • Affects Dashboard, opened tracker ticket
    • Affects Orchestrator, opened tracker ticket
    • No impact that needs to be tracked
  • Documentation (select at least one)
    • Updates relevant documentation
    • No doc update is appropriate
  • Tests (select at least one)

With WITH_SYSTEM_JERASURE=ON, which debian/rules sets, the jerasure and
shec plugins (and their legacy flavors) link the same shared libJerasure,
so they share galois.c's table of default fields. Each plugin's
jerasure_finish() destructor frees those fields at exit without clearing
the table, so the second plugin frees them again. In a monitor that has
loaded both plugins this corrupts the heap, and tcmalloc segfaults under
gf_free() during shutdown.

Only free the fields when the vendored jerasure is linked into the plugin,
where each plugin owns its own copy.

Fixes: https://tracker.ceph.com/issues/82975
Signed-off-by: Abraham Pérez <[email protected]>
@github-actions

Copy link
Copy Markdown

Thank you for your contribution. Since you are not yet a member of the Ceph organization with write permissions on ceph/ceph.git, our CI will not automatically run. Any member of the Ceph organization may label this PR ci-approved to allow Jenkins CI jobs to run.

@abrahamperz
abrahamperz marked this pull request as ready for review November 10, 2026 13:23
@abrahamperz
abrahamperz requested a review from a team as a code owner November 10, 2026 13:23

@tchaikov tchaikov 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.

lgtm

tchaikov

This comment was marked as duplicate.

@SrinivasaBharath

Copy link
Copy Markdown
Contributor

This PR has been added to wip-bharath11-testing-20261114.052454-main.

@ronen-fr

Copy link
Copy Markdown
Contributor

@ljflores
ljflores merged commit 35aa52d into ceph:main Nov 25, 2026
19 of 20 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants