MdeModulePkg/Core/Dxe: Add interrupt-enable nesting guard

Add interrupt-enable recursion depth tracking using
mInterruptEnableNestDepth and a bounded assertion in
CoreSetInterruptState().

This provides early detection for unintended recursive
interrupt-enable loops.

Signed-off-by: Michael D Kinney <michael.d.kinney@intel.com>
This commit is contained in:
Michael D Kinney 2026-07-11 09:47:32 -07:00 committed by mergify[bot]
parent 1d2e73c4af
commit ef437b30ad

View file

@ -9,6 +9,21 @@ SPDX-License-Identifier: BSD-2-Clause-Patent
#include "DxeMain.h"
#include "Event.h"
//
// Maximum interrupt nesting depth allowed by the UEFI/PI specifications.
// Comprised of 3 software TPL levels (TPL_APPLICATION, TPL_CALLBACK,
// TPL_NOTIFY) plus 16 hardware interrupt priority levels (TPL 16..31).
//
#define MAX_INTERRUPT_ENABLE_NEST_DEPTH (3 + 16)
//
// Counter for tracking interrupt enable recursion depth.
// Incremented on entry to CoreSetInterruptState(TRUE) and decremented on exit.
// Prevents stack overflow from infinite interrupt recursion loops.
// Must not exceed MAX_INTERRUPT_ENABLE_NEST_DEPTH per UEFI/PI specs.
//
static volatile UINTN mInterruptEnableNestDepth = 0;
/**
Set Interrupt State.
@ -39,7 +54,12 @@ CoreSetInterruptState (
}
}
mInterruptEnableNestDepth++;
ASSERT (mInterruptEnableNestDepth < MAX_INTERRUPT_ENABLE_NEST_DEPTH);
gCpu->EnableInterrupt (gCpu);
mInterruptEnableNestDepth--;
}
/**