-
Notifications
You must be signed in to change notification settings - Fork 191
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Unsquashfs: fix write outside destination directory exploit
An issue on Github (#72) shows how some specially crafted Squashfs filesystems containing invalid file names (with '/' and ..) can cause Unsquashfs to write files outside of the destination directory. This commit fixes this exploit by checking all names for validity. In doing so I have also added checks for '.' and for names that are shorter than they should be (names in the file system should not have '\0' terminators). Signed-off-by: Phillip Lougher <phillip@squashfs.org.uk>
- Loading branch information
Showing
8 changed files
with
99 additions
and
7 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* | ||
* Unsquash a squashfs filesystem. This is a highly compressed read only | ||
* filesystem. | ||
* | ||
* Copyright (c) 2021 | ||
* Phillip Lougher <phillip@squashfs.org.uk> | ||
* | ||
* This program is free software; you can redistribute it and/or | ||
* modify it under the terms of the GNU General Public License | ||
* as published by the Free Software Foundation; either version 2, | ||
* or (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program; if not, write to the Free Software | ||
* Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. | ||
* | ||
* unsquash-1234.c | ||
* | ||
* Helper functions used by unsquash-1, unsquash-2, unsquash-3 and | ||
* unsquash-4. | ||
*/ | ||
|
||
#define TRUE 1 | ||
#define FALSE 0 | ||
/* | ||
* Check name for validity, name should not | ||
* - be ".", "./", or | ||
* - be "..", "../" or | ||
* - have a "/" anywhere in the name, or | ||
* - be shorter than the expected size | ||
*/ | ||
int check_name(char *name, int size) | ||
{ | ||
char *start = name; | ||
|
||
if(name[0] == '.') { | ||
if(name[1] == '.') | ||
name++; | ||
if(name[1] == '/' || name[1] == '\0') | ||
return FALSE; | ||
} | ||
|
||
while(name[0] != '/' && name[0] != '\0') | ||
name ++; | ||
|
||
if(name[0] == '/') | ||
return FALSE; | ||
|
||
if((name - start) != size) | ||
return FALSE; | ||
|
||
return TRUE; | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
This file contains 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