Skip to contentSkip to conversation

connman: Fix critical CVE-2021-33833 for dunfell branch #poky

PATCH In review Damien HACKETT 2 participants 4 messages Sep 22, 2021

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 connman: Fix critical CVE-2021-33833 for dunfell branch #poky

In dunfell, connman version is 1.37 so is vulnerable to CVE-2021-33833.

For more recent branches like gatesgarth, they use connman version 1.39 at least so already have this CVE fixed.

Seems this CVE was not detected by cve_check as it was affected to "connection_manager" instead of "connman". Probably @Steve Sakoman will do an other patch for that.

=> Here is the thread we discussed about the problem : https://lists.yoctoproject.org/g/yocto-security/topic/update_of_conmann_to_1_39_and/85762164?p=,,,20,0,0,0::recentpostdate/sticky,,,20,2,0,85762164,previd=1632244971072307699,nextid=1629104796496170789&previd=1632244971072307699&nextid=1629104796496170789

From 2ee0da18332cb6030a54fe8b176625bec7b1d3b3 Mon Sep 17 00:00:00 2001
From: Damien Hackett <[email protected]>
Date: Tue, 21 Sep 2021 13:40:40 +0200
Subject: [PATCH] connman: Fix Connman CVE-2021-33833 in 1.37 version

---
.../connman/connman/CVE-2021-33833.patch      | 69 +++++++++++++++++++ .../connman/connman_1.37.bb                   |  1 +

2 files changed, 70 insertions(+)

create mode 100644 meta/recipes-connectivity/connman/connman/CVE-2021-33833.patch

meta/recipes-connectivity/connman/connman/CVE-2021-33833.patch new file +69 -0
new file mode 100644
index 0000000000..773ef8d13e
@@ -0,0 +1,69 @@
+From eceb2e8d2341c041df55a5e2f047d9a8c491463c Mon Sep 17 00:00:00 2001
+From: Valery Kashcheev <[email protected]>
+Date: Mon, 7 Jun 2021 18:58:24 +0200
+Subject: [PATCH] dnsproxy: Check the length of buffers before memcpy
+
+Fix using a stack-based buffer overflow attack by checking the length of
+the ptr and uptr buffers.
+
+Fix debug message output.
+
+Fixes: CVE-2021-33833
+
+Reference to upstream patch:
+https://git.kernel.org/pub/scm/network/connman/connman.git/commit/?id=eceb2e8d2341c041df55a5e2f047d9a8c491463c
+
+Signed-off-by: Damien Hackett <[email protected]>
+---
+ src/dnsproxy.c | 20 +++++++++++---------
+ 1 file changed, 11 insertions(+), 9 deletions(-)
+
+diff --git a/src/dnsproxy.c b/src/dnsproxy.c
+index de52df5a..38dbdd71 100644
+--- a/src/dnsproxy.c
++++ b/src/dnsproxy.c
+@@ -1788,17 +1788,15 @@ static char *uncompress(int16_t field_count, char *start, char *end,
+          * tmp buffer.
+          */
+
+-        debug("pos %d ulen %d left %d name %s", pos, ulen,
+-            (int)(uncomp_len - (uptr - uncompressed)), uptr);
+-
+-        ulen = strlen(name);
+-        if ((uptr + ulen + 1) > uncomp_end) {
++        ulen = strlen(name) + 1;
++        if ((uptr + ulen) > uncomp_end)
+             goto out;
+-        }
+-        strncpy(uptr, name, uncomp_len - (uptr - uncompressed));
++        strncpy(uptr, name, ulen);
++
++        debug("pos %d ulen %d left %d name %s", pos, ulen,
++            (int)(uncomp_end - (uptr + ulen)), uptr);
+
+         uptr += ulen;
+-        *uptr++ = '\0';
+
+         ptr += pos;
+
+@@ -1841,7 +1839,7 @@ static char *uncompress(int16_t field_count, char *start, char *end,
+         } else if (dns_type == ns_t_a || dns_type == ns_t_aaaa) {
+             dlen = uptr[-2] << 8 | uptr[-1];
+
+-            if (ptr + dlen > end) {
++            if ((ptr + dlen) > end || (uptr + dlen) > uncomp_end) {
+                 debug("data len %d too long", dlen);
+                 goto out;
+             }
+@@ -1880,6 +1878,10 @@ static char *uncompress(int16_t field_count, char *start, char *end,
+              * refresh interval, retry interval, expiration
+              * limit and minimum ttl). They are 20 bytes long.
+              */
++            if ((uptr + 20) > uncomp_end || (ptr + 20) > end) {
++                debug("soa record too long");
++                goto out;
++            }
+             memcpy(uptr, ptr, 20);
+             uptr += 20;
+             ptr += 20;
+--
meta/recipes-connectivity/connman/connman_1.37.bb +0 -0
index bdab4c4f18..8a275dd8e2 100644
@@ -9,6 +9,7 @@ SRC_URI  = "${KERNELORG_MIRROR}/linux/network/${BPN}/${BP}.tar.xz \

file://CVE-2021-26675.patch \
file://CVE-2021-26676-0001.patch \
file://CVE-2021-26676-0002.patch \
+            file://CVE-2021-33833.patch \
"

SRC_URI_append_libc-musl = " file://0002-resolve-musl-does-not-implement-res_ninit.patch" --
2.20.1

From 2ee0da18332cb6030a54fe8b176625bec7b1d3b3 Mon Sep 17 00:00:00 2001
From: Damien Hackett <[email protected]>
Date: Tue, 21 Sep 2021 13:40:40 +0200
Subject: [PATCH] connman: Fix Connman CVE-2021-33833 in 1.37 version

---
 .../connman/connman/CVE-2021-33833.patch      | 69 +++++++++++++++++++
 .../connman/connman_1.37.bb                   |  1 +
 2 files changed, 70 insertions(+)
 create mode 100644 meta/recipes-connectivity/connman/connman/CVE-2021-33833.patch
meta/recipes-connectivity/connman/connman/CVE-2021-33833.patch new file +69 -0

69 lines not on this page · raw message

meta/recipes-connectivity/connman/connman_1.37.bb +1 -0
index bdab4c4f18..8a275dd8e2 100644
@@ -9,6 +9,7 @@ SRC_URI  = "${KERNELORG_MIRROR}/linux/network/${BPN}/${BP}.tar.xz \
             file://CVE-2021-26675.patch \
             file://CVE-2021-26676-0001.patch \
             file://CVE-2021-26676-0002.patch \
+            file://CVE-2021-33833.patch \
 "
 
 SRC_URI_append_libc-musl = " file://0002-resolve-musl-does-not-implement-res_ninit.patch"
Signature · 1 line
2.20.1
#1 lore raw

Thanks for the patch, it's basically ok, but:

- the patch file for connman needs 'Upstream-Status: Backport [link]' just above your s-o-b
- use 'git send-email' to send it, no attachments or sending via interactive email clients
(many things can go wrong if you do that)
- the correct mailing list is openembedded-core one
- the patch should apply to current poky master; if it's not relevant or needed for master this needs to be clarified.

Alex

Quoted 125 lines · Damien HACKETT

In dunfell, connman version is 1.37 so is vulnerable to CVE-2021-33833.

For more recent branches like gatesgarth, they use connman version 1.39 at least so already have this CVE fixed.

Seems this CVE was not detected by cve_check as it was affected to "connection_manager" instead of "connman".
Probably @Steve Sakoman will do an other patch for that.

=> Here is the thread we discussed about the problem :
https://lists.yoctoproject.org/g/yocto-security/topic/update_of_conmann_to_1_39_and/85762164?p=,,,20,0,0,0::recentpostdate/sticky,,,20,2,0,85762164,previd=1632244971072307699,nextid=1629104796496170789&previd=1632244971072307699&nextid=1629104796496170789

From 2ee0da18332cb6030a54fe8b176625bec7b1d3b3 Mon Sep 17 00:00:00 2001
From: Damien Hackett <[email protected]>
Date: Tue, 21 Sep 2021 13:40:40 +0200
Subject: [PATCH] connman: Fix Connman CVE-2021-33833 in 1.37 version

---
 .../connman/connman/CVE-2021-33833.patch      | 69 +++++++++++++++++++
 .../connman/connman_1.37.bb                   |  1 +
 2 files changed, 70 insertions(+)
 create mode 100644

meta/recipes-connectivity/connman/connman/CVE-2021-33833.patch

diff --git a/meta/recipes-connectivity/connman/connman/CVE-2021-33833.patch b/meta/recipes-connectivity/connman/connman/CVE-2021-33833.patch new file mode 100644
index 0000000000..773ef8d13e

meta/recipes-connectivity/connman/connman/CVE-2021-33833.patch new file +14 -0
@@ -0,0 +1,69 @@
+From eceb2e8d2341c041df55a5e2f047d9a8c491463c Mon Sep 17 00:00:00 2001
+From: Valery Kashcheev <[email protected]>
+Date: Mon, 7 Jun 2021 18:58:24 +0200
+Subject: [PATCH] dnsproxy: Check the length of buffers before memcpy
+
+Fix using a stack-based buffer overflow attack by checking the length of
+the ptr and uptr buffers.
+
+Fix debug message output.
+
+Fixes: CVE-2021-33833
+
+Reference to upstream patch:
+

https://git.kernel.org/pub/scm/network/connman/connman.git/commit/?id=eceb2e8d2341c041df55a5e2f047d9a8c491463c

meta/recipes-connectivity/connman/connman/CVE-2021-33833.patch new file +11 -0
+
+Signed-off-by: Damien Hackett <[email protected]>
+---
+ src/dnsproxy.c | 20 +++++++++++---------
+ 1 file changed, 11 insertions(+), 9 deletions(-)
+
+diff --git a/src/dnsproxy.c b/src/dnsproxy.c
+index de52df5a..38dbdd71 100644
+--- a/src/dnsproxy.c
++++ b/src/dnsproxy.c
+@@ -1788,17 +1788,15 @@ static char *uncompress(int16_t field_count, char

*start, char *end,

meta/recipes-connectivity/connman/connman/CVE-2021-33833.patch new file +24 -0
+          * tmp buffer.
+          */
+
+-        debug("pos %d ulen %d left %d name %s", pos, ulen,
+-            (int)(uncomp_len - (uptr - uncompressed)), uptr);
+-
+-        ulen = strlen(name);
+-        if ((uptr + ulen + 1) > uncomp_end) {
++        ulen = strlen(name) + 1;
++        if ((uptr + ulen) > uncomp_end)
+             goto out;
+-        }
+-        strncpy(uptr, name, uncomp_len - (uptr - uncompressed));
++        strncpy(uptr, name, ulen);
++
++        debug("pos %d ulen %d left %d name %s", pos, ulen,
++            (int)(uncomp_end - (uptr + ulen)), uptr);
+
+         uptr += ulen;
+-        *uptr++ = '\0';
+
+         ptr += pos;
+
+@@ -1841,7 +1839,7 @@ static char *uncompress(int16_t field_count, char

*start, char *end,

meta/recipes-connectivity/connman/connman/CVE-2021-33833.patch new file +9 -0
+         } else if (dns_type == ns_t_a || dns_type == ns_t_aaaa) {
+             dlen = uptr[-2] << 8 | uptr[-1];
+
+-            if (ptr + dlen > end) {
++            if ((ptr + dlen) > end || (uptr + dlen) > uncomp_end) {
+                 debug("data len %d too long", dlen);
+                 goto out;
+             }
+@@ -1880,6 +1878,10 @@ static char *uncompress(int16_t field_count, char

*start, char *end,

meta/recipes-connectivity/connman/connman/CVE-2021-33833.patch new file +11 -0
+              * refresh interval, retry interval, expiration
+              * limit and minimum ttl). They are 20 bytes long.
+              */
++            if ((uptr + 20) > uncomp_end || (ptr + 20) > end) {
++                debug("soa record too long");
++                goto out;
++            }
+             memcpy(uptr, ptr, 20);
+             uptr += 20;
+             ptr += 20;
+--
meta/recipes-connectivity/connman/connman_1.37.bb +1 -0
index bdab4c4f18..8a275dd8e2 100644
@@ -9,6 +9,7 @@ SRC_URI  =
 "${KERNELORG_MIRROR}/linux/network/${BPN}/${BP}.tar.xz \
             file://CVE-2021-26675.patch \
             file://CVE-2021-26676-0001.patch \
             file://CVE-2021-26676-0002.patch \
+            file://CVE-2021-33833.patch \
 "
 

SRC_URI_append_libc-musl = "
file://0002-resolve-musl-does-not-implement-res_ninit.patch" --
2.20.1

#2 lore raw
Quoted 6 lines · Alexander Kanavin

Thanks for the patch, it's basically ok, but:

- the patch file for connman needs 'Upstream-Status: Backport [link]' just above your s-o-b

Added.

Quoted 5 lines

- use 'git send-email' to send it, no attachments or sending via interactive email clients

Ok sure. I am not used to it.

Quoted 5 lines

(many things can go wrong if you do that)
- the correct mailing list is openembedded-core one

For this point are you sure because my changes are on poky layer not meta-openembedded one ??

Quoted 5 lines

- the patch should apply to current poky master; if it's not relevant or needed for master this needs to be clarified.

I see some people add [dunfell] in message subject to specify a specific branch on which appling the patch.

Quoted 5 lines

Alex

By the way, thanks foryour support to those which try to support the community. ;)

Quoted 3 lines
#3 lore raw
Quoted 3 lines · Damien HACKETT

For this point are you sure because my changes are on poky layer not meta-openembedded one ??

poky is a composite repo made of several original repos, oe-core is where the recipes are. meta-oe is an 'extended' layer and not a part of it. Patches to oe-core go to oe-core list, patches to meta-oe go to oe-devel list. Only patches to poky/meta-poky directory go here.

Quoted 6 lines

- the patch should apply to current poky master; if it's not relevant or needed for master this needs to be clarified.

I see some people add [dunfell] in message subject to specify a specific branch on which appling the patch.

Yes, but the policy is that it goes to master first, if it is applies to both, then backported.

Alex