-
Notifications
You must be signed in to change notification settings - Fork 840
lua: minimal support for Unix socket incoming connections #12510
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
base: master
Are you sure you want to change the base?
Conversation
I will take a look at it this week |
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.
Pull Request Overview
This PR adds minimal support for Unix socket connections in the Lua plugin to prevent crashes when handling AF_UNIX socket addresses. The changes address type confusion issues where AF_UNIX sockaddr structures were being incorrectly treated as AF_INET6 addresses.
Key changes:
- Adds AF_UNIX constant definition for Lua scripts
- Implements proper handling of Unix socket addresses in client and server request functions
- Initializes port variables to prevent undefined behavior when dealing with Unix sockets
Reviewed Changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated no comments.
File | Description |
---|---|
plugins/lua/ts_lua_server_request.cc | Adds TS_LUA_AF_UNIX global constant definition |
plugins/lua/ts_lua_http.cc | Adds AF_UNIX case handling in client address retrieval |
plugins/lua/ts_lua_client_request.cc | Adds AF_UNIX handling and fixes port initialization for Unix sockets |
doc/admin-guide/plugins/lua.en.rst | Documents the new TS_LUA_AF_UNIX constant |
Comments suppressed due to low confidence (1)
plugins/lua/ts_lua_client_request.cc:807
- This else clause will incorrectly treat AF_UNIX addresses as AF_INET6, potentially causing undefined behavior when casting sockaddr_un to sockaddr_in6. Add an explicit AF_INET6 check and handle AF_UNIX case separately.
if (client_ip->sa_family == AF_INET) {
port = ((struct sockaddr_in *)client_ip)->sin_port;
} else {
port = ((struct sockaddr_in6 *)client_ip)->sin6_port;
}
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
d4c8257
to
e9f4625
Compare
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 also think that we need to make changes in ts_lua_vconn.cc
ts_lua_vconn_get_remote_addr() is also not taking care of the situation correctly.
Thanks.
|
||
TS_LUA_AF_INET (2) | ||
TS_LUA_AF_INET6 (10) | ||
TS_LUA_AF_UNIX (1) |
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 think these variables are really used when we are making changes to the outgoing address. So there is no need to support AF_UNIX here
lua_setglobal(L, "TS_LUA_AF_INET6"); | ||
|
||
lua_pushinteger(L, AF_UNIX); | ||
lua_setglobal(L, "TS_LUA_AF_UNIX"); |
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 think these variables are really used when we are making changes to the outgoing address. So there is no need to support AF_UNIX here
e9f4625
to
cdc25c1
Compare
|
Thanks. |
cdc25c1
to
3736160
Compare
Sorry, git error. |
3736160
to
65e3f82
Compare
65e3f82
to
f871528
Compare
On second thought, perhaps we should just take care of the rest consistently. may be we should fix up
Thanks so much for your patience and help. |
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.
Please also consider my latest notes and perhaps to make further changes to ts_lua_server_request.cc
Thanks.
I'll try to look at this during the next week. |
@vuori are you still working on this? Thanks. |
Hopefully yes sometime soonish, but the last weeks have been non-stop firefighting on other fronts and there are still a few blazes to put out this week. |
This adds minimal support to the Lua plugin for cases where the incoming connection is through a Unix socket. Crashing issues are unlikely, but there are two type confusions where an
AF_UNIX
sockaddr will get treated asAF_INET6
. (Technically if the source socket is unnamed, the resultgetpeername()
could be no larger thansizeof(sa_family_t)
asunix(7)
states. The reality will likely be highly platform-dependent.)Basically same deal as #12504