icu icon indicating copy to clipboard operation
icu copied to clipboard

ICU-23359 Fix use-after-free race in TransliteratorAlias compoundFilter

Open hirorogo opened this issue 8 months ago • 10 comments

Checklist

  • [x] Required: Issue filed: ICU-23359
  • [x] Required: The PR title must be prefixed with a JIRA Issue number. Example: "ICU-NNNNN Fix xyz"
  • [x] Required: Each commit message must be prefixed with a JIRA Issue number. Example: "ICU-NNNNN Fix xyz"
  • [ ] Issue accepted (done by Technical Committee after discussion)
  • [x] Tests included, if applicable
  • [ ] API docs and/or User Guide docs changed or added, if applicable
  • [x] CLA signed

Summary

TransliteratorAlias stored a raw non-owning pointer to the TransliteratorEntry's compoundFilter. When the registry mutex is released between registry->get() and alias->create(), a concurrent Transliterator::unregister() call can delete the entry (and its compoundFilter) while the alias still holds a dangling pointer, causing a use-after-free.

The source comment at transreg.cpp lines 30-36 notes that BoundsChecker has reported dangling pointer errors with these entry objects, corroborating this race condition.

Changes

  • Clone compoundFilter in both TransliteratorAlias constructors instead of storing a raw alias pointer
  • Delete owned compoundFilter in ~TransliteratorAlias()
  • Update header comment and type from const UnicodeSet* (alias) to UnicodeSet* (owned)
  • Add TestTransliteratorAliasCompoundFilterRace in tsmthred.cpp to exercise concurrent createInstance() + unregister() with a compound-filter transliterator

Test plan

  • [x] Existing ICU transliterator tests pass
  • [x] Concurrent createInstance + unregister on the same ID no longer triggers UAF (new test: TestTransliteratorAliasCompoundFilterRace)

hirorogo avatar Mar 19 '26 16:03 hirorogo

CLA assistant check
All committers have signed the CLA.

CLAassistant avatar Mar 19 '26 16:03 CLAassistant

@hirorogo Could you please sign the CLA -- otherwise we can't look at your changes -- and create a Jira ticket with the problem description?

markusicu avatar Mar 26 '26 16:03 markusicu

Hooray! The files in the branch are the same across the force-push. 😃

~ Your Friendly Jira-GitHub PR Checker Bot

Hooray! The files in the branch are the same across the force-push. 😃

~ Your Friendly Jira-GitHub PR Checker Bot

Hooray! The files in the branch are the same across the force-push. 😃

~ Your Friendly Jira-GitHub PR Checker Bot

I've restored the PR template, added a unit test (TestTransliteratorAliasCompoundFilterRace), and the CLA is signed. Could you please create a Jira ticket for this issue? I'll update the PR title and commit message with the ticket ID once assigned. Thank you!

hirorogo avatar Apr 03 '26 05:04 hirorogo

Hooray! The files in the branch are the same across the force-push. 😃

~ Your Friendly Jira-GitHub PR Checker Bot

@markusicu CLA is signed, and I've created the Jira ticket: ICU-23359. The PR title and commit message are updated with the ticket ID.

A unit test (TestTransliteratorAliasCompoundFilterRace) is included in tsmthred.cpp — it exercises concurrent createInstance() + unregister() with a compound-filter transliterator.

Could the Technical Committee please accept ICU-23359 when you get a chance? The jira-ticket CI check is currently failing because the ticket status is still "New".

Thank you!

hirorogo avatar Apr 06 '26 15:04 hirorogo

Hooray! The files in the branch are the same across the force-push. 😃

~ Your Friendly Jira-GitHub PR Checker Bot

plz reviews @markusicu @aheninger @qdan8556-glitch

hirorogo avatar Apr 21 '26 08:04 hirorogo