Skip to content

Commit

Permalink
storage: REE fs: make sure dirty flag is set when object is truncated
Browse files Browse the repository at this point in the history
When an object is truncated but the number of blocks is unchanged, only
the metadata's length field is modified. The hash tree layer has to be
notified so that it knows it has to flush the data before closing the
object, otherwise the truncation is lost.
Add a function for that purpose: tee_fs_htree_meta_set_dirty(), and
call it whenever meta->length is updated.

Fixes: OP-TEE#2094
Reported-by: Kevin Peng <[email protected]>
Signed-off-by: Jerome Forissier <[email protected]>
  • Loading branch information
jforissier committed Jan 25, 2018
1 parent 047c1d0 commit a4834b5
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 1 deletion.
5 changes: 5 additions & 0 deletions core/include/tee/fs_htree.h
Original file line number Diff line number Diff line change
Expand Up @@ -125,6 +125,11 @@ void tee_fs_htree_close(struct tee_fs_htree **ht);
*/
struct tee_fs_htree_meta *tee_fs_htree_get_meta(struct tee_fs_htree *ht);

/**
* tee_fs_htree_meta_set_dirty() - tell hash tree that meta were modified
*/
void tee_fs_htree_meta_set_dirty(struct tee_fs_htree *ht);

/**
* tee_fs_htree_sync_to_storage() - synchronize hash tree to storage
* @ht: hash tree
Expand Down
5 changes: 5 additions & 0 deletions core/tee/fs_htree.c
Original file line number Diff line number Diff line change
Expand Up @@ -667,6 +667,11 @@ struct tee_fs_htree_meta *tee_fs_htree_get_meta(struct tee_fs_htree *ht)
return &ht->imeta.meta;
}

void tee_fs_htree_meta_set_dirty(struct tee_fs_htree *ht)
{
ht->dirty = true;
}

static TEE_Result free_node(struct traverse_arg *targ __unused,
struct htree_node *node)
{
Expand Down
5 changes: 4 additions & 1 deletion core/tee/tee_ree_fs.c
Original file line number Diff line number Diff line change
Expand Up @@ -99,8 +99,10 @@ static TEE_Result out_of_place_write(struct tee_fs_fd *fdp, size_t pos,
pos += size_to_write;
}

if (pos > meta->length)
if (pos > meta->length) {
meta->length = pos;
tee_fs_htree_meta_set_dirty(fdp->ht);
}

exit:
free(block);
Expand Down Expand Up @@ -267,6 +269,7 @@ static TEE_Result ree_fs_ftruncate_internal(struct tee_fs_fd *fdp,
return res;

meta->length = new_file_len;
tee_fs_htree_meta_set_dirty(fdp->ht);
}

return TEE_SUCCESS;
Expand Down

0 comments on commit a4834b5

Please sign in to comment.