Skip to content
Permalink
Browse files

fs/nvs: preserve the previous ate searching

Previous ATE searching is accelerate by reading sector
close ate, which allow to skip reading whole storage.

ATE is already covered by crc8. That patch introduce
check on correctness offset read form close ate. This
increases meta-data integrity check level.
This also preserves against possible looping when read
incorrect or not a NVS storage image.

fixes #16899

Signed-off-by: Andrzej Puzdrowski <andrzej.puzdrowski@nordicsemi.no>
  • Loading branch information...
nvlsianpu authored and carlescufi committed Aug 7, 2019
1 parent 5a7a520 commit f42617ad003ab83989f6f4659795aa797c954550
Showing with 12 additions and 5 deletions.
  1. +12 −5 subsys/fs/nvs/nvs.c
@@ -359,12 +359,19 @@ static int nvs_prev_ate(struct nvs_fs *fs, u32_t *addr, struct nvs_ate *ate)
}

if (!nvs_ate_crc8_check(&close_ate)) {
(*addr) &= ADDR_SECT_MASK;
/* update the address so it points to the last added ate */
(*addr) += close_ate.offset;
return 0;
/* update the address so it points to the last added ate.
* do a check on close_ate.offset so that it does not point
* outside a sector and is aligned to ate size.
*/
if (close_ate.offset < (fs->sector_size - ate_size) &&
!(close_ate.offset % ate_size)) {
(*addr) &= ADDR_SECT_MASK;
(*addr) += close_ate.offset;
return 0;
}
}
/* The close_ate had an invalid CRC8, lets find out the last valid ate
/* The close_ate had an invalid CRC8 or the last added ate offset was
* recognized as incorrect, `lets find out the last valid ate
* and point the address to this found ate.
*/
*addr -= ate_size;

0 comments on commit f42617a

Please sign in to comment.
You can’t perform that action at this time.