diff options
author | Gao Xiang <gaoxiang25@huawei.com> | 2019-06-30 16:45:10 +0800 |
---|---|---|
committer | Gao Xiang <hsiangkao@aol.com> | 2019-08-03 11:18:30 +0800 |
commit | 60128f06617a01ba0435d59df066a94d4a34e700 (patch) | |
tree | f3c51cad82142c304ec91fd09c81fc2eb49cbf7d /lib | |
parent | a40e71017177116bb64513509fe800577a497087 (diff) |
erofs-utils: non-inline tail-end block should be zeroed beyond EOF
Otherwise random data from last bdrop() could be readed and
it will cause unexpected behavior accidentally.
Signed-off-by: Gao Xiang <gaoxiang25@huawei.com>
Diffstat (limited to 'lib')
-rw-r--r-- | lib/cache.c | 2 | ||||
-rw-r--r-- | lib/inode.c | 14 | ||||
-rw-r--r-- | lib/io.c | 6 |
3 files changed, 14 insertions, 8 deletions
diff --git a/lib/cache.c b/lib/cache.c index 76e6d78..4f03cb9 100644 --- a/lib/cache.c +++ b/lib/cache.c @@ -304,7 +304,7 @@ bool erofs_bflush(struct erofs_buffer_block *bb) padding = EROFS_BLKSIZ - p->buffers.off % EROFS_BLKSIZ; if (padding != EROFS_BLKSIZ) dev_fillzero(blknr_to_addr(blkaddr) - padding, - padding); + padding, true); DBG_BUGON(!list_empty(&p->buffers.list)); diff --git a/lib/inode.c b/lib/inode.c index d0b1389..093c78f 100644 --- a/lib/inode.c +++ b/lib/inode.c @@ -537,14 +537,20 @@ int erofs_write_tail_end(struct erofs_inode *inode) ibh->op = &erofs_write_inline_bhops; } else { int ret; + erofs_off_t pos; erofs_mapbh(bh->block, true); - ret = dev_write(inode->idata, - erofs_btell(bh, true) - EROFS_BLKSIZ, - inode->idata_size); + pos = erofs_btell(bh, true) - EROFS_BLKSIZ; + ret = dev_write(inode->idata, pos, inode->idata_size); if (ret) return ret; - + if (inode->idata_size < EROFS_BLKSIZ) { + ret = dev_fillzero(pos + inode->idata_size, + EROFS_BLKSIZ - inode->idata_size, + false); + if (ret) + return ret; + } inode->idata_size = 0; free(inode->idata); inode->idata = NULL; @@ -114,7 +114,7 @@ int dev_write(const void *buf, u64 offset, size_t len) return 0; } -int dev_fillzero(u64 offset, size_t len) +int dev_fillzero(u64 offset, size_t len, bool padding) { static const char zero[EROFS_BLKSIZ] = {0}; int ret; @@ -123,8 +123,8 @@ int dev_fillzero(u64 offset, size_t len) return 0; #if defined(HAVE_FALLOCATE) && defined(FALLOC_FL_PUNCH_HOLE) - if (fallocate(erofs_devfd, FALLOC_FL_PUNCH_HOLE | FALLOC_FL_KEEP_SIZE, - offset, len) >= 0) + if (!padding && fallocate(erofs_devfd, FALLOC_FL_PUNCH_HOLE | + FALLOC_FL_KEEP_SIZE, offset, len) >= 0) return 0; #endif while (len > EROFS_BLKSIZ) { |