Skip to content

Conversation

@Jackapyun
Copy link
Contributor

Summary

This PR addresses a critical stack overflow issue in the KASAN (Kernel Address Sanitizer) error reporting mechanism when the report handler recursively triggers additional KASAN checks.

Problem

When kasan_report() is executing and calls _alert() for error reporting, the logging function may trigger additional memory access operations that can fail KASAN checks. This causes recursive re-entry into the KASAN report handler, leading to stack overflow and suppressing the original error report.

Solution

The fix implements a dual-approach strategy:

  1. Call kasan_stop() before reporting: Halts all KASAN checks when entering the panic path, preventing recursive checks during error message printing
  2. Reuse dump_only flag efficiently: Consolidates the panic/non-panic decision logic into a single flag, ensuring consistent behavior without additional stack usage

Key Changes

  • Extract dump_only flag calculation at the beginning of kasan_report()
  • Call kasan_stop() only when panic reporting is needed (before _alert())
  • Reuse the flag for both panic decision and stack dump logic

Impact

Stability

  • ✅ Eliminates stack overflow risk from recursive KASAN reports
  • ✅ Preserves original error reporting despite recursive triggers
  • ✅ Reduces stack memory usage in error paths

Compatibility

  • ✅ No breaking API changes
  • ✅ No impact on non-KASAN builds
  • ✅ Maintains existing panic/dump behavior based on configuration

Code Quality

  • ✅ Improves code maintainability by eliminating duplicate logic
  • ✅ Reduces code duplication in panic decision handling
  • ✅ Clear separation of concerns in error handling flow

Stop the report handler from re-entering KASAN by halting checks when printing.
Reuse the dump_only flag so read/write panic toggles only emit stack traces.
Retain stack dumps for panic-disabled paths without risking another overflow.

Signed-off-by: anpeiyun <anpeiyun@xiaomi.com>
@github-actions github-actions bot added Area: Memory Management Memory Management issues Size: S The size of the change in this PR is small labels Jan 20, 2026
@xiaoxiang781216 xiaoxiang781216 merged commit 3c1712c into apache:master Jan 21, 2026
39 of 40 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Memory Management Memory Management issues Size: S The size of the change in this PR is small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants