xfs: validate transaction header length on log recovery
authorBrian Foster <bfoster@redhat.com>
Wed, 29 Jul 2015 01:51:10 +0000 (11:51 +1000)
committerDave Chinner <david@fromorbit.com>
Wed, 29 Jul 2015 01:51:10 +0000 (11:51 +1000)
commit89cebc8477290b152618ffa110bbeae340d50900
treee17344fbade906bd6fc6f2831770fec66e586db6
parent4703da7b78776140477a023c99683d3be84b7fca
xfs: validate transaction header length on log recovery

When log recovery hits a new transaction, it copies the transaction
header from the expected location in the log to the in-core structure
using the length from the op record header. This length is validated to
ensure it doesn't exceed the length of the record, but not against the
expected size of a transaction header (and thus the size of the in-core
structure). If the on-disk length is corrupted, the associated memcpy()
can overflow, write to unrelated memory and lead to crashes. This has
been reproduced via filesystem fuzzing.

The code currently handles the possibility that the transaction header
is split across two op records. Neither instance accounts for corruption
where the op record length might be larger than the in-core transaction
header. Update both sites to detect such corruption, warn and return an
error from log recovery. Also add some comments and assert that if the
record is split, the copy of the second portion is less than a full
header. Otherwise, this suggests the copy of the second portion could
have overwritten bits from the first and thus that something could be
wrong.

Signed-off-by: Brian Foster <bfoster@redhat.com>
Reviewed-by: Dave Chinner <dchinner@redhat.com>
Signed-off-by: Dave Chinner <david@fromorbit.com>
fs/xfs/xfs_log_recover.c