User may pass testcases with weird filesnames (e.g. from other fuzzing
engines) which may result in a shell injection via system() calls when
ExecuteCommand() method is called with a bad file path.
Details
Diff Detail
- Repository
- rG LLVM Github Monorepo
Event Timeline
compiler-rt/lib/fuzzer/FuzzerCommand.h | ||
---|---|---|
72 | I certainly think it's not good to have platform-specific thing here, but the other solution I had in mind was to get rid of system(), which would be a significant refactoring. Any other ideas are welcome! |
Thanks!
compiler-rt/lib/fuzzer/FuzzerCommand.h | ||
---|---|---|
72 | Is the branching even necessary what's wrong with doing quotes for both? Also, are we sure this method will catch all cases? What if there are quotes in the name of the file? I think ideally we would replace system with a call that runs a shell command that doesn't have a problem parsing args (e.g. if this were os.system in python I'd replace with subprocess.run), but that may be too much effort. |
compiler-rt/lib/fuzzer/FuzzerCommand.h | ||
---|---|---|
72 | I've started it initially but then it seemed like too much code. Will give another try. | |
72 | It errors out on Windows with single quotes :/ Right, using e.g. execv would be much better, but it feels like too much unnecessary effort at this point. I don't think sane users supply files with weird symbols in names. |
I've split the implementation into platform specific files, but I still don't like it. Plus, as Jonathan mentioned, it still has edge cases e.g. if a filename has a single quote. I'll give a shot at refactoring ExecuteCommand into fork-exec. It looks like I need to re-write only Posix implementation, as Fuchsia is already doing good and Windows is less prone to such issues due to its more restrictive file naming.
So, don't review this yet :)
compiler-rt/lib/fuzzer/FuzzerCommand.h | ||
---|---|---|
175 | oops |
compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp | ||
---|---|---|
41 ↗ | (On Diff #274910) | This isn't quite right. We still want the 2>&1 behavior when there isn't an output file. |
compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp | ||
---|---|---|
41 ↗ | (On Diff #274910) | oops, just noticed that my last uploading got stuck on pre-submit linter -- please see lines 45-46, that case is addressed now too |
My preference would be to reject weird file names instead of adding this extra complexity.
so we'll have a list of allowed (or disallowed) characters and error out if any of the arguments passed do not comply?
compiler-rt/lib/fuzzer/FuzzerUtilLinux.cpp | ||
---|---|---|
42 ↗ | (On Diff #274960) | I thought the same but it didn't seem to work! Will double check again if we decide to proceed with this change. |
Alright, we've ended up disabling that behavior in honggfuzz build, so I'll just close this CL for now.
I certainly think it's not good to have platform-specific thing here, but the other solution I had in mind was to get rid of system(), which would be a significant refactoring.
Any other ideas are welcome!