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)系作者
  • 序言:七十年代末,一起剝皮案震驚了整個(gè)濱河市单鹿,隨后出現(xiàn)的幾起案子望艺,更是在濱河造成了極大的恐慌跺涤,老刑警劉巖匾旭,帶你破解...
    沈念sama閱讀 211,265評(píng)論 6 490
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件,死亡現(xiàn)場離奇詭異虽填,居然都是意外死亡,警方通過查閱死者的電腦和手機(jī)蔬咬,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 90,078評(píng)論 2 385
  • 文/潘曉璐 我一進(jìn)店門,熙熙樓的掌柜王于貴愁眉苦臉地迎上來沐寺,“玉大人林艘,你說我怎么就攤上這事』煳耄” “怎么了狐援?”我有些...
    開封第一講書人閱讀 156,852評(píng)論 0 347
  • 文/不壞的土叔 我叫張陵,是天一觀的道長究孕。 經(jīng)常有香客問我啥酱,道長,這世上最難降的妖魔是什么厨诸? 我笑而不...
    開封第一講書人閱讀 56,408評(píng)論 1 283
  • 正文 為了忘掉前任镶殷,我火速辦了婚禮,結(jié)果婚禮上微酬,老公的妹妹穿的比我還像新娘绘趋。我一直安慰自己,他們只是感情好颗管,可當(dāng)我...
    茶點(diǎn)故事閱讀 65,445評(píng)論 5 384
  • 文/花漫 我一把揭開白布陷遮。 她就那樣靜靜地躺著,像睡著了一般忙上。 火紅的嫁衣襯著肌膚如雪拷呆。 梳的紋絲不亂的頭發(fā)上,一...
    開封第一講書人閱讀 49,772評(píng)論 1 290
  • 那天疫粥,我揣著相機(jī)與錄音茬斧,去河邊找鬼。 笑死梗逮,一個(gè)胖子當(dāng)著我的面吹牛项秉,可吹牛的內(nèi)容都是我干的。 我是一名探鬼主播慷彤,決...
    沈念sama閱讀 38,921評(píng)論 3 406
  • 文/蒼蘭香墨 我猛地睜開眼娄蔼,長吁一口氣:“原來是場噩夢啊……” “哼!你這毒婦竟也來了底哗?” 一聲冷哼從身側(cè)響起岁诉,我...
    開封第一講書人閱讀 37,688評(píng)論 0 266
  • 序言:老撾萬榮一對(duì)情侶失蹤,失蹤者是張志新(化名)和其女友劉穎跋选,沒想到半個(gè)月后涕癣,有當(dāng)?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體,經(jīng)...
    沈念sama閱讀 44,130評(píng)論 1 303
  • 正文 獨(dú)居荒郊野嶺守林人離奇死亡前标,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點(diǎn)故事閱讀 36,467評(píng)論 2 325
  • 正文 我和宋清朗相戀三年坠韩,在試婚紗的時(shí)候發(fā)現(xiàn)自己被綠了距潘。 大學(xué)時(shí)的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點(diǎn)故事閱讀 38,617評(píng)論 1 340
  • 序言:一個(gè)原本活蹦亂跳的男人離奇死亡只搁,死狀恐怖音比,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情氢惋,我是刑警寧澤洞翩,帶...
    沈念sama閱讀 34,276評(píng)論 4 329
  • 正文 年R本政府宣布,位于F島的核電站明肮,受9級(jí)特大地震影響菱农,放射性物質(zhì)發(fā)生泄漏缭付。R本人自食惡果不足惜柿估,卻給世界環(huán)境...
    茶點(diǎn)故事閱讀 39,882評(píng)論 3 312
  • 文/蒙蒙 一、第九天 我趴在偏房一處隱蔽的房頂上張望陷猫。 院中可真熱鬧秫舌,春花似錦、人聲如沸绣檬。這莊子的主人今日做“春日...
    開封第一講書人閱讀 30,740評(píng)論 0 21
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽娇未。三九已至墨缘,卻和暖如春,著一層夾襖步出監(jiān)牢的瞬間零抬,已是汗流浹背镊讼。 一陣腳步聲響...
    開封第一講書人閱讀 31,967評(píng)論 1 265
  • 我被黑心中介騙來泰國打工, 沒想到剛下飛機(jī)就差點(diǎn)兒被人妖公主榨干…… 1. 我叫王不留平夜,地道東北人蝶棋。 一個(gè)月前我還...
    沈念sama閱讀 46,315評(píng)論 2 360
  • 正文 我出身青樓,卻偏偏與公主長得像忽妒,于是被迫代替她去往敵國和親玩裙。 傳聞我的和親對(duì)象是個(gè)殘疾皇子,可洞房花燭夜當(dāng)晚...
    茶點(diǎn)故事閱讀 43,486評(píng)論 2 348

推薦閱讀更多精彩內(nèi)容