Skip to content

Fixed possible double deletion of SecurityManager database object #12145

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

Closed

Conversation

AGlass0fMilk
Copy link
Member

Summary of changes

Fixing possible scenario where dynamically-allocated SecurityManager database object could be deleted multiple times, possibly causing stack corruption and subsequent hard faults.

Related to issue #11768 and MR #11831

Calling SecurityManager::reset now checks to see if the database object has already been deleted before attempting to delete it.

Subsequently, when reinitialized, the call to SecurityManager::init_database also tries to delete the database object without checking if it's NULL.

I'm not sure why deleting the database object in reset and then reinitializing it allows the file to be flushed to non-volatile storage (see #11768 ), while deleting it in the init_database call and then reinitializing it does not appear to flush the database to disk first...

However, this patch fixes both issues for me.

I think we need need to refactor the SecurityManager to address this issue from an architectural standpoint very soon.

Impact of changes

Migration actions required

Documentation

Related to issue #11768 and MR #11831


Pull request type

[X] Patch update (Bug fix / Target update / Docs update / Test update / Refactor)
[] Feature update (New feature / Functionality change / New API)
[] Major update (Breaking change E.g. Return code change / API behaviour change)

Test results

[] No Tests required for this change (E.g docs only update)
[X] Covered by existing mbed-os tests (Greentea or Unittest)
[] Tests / results supplied as part of this PR

Reviewers

@paul-szczepanek-arm


@ciarmcom ciarmcom requested review from paul-szczepanek-arm and a team December 19, 2019 20:00
@ciarmcom
Copy link
Member

@AGlass0fMilk, thank you for your changes.
@paul-szczepanek-arm @ARMmbed/mbed-os-pan @ARMmbed/mbed-os-maintainers please review.

Copy link
Member

@paul-szczepanek-arm paul-szczepanek-arm left a comment

Choose a reason for hiding this comment

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

thank you for the fix

Comment on lines 840 to 843
if(_db != NULL) {
delete _db;
_db = NULL;
}

Choose a reason for hiding this comment

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

this is redundant, the fix above is enough

Copy link
Member

@paul-szczepanek-arm paul-szczepanek-arm left a comment

Choose a reason for hiding this comment

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

Please replace tabs with spaces.
The second change is redundant, the fix in reset is enough to guard against double deletion.

@adbridge
Copy link
Contributor

@AGlass0fMilk could you please address @paul-szczepanek-arm last comments ?

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 2, 2020

@AGlass0fMilk could you please address @paul-szczepanek-arm last comments ?

Once done, let us know to restart tests

Copy link
Contributor

@0xc0170 0xc0170 left a comment

Choose a reason for hiding this comment

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

As requested above by @paul-szczepanek-arm , marking this as request changes.

@AGlass0fMilk
Copy link
Member Author

@paul-szczepanek-arm @0xc0170 Implemented requested changes. Please review.

@0xc0170
Copy link
Contributor

0xc0170 commented Jan 7, 2020

BLE: fix pointer not set to null on delete #12185

Lets continue there. I'll close this one.

@0xc0170 0xc0170 closed this Jan 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants