Skip to content

Commit

Permalink
ubifs: Do not skip hash checking in data nodes
Browse files Browse the repository at this point in the history
UBIFS bails out early from try_read_node() when it doesn't have to check
the CRC. Still the node hash has to be checked, otherwise wrong data
could be sneaked into the FS. Fix this by not bailing out early and
always checking the node hash.

Fixes: 16a26b2 ("ubifs: authentication: Add hashes to index nodes")
Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Signed-off-by: Richard Weinberger <richard@nod.at>
  • Loading branch information
Sascha Hauer authored and Richard Weinberger committed May 7, 2019
1 parent f4844b3 commit e9cd7df
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions fs/ubifs/tnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -479,14 +479,13 @@ static int try_read_node(const struct ubifs_info *c, void *buf, int type,
if (node_len != len)
return 0;

if (type == UBIFS_DATA_NODE && c->no_chk_data_crc && !c->mounting &&
!c->remounting_rw)
return 1;

crc = crc32(UBIFS_CRC32_INIT, buf + 8, node_len - 8);
node_crc = le32_to_cpu(ch->crc);
if (crc != node_crc)
return 0;
if (type != UBIFS_DATA_NODE || !c->no_chk_data_crc || c->mounting ||
c->remounting_rw) {
crc = crc32(UBIFS_CRC32_INIT, buf + 8, node_len - 8);
node_crc = le32_to_cpu(ch->crc);
if (crc != node_crc)
return 0;
}

err = ubifs_node_check_hash(c, buf, zbr->hash);
if (err) {
Expand Down

0 comments on commit e9cd7df

Please sign in to comment.