Skip to contentSkip to conversation

libssh: CVE-2020-16135 NULL pointer dereference in sftpserver.c if ssh_buffer_new returns NULL

PATCH New [email protected] 1 participant 1 message Jun 26, 2023

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 libssh: CVE-2020-16135 NULL pointer dereference in sftpserver.c if ssh_buffer_new returns NULL

From: Vijay Anusuri <[email protected]>

Upstream-Status: Backport
[https://gitlab.com/libssh/libssh-mirror/-/commit/533d881b0f4b24c72b35ecc97fa35d295d063e53
&
https://gitlab.com/libssh/libssh-mirror/-/commit/2782cb0495b7450bd8fe43ce4af886b66fea6c40
&
https://gitlab.com/libssh/libssh-mirror/-/commit/10b3ebbe61a7031a3dae97f05834442220447181
&
https://gitlab.com/libssh/libssh-mirror/-/commit/245ad744b5ab0582fef7cf3905a717b791d7e08b]

---
 .../libssh/files/CVE-2020-16135-1.patch       | 40 +++++++++++
 .../libssh/files/CVE-2020-16135-2.patch       | 42 +++++++++++
 .../libssh/files/CVE-2020-16135-3.patch       | 70 +++++++++++++++++++
 .../libssh/files/CVE-2020-16135-4.patch       | 34 +++++++++
 .../recipes-support/libssh/libssh_0.8.9.bb    |  8 ++-
 5 files changed, 193 insertions(+), 1 deletion(-)
 create mode 100644 meta-oe/recipes-support/libssh/files/CVE-2020-16135-1.patch
 create mode 100644 meta-oe/recipes-support/libssh/files/CVE-2020-16135-2.patch
 create mode 100644 meta-oe/recipes-support/libssh/files/CVE-2020-16135-3.patch
 create mode 100644 meta-oe/recipes-support/libssh/files/CVE-2020-16135-4.patch
meta-oe/recipes-support/libssh/files/CVE-2020-16135-1.patch new file +40 -0
new file mode 100644
index 000000000..2944a4462
@@ -0,0 +1,40 @@
+From 533d881b0f4b24c72b35ecc97fa35d295d063e53 Mon Sep 17 00:00:00 2001
+From: Andreas Schneider <[email protected]>
+Date: Wed, 3 Jun 2020 10:04:09 +0200
+Subject: [PATCH] sftpserver: Add missing NULL check for ssh_buffer_new()
+
+Thanks to Ramin Farajpour Cami for spotting this.
+
+Fixes T232
+
+Signed-off-by: Andreas Schneider <[email protected]>
+Reviewed-by: Anderson Toshiyuki Sasaki <[email protected]>
+Reviewed-by: Jakub Jelen <[email protected]>
+
+Upstream-Status: Backport [https://gitlab.com/libssh/libssh-mirror/-/commit/533d881b0f4b24c72b35ecc97fa35d295d063e53]
+CVE: CVE-2020-16135
+Signed-off-by: Vijay Anusuri <[email protected]>
+---
+ src/sftpserver.c | 6 ++++++
+ 1 file changed, 6 insertions(+)
+
+diff --git a/src/sftpserver.c b/src/sftpserver.c
+index 5a2110e58..b639a2ce3 100644
+--- a/src/sftpserver.c
++++ b/src/sftpserver.c
+@@ -67,6 +67,12 @@ sftp_client_message sftp_get_client_message(sftp_session sftp) {
+ 
+   /* take a copy of the whole packet */
+   msg->complete_message = ssh_buffer_new();
++  if (msg->complete_message == NULL) {
++      ssh_set_error_oom(session);
++      sftp_client_message_free(msg);
++      return NULL;
++  }
++
+   ssh_buffer_add_data(msg->complete_message,
+                       ssh_buffer_get(payload),
+                       ssh_buffer_get_len(payload));
+-- 
+GitLab
+
meta-oe/recipes-support/libssh/files/CVE-2020-16135-2.patch new file +42 -0

42 lines not on this page · raw message

meta-oe/recipes-support/libssh/files/CVE-2020-16135-3.patch new file +70 -0

70 lines not on this page · raw message

meta-oe/recipes-support/libssh/files/CVE-2020-16135-4.patch new file +34 -0
new file mode 100644
index 000000000..8e9a4c3f5
@@ -0,0 +1,34 @@
+From 245ad744b5ab0582fef7cf3905a717b791d7e08b Mon Sep 17 00:00:00 2001
+From: Andreas Schneider <[email protected]>
+Date: Wed, 3 Jun 2020 10:11:21 +0200
+Subject: [PATCH] buffer: Add NULL check for 'buffer' argument
+
+Signed-off-by: Andreas Schneider <[email protected]>
+Reviewed-by: Anderson Toshiyuki Sasaki <[email protected]>
+Reviewed-by: Jakub Jelen <[email protected]>
+
+Upstream-Status: Backport [https://gitlab.com/libssh/libssh-mirror/-/commit/245ad744b5ab0582fef7cf3905a717b791d7e08b]
+CVE: CVE-2020-16135
+Signed-off-by: Vijay Anusuri <[email protected]>
+---
+ src/buffer.c | 4 ++++
+ 1 file changed, 4 insertions(+)
+
+diff --git a/src/buffer.c b/src/buffer.c
+index 476bc1358..ce12f491a 100644
+--- a/src/buffer.c
++++ b/src/buffer.c
+@@ -299,6 +299,10 @@ int ssh_buffer_reinit(struct ssh_buffer_struct *buffer)
+  */
+ int ssh_buffer_add_data(struct ssh_buffer_struct *buffer, const void *data, uint32_t len)
+ {
++    if (buffer == NULL) {
++        return -1;
++    }
++
+     buffer_verify(buffer);
+ 
+     if (data == NULL) {
+-- 
+GitLab
+
meta-oe/recipes-support/libssh/libssh_0.8.9.bb +7 -1
index 39ed8a8fb..0fb07a0eb 100644
@@ -6,7 +6,13 @@ LIC_FILES_CHKSUM = "file://COPYING;md5=dabb4958b830e5df11d2b0ed8ea255a0"
 
 DEPENDS = "zlib openssl libgcrypt"
 
-SRC_URI = "git://git.libssh.org/projects/libssh.git;branch=stable-0.8"
+SRC_URI = "git://git.libssh.org/projects/libssh.git;branch=stable-0.8 \
+           file://CVE-2020-16135-1.patch \
+           file://CVE-2020-16135-2.patch \
+           file://CVE-2020-16135-3.patch \
+           file://CVE-2020-16135-4.patch \
+          "
+
 SRCREV = "04685a74df9ce1db1bc116a83a0da78b4f4fa1f8"
 
 S = "${WORKDIR}/git"
Signature · 1 line
2.25.1