diff options
-rw-r--r-- | meta-oe/recipes-support/c-ares/c-ares/CVE-2022-4904.patch | 66 | ||||
-rw-r--r-- | meta-oe/recipes-support/c-ares/c-ares_1.18.1.bb | 4 |
2 files changed, 69 insertions, 1 deletions
diff --git a/meta-oe/recipes-support/c-ares/c-ares/CVE-2022-4904.patch b/meta-oe/recipes-support/c-ares/c-ares/CVE-2022-4904.patch new file mode 100644 index 0000000000..0a0e8f0b61 --- /dev/null +++ b/meta-oe/recipes-support/c-ares/c-ares/CVE-2022-4904.patch | |||
@@ -0,0 +1,66 @@ | |||
1 | From 9903253c347f9e0bffd285ae3829aef251cc852d Mon Sep 17 00:00:00 2001 | ||
2 | From: hopper-vul <118949689+hopper-vul@users.noreply.github.com> | ||
3 | Date: Wed, 18 Jan 2023 22:14:26 +0800 | ||
4 | Subject: [PATCH] Add str len check in config_sortlist to avoid stack overflow | ||
5 | (#497) | ||
6 | |||
7 | In ares_set_sortlist, it calls config_sortlist(..., sortstr) to parse | ||
8 | the input str and initialize a sortlist configuration. | ||
9 | |||
10 | However, ares_set_sortlist has not any checks about the validity of the input str. | ||
11 | It is very easy to create an arbitrary length stack overflow with the unchecked | ||
12 | `memcpy(ipbuf, str, q-str);` and `memcpy(ipbufpfx, str, q-str);` | ||
13 | statements in the config_sortlist call, which could potentially cause severe | ||
14 | security impact in practical programs. | ||
15 | |||
16 | This commit add necessary check for `ipbuf` and `ipbufpfx` which avoid the | ||
17 | potential stack overflows. | ||
18 | |||
19 | fixes #496 | ||
20 | |||
21 | Fix By: @hopper-vul | ||
22 | |||
23 | CVE: CVE-2022-4415 | ||
24 | Upstream-Status: Backport [https://github.com/c-ares/c-ares/commit/9903253c347f9e0bffd285ae3829aef251cc852d] | ||
25 | |||
26 | Signed-off-by: Peter Marko <peter.marko@siemens.com> | ||
27 | --- | ||
28 | src/lib/ares_init.c | 4 ++++ | ||
29 | test/ares-test-init.cc | 2 ++ | ||
30 | 2 files changed, 6 insertions(+) | ||
31 | |||
32 | diff --git a/src/lib/ares_init.c b/src/lib/ares_init.c | ||
33 | index 51668a5c..3f9cec65 100644 | ||
34 | --- a/src/lib/ares_init.c | ||
35 | +++ b/src/lib/ares_init.c | ||
36 | @@ -1913,6 +1913,8 @@ static int config_sortlist(struct apattern **sortlist, int *nsort, | ||
37 | q = str; | ||
38 | while (*q && *q != '/' && *q != ';' && !ISSPACE(*q)) | ||
39 | q++; | ||
40 | + if (q-str >= 16) | ||
41 | + return ARES_EBADSTR; | ||
42 | memcpy(ipbuf, str, q-str); | ||
43 | ipbuf[q-str] = '\0'; | ||
44 | /* Find the prefix */ | ||
45 | @@ -1921,6 +1923,8 @@ static int config_sortlist(struct apattern **sortlist, int *nsort, | ||
46 | const char *str2 = q+1; | ||
47 | while (*q && *q != ';' && !ISSPACE(*q)) | ||
48 | q++; | ||
49 | + if (q-str >= 32) | ||
50 | + return ARES_EBADSTR; | ||
51 | memcpy(ipbufpfx, str, q-str); | ||
52 | ipbufpfx[q-str] = '\0'; | ||
53 | str = str2; | ||
54 | diff --git a/test/ares-test-init.cc b/test/ares-test-init.cc | ||
55 | index 63c6a228..ee845181 100644 | ||
56 | --- a/test/ares-test-init.cc | ||
57 | +++ b/test/ares-test-init.cc | ||
58 | @@ -275,6 +275,8 @@ TEST_F(DefaultChannelTest, SetAddresses) { | ||
59 | |||
60 | TEST_F(DefaultChannelTest, SetSortlistFailures) { | ||
61 | EXPECT_EQ(ARES_ENODATA, ares_set_sortlist(nullptr, "1.2.3.4")); | ||
62 | + EXPECT_EQ(ARES_EBADSTR, ares_set_sortlist(channel_, "111.111.111.111*/16")); | ||
63 | + EXPECT_EQ(ARES_EBADSTR, ares_set_sortlist(channel_, "111.111.111.111/255.255.255.240*")); | ||
64 | EXPECT_EQ(ARES_SUCCESS, ares_set_sortlist(channel_, "xyzzy ; lwk")); | ||
65 | EXPECT_EQ(ARES_SUCCESS, ares_set_sortlist(channel_, "xyzzy ; 0x123")); | ||
66 | } | ||
diff --git a/meta-oe/recipes-support/c-ares/c-ares_1.18.1.bb b/meta-oe/recipes-support/c-ares/c-ares_1.18.1.bb index 2cd00cb578..5614d1310f 100644 --- a/meta-oe/recipes-support/c-ares/c-ares_1.18.1.bb +++ b/meta-oe/recipes-support/c-ares/c-ares_1.18.1.bb | |||
@@ -5,7 +5,9 @@ SECTION = "libs" | |||
5 | LICENSE = "MIT" | 5 | LICENSE = "MIT" |
6 | LIC_FILES_CHKSUM = "file://LICENSE.md;md5=fb997454c8d62aa6a47f07a8cd48b006" | 6 | LIC_FILES_CHKSUM = "file://LICENSE.md;md5=fb997454c8d62aa6a47f07a8cd48b006" |
7 | 7 | ||
8 | SRC_URI = "git://github.com/c-ares/c-ares.git;branch=main;protocol=https" | 8 | SRC_URI = "git://github.com/c-ares/c-ares.git;branch=main;protocol=https \ |
9 | file://CVE-2022-4904.patch \ | ||
10 | " | ||
9 | SRCREV = "2aa086f822aad5017a6f2061ef656f237a62d0ed" | 11 | SRCREV = "2aa086f822aad5017a6f2061ef656f237a62d0ed" |
10 | 12 | ||
11 | UPSTREAM_CHECK_GITTAGREGEX = "cares-(?P<pver>\d+_(\d_?)+)" | 13 | UPSTREAM_CHECK_GITTAGREGEX = "cares-(?P<pver>\d+_(\d_?)+)" |