Sdílet prostřednictvím


Dotazy a sady CodeQL pro testování ovladačů windows

Úložiště Microsoft CodeQL Na GitHubu nabízí dvě sady dotazů pro zjednodušení vývoje ovladačů windows a zajištění souladu s programem WHCP (Windows Hardware Compatibility Program). Sada recommended.qls zahrnuje všechny doporučené dotazy pro vývojáře ovladačů, zatímco sada mustfix.qls se zaměřuje na dotazy "Must-Fix" vyžadované pro certifikaci WHCP. Obě apartmá se pravidelně aktualizují.

Must-Fix dotazy k certifikaci WCHP

Následující podmnožina dotazů je nutné opravit pro certifikaci WHCP a jsou také součástí sady Doporučených oprav .

Tato sada pravidel je součástí souboru mustfix.qls.

ID Umístění Společný výčet slabosti
cpp/špatná-kontrola-přetečení-při-sčítání codeql/cpp-queries/<Version>/Likely Bugs/Arithmetic/BadAdditionOverflowCheck.ql CWE-190, CWE-192
cpp/pointer-overflow-check codeql/cpp-queries/<Version>/Likely Bugs/Memory Management/PointerOverflow.ql není k dispozici
cpp/příliš málo argumentů codeql/cpp-queries/<Version>/Pravděpodobné chyby/Podspecifikované funkce/Příliš málo argumentů.ql není k dispozici
cpp/porovnání s širším typem codeql/cpp-queries/<Version>/Security/CWE/CWE-190/ComparisonWithWiderType.ql CWE-190, CWE-197, CWE-835
cpp/hresult-boolean-conversion codeql/cpp-queries/<Version>/Security/CWE/CWE-253/HResultBooleanConversion.ql CWE-253

Soubor mustfix.qls obsahuje následující dotazy kódu Must-Fix .

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

- description: Security queries required to fix when certifying Windows Drivers
- queries: .
  from: codeql/cpp-queries
  version: 0.9.0
- include:
    query path:
      - Likely Bugs/Arithmetic/BadAdditionOverflowCheck.ql
      - Likely Bugs/Memory Management/PointerOverflow.ql
      - Likely Bugs/Underspecified Functions/TooFewArguments.ql
      - Security/CWE/CWE-190/ComparisonWithWiderType.ql
      - Security/CWE/CWE-253/HResultBooleanConversion.ql
- import: windows-driver-suites/windows_mustfix_partial.qls
  from: microsoft/windows-drivers

Tato sada pravidel je součástí windows-driver-suites/windows_mustfix_partial.qls.

ID Umístění Společný výčet slabosti
cpp/windows/wdk/odstraněné-api /microsoft/windows-drivers//<Version>drivers/general/queries/WdkDeprecatedApis/wdk-deprecated-api.ql není k dispozici
microsoft/Security/CWE/CWE-704/WcharCharConversionLimited /microsoft/windows-drivers/<Version>/microsoft/Security/CWE/CWE-704/WcharCharConversionLimited.ql CWE-704

Soubor windows_mustfix_partial.qls obsahuje následující dotazy kódu Must-Fix .

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

- description: Security queries required to fix when certifying Windows Drivers
- queries: .
  from: microsoft/windows-drivers
- include:
    query path:
      - drivers/general/queries/WdkDeprecatedApis/wdk-deprecated-api.ql
      - microsoft/Security/CWE/CWE-704/WcharCharConversionLimited.ql

Tyto dotazy jsou součástí sady dotazů recommended.qls v úložišti Microsoft GitHub CodeQL. Sloupec "Common Weakness Enumeration" (CWE) identifikuje druhy problémů se zabezpečením, které daný dotaz hledá. Další podrobnosti o CWEs najdete na stránce Mitre na webu CWE .

Sloupec CWE (Common Weakness Enumeration) zobrazuje typy problémů se zabezpečením, které dotaz identifikuje.

Osvědčené postupy

ID Umístění Společný výčet slabosti
cpp/offset-use-before-range-check codeql/cpp-queries/<Version>//Best Practices/Likely Errors/OffsetUseBeforeRangeCheck.ql není k dispozici

Pravděpodobné chyby

