CWE-560
Weakness AllowedUse of umask() with chmod-style Argument
Abstraction: Variant · Status: Draft
The product calls umask() with an incorrect argument that is specified as if it is an argument to chmod().
Mapping guidance
This CWE entry is at the Variant level of abstraction, which is a preferred level of abstraction for mapping to the root causes of vulnerabilities.
Carefully read both the name and description to ensure that this mapping is an appropriate fit. Do not try to 'force' a mapping to a lower-level Base/Variant simply to comply with this preferred level of abstraction.
Modes of introduction
Detection methods
Automated Static Analysis
If you suspect misuse of umask(), you can use grep to spot call instances of umask().
Notes
Other
Some umask() manual pages begin with the false statement: "umask sets the umask to mask & 0777" Although this behavior would better align with the usage of chmod(), where the user provided argument specifies the bits to enable on the specified file, the behavior of umask() is in fact opposite: umask() sets the umask to ~mask & 0777. The documentation goes on to describe the correct usage of umask(): "The umask is used by open() to set initial file permissions on a newly-created file. Specifically, permissions in the umask are turned off from the mode argument to open(2) (so, for example, the common umask default value of 022 results in new files being created with permissions 0666 & ~022 = 0644 = rw-r--r-- in the usual case where the mode is specified as 0666)."
Content history
updated Potential_Mitigations
updated Relationships, Other_Notes, Taxonomy_Mappings
updated Common_Consequences
updated Relationships
updated Potential_Mitigations
updated Relationships
updated Taxonomy_Mappings
updated Relationships
updated Other_Notes
updated Relationships
updated Mapping_Notes
updated Detection_Factors, Potential_Mitigations, Weakness_Ordinalities
0 vulnerabilities reference this CWE, most recent first.
No vulnerabilities reference this CWE.
Mitigation
Use umask() with the correct argument.
No CAPEC attack patterns related to this CWE.