Skip to content

Commit 4476dc6

Browse files
vegardsashalevin
authored andcommitted
udf: limit the maximum number of indirect extents in a row
[ Upstream commit b0918d9 ] udf_next_aext() just follows extent pointers while extents are marked as indirect. This can loop forever for corrupted filesystem. Limit number the of indirect extents we are willing to follow in a row. [JK: Updated changelog, limit, style] Signed-off-by: Vegard Nossum <[email protected]> Cc: [email protected] Cc: Jan Kara <[email protected]> Cc: Quentin Casasnovas <[email protected]> Cc: Andrew Morton <[email protected]> Signed-off-by: Jan Kara <[email protected]> Signed-off-by: Sasha Levin <[email protected]>
1 parent a2da01c commit 4476dc6

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

fs/udf/inode.c

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2052,14 +2052,29 @@ void udf_write_aext(struct inode *inode, struct extent_position *epos,
20522052
epos->offset += adsize;
20532053
}
20542054

2055+
/*
2056+
* Only 1 indirect extent in a row really makes sense but allow upto 16 in case
2057+
* someone does some weird stuff.
2058+
*/
2059+
#define UDF_MAX_INDIR_EXTS 16
2060+
20552061
int8_t udf_next_aext(struct inode *inode, struct extent_position *epos,
20562062
struct kernel_lb_addr *eloc, uint32_t *elen, int inc)
20572063
{
20582064
int8_t etype;
2065+
unsigned int indirections = 0;
20592066

20602067
while ((etype = udf_current_aext(inode, epos, eloc, elen, inc)) ==
20612068
(EXT_NEXT_EXTENT_ALLOCDECS >> 30)) {
20622069
int block;
2070+
2071+
if (++indirections > UDF_MAX_INDIR_EXTS) {
2072+
udf_err(inode->i_sb,
2073+
"too many indirect extents in inode %lu\n",
2074+
inode->i_ino);
2075+
return -1;
2076+
}
2077+
20632078
epos->block = *eloc;
20642079
epos->offset = sizeof(struct allocExtDesc);
20652080
brelse(epos->bh);

0 commit comments

Comments
 (0)