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

ambind: fix unsecure use of FD_SET() #225

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

jeffbencteux
Copy link

ambind does not check user-provided fd value given on its command-line. This fd is then used in calls to FD_SET() and then select().

from man(3) fd_set:

An fd_set is a fixed size buffer. Executing FD_CLR() or FD_SET() with a value of fd that is negative or is equal to or larger than FD_SETSIZE will result in undefined
behavior. Moreover, POSIX requires fd to be a valid file descriptor.

For example, it can be triggered with an int overflow:

$ LD_LIBRARY_PATH=./common-src/.libs/:"$LD_LIBRARY_PATH" ./common-src/.libs/ambind 2147483648 zsh: segmentation fault  LD_LIBRARY_PATH=./common-src/.libs/:"$LD_LIBRARY_PATH"  2147483648

ltrace stack:

$ LD_LIBRARY_PATH=./common-src/.libs/:"$LD_LIBRARY_PATH" ltrace ./common-src/.libs/ambind 2147483648
atoi(0x7ffefcb73354, 0x7ffefcb728e8, 0x7ffefcb72900, 0x55797923ddb8)                                                 = 0x80000000
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++

Current patch fix this behaviour by checking for fd being in range ]0;FD_SETSIZE[. Note that FD_SETSIZE is often 1024 but it is not guaranteed.

I am unsure of the security implications of the misuse. ambind is currently SUID root on my debian. However I do not have a clear picture of how that binary is typically used and how often. It is possible that it can lead to denial of service (DoS) if an attacker can provide the port to bind to but I doubt exploitation could go further. I am interested in getting your feedback on that.

Similar issue in other projects:

https://www.chiark.greenend.org.uk/~sgtatham/putty/wishlist/vuln-fd-set-overflow.html
https://www.cvedetails.com/cve/CVE-2011-0719/

ambind does not check user-provided fd value given on its command-line. This fd is then used in calls to FD_SET() and then select().

from man(3) fd_set:

> An fd_set is a fixed size buffer. Executing FD_CLR() or FD_SET() with a value of fd that is negative or is equal to or larger than FD_SETSIZE will result in undefined
> behavior. Moreover, POSIX requires fd to be a valid file descriptor.

For example, it can be triggered with an int overflow:

$ LD_LIBRARY_PATH=./common-src/.libs/:"$LD_LIBRARY_PATH" ./common-src/.libs/ambind 2147483648
zsh: segmentation fault  LD_LIBRARY_PATH=./common-src/.libs/:"$LD_LIBRARY_PATH"  2147483648

ltrace stack:

$ LD_LIBRARY_PATH=./common-src/.libs/:"$LD_LIBRARY_PATH" ltrace ./common-src/.libs/ambind 2147483648
atoi(0x7ffefcb73354, 0x7ffefcb728e8, 0x7ffefcb72900, 0x55797923ddb8)                                                 = 0x80000000
--- SIGSEGV (Segmentation fault) ---
+++ killed by SIGSEGV +++

Current patch fix this behaviour by checking for fd being in range ]0;FD_SETSIZE[. Note that FD_SETSIZE is often 1024 but it is not guaranteed.
Copy link

@konidev20 konidev20 left a comment

Choose a reason for hiding this comment

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

LGTM.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants