Commit 1e21fa3a authored by Jan Kara's avatar Jan Kara Committed by Ben Hutchings

udf: Check component length before reading it

commit e237ec37 upstream.

Check that length specified in a component of a symlink fits in the
input buffer we are reading. Also properly ignore component length for
component types that do not use it. Otherwise we read memory after end
of buffer for corrupted udf image.
Reported-by: default avatarCarl Henrik Lunde <chlunde@ping.uio.no>
Signed-off-by: default avatarJan Kara <jack@suse.cz>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent ba405517
...@@ -42,14 +42,17 @@ static int udf_pc_to_char(struct super_block *sb, unsigned char *from, ...@@ -42,14 +42,17 @@ static int udf_pc_to_char(struct super_block *sb, unsigned char *from,
tolen--; tolen--;
while (elen < fromlen) { while (elen < fromlen) {
pc = (struct pathComponent *)(from + elen); pc = (struct pathComponent *)(from + elen);
elen += sizeof(struct pathComponent);
switch (pc->componentType) { switch (pc->componentType) {
case 1: case 1:
/* /*
* Symlink points to some place which should be agreed * Symlink points to some place which should be agreed
* upon between originator and receiver of the media. Ignore. * upon between originator and receiver of the media. Ignore.
*/ */
if (pc->lengthComponentIdent > 0) if (pc->lengthComponentIdent > 0) {
elen += pc->lengthComponentIdent;
break; break;
}
/* Fall through */ /* Fall through */
case 2: case 2:
if (tolen == 0) if (tolen == 0)
...@@ -74,6 +77,9 @@ static int udf_pc_to_char(struct super_block *sb, unsigned char *from, ...@@ -74,6 +77,9 @@ static int udf_pc_to_char(struct super_block *sb, unsigned char *from,
/* that would be . - just ignore */ /* that would be . - just ignore */
break; break;
case 5: case 5:
elen += pc->lengthComponentIdent;
if (elen > fromlen)
return -EIO;
comp_len = udf_get_filename(sb, pc->componentIdent, comp_len = udf_get_filename(sb, pc->componentIdent,
pc->lengthComponentIdent, pc->lengthComponentIdent,
p, tolen); p, tolen);
...@@ -85,7 +91,6 @@ static int udf_pc_to_char(struct super_block *sb, unsigned char *from, ...@@ -85,7 +91,6 @@ static int udf_pc_to_char(struct super_block *sb, unsigned char *from,
tolen--; tolen--;
break; break;
} }
elen += sizeof(struct pathComponent) + pc->lengthComponentIdent;
} }
if (p > to + 1) if (p > to + 1)
p[-1] = '\0'; p[-1] = '\0';
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment