Observação
O acesso a essa página exige autorização. Você pode tentar entrar ou alterar diretórios.
O acesso a essa página exige autorização. Você pode tentar alterar os diretórios.
Visão geral
Para a versão 2004 do Windows 10, a Microsoft introduziu novas APIs de zeramento de pool que zeram por padrão: ExAllocatePool2 e ExAllocatePool3.
A consulta do CodeQLwdk-deprecated-api encontra todas as instâncias de APIs obsoletas que um driver não deve chamar. As APIs preteridas são:
Atualizações de driver para versões do Windows posteriores ao Windows 10, versão 2004
Se você estiver criando um driver destinado ao Windows 10, versão 2004 e versões posteriores, use as APIs de substituição ExAllocatePool2 e ExAllocatePool3 .
| API antiga | Nova API |
|---|---|
| ExAllocatePool | ExAllocatePool2 |
| ExAllocatePoolWithTag | ExAllocatePool2 |
| ExAllocatePoolWithQuota | ExAllocatePool2 |
| ExAllocatePoolWithQuotaTag | ExAllocatePool2 |
| ExAllocatePoolWithTagPriority | ExAllocatePool3 |
As novas APIs irão zerar as alocações de pool por padrão para ajudar a evitar possíveis vulnerabilidades de divulgação de memória.
ExAllocatePoolWithTag
// Old code
PVOID Allocation = ExAllocatePoolWithTag(PagedPool, 100, 'abcd');
RtlZeroMemory(Allocation, 100);
// New code
PVOID Allocation = ExAllocatePool2(POOL_FLAG_PAGED, 100, 'abcd');
As APIs de alocação de pool antigas aceitam um argumento POOL_TYPE , mas as novas APIs de alocação aceitam um argumento POOL_FLAGS . Atualize qualquer código associado para usar o novo argumento POOL_FLAGS .
ExAllocatePoolWithQuota/ExAllocatePoolWithQuotaTag
A nova função agora retornará NULL em caso de falha de alocação por padrão. Para que o alocador levante uma exceção em caso de falha, o sinalizador POOL_FLAG_RAISE_ON_FAILURE deve ser passado conforme discutido em ExAllocatePool2.
// Old code
PVOID Allocation = ExAllocatePoolWithQuotaTag(PagedPool | POOL_QUOTA_FAIL_INSTEAD_OF_RAISE, 100, 'abcd');
RtlZeroMemory(Allocation, 100);
// New code
PVOID Allocation = ExAllocatePool2(POOL_FLAG_PAGED | POOL_FLAG_USE_QUOTA, 100, 'abcd');
ExAllocatePoolWithTagPriority
// Old code
PVOID Allocation = ExAllocatePoolWithTagPriority(PagedPool, 100, 'abcd', HighPoolPriority);
RtlZeroMemory(Allocation, 100);
// New code
POOL_EXTENDED_PARAMETER params = {0};
params.Type = PoolExtendedParameterPriority;
params.Priority = HighPoolPriority;
PVOID Allocation = ExAllocatePool3(POOL_FLAG_PAGED, 100, 'abcd', ¶ms, 1);
Atualizações de driver para versões do Windows anteriores ao Windows 10, versão 2004
Se você estiver criando um driver destinado a versões do Windows antes do Windows 10, versão 2004, deverá usar as seguintes funções de wrapper de força embutida.
Você também deve #define POOL_ZERO_DOWN_LEVEL_SUPPORT e chamar ExInitializeDriverRuntime durante a inicialização do driver antes de chamar as funções de alocação do pool.
Funções embutidas definidas localmente
PVOID
NTAPI
ExAllocatePoolZero (
_In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
_In_ SIZE_T NumberOfBytes,
_In_ ULONG Tag
)
PVOID
NTAPI
ExAllocatePoolQuotaZero (
_In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
_In_ SIZE_T NumberOfBytes,
_In_ ULONG Tag
)
PVOID
NTAPI
ExAllocatePoolPriorityZero (
_In_ __drv_strictTypeMatch(__drv_typeExpr) POOL_TYPE PoolType,
_In_ SIZE_T NumberOfBytes,
_In_ ULONG Tag,
_In_ EX_POOL_PRIORITY Priority
)
Consulte o cabeçalho wdm.h mais recente para o código de implementação desses wrappers de código. Por exemplo, esta é a implementação para ExAllocatePoolPriorityZero, mostrando o uso de RtlZeroMemory.
{
PVOID Allocation;
Allocation = ExAllocatePoolWithTagPriority((POOL_TYPE) (PoolType | POOL_ZERO_ALLOCATION),
NumberOfBytes,
Tag,
Priority);
#if defined(POOL_ZERO_DOWN_LEVEL_SUPPORT)
if ((!ExPoolZeroingNativelySupported) && (Allocation != NULL)) {
RtlZeroMemory(Allocation, NumberOfBytes);
}
#endif
return Allocation;
}
Mapeamento de APIs antigas para novas APIs
| API antiga | Nova API |
|---|---|
| ExAllocatePool | ExAllocatePoolZero |
| ExAllocatePoolWithTag | ExAllocatePoolZero |
| ExAllocatePoolWithQuota | ExAllocatePoolQuotaZero |
| ExAllocatePoolWithQuotaTag | ExAllocatePoolQuotaZero |
| ExAllocatePoolWithTagPriority | ExAllocatePoolPriorityZero |
Exemplo
// Old code
PVOID Allocation = ExAllocatePoolWithTag(PagedPool, 100, 'abcd');
// New code
// Before headers are pulled in (or compiler defined)
#define POOL_ZERO_DOWN_LEVEL_SUPPORT
// Once during driver initialization
// Argument can be any value
ExInitializeDriverRuntime(0);
// Replacement for each pool allocation
PVOID Allocation = ExAllocatePoolZero(PagedPool, 100, 'abcd');
Detalhes adicionais
Essa consulta pode ser encontrada no repositório CodeQL do Microsoft GitHub. Consulte a página CodeQL e o Teste do Logotipo das Ferramentas Estáticas para obter detalhes sobre como os desenvolvedores de Drivers do Windows podem baixar e executar o CodeQL.