Skip to content

Commit 3419284

Browse files
committed
Fixed issue with corruption due to different cache sizes
The lfs_cache_zero function that was recently added assumed a single cache size, which is incorrect. This would cause a buffer overflow if read_size != prog_size. Since lfs_cache_zero is only used for scrubbing prog caches, the fix here is to use lfs_cache_drop instead on read caches. Info in read caches should never make its way to disk. Found by nstcl
1 parent 510cd13 commit 3419284

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

lfs.c

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1373,7 +1373,10 @@ int lfs_file_opencfg(lfs_t *lfs, lfs_file_t *file,
13731373
}
13741374

13751375
// zero to avoid information leak
1376-
lfs_cache_zero(lfs, &file->cache);
1376+
lfs_cache_drop(lfs, &file->cache);
1377+
if ((file->flags & 3) != LFS_O_RDONLY) {
1378+
lfs_cache_zero(lfs, &file->cache);
1379+
}
13771380

13781381
// add to list of files
13791382
file->next = lfs->files;
@@ -2055,8 +2058,8 @@ static int lfs_init(lfs_t *lfs, const struct lfs_config *cfg) {
20552058
}
20562059

20572060
// zero to avoid information leaks
2058-
lfs_cache_zero(lfs, &lfs->rcache);
20592061
lfs_cache_zero(lfs, &lfs->pcache);
2062+
lfs_cache_drop(lfs, &lfs->rcache);
20602063

20612064
// setup lookahead, round down to nearest 32-bits
20622065
LFS_ASSERT(lfs->cfg->lookahead % 32 == 0);

0 commit comments

Comments
 (0)