ID Umístění Společný výčet slabosti
cpp/špatná-kontrola-přetečení-při-sčítání codeql/cpp-queries/<Version>/Likely Bugs/Arithmetic/BadAdditionOverflowCheck.ql CWE-190, CWE-192
cpp/integer-multiplication-cast-to-long codeql/cpp-queries/<Version>/Likely Bugs/Arithmetic/IntMultToLong.ql CWE-190, CWE-192, CWE-197, CWE-681
cpp/signed-overflow-check codeql/cpp-queries/<Version>/Likely Bugs/Arithmetic/SignedOverflowCheck.ql není k dispozici
cpp/upcast-array-pointer-arithmetic codeql/cpp-queries/<Version>/Likely Bugs/Conversion/CastArrayPointerArithmetic.ql CWE-119, CWE-843
cpp/pointer-overflow-check codeql/cpp-queries/<Version>/Likely Bugs/Memory Management/PointerOverflow.ql není k dispozici
cpp/příliš málo argumentů codeql/cpp-queries/<Version>/Pravděpodobné chyby/Podspecifikované funkce/Příliš málo argumentů.ql není k dispozici
cpp/nesprávné použití operátoru NOT codeql/cpp-queries/<Version>/Likely Bugs/Likely Typos/IncorrectNotOperatorUsage.ql CWE-480
cpp/suspicious-add-sizeof codeql/cpp-queries/<Version>//Likely Bugs/Memory Management/SuspiciousSizeof.ql CWE-468
cpp/uninitialized-local codeql/cpp-queries/<Version>/Likely Bugs/Memory Management/UninitializedLocal.ql CWE-457, CWE-665

Zabezpečení

ID Umístění Společný výčet slabosti
cpp/podmíněně-neinicializovaná-proměnná codeql/cpp-queries/<Version>/Security/CWE/CWE-457/ConditionallyUninitializedVariable.ql. CWE-457
cpp/neukončené-variadické-volání codeql/cpp-queries/<Version>/Security/CWE/CWE-121/UnterminatedVarargsCall.ql CWE-121
cpp/podezřelé škálování ukazatele codeql/cpp-queries/<Version>/Security/CWE/CWE-468/IncorrectPointerScaling.ql CWE-468
cpp/suspicious-pointer-scaling-void codeql/cpp-queries/<Version>/Security/CWE/CWE-468/IncorrectPointerScalingVoid.ql CWE-468
cpp/potenciálně nebezpečná funkce codeql/cpp-queries/<Version>/Security/CWE/CWE-676/PotentiallyDangerousFunction.ql CWE-676
cpp/incorrect-string-type-conversion codeql/cpp-queries/<Version>/Security/CWE/CWE-704/WcharCharConversion.ql CWE-704
cpp/porovnání s širším typem codeql/cpp-queries/<Version>/Security/CWE/CWE-190/ComparisonWithWiderType.ql CWE-190, CWE-197, CWE-835
cpp/hresult-boolean-conversion codeql/cpp-queries/<Version>/Security/CWE/CWE-253/HResultBooleanConversion.ql CWE-253
cpp/suspicious-add-sizeof codeql/cpp-queries/<Version>/Security/CWE/CWE-468/CWE-468/SuspiciousAddWithSizeof.ql CWE-468

Soubor recommended.qls obsahuje následující doporučené dotazy na kód.

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

- description: Recommended and required queries for Windows Drivers.
- import: windows-driver-suites/windows_mustfix_partial.qls
  from: microsoft/windows-drivers
- import: windows-driver-suites/windows_recommended_partial.qls
  from: microsoft/windows-drivers
- queries: .
  from: codeql/cpp-queries
  version: 0.9.0
