OP-TEE4-REE FS0

2019-04-07  本文已影响0人  阿棍儿_Leon

REE File System

这是OP-TEE支持的基本存储形式之一,基本套路就是把信息经过加密存储到一般文件系统上。理论上,骇客只能破坏信息,而不能解密信息。

storage svc

TEE OS是TEE的kernel space,在这里面实现了GP定义的内部接口,secure storage相关的接入在optee_os/core/tee/tee_svc_storage.c里面。从这一层再向下就要区分是REE还是RPMB FS了。
这里有点像Linux kernel的文件系统,下面随便拿一个系统调用的实现看,第一步都是要使用tee_svc_storage_file_ops来获取一个关于operation的结构体,这个就很像Linux kernel里面那些文件系统了,每个文件系统都有一个自己的file operations结构体来定义接口。

TEE_Result syscall_storage_obj_open(unsigned long storage_id, void *object_id,
            size_t object_id_len, unsigned long flags,
            uint32_t *obj)
{
...
    const struct tee_file_operations *fops =
            tee_svc_storage_file_ops(storage_id);
...
}

tee_svc_storage_file_ops这个函数虽然挺长,但是逻辑很简单,只是把对应存储形式的operation结构体实例的地址返回而已。

const struct tee_file_operations *tee_svc_storage_file_ops(uint32_t storage_id)
{

    switch (storage_id) {
    case TEE_STORAGE_PRIVATE:
#if defined(CFG_REE_FS)
        return &ree_fs_ops;
#elif defined(CFG_RPMB_FS)
        return &rpmb_fs_ops;
#else
#error At least one filesystem must be enabled.
#endif
#ifdef CFG_REE_FS
    case TEE_STORAGE_PRIVATE_REE:
        return &ree_fs_ops;
#endif
#ifdef CFG_RPMB_FS
    case TEE_STORAGE_PRIVATE_RPMB:
        return &rpmb_fs_ops;
#endif
    default:
        return NULL;
    }
}

REE FS的实现

ree_fs_ops就定义和operation的实现都在optee_os/core/tee/tee_ree_fs.c里,要研究REE FS加解密的流程,可以研究这个文件。

const struct tee_file_operations ree_fs_ops = {
    .open = ree_fs_open,
    .create = ree_fs_create,
    .close = ree_fs_close,
    .read = ree_fs_read,
    .write = ree_fs_write,
    .truncate = ree_fs_truncate,
    .rename = ree_fs_rename,
    .remove = ree_fs_remove,
    .opendir = ree_fs_opendir_rpc,
    .closedir = ree_fs_closedir_rpc,
    .readdir = ree_fs_readdir_rpc,
};

这个版本的REE FS读写过程我还没吃透,所以先不展开,不过要提醒的是,不要以为数据是直接写下来的。
用户存储数据,会提供一个文件名和一份数据,到了svc这一层,就不只是加密一下直接写一下元数据和用户数据那么简单了。为了达到安全的目的,存储一份数据或这说构造一份加密文件的过程可能会更多次地访问一般文件系统。

上一篇下一篇

猜你喜欢

热点阅读