OP-TEE / optee_os

Trusted side of the TEE
Other
1.59k stars 1.07k forks source link

ta: pkcs11: write db_main and db_objs in one operation #6989

Closed weizhaojiang closed 2 months ago

weizhaojiang commented 3 months ago

Problem: There is a potenssial issue in persistent_token.c::init_persistent_db(). There are two steps to initialize a token db if it doesn’t exist:

  1. Call TEE_CreatePersistentObject() with db_main as the initial data.
  2. Truncate the object data and then insert db_obj data. If a power loss occurs between above two steps, only the db_main data is present in the database. When the device restarts, it detects the existing database and successfully reads db_main, but fails to read db_obj, leading to a TA panic each time. https://github.com/OP-TEE/optee_os/issues/6977

Solution: Write both db_main and the initial 4 bytes of db_objs (with a count of 0) in a single operation during TEE_CreatePersistentObject().

Tested-by: Weizhao Jiang weizhaoj@amazon.com

jenswi-linaro commented 3 months ago

The fix looks good to me. @etienne-lms, fine with you too?

weizhaojiang commented 3 months ago

@etienne-lms, please let me know any concern if you have. Thanks.

etienne-lms commented 2 months ago

Looks all good to me.

weizhaojiang commented 2 months ago

thank you!