-
Notifications
You must be signed in to change notification settings - Fork 198
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
Add some validation for remove_job_data in the executor server #468
Conversation
Hi @andygrove @avantgardnerio, could you help review this PR? It's part of #466. |
Why we return errors in this RPC? |
Although currently we do nothing for the result, it's better to know the detailed error which may be helpful for the scheduler to take future actions. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this has a critical vulnerability of allowing deletion of paths outside of the workdir.
info!("Remove data for job {:?}", job_id); | ||
|
||
// Verify whether it's a legal job id | ||
{ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why the redundant scope?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's unnecessary. Just for making the verification steps more clearly
if path.is_dir() { | ||
info!("Remove data for job {:?}", job_id); | ||
std::fs::remove_dir_all(&path)?; | ||
path.push(job_id); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Love the work_dir
subdirectory check... that's the critical vulnerability here.
"Job id should not be empty!!!".to_string(), | ||
)); | ||
} | ||
if job_id.contains('.') { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is to prevent files with extensions? Or parent directories?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's for prevent deleting parent directory. Generally, a directory should not contain '.'
} | ||
|
||
std::fs::remove_dir_all(&path)?; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
According to the docs we have a vulnerability here:
if self has a verbatim prefix (e.g. \\?\C:\windows) and path is not empty, the new path is normalized: all references to . and .. are removed.
I can bypass the .
string check on Windows by doing a \\?
. It is impossible to validate directories at a string level. The missing check is to fully normalize this directory, then check if the normalized directory is a subdirectory of the work_dir
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agree. I'll refine it to use a more standard and robust way for the subdirectory check.
This (downvoted) solution is correct:
|
80483f2
to
6a78684
Compare
6a78684
to
08886aa
Compare
Hi @avantgardnerio, could you help review again for the refined commit? |
Looks great, thank you @yahoNanJing ! |
Thanks @avantgardnerio. Then I'll merge it. |
Which issue does this PR close?
Closes #467.
Rationale for this change
What changes are included in this PR?
Are there any user-facing changes?