Fix Path Traversal Vulnerabilities (CWE-23) in raw_write.py – Arbitrary file read/write as root#144
Closed
rgfegegeegege wants to merge 2 commits intolinuxmint:masterfrom
Closed
Fix Path Traversal Vulnerabilities (CWE-23) in raw_write.py – Arbitrary file read/write as root#144rgfegegeegege wants to merge 2 commits intolinuxmint:masterfrom
rgfegegeegege wants to merge 2 commits intolinuxmint:masterfrom
Conversation
Author
|
Additional commit: Mitigated potential command injection risk in mountutils.py by changing shell=True to shell=False with list argument. While upstream validation in raw_write.py already prevents malicious target strings from reaching do_umount(), this change follows best practices and eliminates any potential risk (CWE-78). |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes a critical path traversal vulnerability in raw_write.py that allowed arbitrary file read and device overwrite as root when using pkexec.
Vulnerabilities fixed:
Changes:
Full reproducible PoC (original vulnerable behavior):
Create a dummy block device with size:
truncate -s 1G big_dummy.img
sudo losetup -f --show big_dummy.img
... Note the device, e.g. /dev/loop1
Run the vulnerable write:
pkexec python3 /usr/lib/mintstick/raw_write.py -s /etc/passwd -t /dev/loop1
Expected result (vulnerable):
Verify the content was written:
sudo dd if=/dev/loop1 bs=4096 count=10 | strings | head -n 20
→ You will see the lines of /etc/passwd (root:x:0:0:root... etc.)
Cleanup:
sudo losetup -d /dev/loop1
rm big_dummy.img
With this PR applied: the command above will fail with a clear error message ("Invalid source file" or "Source path not allowed"), preventing the read and write.
Tested on Linux Mint with dummy.img and loop devices works as expected with valid .iso files, rejects invalid paths.
Thanks for reviewing