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 open #310

Open
ArielSAdamsNASA opened this issue Oct 6, 2021 · 1 comment
Open

TOCTOU Bug for open #310

ArielSAdamsNASA opened this issue Oct 6, 2021 · 1 comment
Labels
bug Something isn't working

Comments

@ArielSAdamsNASA
Copy link

Describe the bug
Calling function open that uses "EEPROM.DAT" after a check function. This can cause a time-of-check, time-of-use race condition.

Expected behavior
The most basic advice for TOCTOU vulnerabilities is to not perform a check before the use. Could also use the O_CREAT and O_EXCL flags of POSIX's open() function.
https://cwe.mitre.org/data/definitions/367.html
https://wiki.sei.cmu.edu/confluence/display/c/FIO45-C.+Avoid+TOCTOU+race+conditions+while+accessing+files

Code snips

FileDescriptor = open(EEPROM_FILE, O_RDWR);
if (FileDescriptor == -1)
{
OS_printf("CFE_PSP: Cannot open EEPROM File: %s\n", EEPROM_FILE);
perror("CFE_PSP: open");
return (-1);
}

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

Reporter Info
Ariel Adams, ASRC Federal

@ArielSAdamsNASA ArielSAdamsNASA added the bug Something isn't working label Oct 6, 2021
@skliper
Copy link
Contributor

skliper commented Oct 7, 2021

Could just open w/ O_CREAT, fstat to get the size and lseek/write if it's not EEPROMSize to get the same behavior as currently implemented.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants