Bug 133372 - osl_connectSocketTo crashes with > 1024 file descriptors
Summary: osl_connectSocketTo crashes with > 1024 file descriptors
Status: NEW
Alias: None
Product: LibreOffice
Classification: Unclassified
Component: sdk (show other bugs)
Version:
(earliest affected)
Inherited From OOo
Hardware: All Linux (All)
: medium normal
Assignee: Not Assigned
URL:
Whiteboard:
Keywords:
Depends on:
Blocks: Crash
  Show dependency treegraph
 
Reported: 2020-05-25 12:58 UTC by straub
Modified: 2022-10-19 15:29 UTC (History)
2 users (show)

See Also:
Crash report or crash signature:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description straub 2020-05-25 12:58:44 UTC
osl_connectSocketTo() uses the select(...) call together with the fd_set data structures to wait for a connection to be established.

The fd_set data structure contains a fixed-size array that uses the the __FD_SETSIZE macro. This macro is typically set to 1024.

By calling ulimit -n 4096, a user can typically increase the number of usable file descriptors beyond 1024 up to the hard limit as set by the system administrator.

But since fd_set supports up to 1024 file descriptors (unless someone changed the __FD_SETSIZE macro), the osl_connectToSocket() method will corrupt the stack if a socket uses a file descriptor >= 1024.

In my scenario, the method crashed with stack corruption when creating a new IPC bridge:
/lib64/libc.so.6(gsignal+0x37)[0x7ffff685e1f7]
/lib64/libc.so.6(abort+0x148)[0x7ffff685f8e8]
/lib64/libc.so.6(+0x74f47)[0x7ffff689df47]
/lib64/libc.so.6(__fortify_fail+0x37)[0x7ffff6938d87]
/lib64/libc.so.6(__fortify_fail+0x0)[0x7ffff6938d50]
libuno_sal.so.3(osl_connectSocketTo+0xa38)[0x7ffff5a93098]
libiolo.so(+0x1b004)[0x7fffe7eea004]
libuuresolverlo.so(+0x37ee)[0x7fffe81237ee]

Stack overflow suggests to use poll instead of select:
https://stackoverflow.com/questions/7976388/increasing-limit-of-fd-setsize-and-select
Comment 1 Stephan Bergmann 2020-05-25 13:41:30 UTC
Indeed, SUSv4 states that the behavior of FD_SET "is undefined if the fd argument is less than 0 or greater than or equal to FD_SETSIZE".  (It also states that select shall return EINVAL if its "nfds argument is less than 0 or greater than FD_SETSIZE", but by then we've already run into undefined behavior.)

A patch switching to poll is welcome.  :)
Comment 2 QA Administrators 2022-05-26 03:43:13 UTC Comment hidden (obsolete)
Comment 3 Marc-Oliver Straub 2022-05-27 06:59:27 UTC
Still present in HEAD