Skip to content

Commit

Permalink
Avoid redundantly validating symbolic link names
Browse files Browse the repository at this point in the history
qubes_pure_validate_symbolic_link() validates both the symlink path and
target, so validating the path with a separate
qubes_pure_validate_file_name() call is unnecessary.

(cherry picked from commit 2a0da19)
  • Loading branch information
DemiMarie authored and marmarek committed Jun 22, 2024
1 parent 8db9b67 commit be7940c
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
3 changes: 1 addition & 2 deletions qrexec-lib/unpack.c
Original file line number Diff line number Diff line change
Expand Up @@ -298,8 +298,6 @@ static void process_one_file_link(struct file_header *untrusted_hdr,
const char *last_segment;
char *path_dup;
unsigned int filelen;
if (!qubes_pure_validate_file_name((const uint8_t *)untrusted_name))
do_exit(EILSEQ, untrusted_name); /* FIXME: better error message */
int safe_dirfd;
if (untrusted_hdr->filelen > MAX_PATH_LENGTH - 1)
do_exit(ENAMETOOLONG, untrusted_name);
Expand All @@ -312,6 +310,7 @@ static void process_one_file_link(struct file_header *untrusted_hdr,
do_exit(LEGAL_EOF, untrusted_name); // hopefully remote has produced error message
untrusted_content[filelen] = 0;
/*
* Sanitize both the path of the symbolic link and its target.
* Ensure that no immediate subdirectory of ~/QubesIncoming/VMNAME
* may have symlinks that point out of it.
*/
Expand Down
2 changes: 2 additions & 0 deletions qrexec-lib/validator-test.c
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,8 @@ int main(int argc, char **argv)
assert(qubes_pure_validate_symbolic_link((const uint8_t *)"a/b/c", (const uint8_t *)".."));
// Symlinks may end in "/".
assert(qubes_pure_validate_symbolic_link((const uint8_t *)"a/b/c", (const uint8_t *)"a/"));
// Symlinks reject invalid paths.
assert(!qubes_pure_validate_symbolic_link((const uint8_t *)"..", (const uint8_t *)"a/"));

// Greek letters are safe
assert(qubes_pure_validate_file_name((uint8_t *)u8"\u03b2.txt"));
Expand Down

0 comments on commit be7940c

Please sign in to comment.