OP-TEE6-REE FS文件存儲(chǔ)方式變化

Since commit 874a9121e40df114d850c918e5e240f2, the file structure of optee secure store REE FS has changed. The tag 2.5.0-rc1 (or later) includes this change.

Basic knowledge

  • block size = 4096B = 4KB
    The data to be encrypted is devided into blocks firstly, and the encryption and decryption is executed block by block.
  • dual version
    There are always two versions of encrypted blocks after second writing. One is current version, and the other one is the last version.

Before 2.5.0-rc1

Files in REE side

A file of a TA is represented in following form:

<TEE Path>
|--<TA uuid>
   |--<object id>
      |--meta.0 or meta.1
      |--block0.0
      |--block0.1
      |--block1.0
      |--block1.1
      |--...
      |--blockN.0
      |--blockN.1

The path /data/tee is often used as TEE Path.
object id is a series of hex number, which is output of coverting TA file name. The convertion function is tee_b2hs.

  • blockX.Y file
    As is mentioned above, every block saves 4KB data. The file with name blockX.Y is a block with index X and version Y.
  • meta.* file
    Every time the data is changed, the meta.* file will alternate. For example, if meta.0 exists at first, it will be deleted and meta.1 will be created after data was updated.

From TA file to REE file

Here is an example that a TA file updates partially.
Because block 0 (0~4095B) has no change, there's nothing to do about block 0. So do block0.0 and block0.1. And for block 1, current version is 0, so block1.0 is unchanged too.
4096~6144B is in block 1, so the updated block is encrypted into another version (ver 1) of block (block 1). After that current version is changed from 0 to 1, and this is revorded in the new meta file.


from date to file

Since 2.5.0-rc1

files in REE side

Secure file in REE side is represented in following form:

<TEE Path>/
|--dirf.db
|--0
|--1
|--...
|--N

dirf.db is a special file, which only saves information of other TA files and doesn't save any TA file data. And every file else saves a file of a TA.


mapping between TA data and REE file

Hash Tree

Hash tree is a data structure, which saves encrypted data and meta data. It's a complete binary tree.


hash tree

So it's easy to imagine that there should be at least three types of data structures. The first one saves information about the whole tree, the second one saves information about a node, and the third one saves data corresponding to nodes.

Information type data structure type
tree info struct tee_fs_htree_image
node info struct tee_fs_htree_node_image
node data just bytes

From TA file to REE file

First physical block
File offset(B)
S=sizeof(struct tee_fs_htree_image)
Version Content
0 0 hash tree image version 【0】
S 1 hash tree image version 【1】
2S - no data

The (63n+1, n=0,1,2...) block saves node images.

block offset(B)
S=sizeof(struct tee_fs_htree_node_image)
Index Version Content
(2(N mod 63)+V)S N V
(V=0,1)
node 【N】 version 【V】

The (63(n+1)-m, n=0,1,2..., m=0,1...61) block saves node data.

physical block index data type
0 tree block
1 node block 1~31
2~63 data block 2~31
64 node block 32~62
65~126 data block 32~62
... ...

The struct tee_fs_htree_image isn't shown in the following picture.

from data to file

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容