Skip to contentSkip to conversation

corosync: patch CVE-2026-35091

PATCH New [email protected] 1 participant 5 messages Apr 28

lore
Share & tools
lore
#0 lore raw

PATCH 1/5 corosync: patch CVE-2026-35091

From: Gyorgy Sarvari <[email protected]>

Details: https://nvd.nist.gov/vuln/detail/CVE-2026-35091

Pick the patch that mentions the CVE ID explicitly (it was identified by Debian also as the fix[1])

[1]: https://security-tracker.debian.org/tracker/CVE-2026-35091

(cherry picked from commit 701b22fda35648efc333d6e6e7abd8e70aa49870)
---
 .../corosync/corosync/CVE-2026-35091.patch    | 47 +++++++++++++++++++
 .../corosync/corosync_3.1.10.bb               |  1 +
 2 files changed, 48 insertions(+)
 create mode 100644 meta-networking/recipes-extended/corosync/corosync/CVE-2026-35091.patch
meta-networking/recipes-extended/corosync/corosync/CVE-2026-35091.patch new file +47 -0
new file mode 100644
index 0000000000..8afa5d6841
@@ -0,0 +1,47 @@
+From b9cb461121c8721c94a94309eb345a3c2f9ee9b4 Mon Sep 17 00:00:00 2001
+From: Jan Friesse <[email protected]>
+Date: Thu, 2 Apr 2026 09:00:39 +0200
+Subject: [PATCH] totemsrp: Return error if sanity check fails
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+Previously, the check_memb_commit_token_sanity function correctly
+checked the minimum message length. However, if the message was too
+short, it incorrectly returned a success code (0) instead of the
+expected failure code (-1).
+
+This commit ensures the appropriate error code is returned when the
+message length sanity check fails.
+
+Fixes: CVE-2026-35091
+
+Reported-by: Sebastián Alba Vives (@Sebasteuo / 0xS4bb1) <[email protected]>
+Signed-off-by: Jan Friesse <[email protected]>
+Also-proposed-by: nicholasyang <[email protected]>
+Reviewed-by: Christine Caulfield <[email protected]>
+
+CVE: CVE-2026-35091
+Upstream-Status: Backport [https://github.com/corosync/corosync/commit/a16614accfdb3481264d7281843fadf439d9ab1b]
+Signed-off-by: Gyorgy Sarvari <[email protected]>
+---
+ exec/totemsrp.c | 4 ++--
+ 1 file changed, 2 insertions(+), 2 deletions(-)
+
+diff --git a/exec/totemsrp.c b/exec/totemsrp.c
+index 35bf971..94d6c21 100644
+--- a/exec/totemsrp.c
++++ b/exec/totemsrp.c
+@@ -3811,10 +3811,10 @@ static int check_memb_commit_token_sanity(
+ 		log_printf (instance->totemsrp_log_level_security,
+ 		    "Received memb_commit_token message is too short...  ignoring.");
+ 
+-		return (0);
++		return (-1);
+ 	}
+ 
+-	addr_entries= mct_msg->addr_entries;
++	addr_entries = mct_msg->addr_entries;
+ 	if (endian_conversion_needed) {
+ 		addr_entries = swab32(addr_entries);
+ 	}
meta-networking/recipes-extended/corosync/corosync_3.1.10.bb +1 -0
index 0cb475a4d4..0e7f48272f 100644
@@ -9,6 +9,7 @@ inherit autotools pkgconfig systemd github-releases
 
 SRC_URI = "${GITHUB_BASE_URI}/download/v${PV}/${BP}.tar.gz \
            file://corosync.conf \
+           file://CVE-2026-35091.patch \
            "
 SRC_URI[sha256sum] = "be361c827f99b215b3bd3fa2fb071c03dac6831c2a351963d938caef62604bc8"
 UPSTREAM_CHECK_GITTAGREGEX = "v(?P<pver>\d+(\.\d+)+)"
#1 lore raw

PATCH 2/5 corosync: patch CVE-2026-35092

From: Gyorgy Sarvari <[email protected]>

Details: https://nvd.nist.gov/vuln/detail/CVE-2026-35092

Pick the patch that mentions the CVE ID explicitly (the same commit was identified by Debian also[1])

[1]: https://security-tracker.debian.org/tracker/CVE-2026-35092

(cherry picked from commit af73e716bc7150ae8d912d8af00f6995e25f2031)
---
 .../corosync/corosync/CVE-2026-35092.patch    | 57 +++++++++++++++++++
 .../corosync/corosync_3.1.10.bb               |  1 +
 2 files changed, 58 insertions(+)
 create mode 100644 meta-networking/recipes-extended/corosync/corosync/CVE-2026-35092.patch
meta-networking/recipes-extended/corosync/corosync/CVE-2026-35092.patch new file +57 -0
new file mode 100644
index 0000000000..8182647840
@@ -0,0 +1,57 @@
+From 8f8a4747a0223b8897deda9a40a8a099c61fa80f Mon Sep 17 00:00:00 2001
+From: Jan Friesse <[email protected]>
+Date: Thu, 2 Apr 2026 09:44:06 +0200
+Subject: [PATCH] totemsrp: Fix integer overflow in memb_join_sanity
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+This commit addresses an integer overflow (wraparound) vulnerability
+in the check_memb_join_sanity function.
+
+Previously, the 32-bit unsigned network values proc_list_entries and
+failed_list_entries were added together before being promoted to
+size_t. This allowed the addition to wrap around in 32-bit arithmetic
+(e.g., 0x80000000 + 0x80000000 = 0), resulting in a required_len
+calculation that was incorrectly small.
+
+The solution is to cast the list entries to size_t and verify that
+neither exceeds the maximum allowed value before the addition occurs.
+
+Fixes: CVE-2026-35092
+
+Reported-by: Sebastián Alba Vives (@Sebasteuo / 0xS4bb1) <[email protected]>
+Signed-off-by: Jan Friesse <[email protected]>
+Also-proposed-by: nicholasyang <[email protected]>
+Reviewed-by: Christine Caulfield <[email protected]>
+
+CVE: CVE-2026-35092
+Upstream-Status: Backport [https://github.com/corosync/corosync/commit/4082294f5094a7591e4e00658c5a605f05d644f1]
+Signed-off-by: Gyorgy Sarvari <[email protected]>
+---
+ exec/totemsrp.c | 12 +++++++++++-
+ 1 file changed, 11 insertions(+), 1 deletion(-)
+
+diff --git a/exec/totemsrp.c b/exec/totemsrp.c
+index 94d6c21..6845cec 100644
+--- a/exec/totemsrp.c
++++ b/exec/totemsrp.c
+@@ -3786,7 +3786,17 @@ static int check_memb_join_sanity(
+ 		failed_list_entries = swab32(failed_list_entries);
+ 	}
+ 
+-	required_len = sizeof(struct memb_join) + ((proc_list_entries + failed_list_entries) * sizeof(struct srp_addr));
++	if (proc_list_entries > PROCESSOR_COUNT_MAX ||
++	    failed_list_entries > PROCESSOR_COUNT_MAX) {
++		log_printf (instance->totemsrp_log_level_security,
++		    "Received memb_join message list_entries exceeds the maximum "
++		    "allowed value...  ignoring.");
++
++		return (-1);
++	}
++
++	required_len = sizeof(struct memb_join) +
++	  (((size_t)proc_list_entries + (size_t)failed_list_entries) * sizeof(struct srp_addr));
+ 	if (msg_len < required_len) {
+ 		log_printf (instance->totemsrp_log_level_security,
+ 		    "Received memb_join message is too short...  ignoring.");
meta-networking/recipes-extended/corosync/corosync_3.1.10.bb +1 -0
index 0e7f48272f..722dbcbbbc 100644
@@ -10,6 +10,7 @@ inherit autotools pkgconfig systemd github-releases
 SRC_URI = "${GITHUB_BASE_URI}/download/v${PV}/${BP}.tar.gz \
            file://corosync.conf \
            file://CVE-2026-35091.patch \
+           file://CVE-2026-35092.patch \
            "
 SRC_URI[sha256sum] = "be361c827f99b215b3bd3fa2fb071c03dac6831c2a351963d938caef62604bc8"
 UPSTREAM_CHECK_GITTAGREGEX = "v(?P<pver>\d+(\.\d+)+)"
#2 lore raw

PATCH 3/5 libssh: patch CVE-2026-0968

In reply to [email protected]

From: Ankur Tyagi <[email protected]>

Backport patches [1] and [2] as mentioned in [3]

[1] https://git.libssh.org/projects/libssh.git/commit/?id=796d85f786dff62bd4bcc4408d9b7bbc855841e9
[2] https://git.libssh.org/projects/libssh.git/commit/?id=212121971fb26e1e00b72bd5402c0454a4d84c03
[3] https://security-tracker.debian.org/tracker/CVE-2026-0968

Certain functions from sftp.c were moved to a new file sftp_common.c in version 0.11.0 by following commit:
https://git.libssh.org/projects/libssh.git/commit/src/sftp_common.c?id=c3e03ab4651e4f3382e3a51c0273ade894f0c48a

This is the backport of the changes using the original file sftp.c

---
 .../libssh/libssh/CVE-2026-0968-1.patch       |  64 +++++++++
 .../libssh/libssh/CVE-2026-0968-2.patch       | 136 ++++++++++++++++++
 .../recipes-support/libssh/libssh_0.10.6.bb   |   2 +
 3 files changed, 202 insertions(+)
 create mode 100644 meta-oe/recipes-support/libssh/libssh/CVE-2026-0968-1.patch
 create mode 100644 meta-oe/recipes-support/libssh/libssh/CVE-2026-0968-2.patch
meta-oe/recipes-support/libssh/libssh/CVE-2026-0968-1.patch new file +64 -0
new file mode 100644
index 0000000000..5ed1a4e940
@@ -0,0 +1,64 @@
+From 9fd388141c973ba6fb7d45966c25d1fad9e1d419 Mon Sep 17 00:00:00 2001
+From: Jakub Jelen <[email protected]>
+Date: Mon, 22 Dec 2025 20:59:11 +0100
+Subject: [PATCH] CVE-2026-0968: sftp: Sanitize input handling in
+ sftp_parse_longname()
+
+Signed-off-by: Jakub Jelen <[email protected]>
+Reviewed-by: Andreas Schneider <[email protected]>
+
+CVE: CVE-2026-0968
+Upstream-Status: Backport [https://git.libssh.org/projects/libssh.git/commit/?id=796d85f786dff62bd4bcc4408d9b7bbc855841e9]
+
+Certain functions from sftp.c were moved to a new file sftp_common.c
+in version 0.11.0 by following commit:
+https://git.libssh.org/projects/libssh.git/commit/src/sftp_common.c?id=c3e03ab4651e4f3382e3a51c0273ade894f0c48a
+
+This is the backport of the changes which fixes the CVE in the original file
+sftp.c
+
+Signed-off-by: Ankur Tyagi <[email protected]>
+---
+ src/sftp.c | 16 +++++++++++++---
+ 1 file changed, 13 insertions(+), 3 deletions(-)
+
+diff --git a/src/sftp.c b/src/sftp.c
+index 4a77141b..2194a9ef 100644
+--- a/src/sftp.c
++++ b/src/sftp.c
+@@ -1289,13 +1289,18 @@ static char *sftp_parse_longname(const char *longname,
+     const char *p, *q;
+     size_t len, field = 0;
+ 
++    if (longname == NULL || longname_field < SFTP_LONGNAME_PERM ||
++        longname_field > SFTP_LONGNAME_NAME) {
++        return NULL;
++    }
++
+     p = longname;
+     /* Find the beginning of the field which is specified by sftp_longname_field_e. */
+-    while(field != longname_field) {
++    while (*p != '\0' && field != longname_field) {
+         if(isspace(*p)) {
+             field++;
+             p++;
+-            while(*p && isspace(*p)) {
++            while (*p != '\0' && isspace(*p)) {
+                 p++;
+             }
+         } else {
+@@ -1303,8 +1308,13 @@ static char *sftp_parse_longname(const char *longname,
+         }
+     }
+ 
++    /* If we reached NULL before we got our field fail */
++    if (field != longname_field) {
++        return NULL;
++    }
++
+     q = p;
+-    while (! isspace(*q)) {
++    while (*q != '\0' && !isspace(*q)) {
+         q++;
+     }
+ 
meta-oe/recipes-support/libssh/libssh/CVE-2026-0968-2.patch new file +136 -0

136 lines not on this page · raw message

meta-oe/recipes-support/libssh/libssh_0.10.6.bb +2 -0
index 30f68f87ce..e0ade7f67c 100644
@@ -28,6 +28,8 @@ SRC_URI = "git://git.libssh.org/projects/libssh.git;protocol=https;branch=stable
            file://CVE-2026-0966-1.patch \
            file://CVE-2026-0966-2.patch \
            file://CVE-2026-0966-3.patch \
+           file://CVE-2026-0968-1.patch \
+           file://CVE-2026-0968-2.patch \
           "
 SRCREV = "10e09e273f69e149389b3e0e5d44b8c221c2e7f6"
 
#3 lore raw

PATCH 4/5 libssh: patch CVE-2026-0967

In reply to [email protected]

From: Ankur Tyagi <[email protected]>

Backport patch [1] as mentioned in [2]

[1] https://git.libssh.org/projects/libssh.git/commit/?id=6d74aa6138895b3662bade9bd578338b0c4f8a15
[2] https://security-tracker.debian.org/tracker/CVE-2026-0967

---
 .../libssh/libssh/CVE-2026-0967.patch         | 360 ++++++++++++++++++
 .../recipes-support/libssh/libssh_0.10.6.bb   |   1 +
 2 files changed, 361 insertions(+)
 create mode 100644 meta-oe/recipes-support/libssh/libssh/CVE-2026-0967.patch
meta-oe/recipes-support/libssh/libssh/CVE-2026-0967.patch new file +360 -0
new file mode 100644
index 0000000000..c34bced2a8
@@ -0,0 +1,360 @@
+From bd18dd3a2e1fc1f76a65fbdcc4d88b8d77ff7cab Mon Sep 17 00:00:00 2001
+From: Jakub Jelen <[email protected]>
+Date: Wed, 17 Dec 2025 18:48:34 +0100
+Subject: [PATCH] CVE-2026-0967 match: Avoid recursive matching (ReDoS)
+MIME-Version: 1.0
+Content-Type: text/plain; charset=UTF-8
+Content-Transfer-Encoding: 8bit
+
+The specially crafted patterns (from configuration files) could cause
+exhaustive search or timeouts.
+
+Previous attempts to fix this by limiting recursion to depth 16 avoided
+stack overflow, but not timeouts. This is due to the backtracking,
+which caused the exponential time complexity O(N^16) of existing algorithm.
+
+This is code comes from the same function from OpenSSH, where this code
+originates from, which is not having this issue (due to not limiting the number
+of recursion), but will also easily exhaust stack due to unbound recursion:
+
+https://github.com/openssh/openssh-portable/commit/05bcd0cadf160fd4826a2284afa7cba6ec432633
+
+This is an attempt to simplify the algorithm by preventing the backtracking
+to previous wildcard, which should keep the same behavior for existing inputs
+while reducing the complexity to linear O(N*M).
+
+This fixes the long-term issue we had with fuzzing as well as recently reported
+security issue by Kang Yang.
+
+Signed-off-by: Jakub Jelen <[email protected]>
+Reviewed-by: Pavol Žáčik <[email protected]>
+(cherry picked from commit a411de5ce806e3ea24d088774b2f7584d6590b5f)
+(cherry picked from commit 6d74aa6138895b3662bade9bd578338b0c4f8a15)
+
+CVE: CVE-2026-0967
+Upstream-Status: Backport [https://git.libssh.org/projects/libssh.git/commit/?id=6d74aa6138895b3662bade9bd578338b0c4f8a15]
+
+Signed-off-by: Ankur Tyagi <[email protected]>
+---
+ src/match.c                      | 111 +++++++++++++----------------
+ tests/unittests/torture_config.c | 116 +++++++++++++++++++++++--------
+ 2 files changed, 135 insertions(+), 92 deletions(-)
+
+diff --git a/src/match.c b/src/match.c
+index 3e58f733..896d87cb 100644
+--- a/src/match.c
++++ b/src/match.c
+@@ -43,85 +43,70 @@
+ 
+ #include "libssh/priv.h"
+ 
+-#define MAX_MATCH_RECURSION 16
+-
+-/*
+- * Returns true if the given string matches the pattern (which may contain ?
+- * and * as wildcards), and zero if it does not match.
++/**
++ * @brief Compare a string with a pattern containing wildcards `*` and `?`
++ *
++ * This function is an iterative replacement for the previously recursive
++ * implementation to avoid exponential complexity (DoS) with specific patterns.
++ *
++ * @param[in]  s        The string to match.
++ * @param[in]  pattern  The pattern to match against.
++ *
++ * @return              1 if the pattern matches, 0 otherwise.
+  */
+-static int match_pattern(const char *s, const char *pattern, size_t limit)
++static int match_pattern(const char *s, const char *pattern)
+ {
+-    bool had_asterisk = false;
++    const char *s_star = NULL; /* Position in s when last `*` was met */
++    const char *p_star = NULL; /* Position in pattern after last `*` */
+ 
+-    if (s == NULL || pattern == NULL || limit <= 0) {
++    if (s == NULL || pattern == NULL) {
+         return 0;
+     }
+ 
+-    for (;;) {
+-        /* If at end of pattern, accept if also at end of string. */
+-        if (*pattern == '\0') {
+-            return (*s == '\0');
+-        }
+-
+-        /* Skip all the asterisks and adjacent question marks */
+-        while (*pattern == '*' || (had_asterisk && *pattern == '?')) {
+-            if (*pattern == '*') {
+-                had_asterisk = true;
+-            }
++    while (*s) {
++        /* Case 1: Exact match or '?' wildcard */
++        if (*pattern == *s || *pattern == '?') {
++            s++;
+             pattern++;
++            continue;
+         }
+ 
+-        if (had_asterisk) {
+-            /* If at end of pattern, accept immediately. */
+-            if (!*pattern)
+-                return 1;
+-
+-            /* If next character in pattern is known, optimize. */
+-            if (*pattern != '?') {
+-                /*
+-                 * Look instances of the next character in
+-                 * pattern, and try to match starting from
+-                 * those.
+-                 */
+-                for (; *s; s++)
+-                    if (*s == *pattern && match_pattern(s + 1, pattern + 1, limit - 1)) {
+-                        return 1;
+-                    }
+-                /* Failed. */
+-                return 0;
+-            }
+-            /*
+-             * Move ahead one character at a time and try to
+-             * match at each position.
++        /* Case 2: '*' wildcard */
++        if (*pattern == '*') {
++            /* Record the position of the star and the current string position.
++             * We optimistically assume * matches 0 characters first.
+              */
+-            for (; *s; s++) {
+-                if (match_pattern(s, pattern, limit - 1)) {
+-                    return 1;
+-                }
+-            }
+-            /* Failed. */
+-            return 0;
+-        }
+-        /*
+-         * There must be at least one more character in the string.
+-         * If we are at the end, fail.
+-         */
+-        if (!*s) {
+-            return 0;
++            p_star = ++pattern;
++            s_star = s;
++            continue;
+         }
+ 
+-        /* Check if the next character of the string is acceptable. */
+-        if (*pattern != '?' && *pattern != *s) {
+-            return 0;
++        /* Case 3: Mismatch */
++        if (p_star) {
++            /* If we have seen a star previously, backtrack.
++             * We restore the pattern to just after the star,
++             * but advance the string position (consume one more char for the
++             * star).
++             * No need to backtrack to previous stars as any match of the last
++             * star could be eaten the same way by the previous star.
++             */
++            pattern = p_star;
++            s = ++s_star;
++            continue;
+         }
+ 
+-        /* Move to the next character, both in string and in pattern. */
+-        s++;
++        /* Case 4: Mismatch and no star to backtrack to */
++        return 0;
++    }
++
++    /* Handle trailing stars in the pattern
++     * (e.g., pattern "abc*" matching "abc") */
++    while (*pattern == '*') {
+         pattern++;
+     }
+ 
+-    /* NOTREACHED */
+-    return 0;
++    /* If we reached the end of the pattern, it's a match */
++    return (*pattern == '\0');
+ }
+ 
+ /*
+@@ -172,7 +157,7 @@ int match_pattern_list(const char *string, const char *pattern,
+     sub[subi] = '\0';
+ 
+     /* Try to match the subpattern against the string. */
+-    if (match_pattern(string, sub, MAX_MATCH_RECURSION)) {
++    if (match_pattern(string, sub)) {
+       if (negated) {
+         return -1;        /* Negative */
+       } else {
+diff --git a/tests/unittests/torture_config.c b/tests/unittests/torture_config.c
+index b7c763af..3569b51a 100644
+--- a/tests/unittests/torture_config.c
++++ b/tests/unittests/torture_config.c
+@@ -1656,80 +1656,138 @@ static void torture_config_match_pattern(void **state)
+     (void) state;
+ 
+     /* Simple test "a" matches "a" */
+-    rv = match_pattern("a", "a", MAX_MATCH_RECURSION);
++    rv = match_pattern("a", "a");
+     assert_int_equal(rv, 1);
+ 
+     /* Simple test "a" does not match "b" */
+-    rv = match_pattern("a", "b", MAX_MATCH_RECURSION);
++    rv = match_pattern("a", "b");
+     assert_int_equal(rv, 0);
+ 
+     /* NULL arguments are correctly handled */
+-    rv = match_pattern("a", NULL, MAX_MATCH_RECURSION);
++    rv = match_pattern("a", NULL);
+     assert_int_equal(rv, 0);
+-    rv = match_pattern(NULL, "a", MAX_MATCH_RECURSION);
++    rv = match_pattern(NULL, "a");
+     assert_int_equal(rv, 0);
+ 
+     /* Simple wildcard ? is handled in pattern */
+-    rv = match_pattern("a", "?", MAX_MATCH_RECURSION);
++    rv = match_pattern("a", "?");
+     assert_int_equal(rv, 1);
+-    rv = match_pattern("aa", "?", MAX_MATCH_RECURSION);
++    rv = match_pattern("aa", "?");
+     assert_int_equal(rv, 0);
+     /* Wildcard in search string */
+-    rv = match_pattern("?", "a", MAX_MATCH_RECURSION);
++    rv = match_pattern("?", "a");
+     assert_int_equal(rv, 0);
+-    rv = match_pattern("?", "?", MAX_MATCH_RECURSION);
++    rv = match_pattern("?", "?");
+     assert_int_equal(rv, 1);
+ 
+     /* Simple wildcard * is handled in pattern */
+-    rv = match_pattern("a", "*", MAX_MATCH_RECURSION);
++    rv = match_pattern("a", "*");
+     assert_int_equal(rv, 1);
+-    rv = match_pattern("aa", "*", MAX_MATCH_RECURSION);
++    rv = match_pattern("aa", "*");
+     assert_int_equal(rv, 1);
+     /* Wildcard in search string */
+-    rv = match_pattern("*", "a", MAX_MATCH_RECURSION);
++    rv = match_pattern("*", "a");
+     assert_int_equal(rv, 0);
+-    rv = match_pattern("*", "*", MAX_MATCH_RECURSION);
++    rv = match_pattern("*", "*");
+     assert_int_equal(rv, 1);
+ 
+     /* More complicated patterns */
+-    rv = match_pattern("a", "*a", MAX_MATCH_RECURSION);
++    rv = match_pattern("a", "*a");
+     assert_int_equal(rv, 1);
+-    rv = match_pattern("a", "a*", MAX_MATCH_RECURSION);
++    rv = match_pattern("a", "a*");
+     assert_int_equal(rv, 1);
+-    rv = match_pattern("abababc", "*abc", MAX_MATCH_RECURSION);
++    rv = match_pattern("abababc", "*abc");
+     assert_int_equal(rv, 1);
+-    rv = match_pattern("ababababca", "*abc", MAX_MATCH_RECURSION);
++    rv = match_pattern("ababababca", "*abc");
+     assert_int_equal(rv, 0);
+-    rv = match_pattern("ababababca", "*abc*", MAX_MATCH_RECURSION);
++    rv = match_pattern("ababababca", "*abc*");
+     assert_int_equal(rv, 1);
+ 
+     /* Multiple wildcards in row */
+-    rv = match_pattern("aa", "??", MAX_MATCH_RECURSION);
++    rv = match_pattern("aa", "??");
+     assert_int_equal(rv, 1);
+-    rv = match_pattern("bba", "??a", MAX_MATCH_RECURSION);
++    rv = match_pattern("bba", "??a");
+     assert_int_equal(rv, 1);
+-    rv = match_pattern("aaa", "**a", MAX_MATCH_RECURSION);
++    rv = match_pattern("aaa", "**a");
+     assert_int_equal(rv, 1);
+-    rv = match_pattern("bbb", "**a", MAX_MATCH_RECURSION);
++    rv = match_pattern("bbb", "**a");
+     assert_int_equal(rv, 0);
+ 
+     /* Consecutive asterisks do not make sense and do not need to recurse */
+-    rv = match_pattern("hostname", "**********pattern", 5);
++    rv = match_pattern("hostname", "**********pattern");
+     assert_int_equal(rv, 0);
+-    rv = match_pattern("hostname", "pattern**********", 5);
++    rv = match_pattern("hostname", "pattern**********");
+     assert_int_equal(rv, 0);
+-    rv = match_pattern("pattern", "***********pattern", 5);
++    rv = match_pattern("pattern", "***********pattern");
+     assert_int_equal(rv, 1);
+-    rv = match_pattern("pattern", "pattern***********", 5);
++    rv = match_pattern("pattern", "pattern***********");
+     assert_int_equal(rv, 1);
+ 
+-    /* Limit the maximum recursion */
+-    rv = match_pattern("hostname", "*p*a*t*t*e*r*n*", 5);
++    rv = match_pattern("hostname", "*p*a*t*t*e*r*n*");
+     assert_int_equal(rv, 0);
+-    /* Too much recursion */
+-    rv = match_pattern("pattern", "*p*a*t*t*e*r*n*", 5);
++    rv = match_pattern("pattern", "*p*a*t*t*e*r*n*");
++    assert_int_equal(rv, 1);
++
++    /* Regular Expression Denial of Service */
++    rv = match_pattern("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
++                       "*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a");
++    assert_int_equal(rv, 1);
++    rv = match_pattern("ababababababababababababababababababababab",
++                       "*a*b*a*b*a*b*a*b*a*b*a*b*a*b*a*b");
++    assert_int_equal(rv, 1);
++
++    /* A lot of backtracking */
++    rv = match_pattern("aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaax",
++                       "a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*a*ax");
++    assert_int_equal(rv, 1);
++
++    /* Test backtracking: *a matches first 'a', fails on 'b', must backtrack */
++    rv = match_pattern("axaxaxb", "*a*b");
++    assert_int_equal(rv, 1);
++
++    /* Test greedy consumption with suffix */
++    rv = match_pattern("foo_bar_baz_bar", "*bar");
++    assert_int_equal(rv, 1);
++
++    /* Test exact suffix requirement (ensure no partial match acceptance) */
++    rv = match_pattern("foobar_extra", "*bar");
++    assert_int_equal(rv, 0);
++
++    /* Test multiple distinct wildcards */
++    rv = match_pattern("a_very_long_string_with_a_pattern", "*long*pattern");
++    assert_int_equal(rv, 1);
++
++    /* ? inside a * sequence */
++    rv = match_pattern("abcdefg", "a*c?e*g");
++    assert_int_equal(rv, 1);
++
++    /* Consecutive mixed wildcards */
++    rv = match_pattern("abc", "*?c");
++    assert_int_equal(rv, 1);
++
++    /* ? at the very end after * */
++    rv = match_pattern("abc", "ab?");
++    assert_int_equal(rv, 1);
++    rv = match_pattern("abc", "ab*?");
++    assert_int_equal(rv, 1);
++
++    /* Consecutive stars should be collapsed or handled gracefully */
++    rv = match_pattern("abc", "a**c");
++    assert_int_equal(rv, 1);
++    rv = match_pattern("abc", "***");
++    assert_int_equal(rv, 1);
++
++    /* Empty string handling */
++    rv = match_pattern("", "*");
++    assert_int_equal(rv, 1);
++    rv = match_pattern("", "?");
+     assert_int_equal(rv, 0);
++    rv = match_pattern("", "");
++    assert_int_equal(rv, 1);
+ 
++    /* Pattern longer than string */
++    rv = match_pattern("short", "short_but_longer");
++    assert_int_equal(rv, 0);
+ }
+ 
+ /* Identity file can be specified multiple times in the configuration
meta-oe/recipes-support/libssh/libssh_0.10.6.bb +1 -0
index e0ade7f67c..e4a28af7a6 100644
@@ -30,6 +30,7 @@ SRC_URI = "git://git.libssh.org/projects/libssh.git;protocol=https;branch=stable
            file://CVE-2026-0966-3.patch \
            file://CVE-2026-0968-1.patch \
            file://CVE-2026-0968-2.patch \
+           file://CVE-2026-0967.patch \
           "
 SRCREV = "10e09e273f69e149389b3e0e5d44b8c221c2e7f6"
 
#4 lore raw

PATCH 5/5 libssh: Fix CVE-2026-0965

In reply to [email protected]

From: Ankur Tyagi <[email protected]>

Backport the patch [1] as mentioned in [2]

[1] https://git.libssh.org/projects/libssh.git/commit/?id=bf390a042623e02abc8f421c4c5fadc0429a8a76
[2] https://security-tracker.debian.org/tracker/CVE-2026-0965

Ptests passed:

root@qemux86:~# ptest-runner libssh
START: ptest-runner
2026-04-28T04:44
BEGIN: /usr/lib/libssh/ptest
...
...
DURATION: 269
END: /usr/lib/libssh/ptest
2026-04-28T04:49
STOP: ptest-runner
TOTAL: 1 FAIL: 0
---
 .../libssh/libssh/CVE-2026-0965.patch         | 284 ++++++++++++++++++
 .../recipes-support/libssh/libssh_0.10.6.bb   |   1 +
 2 files changed, 285 insertions(+)
 create mode 100644 meta-oe/recipes-support/libssh/libssh/CVE-2026-0965.patch
meta-oe/recipes-support/libssh/libssh/CVE-2026-0965.patch new file +284 -0
new file mode 100644
index 0000000000..c30310bc70
@@ -0,0 +1,284 @@
+From cc84dbc554e4e3d760234ea0e24284ef09fd3428 Mon Sep 17 00:00:00 2001
+From: Jakub Jelen <[email protected]>
+Date: Thu, 11 Dec 2025 17:33:19 +0100
+Subject: [PATCH] CVE-2026-0965 config: Do not attempt to read non-regular and
+ too large configuration files
+
+Changes also the reading of known_hosts to use the new helper function
+
+Signed-off-by: Jakub Jelen <[email protected]>
+Reviewed-by: Andreas Schneider <[email protected]>
+(cherry picked from commit a5eb30dbfd8f3526b2d04bd9f0a3803b665f5798)
+
+CVE: CVE-2026-0965
+Upstream-Status: Backport [https://git.libssh.org/projects/libssh.git/commit/?id=bf390a042623e02abc8f421c4c5fadc0429a8a76]
+
+Signed-off-by: Ankur Tyagi <[email protected]>
+---
+ include/libssh/misc.h            |  4 +-
+ include/libssh/priv.h            |  3 ++
+ src/bind_config.c                |  4 +-
+ src/config.c                     |  8 ++--
+ src/dh-gex.c                     |  4 +-
+ src/known_hosts.c                |  2 +-
+ src/knownhosts.c                 |  2 +-
+ src/misc.c                       | 74 ++++++++++++++++++++++++++++++++
+ tests/unittests/torture_config.c | 20 +++++++++
+ 9 files changed, 110 insertions(+), 11 deletions(-)
+
+diff --git a/include/libssh/misc.h b/include/libssh/misc.h
+index 0924ba7f..5591c925 100644
+--- a/include/libssh/misc.h
++++ b/include/libssh/misc.h
+@@ -20,7 +20,7 @@
+ 
+ #ifndef MISC_H_
+ #define MISC_H_
+-
++#include <stdio.h>
+ #ifdef __cplusplus
+ extern "C" {
+ #endif
+@@ -106,6 +106,8 @@ char *ssh_strreplace(const char *src, const char *pattern, const char *repl);
+ 
+ int ssh_check_hostname_syntax(const char *hostname);
+ 
++FILE *ssh_strict_fopen(const char *filename, size_t max_file_size);
++
+ #ifdef __cplusplus
+ }
+ #endif
+diff --git a/include/libssh/priv.h b/include/libssh/priv.h
+index 47af57f4..b55df501 100644
+--- a/include/libssh/priv.h
++++ b/include/libssh/priv.h
+@@ -438,6 +438,9 @@ bool is_ssh_initialized(void);
+ #define SSH_ERRNO_MSG_MAX   1024
+ char *ssh_strerror(int err_num, char *buf, size_t buflen);
+ 
++/** The default maximum file size for a configuration file */
++#define SSH_MAX_CONFIG_FILE_SIZE 16 * 1024 * 1024
++
+ #ifdef __cplusplus
+ }
+ #endif
+diff --git a/src/bind_config.c b/src/bind_config.c
+index ed42cbe3..c429bce2 100644
+--- a/src/bind_config.c
++++ b/src/bind_config.c
+@@ -212,7 +212,7 @@ local_parse_file(ssh_bind bind,
+         return;
+     }
+ 
+-    f = fopen(filename, "r");
++    f = ssh_strict_fopen(filename, SSH_MAX_CONFIG_FILE_SIZE);
+     if (f == NULL) {
+         SSH_LOG(SSH_LOG_RARE, "Cannot find file %s to load",
+                 filename);
+@@ -636,7 +636,7 @@ int ssh_bind_config_parse_file(ssh_bind bind, const char *filename)
+      * option to be redefined later by another file. */
+     uint8_t seen[BIND_CFG_MAX] = {0};
+ 
+-    f = fopen(filename, "r");
++    f = ssh_strict_fopen(filename, SSH_MAX_CONFIG_FILE_SIZE);
+     if (f == NULL) {
+         return 0;
+     }
+diff --git a/src/config.c b/src/config.c
+index d4d8d419..87cdaaaf 100644
+--- a/src/config.c
++++ b/src/config.c
+@@ -215,10 +215,9 @@ local_parse_file(ssh_session session,
+         return;
+     }
+ 
+-    f = fopen(filename, "r");
++    f = ssh_strict_fopen(filename, SSH_MAX_CONFIG_FILE_SIZE);
+     if (f == NULL) {
+-        SSH_LOG(SSH_LOG_RARE, "Cannot find file %s to load",
+-                filename);
++        /* The underlying function logs the reasons */
+         return;
+     }
+ 
+@@ -1205,8 +1204,9 @@ int ssh_config_parse_file(ssh_session session, const char *filename)
+     int parsing, rv;
+     bool global = 0;
+ 
+-    f = fopen(filename, "r");
++    f = ssh_strict_fopen(filename, SSH_MAX_CONFIG_FILE_SIZE);
+     if (f == NULL) {
++        /* The underlying function logs the reasons */
+         return 0;
+     }
+ 
+diff --git a/src/dh-gex.c b/src/dh-gex.c
+index 642a88ae..aadc7c09 100644
+--- a/src/dh-gex.c
++++ b/src/dh-gex.c
+@@ -520,9 +520,9 @@ static int ssh_retrieve_dhgroup(char *moduli_file,
+     }
+ 
+     if (moduli_file != NULL)
+-        moduli = fopen(moduli_file, "r");
++        moduli = ssh_strict_fopen(moduli_file, SSH_MAX_CONFIG_FILE_SIZE);
+     else
+-        moduli = fopen(MODULI_FILE, "r");
++        moduli = ssh_strict_fopen(MODULI_FILE, SSH_MAX_CONFIG_FILE_SIZE);
+ 
+     if (moduli == NULL) {
+         char err_msg[SSH_ERRNO_MSG_MAX] = {0};
+diff --git a/src/known_hosts.c b/src/known_hosts.c
+index f660a6f3..ba2ae4d5 100644
+--- a/src/known_hosts.c
++++ b/src/known_hosts.c
+@@ -83,7 +83,7 @@ static struct ssh_tokens_st *ssh_get_knownhost_line(FILE **file,
+     struct ssh_tokens_st *tokens = NULL;
+ 
+     if (*file == NULL) {
+-        *file = fopen(filename,"r");
++        *file = ssh_strict_fopen(filename, SSH_MAX_CONFIG_FILE_SIZE);
+         if (*file == NULL) {
+             return NULL;
+         }
+diff --git a/src/knownhosts.c b/src/knownhosts.c
+index 109b4f06..f0fde696 100644
+--- a/src/knownhosts.c
++++ b/src/knownhosts.c
+@@ -232,7 +232,7 @@ static int ssh_known_hosts_read_entries(const char *match,
+     FILE *fp = NULL;
+     int rc;
+ 
+-    fp = fopen(filename, "r");
++    fp = ssh_strict_fopen(filename, SSH_MAX_CONFIG_FILE_SIZE);
+     if (fp == NULL) {
+         char err_msg[SSH_ERRNO_MSG_MAX] = {0};
+         SSH_LOG(SSH_LOG_WARN, "Failed to open the known_hosts file '%s': %s",
+diff --git a/src/misc.c b/src/misc.c
+index 565abcfc..e78c92ba 100644
+--- a/src/misc.c
++++ b/src/misc.c
+@@ -37,6 +37,7 @@
+ #endif /* _WIN32 */
+ 
+ #include <errno.h>
++#include <fcntl.h>
+ #include <limits.h>
+ #include <stdio.h>
+ #include <string.h>
+@@ -2074,4 +2075,77 @@ int ssh_check_hostname_syntax(const char *hostname)
+     return SSH_OK;
+ }
+ 
++/**
++ * @internal
++ *
++ * @brief Safely open a file containing some configuration.
++ *
++ * Runs checks if the file can be used as some configuration file (is regular
++ * file and is not too large). If so, returns the opened file (for reading).
++ * Otherwise logs error and returns `NULL`.
++ *
++ * @param filename      The path to the file to open.
++ * @param max_file_size Maximum file size that is accepted.
++ *
++ * @returns the opened file or `NULL` on error.
++ */
++FILE *ssh_strict_fopen(const char *filename, size_t max_file_size)
++{
++    FILE *f = NULL;
++    struct stat sb;
++    char err_msg[SSH_ERRNO_MSG_MAX] = {0};
++    int r, fd;
++
++    /* open first to avoid TOCTOU */
++    fd = open(filename, O_RDONLY);
++    if (fd == -1) {
++        SSH_LOG(SSH_LOG_RARE,
++                "Failed to open a file %s for reading: %s",
++                filename,
++                ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
++        return NULL;
++    }
++
++    /* Check the file is sensible for a configuration file */
++    r = fstat(fd, &sb);
++    if (r != 0) {
++        SSH_LOG(SSH_LOG_RARE,
++                "Failed to stat %s: %s",
++                filename,
++                ssh_strerror(errno, err_msg, SSH_ERRNO_MSG_MAX));
++        close(fd);
++        return NULL;
++    }
++    if ((sb.st_mode & S_IFMT) != S_IFREG) {
++        SSH_LOG(SSH_LOG_RARE,
++                "The file %s is not a regular file: skipping",
++                filename);
++        close(fd);
++        return NULL;
++    }
++
++    if ((size_t)sb.st_size > max_file_size) {
++        SSH_LOG(SSH_LOG_RARE,
++                "The file %s is too large (%jd MB > %zu MB): skipping",
++                filename,
++                (intmax_t)sb.st_size / 1024 / 1024,
++                max_file_size / 1024 / 1024);
++        close(fd);
++        return NULL;
++    }
++
++    f = fdopen(fd, "r");
++    if (f == NULL) {
++        SSH_LOG(SSH_LOG_RARE,
++                "Failed to open a file %s for reading: %s",
++                filename,
++                ssh_strerror(r, err_msg, SSH_ERRNO_MSG_MAX));
++        close(fd);
++        return NULL;
++    }
++
++    /* the flcose() will close also the underlying fd */
++    return f;
++}
++
+ /** @} */
+diff --git a/tests/unittests/torture_config.c b/tests/unittests/torture_config.c
+index 3569b51a..b4c7b0a7 100644
+--- a/tests/unittests/torture_config.c
++++ b/tests/unittests/torture_config.c
+@@ -1908,6 +1908,23 @@ static void torture_config_make_absolute_no_sshdir(void **state)
+     torture_config_make_absolute_int(state, 1);
+ }
+ 
++/* Invalid configuration files
++ */
++static void torture_config_invalid(void **state)
++{
++    ssh_session session = *state;
++
++    ssh_options_set(session, SSH_OPTIONS_HOST, "Bar");
++
++    /* non-regular file -- ignored (or missing on non-unix) so OK */
++    _parse_config(session, "/dev/random", NULL, SSH_OK);
++
++#ifndef _WIN32
++    /* huge file -- ignored (or missing on non-unix) so OK */
++    _parse_config(session, "/proc/kcore", NULL, SSH_OK);
++#endif
++}
++
+ int torture_run_tests(void)
+ {
+     int rc;
+@@ -1980,6 +1997,9 @@ int torture_run_tests(void)
+                                         setup, teardown),
+         cmocka_unit_test_setup_teardown(torture_config_make_absolute_no_sshdir,
+                                         setup_no_sshdir, teardown),
++        cmocka_unit_test_setup_teardown(torture_config_invalid,
++                                        setup,
++                                        teardown),
+     };
+ 
+ 
meta-oe/recipes-support/libssh/libssh_0.10.6.bb +1 -0
index e4a28af7a6..189305fd2e 100644
@@ -31,6 +31,7 @@ SRC_URI = "git://git.libssh.org/projects/libssh.git;protocol=https;branch=stable
            file://CVE-2026-0968-1.patch \
            file://CVE-2026-0968-2.patch \
            file://CVE-2026-0967.patch \
+           file://CVE-2026-0965.patch \
           "
 SRCREV = "10e09e273f69e149389b3e0e5d44b8c221c2e7f6"