Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

secure storage: update head message when info->dataSize update #1217

Closed
wants to merge 1 commit into from

Conversation

lackan
Copy link

@lackan lackan commented Dec 5, 2016

When one invokes TEE_WriteObjectData and write some data into the secure storage file, the data size of the file may change, but currently it will not update the head message in persistent objects. This commit will fix this problem by updating head message when info->dataSize update.

Relates to:
#814
Output:(test on FVP)

Object data size : 50 and position : 50
Object data size : 50 and position : 0

Test for xtest have add to OP-TEE/optee_test#151

Signed-off-by: Guanchao Liang [email protected]
Reviewed-by: Joakim Bech [email protected]
Reviewed-by: Jens Wiklander [email protected]

res = fops->read(o->fh, &head, &bytes);
if (res != TEE_SUCCESS) {
if (res == TEE_ERROR_CORRUPT_OBJECT)
EMSG("Head corrupt.\n");
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

\n not needed.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@jbech-linaro
Copy link
Contributor

With or without my comment fixed.
Reviewed-by: Joakim Bech <[email protected]>


/* read head */
bytes = sizeof(struct tee_svc_storage_head);
res = fops->read(o->fh, &head, &bytes);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You could skip the read step if you'd only update the position field in the file.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But should we assert that head.magic == TEE_SVC_STORAGE_MAGIC? If not need, I think we can skip the read step.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we're good without that assert.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

@lackan lackan force-pushed the fix-persistent-objects branch from 106c48e to bf93c00 Compare December 6, 2016 08:24
@@ -1069,8 +1098,10 @@ TEE_Result syscall_storage_obj_write(unsigned long obj, void *data, size_t len)
goto exit;

o->info.dataPosition += len;
if (o->info.dataPosition > o->info.dataSize)
if (o->info.dataPosition > o->info.dataSize) {
o->info.dataSize = o->info.dataPosition;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

update dataPosition and dataSize only if successfully updated the head ?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch!

@@ -1069,8 +1097,12 @@ TEE_Result syscall_storage_obj_write(unsigned long obj, void *data, size_t len)
goto exit;

o->info.dataPosition += len;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't think this should be updated if we can't update head below.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But the write operation have overwrote the data, the data position actually have changed? So we ignore this overwrite?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmm, this is actually a problem with the way we're layering this. The update in the lower layer is already committed and what we would need now is unrolling it. This problem is out of scope of this P-R so please ignore my previous comment for now.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK, so I just keep it as now.

@jforissier
Copy link
Contributor

@lackan did @jenswi-linaro give is R-b? I can't see it in the discussion, yet you added it to your first commit. @jenswi-linaro please let us know if you're OK with the current state.

Also, @lackan could you please add a test to xtest for this case?

@jenswi-linaro
Copy link
Contributor

Fine with me:
Reviewed-by: Jens Wiklander <[email protected]>

@lackan
Copy link
Author

lackan commented Dec 18, 2016

@jforissier Yes, I will add a test to xtest soon.

When one invokes TEE_WriteObjectData and write some data
into the secure storage file, the data size of the file
may change, but currently it will not update the head
message in persistent objects. This commit will fix this
problem by updating head message when info->dataSize update.

Signed-off-by: Guanchao Liang <[email protected]>
Reviewed-by: Joakim Bech <[email protected]>
Reviewed-by: Jens Wiklander <[email protected]>
@jforissier
Copy link
Contributor

Rebased on top of master and merged. Thanks @lackan.

@jforissier jforissier closed this Jan 3, 2017
@lackan lackan deleted the fix-persistent-objects branch January 4, 2017 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants