Skip to content

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

Merged
bradh352 merged 1 commit into
c-ares:mainfrom
hopper-vul:add-str-check-in-config_sortlist
Jan 18, 2023
Merged

Add str len check in config_sortlist to avoid stack overflow#497
bradh352 merged 1 commit into
c-ares:mainfrom
hopper-vul:add-str-check-in-config_sortlist

Conversation

@hopper-vul

Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown

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

@ncook-hxgn

Copy link
Copy Markdown

@mmuehlenhoff thanks for maintaining the record :)

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

4 participants