Resolves: rhbz#2170867 - c-ares: buffer overflow in config_sortlist() due to missing string length check [rhel-8]
This commit is contained in:
		
							parent
							
								
									7170f1b111
								
							
						
					
					
						commit
						2067b47353
					
				| @ -0,0 +1,64 @@ | |||||||
|  | From 9903253c347f9e0bffd285ae3829aef251cc852d Mon Sep 17 00:00:00 2001 | ||||||
|  | From: hopper-vul <118949689+hopper-vul@users.noreply.github.com> | ||||||
|  | Date: Wed, 18 Jan 2023 22:14:26 +0800 | ||||||
|  | Subject: [PATCH] Add str len check in config_sortlist to avoid stack overflow | ||||||
|  |  (#497) | ||||||
|  | 
 | ||||||
|  | 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 | ||||||
|  | 
 | ||||||
|  | Fix By: @hopper-vul | ||||||
|  | ---
 | ||||||
|  |  ares_init.c            | 4 ++++ | ||||||
|  |  test/ares-test-init.cc | 2 ++ | ||||||
|  |  2 files changed, 6 insertions(+) | ||||||
|  | 
 | ||||||
|  | diff --git a/ares_init.c b/ares_init.c
 | ||||||
|  | index f7b700b..5aad7c8 100644
 | ||||||
|  | --- a/ares_init.c
 | ||||||
|  | +++ b/ares_init.c
 | ||||||
|  | @@ -2065,6 +2065,8 @@ static int config_sortlist(struct apattern **sortlist, int *nsort,
 | ||||||
|  |        q = str; | ||||||
|  |        while (*q && *q != '/' && *q != ';' && !ISSPACE(*q)) | ||||||
|  |          q++; | ||||||
|  | +      if (q-str >= 16)
 | ||||||
|  | +        return ARES_EBADSTR;
 | ||||||
|  |        memcpy(ipbuf, str, q-str); | ||||||
|  |        ipbuf[q-str] = '\0'; | ||||||
|  |        /* Find the prefix */ | ||||||
|  | @@ -2073,6 +2075,8 @@ static int config_sortlist(struct apattern **sortlist, int *nsort,
 | ||||||
|  |            const char *str2 = q+1; | ||||||
|  |            while (*q && *q != ';' && !ISSPACE(*q)) | ||||||
|  |              q++; | ||||||
|  | +          if (q-str >= 32)
 | ||||||
|  | +            return ARES_EBADSTR;
 | ||||||
|  |            memcpy(ipbufpfx, str, q-str); | ||||||
|  |            ipbufpfx[q-str] = '\0'; | ||||||
|  |            str = str2; | ||||||
|  | diff --git a/test/ares-test-init.cc b/test/ares-test-init.cc
 | ||||||
|  | index 63c6a22..ee84518 100644
 | ||||||
|  | --- a/test/ares-test-init.cc
 | ||||||
|  | +++ b/test/ares-test-init.cc
 | ||||||
|  | @@ -275,6 +275,8 @@ TEST_F(DefaultChannelTest, SetAddresses) {
 | ||||||
|  |   | ||||||
|  |  TEST_F(DefaultChannelTest, SetSortlistFailures) { | ||||||
|  |    EXPECT_EQ(ARES_ENODATA, ares_set_sortlist(nullptr, "1.2.3.4")); | ||||||
|  | +  EXPECT_EQ(ARES_EBADSTR, ares_set_sortlist(channel_, "111.111.111.111*/16"));
 | ||||||
|  | +  EXPECT_EQ(ARES_EBADSTR, ares_set_sortlist(channel_, "111.111.111.111/255.255.255.240*"));
 | ||||||
|  |    EXPECT_EQ(ARES_SUCCESS, ares_set_sortlist(channel_, "xyzzy ; lwk")); | ||||||
|  |    EXPECT_EQ(ARES_SUCCESS, ares_set_sortlist(channel_, "xyzzy ; 0x123")); | ||||||
|  |  } | ||||||
|  | -- 
 | ||||||
|  | 2.37.3 | ||||||
|  | 
 | ||||||
| @ -1,7 +1,7 @@ | |||||||
| Summary: A library that performs asynchronous DNS operations | Summary: A library that performs asynchronous DNS operations | ||||||
| Name: c-ares | Name: c-ares | ||||||
| Version: 1.13.0 | Version: 1.13.0 | ||||||
| Release: 6%{?dist} | Release: 7%{?dist} | ||||||
| License: MIT | License: MIT | ||||||
| Group: System Environment/Libraries | Group: System Environment/Libraries | ||||||
| URL: http://c-ares.haxx.se/ | URL: http://c-ares.haxx.se/ | ||||||
| @ -10,6 +10,7 @@ Source0: http://c-ares.haxx.se/download/%{name}-%{version}.tar.gz | |||||||
| Source1: LICENSE | Source1: LICENSE | ||||||
| Patch0: 0001-Use-RPM-compiler-options.patch | Patch0: 0001-Use-RPM-compiler-options.patch | ||||||
| Patch1: 0002-fix-CVE-2021-3672.patch | Patch1: 0002-fix-CVE-2021-3672.patch | ||||||
|  | Patch2: 0003-Add-str-len-check-in-config_sortlist-to-avoid-stack-.patch | ||||||
| 
 | 
 | ||||||
| BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) | BuildRoot: %{_tmppath}/%{name}-%{version}-%{release}-root-%(%{__id_u} -n) | ||||||
| 
 | 
 | ||||||
| @ -36,6 +37,7 @@ compile applications or shared objects that use c-ares. | |||||||
| %setup -q | %setup -q | ||||||
| %patch0 -p1 -b .optflags | %patch0 -p1 -b .optflags | ||||||
| %patch1 -p1 -b .dns | %patch1 -p1 -b .dns | ||||||
|  | %patch2 -p1 -b .sortlist | ||||||
| 
 | 
 | ||||||
| cp %{SOURCE1} . | cp %{SOURCE1} . | ||||||
| f=CHANGES ; iconv -f iso-8859-1 -t utf-8 $f -o $f.utf8 ; mv $f.utf8 $f | f=CHANGES ; iconv -f iso-8859-1 -t utf-8 $f -o $f.utf8 ; mv $f.utf8 $f | ||||||
| @ -74,6 +76,9 @@ rm -rf $RPM_BUILD_ROOT | |||||||
| %{_mandir}/man3/ares_* | %{_mandir}/man3/ares_* | ||||||
| 
 | 
 | ||||||
| %changelog | %changelog | ||||||
|  | * Fri May 12 2023 Alexey Tikhonov <atikhono@redhat.com> - 1.13.0-7 | ||||||
|  | - Resolves: rhbz#2170867 - c-ares: buffer overflow in config_sortlist() due to missing string length check [rhel-8] | ||||||
|  | 
 | ||||||
| * Fri Oct 15 2021 Alexey Tikhonov <atikhono@redhat.com> - 1.13.0-6 | * Fri Oct 15 2021 Alexey Tikhonov <atikhono@redhat.com> - 1.13.0-6 | ||||||
| - Resolves: rhbz#1989425 - CVE-2021-3672 c-ares: missing input validation of host names may lead to Domain Hijacking [rhel-8] | - Resolves: rhbz#1989425 - CVE-2021-3672 c-ares: missing input validation of host names may lead to Domain Hijacking [rhel-8] | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
		Reference in New Issue
	
	Block a user