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

[Backport 2.28] net/mbedtls_net_connect: Preventing double close problem #9715

Merged

Conversation

ThePassionate
Copy link

@ThePassionate ThePassionate commented Oct 22, 2024

In the test examples and real usage scenarios, 'mbedtls_net_free' is called after 'mbedtls_net_connect' fails, which will cause the problem of double close the same fd. It is possible to close this closed fd which has been applied by other link.

Description

hi all. We found that in the scenario of sudden network disconnection, ‘mbedtls_net_connect’ will close fd after the connection fails, and then call ‘mbedtls_net_free’ to close it again. There is a risk of double close here. At first, we suspected that it was used incorrectly, but after referring to the implementation and case in the programs directory, we did not find that it was a usage error. Therefore, we suggest to mark fd as unavailable after closing it to prevent fd from being used by other programs during the interval between 'mbedtls_net_connect' and 'mbedtls_net_free'.

PR checklist

Please remove the segment/s on either side of the | symbol as appropriate, and add any relevant link/s to the end of the line.
If the provided content is part of the present PR remove the # symbol.

Notes for the submitter

Please refer to the contributing guidelines, especially the
checklist for PR contributors.

Help make review efficient:

  • Multiple simple commits
    • please structure your PR into a series of small commits, each of which does one thing
  • Avoid force-push
    • please do not force-push to update your PR - just add new commit(s)
  • See our Guidelines for Contributors for more details about the review process.

@gowthamsk-arm gowthamsk-arm changed the title net/mbedtls_net_connect: Preventing double close problem [Backport 2.28] net/mbedtls_net_connect: Preventing double close problem Oct 22, 2024
@gowthamsk-arm gowthamsk-arm added needs-review Every commit must be reviewed by at least two team members, component-platform Portability layer and build scripts needs-ci Needs to pass CI tests needs-reviewer This PR needs someone to pick it up for review size-xs Estimated task size: extra small (a few hours at most) labels Oct 22, 2024
@gowthamsk-arm gowthamsk-arm removed the needs-reviewer This PR needs someone to pick it up for review label Oct 22, 2024
gowthamsk-arm
gowthamsk-arm previously approved these changes Oct 22, 2024
Copy link
Contributor

@gowthamsk-arm gowthamsk-arm left a comment

Choose a reason for hiding this comment

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

LGTM

In the test examples and real usage scenarios, 'mbedtls_net_free' is called after 'mbedtls_net_connect' fails, which will cause the problem of double close the same fd. It is possible to close this closed fd which has been applied by other link.

Signed-off-by: makejian <[email protected]>
Copy link
Contributor

@davidhorstmann-arm davidhorstmann-arm left a comment

Choose a reason for hiding this comment

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

LGTM, thanks!

@davidhorstmann-arm davidhorstmann-arm added approved Design and code approved - may be waiting for CI or backports and removed needs-review Every commit must be reviewed by at least two team members, needs-ci Needs to pass CI tests labels Oct 22, 2024
@davidhorstmann-arm davidhorstmann-arm added this pull request to the merge queue Oct 22, 2024
Merged via the queue into Mbed-TLS:mbedtls-2.28 with commit f87e855 Oct 22, 2024
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Design and code approved - may be waiting for CI or backports component-platform Portability layer and build scripts size-xs Estimated task size: extra small (a few hours at most)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants