|
| 1 | +// Copyright (c) Microsoft Corporation. |
| 2 | +// Licensed under the MIT license. |
| 3 | +/** |
| 4 | + * @id cpp/drivers/irql-float-state-mismatch |
| 5 | + * @kind problem |
| 6 | + * @name Irql Float State Mismatch |
| 7 | + * @description The IRQL where the floating-point state was saved does not match the current IRQL (for this restore operation). |
| 8 | + * @platform Desktop |
| 9 | + * @feature.area Multiple |
| 10 | + * @impact Insecure Coding Practice |
| 11 | + * @repro.text The IRQL at which the driver is executing when it restores a floating-point state is different than the IRQL at which it was executing when it saved the floating-point state. |
| 12 | + * Because the IRQL at which the driver runs determines how the floating-point state is saved, the driver must be executing at the same IRQL when it calls the functions to save and to restore the floating-point state. |
| 13 | + |
| 14 | + * @opaqueid CQLD-C28111 |
| 15 | + * @problem.severity warning |
| 16 | + * @precision medium |
| 17 | + * @tags correctness |
| 18 | + * @scope domainspecific |
| 19 | + * @query-version v1 |
| 20 | + */ |
| 21 | + |
| 22 | +import cpp |
| 23 | +import drivers.libraries.Irql |
| 24 | +import semmle.code.cpp.dataflow.new.DataFlow |
| 25 | + |
| 26 | +module FloatStateFlowConfig implements DataFlow::ConfigSig { |
| 27 | + predicate isSource(DataFlow::Node source) { |
| 28 | + exists(FunctionCall fc | |
| 29 | + fc.getTarget().getName().matches("KeSaveFloatingPointState") and |
| 30 | + source.asIndirectExpr() = fc.getArgument(0) |
| 31 | + ) |
| 32 | + } |
| 33 | + |
| 34 | + predicate isSink(DataFlow::Node sink) { |
| 35 | + exists(FunctionCall fc | |
| 36 | + fc.getTarget().getName().matches("KeRestoreFloatingPointState") and |
| 37 | + sink.asIndirectExpr() = fc.getArgument(0) |
| 38 | + ) |
| 39 | + } |
| 40 | +} |
| 41 | + |
| 42 | +module FloatStateFlow = DataFlow::Global<FloatStateFlowConfig>; |
| 43 | + |
| 44 | +from DataFlow::Node source, DataFlow::Node sink, int irqlSink, int irqlSource |
| 45 | +where |
| 46 | + FloatStateFlow::flow(source, sink) and |
| 47 | + irqlSource = getPotentialExitIrqlAtCfn(source.asIndirectExpr()) and |
| 48 | + irqlSink = getPotentialExitIrqlAtCfn(sink.asIndirectExpr()) and |
| 49 | + irqlSink != irqlSource |
| 50 | +select sink.asIndirectExpr(), |
| 51 | + "The irql level where the floating-point state was saved (" + irqlSource + |
| 52 | + ") does not match the irql level for the restore operation (" + irqlSink + ")." |
0 commit comments