Commit 41ba2abbb3ce394c208fe509438a4691d588ad94

Authored by Jan Kara
Committed by Greg Kroah-Hartman
1 parent 53fbe4cb77

udf: Check component length before reading it

commit e237ec37ec154564f8690c5bd1795339955eeef9 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: Carl Henrik Lunde <chlunde@ping.uio.no>
Signed-off-by: Jan Kara <jack@suse.cz>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>

Showing 1 changed file with 7 additions and 2 deletions Side-by-side Diff

... ... @@ -42,14 +42,17 @@
42 42 tolen--;
43 43 while (elen < fromlen) {
44 44 pc = (struct pathComponent *)(from + elen);
  45 + elen += sizeof(struct pathComponent);
45 46 switch (pc->componentType) {
46 47 case 1:
47 48 /*
48 49 * Symlink points to some place which should be agreed
49 50 * upon between originator and receiver of the media. Ignore.
50 51 */
51   - if (pc->lengthComponentIdent > 0)
  52 + if (pc->lengthComponentIdent > 0) {
  53 + elen += pc->lengthComponentIdent;
52 54 break;
  55 + }
53 56 /* Fall through */
54 57 case 2:
55 58 if (tolen == 0)
... ... @@ -74,6 +77,9 @@
74 77 /* that would be . - just ignore */
75 78 break;
76 79 case 5:
  80 + elen += pc->lengthComponentIdent;
  81 + if (elen > fromlen)
  82 + return -EIO;
77 83 comp_len = udf_get_filename(sb, pc->componentIdent,
78 84 pc->lengthComponentIdent,
79 85 p, tolen);
... ... @@ -85,7 +91,6 @@
85 91 tolen--;
86 92 break;
87 93 }
88   - elen += sizeof(struct pathComponent) + pc->lengthComponentIdent;
89 94 }
90 95 if (p > to + 1)
91 96 p[-1] = '\0';