- include:
    query path:
      - Best Practices/Likely Errors/OffsetUseBeforeRangeCheck.ql
      - Likely Bugs/Arithmetic/IntMultToLong.ql
      - Likely Bugs/Arithmetic/SignedOverflowCheck.ql
      - Likely Bugs/Conversion/CastArrayPointerArithmetic.ql
      - Likely Bugs/Likely Typos/IncorrectNotOperatorUsage.ql
      - Likely Bugs/Memory Management/SuspiciousSizeof.ql
      - Likely Bugs/Memory Management/UninitializedLocal.ql
      - Security/CWE/CWE-121/UnterminatedVarargsCall.ql
      - Security/CWE/CWE-457/ConditionallyUninitializedVariable.ql
      - Security/CWE/CWE-468/IncorrectPointerScaling.ql
      - Security/CWE/CWE-468/IncorrectPointerScalingVoid.ql
      - Security/CWE/CWE-468/SuspiciousAddWithSizeof.ql
      - Security/CWE/CWE-676/PotentiallyDangerousFunction.ql
      - Security/CWE/CWE-704/WcharCharConversion.ql
      - Likely Bugs/Arithmetic/BadAdditionOverflowCheck.ql
      - Likely Bugs/Memory Management/PointerOverflow.ql
      - Likely Bugs/Underspecified Functions/TooFewArguments.ql
      - Security/CWE/CWE-190/ComparisonWithWiderType.ql
      - Security/CWE/CWE-253/HResultBooleanConversion.ql

Tyto dotazy jsou součástí sady dotazů windows_recommended_partial.qls .

ID Umístění Společný výčet slabosti
cpp/paddingbyteinformationdisclosure microsoft/windows-drivers/<Version>/microsoft/Pravděpodobné chyby/Boundary Violations/PaddingByteInformationDisclosure.ql není k dispozici
cpp/badoverflowguard microsoft/windows-drivers/<Version>/microsoft/Pravděpodobné chyby/Konverze/BadOverflowGuard.ql není k dispozici
cpp/infiniteloop microsoft/windows-drivers/<Version>/microsoft/Likely Bugs/Conversion/InfiniteLoop.ql není k dispozici
cpp/uninitializedptrfield microsoft/windows-drivers/<Version>/microsoft/Likely Bugs/UninitializedPtrField.ql není k dispozici
cpp/use-after-free microsoft/windows-drivers/<Version>/microsoft/Likely Bugs/Memory Management/UseAfterFree/UseAfterFree.ql není k dispozici
ID Umístění Upozornění analýzy kódu
cpp/weak-crypto/cng/hardcoded-iv /microsoft/windows-drivers/<Version>/microsoft/Security/Cryptography/HardcodedIVCNG.ql není k dispozici

Ovladače – Obecně

ID Umístění Upozornění analýzy kódu
cpp/drivers/ke-set-event-pageable /microsoft/windows-drivers//<Version>drivers/general/queries/KeSetEventPageable/KeSetEventPageable.ql Žádná přidružená kontrola certifikační autority
cpp/drivers/role-type-correctly-used /microsoft/windows-drivers//<Version>drivers/general/queries/RoleTypeCorrectlyUsed/RoleTypeCorrectlyUsed.ql Žádná přidružená kontrola certifikační autority
cpp/drivers/extended-deprecated-apis /microsoft/windows-drivers//<Version>drivers/general/queries/ExtendedDeprecatedApis.ql Upozornění C28719, upozornění C28726, upozornění C28735, upozornění C28750
cpp/drivers/irql-not-saved /microsoft/windows-drivers//<Version>drivers/general/queries/IrqlNotSaved/IrqlNotSaved.ql Upozornění C28158
cpp/ovladače/irql-not-used /microsoft/windows-drivers//<Version>drivers/general/queries/IrqlNotUsed/IrqlNotUsed.ql Upozornění C28157
cpp/drivers/irql-set-too-high /microsoft/windows-drivers//<Version>drivers/general/queries/IrqlTooHigh/IrqlTooHigh.ql Upozornění C28150
cpp/drivers/irql-too-low /microsoft/windows-drivers//<Version>drivers/general/queries/IrqlTooLow/IrqlTooLow.ql Upozornění C28120
cpp/drivers/irql-set-too-high /microsoft/windows-drivers//<Version>drivers/general/queries/IrqlSetTooHigh/IrqlTooHigh.ql Upozornění C28121
cpp/drivers/irql-set-too-low /microsoft/windows-drivers//<Version>drivers/general/queries/IrqlSetTooLow/IrqlSetTooLow.ql Upozornění C28124
cpp/drivers/pool-tag-integral /microsoft/windows-drivers//<Version>drivers/general/queries/PoolTagIntegral/PoolTagIntegral.ql Upozornění C28134
cpp/drivers/str-safe /microsoft/windows-drivers/<Version>/drivers/general/queries/StrSafe/StrSafe.ql Upozornění C28146

