Tainted source used with sensitive function
Data obtained from an untrusted source is passed to user-defined sensitive function
Since R2023b
Description
This defect occurs when data obtained from an untrusted source is passed to a sensitive function.
Untrusted sources include data obtained from:
Functions that read user input such as
getenv()
,gets()
,read()
,scanf()
, orfopen()
. For more information, see Sources of Tainting in a Polyspace Analysis.Functions that you explicitly define as untrusted. See Extend Checker.
For this checker, you have to explicitly define functions that must be considered as sensitive. See Extend Checker.
Risk
If you pass untrusted data to a sensitive function without validating and cleaning up (sanitizing) the data, an attacker can pass malicious data to perform tasks other than what the function is supposed to do. Such attacks can gain access to secured resources, or trigger data corruption or system failures.
Fix
Perform appropriate validation and sanitization on untrusted data before passing the data to a sensitive function. To prevent the checker from flagging sanitized data, specify your sanitization function to the analysis.
Extend Checker
For the checker to report defects as expected, you have to specify the following in a checker definition file:
Untrusted sources (optional)
Sensitive function (mandatory)
Sanitization function (mandatory)
Suppose that you want to specify the following information:
The return value of the function
getResponse()
is untrusted.The function
changeSystemState()
is a sensitive function that is vulnerable to attacks via its
-th argument.n_sensitive
The function
ensureSafeResponse()
takes a pointer input as its
-th argument and sanitizes the data that the input points to.n_sanitize
To create a checker with this information:
In a file with extension
.dl
, add this code:.include "models/interfaces/tainted_source_use_custom.dl" .include "pql/checkers/tainted_source_use_custom_impl.dl" .comp checkerConfig : CustomTainted { Basic.taintSource("getResponse",$OutReturnValue(),"Data from getResponse() is tainted."). Basic.sensitive("changeSystemState",$InParameterValue(n_sensitive-1),"changeSystemState() must not use tainted data."). Basic.sanitizing("ensureSafeResponse",$OutParameterDeref(n_sanitize-1)). } .init customTaintedChecker = tainted_source_use_custom<checkerConfig>
If
andn_sensitive
are both 1 (that is, the first parameters of each function are the parameters of interest), then the statements become:n_sanitize
.include "models/interfaces/tainted_source_use_custom.dl" .include "pql/checkers/tainted_source_use_custom_impl.dl" .comp checkerConfig : CustomTainted { Basic.taintSource("getResponse",$OutReturnValue(),"Data from getResponse() is tainted."). Basic.sensitive("changeSystemState",$InParameterValue(0),"changeSystemState() must not use tainted data."). Basic.sanitizing("ensureSafeResponse",$OutParameterDeref(0)). } .init customTaintedChecker = tainted_source_use_custom<checkerConfig>
Specify this file using the option
-create-checkers
. For instance, if the file is namedtaintSourcesAndSinks.dl
, use the analysis option when enabling the checker:-create-checkers taintSourcesAndSinks.dl -checkers TAINTED_SOURCE_USE_CUSTOM
Examples
Result Information
Group: Tainted Data |
Language: C | C++ |
Default: Off |
Command-Line Syntax: TAINTED_SOURCE_USE_CUSTOM |
Impact: High |
Version History
Introduced in R2023b
See Also
Find defects (-checkers)
| -create-checkers
Topics
- Interpret Bug Finder Results in Polyspace Desktop User Interface
- Interpret Bug Finder Results in Polyspace Access Web Interface (Polyspace Access)
- Address Results in Polyspace User Interface Through Bug Fixes or Justifications
- Address Results in Polyspace Access Through Bug Fixes or Justifications (Polyspace Access)
- Sources of Tainting in a Polyspace Analysis
- Modify Default Behavior of Bug Finder Checkers