Skip to content

Commit 9491226

Browse files
committed
fs/iso9660: Require sector-aligned directory sizes
1 parent 89ce18c commit 9491226

File tree

1 file changed

+9
-4
lines changed

1 file changed

+9
-4
lines changed

common/fs/iso9660.s2.c

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,8 +143,10 @@ static void iso9660_cache_root(struct volume *vol,
143143

144144
*root_size = pv.root.extent_size.little;
145145

146-
// Validate root directory size to prevent memory exhaustion
147-
if (*root_size == 0 || *root_size > ISO9660_MAX_DIR_SIZE) {
146+
// Validate root directory size to prevent memory exhaustion, and require
147+
// sector alignment so directory-traversal sector-skip arithmetic is sound.
148+
if (*root_size == 0 || *root_size > ISO9660_MAX_DIR_SIZE
149+
|| *root_size % ISO9660_SECTOR_SIZE != 0) {
148150
panic(false, "ISO9660: Invalid root directory size");
149151
}
150152

@@ -490,8 +492,11 @@ struct file_handle *iso9660_open(struct volume *vol, const char *path) {
490492
pmm_free(current, current_size);
491493
}
492494

493-
// Validate directory size to prevent memory exhaustion
494-
if (next_size == 0 || next_size > ISO9660_MAX_DIR_SIZE) {
495+
// Validate directory size to prevent memory exhaustion, and require
496+
// sector alignment so directory-traversal sector-skip arithmetic is
497+
// sound.
498+
if (next_size == 0 || next_size > ISO9660_MAX_DIR_SIZE
499+
|| next_size % ISO9660_SECTOR_SIZE != 0) {
495500
pmm_free(ret, sizeof(struct iso9660_file_handle));
496501
return NULL;
497502
}

0 commit comments

Comments
 (0)