Nota
O acesso a esta página requer autorização. Podes tentar iniciar sessão ou mudar de diretório.
O acesso a esta página requer autorização. Podes tentar mudar de diretório.
Visão geral
Para a versão 2004 do Windows 10, a Microsoft introduziu novas APIs de zeragem de pool que zeram por padrão: ExAllocatePool2 e ExAllocatePool3.
A consulta CodeQLwdk-deprecated-api localiza 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 anularão as alocações de pool como padrão, para ajudar a evitar possíveis falhas de revelaçã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 retornará NULL por padrão na falha de alocação. Para que o alocador em vez disso gere 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 estiver a criar um controlador destinado a versões do Windows anteriores ao Windows 10, versão 2004, tem de utilizar as seguintes funções de wrapper force inline.
Você também deve usar #define POOL_ZERO_DOWN_LEVEL_SUPPORT e chamar ExInitializeDriverRuntime durante a inicialização do driver antes de chamar as funções de alocação de 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 obter o código de implementação para esses 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
Esta consulta pode ser encontrada no repositório Microsoft GitHub CodeQL. Consulte a página CodeQL e Teste de logotipo de ferramentas estáticas para obter detalhes sobre como os desenvolvedores de drivers do Windows podem baixar e executar o CodeQL.