llvm / llvm/llvm-project

[MSan] Destructor poisoning of trivial base includes reused tail padding

Open
#217,024 0 comments 0 reactions 0 assignees View on GitHub
compiler-rt:msan generated by fuzzer
Dominant language
LLVM
Stars
40.5k
Forks
18.7k
PR merge metrics
PR metrics pending

Description

LLM Text. The problem is real, although I didn't check it's proposed solution
-----
MemorySanitizer's use-after-destructor instrumentation produces a false
positive when another base subobject occupies the reusable tail padding of
a trivially destructible polymorphic base.

Reproducer: https://godbolt.org/z/v59Yfs4Ea

Compile with:

clang++ -std=c++17 -O0 -g \
-fsanitize=memory \
-fsanitize-memory-use-after-dtor \
-fPIE -pie repro.cpp

Clang 14 exits successfully. Clang 15 and current trunk report
use-of-uninitialized-value inside ReadDuringDestruction::~ReadDuringDestruction().

The object layout is:

- Polymorphic: sizeof=16, data size=12
- ReadDuringDestruction base: offset 12

SanitizeDtorTrivialBase passes BaseLayout.getSize() (16) to the destructor
poisoning callback before ReadDuringDestruction's destructor runs. This
poisons bytes 12–15, even though they contain the still-live base's `value`
member.

Current code:
https://github.com/llvm/llvm-project/blob/main/clang/lib/CodeGen/CGClass.cpp

The instrumentation appears to need the base's data size rather than its
standalone size, or otherwise avoid poisoning reusable tail padding.

Contributor guide

Open the contributing guide

Research direction

Start in clang/lib/CodeGen/CGClass.cpp at SanitizeDtorTrivialBase and reproduce the report with the linked Godbolt example using the provided Clang and MemorySanitizer flags. Trace the size passed to the destructor-poisoning callback and verify that the still-live base member is not poisoned. Done means the reproducer no longer reports a false positive while destructor poisoning remains covered by an appropriate regression test.

Written by the indexing model from the issue text.

Assessment

Tech stack
cpp
Domain
compilers
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.