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

Add str len check in config_sortlist to avoid stack overflow #497

Merged
merged 1 commit into from Jan 18, 2023

Conversation

hopper-vul
Copy link
Contributor

In ares_set_sortlist, it calls config_sortlist(..., sortstr) to parse the input str and initialize a sortlist configuration.

However, ares_set_sortlist has not any checks about the validity of the input str. It is very easy to create an arbitrary length stack overflow with the unchecked memcpy(ipbuf, str, q-str); and memcpy(ipbufpfx, str, q-str); statements in the config_sortlist call, which could potentially cause severe security impact in practical programs.

This commit add necessary check for ipbuf and ipbufpfx which avoid the potential stack overflows.

fixes #496

Signed-off-by: hopper-vul hopper.vul@gmail.com

In ares_set_sortlist, it calls config_sortlist(..., sortstr) to parse
the input str and initialize a sortlist configuration.

However, ares_set_sortlist has not any checks about the validity of the input str.
It is very easy to create an arbitrary length stack overflow with the unchecked
`memcpy(ipbuf, str, q-str);` and `memcpy(ipbufpfx, str, q-str);`
statements in the config_sortlist call, which could potentially cause severe
security impact in practical programs.

This commit add necessary check for `ipbuf` and `ipbufpfx` which avoid the
potential stack overflows.

fixes c-ares#496

Signed-off-by: hopper-vul <hopper.vul@gmail.com>
@bradh352
Copy link
Member

I'm not aware of any users of this interface, but in general it just looks broken to me.

It looks like via the documentation its supposed to only take ip addresses or ip addresses with subnet masks, however looking at the pre-existing test cases, its accepting garbage and actively being tested to ensure it accepts garbage ???

@hopper-vul
Copy link
Contributor Author

Yes, the str in document are constrained by "The provided sortstr string that holds a space separated list of IP-address-netmask pairs", but adding a few checks to avoid potential security bugs isn't a bad thing overall.

In current change, if it detects overflow (or means bad input string), it will return with a ARES_EBADSTR. Thus, i added the two test cases with the minimal invalid strings input in the SetSortlistFailures test (which i think it is to trigger some failures) to test whether the added checks work.

@bradh352 bradh352 merged commit 9903253 into c-ares:main Jan 18, 2023
@mmuehlenhoff
Copy link

JFTR, this was assigned CVE-2022-4904 (via https://bugzilla.redhat.com/show_bug.cgi?id=2168631)

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.

Potential stack overflow in ares_set_sortlist
3 participants