-
Notifications
You must be signed in to change notification settings - Fork 326
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
[Bug]: Double Close of File Descriptors by Libwebsockets Causing System Bugs #1807
Comments
Hi @YOSI-yoshidayuji, thanks for reporting this. We are already tracking this internally as well. We'll notify you once we have a fix out |
I appreciate the deep dive you have done! Before we investigate including this as a patch in the SDK, can you clarify what the fatal bug is? Is it a crash? Was the application run under gdb to confirm the source of the crash? If so, do you have a stack trace you can attach here? |
My program uses a token with a set validity period for connecting to the signaling server. Even if the program does not crash, problems occurred, -- |
As additional information, while the failure rarely occurs, the double closure of the file descriptor by libwebsocket always occurs every time. |
Got it. Thank you for the stack trace @YOSI-yoshidayuji . Will take a look at it and revert back in a few days. |
I know that lws is planned to be updated to v4.3.2 in "Update lws version #1820" and tried v4.3.2 locally. [Fixes leaking fds created by 'pipe()' call #2745] Thank you and best regards. |
Thanks @YOSI-yoshidayuji , Will look into updating it. |
Closing since LWS has been updated. |
Please confirm you have already done the following
Describe the bug
By applying the libwebsockets-leak-pipe-fix.patch, a double close of file descriptors by libwebsockets occurs.
This causes a hard-to-reproduce, sometimes fatal bug in the system.
To resolve this issue, the following patch for libwebsockets is also required.
warmcat/libwebsockets@f7aff78
Our organization has reported this issue through support, but as it has not yet been resolved, I will also report it as a bug.
Expected Behavior
Ensure that libwebsockets does not arbitrarily close file descriptors that are unrelated to itself.
Current Behavior
If a process opens the same file descriptor between the first close and the second close, that file descriptor is arbitrarily closed.
Reproduction Steps
I discovered the double close of libwebsocket by creating closehook.so from the following close_hook.c,
and replacing the close process with LD_PRELOAD.
Compile command:
gcc -g -Wall -D_GNU_SOURCE -fPIC -shared -o closehook.so close_hook.c -ldl
Execution of the program:
LD_PRELOAD=/path/to/closehook.so target
-- close_hook.c
#include <stdio.h>
#include <dlfcn.h>
#include <errno.h>
#include <string.h>
typedef int (*ORIGINAL_CLOSE)(int fd);
int close( int fd)
{
ORIGINAL_CLOSE original_close = (ORIGINAL_CLOSE)dlsym(RTLD_NEXT, "close");
int ret;
ret = original_close( fd );
if( ret == -1 ) {
fprintf( stderr, "close error fd=%d errno(%d) %s\n", fd, errno, strerror(errno) );
}
return ret;
}
WebRTC C SDK version being used
1.7.3 (But 1.8.1 is same)
Compiler and Version used
gcc (Ubuntu 11.4.0-1ubuntu1~22.04) 11.4.0
Operating System and version
Ubuntu 11.4.0
Platform being used
Linux
The text was updated successfully, but these errors were encountered: