Skip to content

bug of lfs_cache_zero cause corruption #89

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
nstcl opened this issue Aug 15, 2018 · 1 comment · Fixed by #91
Closed

bug of lfs_cache_zero cause corruption #89

nstcl opened this issue Aug 15, 2018 · 1 comment · Fixed by #91

Comments

@nstcl
Copy link

nstcl commented Aug 15, 2018

The lfs_cache_zero will cause corruption if prog_size != read_size.

static inline void lfs_cache_zero(lfs_t *lfs, lfs_cache_t *pcache) {
    // zero to avoid information leak
    memset(pcache->buffer, 0xff, lfs->cfg->prog_size);
    pcache->block = CACHE_BLOCK_MAGIC;
}

The lfs->cfg->prog_size is error here when prog_size != read_size, especially read_size<prog_size. When read_size<prog_size, the memset function will set part of memory that not belong to it to 0xff, this will cause secrious problem.
I have tested the bug on my board( stm32 + freertos 10.0.1 + littlefs 1.6)

@geky
Copy link
Member

geky commented Aug 23, 2018

Good catch!

I had assumed lfs_cache_zero would only be used on prog caches, then used it for read caches. Here's a fix: #91

In the next major version (#85), the cache sizes will be the same and configured by a separate option.

Thanks for opening the issue!

@geky geky closed this as completed in #91 Sep 4, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants