Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

TOCTOU Bug for chmod #1175

Closed
ArielSAdamsNASA opened this issue Oct 5, 2021 · 1 comment · Fixed by #1181
Closed

TOCTOU Bug for chmod #1175

ArielSAdamsNASA opened this issue Oct 5, 2021 · 1 comment · Fixed by #1181

Comments

@ArielSAdamsNASA
Copy link
Contributor

Describe the bug
Calling function chmod that uses Filename after a check function. This can cause a time-of-check, time-of-use race condition.

Expected behavior
Use fchmod as seen in OS_FileChmod_Impl.

Code snips

if ((fp = fopen(Filename, "w")))
{
if (stat(Filename, &dststat) == 0)
{
chmod(Filename, dststat.st_mode & ~(S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH));
stat(Filename, &dststat);
}

if ((fp = fopen(Filename, "w")))
{
if (stat(Filename, &dststat) == 0)
{
chmod(Filename, dststat.st_mode & ~(S_IRGRP | S_IWGRP | S_IXGRP | S_IROTH | S_IWOTH | S_IXOTH));
stat(Filename, &dststat);
}

System observed on:
Coverity: https://scan.coverity.com/projects/arielsadamsnasa-cfs-jsf-rules?tab=overview

Reporter Info
Ariel Adams, ASRC Federal

@skliper
Copy link
Contributor

skliper commented Oct 7, 2021

Could change to fstat and fchmod.

ArielSAdamsNASA pushed a commit to ArielSAdamsNASA/osal that referenced this issue Oct 13, 2021
ArielSAdamsNASA pushed a commit to ArielSAdamsNASA/osal that referenced this issue Oct 13, 2021
ArielSAdamsNASA pushed a commit to ArielSAdamsNASA/osal that referenced this issue Oct 13, 2021
ArielSAdamsNASA pushed a commit to ArielSAdamsNASA/osal that referenced this issue Oct 13, 2021
ArielSAdamsNASA pushed a commit to ArielSAdamsNASA/osal that referenced this issue Oct 13, 2021
ArielSAdamsNASA pushed a commit to ArielSAdamsNASA/osal that referenced this issue Oct 19, 2021
ArielSAdamsNASA pushed a commit to ArielSAdamsNASA/osal that referenced this issue Oct 19, 2021
ArielSAdamsNASA pushed a commit to ArielSAdamsNASA/osal that referenced this issue Oct 19, 2021
ArielSAdamsNASA pushed a commit to ArielSAdamsNASA/osal that referenced this issue Oct 19, 2021
jphickey pushed a commit to jphickey/osal that referenced this issue Aug 10, 2022
dzbaker added a commit that referenced this issue Oct 3, 2022
@dzbaker dzbaker closed this as completed in 9157b78 Oct 3, 2022
@chillfig chillfig added this to the Draco milestone Feb 7, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants