diff options
author | Miquel Raynal <miquel.raynal@bootlin.com> | 2022-06-09 16:02:06 +0200 |
---|---|---|
committer | Tom Rini <trini@konsulko.com> | 2022-06-16 15:22:55 -0400 |
commit | 2ac0baab4aff1a0b45067d0b62f00c15f4e86856 (patch) | |
tree | 4d2ecceeb23f7a4e7221cf85c98022cec89d50ce /fs/squashfs | |
parent | e744bf3a4ba442a0e9ee1c509c70e1452e3a15d0 (diff) | |
download | u-boot-2ac0baab4aff1a0b45067d0b62f00c15f4e86856.zip u-boot-2ac0baab4aff1a0b45067d0b62f00c15f4e86856.tar.gz u-boot-2ac0baab4aff1a0b45067d0b62f00c15f4e86856.tar.bz2 |
fs/squashfs: sqfs_read: Prevent arbitrary code execution
Following Jincheng's report, an out-of-band write leading to arbitrary
code execution is possible because on one side the squashfs logic
accepts directory names up to 65535 bytes (u16), while U-Boot fs logic
accepts directory names up to 255 bytes long.
Prevent such an exploit from happening by capping directory name sizes
to 255. Use a define for this purpose so that developers can link the
limitation to its source and eventually kill it some day by dynamically
allocating this array (if ever desired).
Link: https://lore.kernel.org/all/CALO=DHFB+yBoXxVr5KcsK0iFdg+e7ywko4-e+72kjbcS8JBfPw@mail.gmail.com
Reported-by: Jincheng Wang <jc.w4ng@gmail.com>
Signed-off-by: Miquel Raynal <miquel.raynal@bootlin.com>
Tested-by: Jincheng Wang <jc.w4ng@gmail.com>
Diffstat (limited to 'fs/squashfs')
-rw-r--r-- | fs/squashfs/sqfs.c | 8 |
1 files changed, 5 insertions, 3 deletions
diff --git a/fs/squashfs/sqfs.c b/fs/squashfs/sqfs.c index 547d2fd..b9f05ef 100644 --- a/fs/squashfs/sqfs.c +++ b/fs/squashfs/sqfs.c @@ -975,6 +975,7 @@ int sqfs_readdir(struct fs_dir_stream *fs_dirs, struct fs_dirent **dentp) int i_number, offset = 0, ret; struct fs_dirent *dent; unsigned char *ipos; + u16 name_size; dirs = (struct squashfs_dir_stream *)fs_dirs; if (!dirs->size) { @@ -1057,9 +1058,10 @@ int sqfs_readdir(struct fs_dir_stream *fs_dirs, struct fs_dirent **dentp) return -SQFS_STOP_READDIR; } - /* Set entry name */ - strncpy(dent->name, dirs->entry->name, dirs->entry->name_size + 1); - dent->name[dirs->entry->name_size + 1] = '\0'; + /* Set entry name (capped at FS_DIRENT_NAME_LEN which is a U-Boot limitation) */ + name_size = min_t(u16, dirs->entry->name_size + 1, FS_DIRENT_NAME_LEN - 1); + strncpy(dent->name, dirs->entry->name, name_size); + dent->name[name_size] = '\0'; offset = dirs->entry->name_size + 1 + SQFS_ENTRY_BASE_LENGTH; dirs->entry_count--; |