-
Notifications
You must be signed in to change notification settings - Fork 8.2k
Fix secure sockets after FD table introduction #11405
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
Fix secure sockets after FD table introduction #11405
Conversation
ztls_setsockopt and ztls_getsockopt returned error codes instead of setting errno in particular cases. This commit fixes it. Signed-off-by: Robert Lubos <[email protected]>
Codecov Report
@@ Coverage Diff @@
## master #11405 +/- ##
=======================================
Coverage 48.37% 48.37%
=======================================
Files 265 265
Lines 42188 42188
Branches 10137 10137
=======================================
Hits 20408 20408
Misses 17703 17703
Partials 4077 4077Continue to review full report at Codecov.
|
With FD table introduction, net_context can no longer be reached by typecasting socket descriptor. Instead, file descriptor API have to be used. Signed-off-by: Robert Lubos <[email protected]>
1d2e749 to
b53e57a
Compare
|
|
||
| static inline struct net_context *sock_to_net_ctx(int sock) | ||
| { | ||
| return z_get_fd_obj(sock, NULL, ENOTSOCK); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I hope we both understand that passing vtable=NULL is a hack.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, we do. I'm already working on a solution for secure sockets, according to this comment.
| if (tls_proto != 0) { | ||
| /* If TLS protocol is used, allocate TLS context */ | ||
| struct net_context *context = INT_TO_POINTER(sock); | ||
| struct net_context *context = sock_to_net_ctx(sock); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
No NULL check here, unlike done in other places.
pfalcon
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Let me invoke "Trivial patch" spell and approve.
note that trivial sets minimum review time, it does not mean it needs to be expedited. hope that was clear in the proposal. |
|
@nashif :
For me, those are quite related. Having "Trivial" category from my PoV is effectively a pledge along the lines of: "Dear fellow developer, you see that we're stuck at 250+ unprocessed patches, and that number is only growing. Then you may wonder, if you see any c%ap in our code, does it make sense to try to fix it, or it's useless, and it's better to just stick to work on what your boss told you. We have good news for you - if you submit us an easy to review patch, we'll actually try review it as soon as 4 hrs." If that's (improving the process for contributors, again, as was announced by you 3 weeks ago) not the intention behind all this, then well, d'oh. |
This PR fixes secure sockets implementation by removing invalid typecasts between socket descriptor and
net_context. Note, that this PR does not add full support for POSIX APIs for secure sockets (like read/write), it's just a bugfix.With FD table introduction, net_context can no longer be reached by typecasting socket descriptor to
net_context, and vice versa. Instead, file descriptor API have to be used to reach thenet_context.As reverse conversion is not possible (
net_context-> file descriptor), we need to provide file descriptor to functions that callzsock_*API (i.e. mbedTLS bio functions).Additionally, second commit fixes a bug with
getsockopt/setsockoptreuturn values, spotted during rework.