Ovladače – WDM

ID Umístění Upozornění analýzy kódu
cpp/drivers/illegal-field-access /microsoft/windows-drivers//<Version>drivers/wdm/queries/IllegalFieldAccess/IllegalFieldAccess.ql Upozornění C28128
cpp/drivers/illegal-field-access2 /microsoft/windows-drivers//<Version>drivers/wdm/queries/IllegalFieldAccess2/IllegalFieldAccess2.ql Upozornění C28175
cpp/drivers/nezákonný zápis do pole /microsoft/windows-drivers//<Version>drivers/wdm/queries/IllegalFieldWrite/IllegalFieldWrite.ql Upozornění C28176
cpp/drivers/opaque-mdl-use /microsoft/windows-drivers//<Version>drivers/wdm/queries/OpaqueMdlUse/OpaqueMdlUse.ql (Žádná přidružená kontrola certifikační autority)
cpp/drivers/opaque-mdl-write /microsoft/windows-drivers//<Version>drivers/wdm/queries/OpaqueMdlUse/OpaqueMdlWrite.ql Upozornění C28145
cpp/ovladače/chyba-při-odesílání-stavu /microsoft/windows-drivers/<Version>/drivers/wdm/queries/PendingStatusError/PendingStatusError.ql Upozornění C28143
cpp/drivers/wrong-dispatch-table-assignment /microsoft/windows-drivers//<Version>drivers/wdm/queries/WrongDispatchTableAssignment/WrongDispatchTableAssignment.ql Upozornění C28169

Soubor windows-driver-suites/windows_recommended_partial.qls obsahuje následující doporučené dotazy na kód.

# Copyright (c) Microsoft Corporation.
# Licensed under the MIT license.

- description: Recommended and required queries for Windows Drivers.
- import: windows-driver-suites/windows_mustfix_partial.qls
- queries: .
  from: microsoft/windows-drivers
- include:
    query path:
      - microsoft/Likely Bugs/Boundary Violations/PaddingByteInformationDisclosure.ql
      - microsoft/Likely Bugs/Conversion/BadOverflowGuard.ql
      - microsoft/Likely Bugs/Conversion/InfiniteLoop.ql
      - microsoft/Likely Bugs/Memory Management/UseAfterFree/UseAfterFree.ql
      - microsoft/Likely Bugs/UninitializedPtrField.ql
      - microsoft/Security/Crytpography/HardcodedIVCNG.ql
      - drivers/general/queries/KeSetEventPageable/KeSetEventPageable.ql
      - drivers/general/queries/RoleTypeCorrectlyUsed/RoleTypeCorrectlyUsed.ql
      - drivers/general/queries/DefaultPoolTag/DefaultPoolTag.ql
      - drivers/general/queries/ExaminedValue/ExaminedValue.ql
      - drivers/general/queries/ExtendedDeprecatedApis/ExtendedDeprecatedApis.ql
      - drivers/general/queries/IrqlNotSaved/IrqlNotSaved.ql
      - drivers/general/queries/IrqlNotUsed/IrqlNotUsed.ql
      - drivers/general/queries/IrqlTooHigh/IrqlTooHigh.ql
      - drivers/general/queries/IrqlTooLow/IrqlTooLow.ql
      - drivers/general/queries/IrqlSetTooHigh/IrqlTooHigh.ql
      - drivers/general/queries/IrqlSetTooLow/IrqlSetTooLow.ql
      - drivers/general/queries/PoolTagIntegral/PoolTagIntegral.ql
      - drivers/general/queries/StrSafe/StrSafe.ql
      - drivers/wdm/queries/IllegalFieldAccess/IllegalFieldAccess.ql
      - drivers/wdm/queries/IllegalFieldAccess2/IllegalFieldAccess2.ql
      - drivers/wdm/queries/IllegalFieldWrite/IllegalFieldWrite.ql
      - drivers/wdm/queries/OpaqueMdlUse/OpaqueMdlUse.ql
      - drivers/wdm/queries/OpaqueMdlUse/OpaqueMdlWrite.ql
      - drivers/wdm/queries/PendingStatusError/PendingStatusError.ql
      - drivers/wdm/queries/WrongDispatchTableAssignment/WrongDispatchTableAssignment.ql