RHEL Engineering is moving the tracking of its product development work on RHEL 6 through RHEL 9 to Red Hat Jira (issues.redhat.com). If you're a Red Hat customer, please continue to file support cases via the Red Hat customer portal. If you're not, please head to the "RHEL project" in Red Hat Jira and file new tickets here. Individual Bugzilla bugs in the statuses "NEW", "ASSIGNED", and "POST" are being migrated throughout September 2023. Bugs of Red Hat partners with an assigned Engineering Partner Manager (EPM) are migrated in late September as per pre-agreed dates. Bugs against components "kernel", "kernel-rt", and "kpatch" are only migrated if still in "NEW" or "ASSIGNED". If you cannot log in to RH Jira, please consult article #7032570. That failing, please send an e-mail to the RH Jira admins at rh-issues@redhat.com to troubleshoot your issue as a user management inquiry. The email creates a ServiceNow ticket with Red Hat. Individual Bugzilla bugs that are migrated will be moved to status "CLOSED", resolution "MIGRATED", and set with "MigratedToJIRA" in "Keywords". The link to the successor Jira issue will be found under "Links", have a little "two-footprint" icon next to it, and direct you to the "RHEL project" in Red Hat Jira (issue links are of type "https://issues.redhat.com/browse/RHEL-XXXX", where "X" is a digit). This same link will be available in a blue banner at the top of the page informing you that that bug has been migrated.
Bug 1975500 - [RFE] Zero errno before check strtoul() possible error at ssh_analyze_banner()
Summary: [RFE] Zero errno before check strtoul() possible error at ssh_analyze_banner()
Keywords:
Status: CLOSED ERRATA
Alias: None
Product: Red Hat Enterprise Linux 9
Classification: Red Hat
Component: libssh
Version: 9.0
Hardware: Unspecified
OS: Unspecified
low
low
Target Milestone: beta
: ---
Assignee: Norbert Pócs
QA Contact: Alexander Sosedkin
URL:
Whiteboard:
Depends On:
Blocks:
TreeView+ depends on / blocked
 
Reported: 2021-06-23 19:44 UTC by Marco Benatto
Modified: 2023-05-09 10:18 UTC (History)
1 user (show)

Fixed In Version: libssh-0.10.4-3.el9
Doc Type: No Doc Update
Doc Text:
Clone Of:
Environment:
Last Closed: 2023-05-09 08:15:49 UTC
Type: Bug
Target Upstream Version:
Embargoed:


Attachments (Terms of Use)


Links
System ID Private Priority Status Summary Last Updated
Red Hat Issue Tracker CRYPTO-7178 0 None None None 2022-05-10 09:25:15 UTC
Red Hat Product Errata RHBA-2023:2476 0 None None None 2023-05-09 08:15:55 UTC

Description Marco Benatto 2021-06-23 19:44:30 UTC
Description of problem:
Currently libssh uses strtoul function to convert ssh version from string to unsigned long int at ssh_analyze_banner(), in case of error this call returns a code via errno variable. The function uses errno return to check for possible errors when converting the string for both major and minor version values, however it doesn't zero errno value. As it's possible previous errors values may be still stored, even on success of strtoul() call, the verification may fail. This can lead to unpredicted behavior as OpenSSH version in the session will remain uninitialized. 

int ssh_analyze_banner(ssh_session session, int server)
1222 {
.
.
.
    openssh = strstr(banner, "OpenSSH");
1271     if (openssh != NULL) {
1272         char *tmp = NULL;
1273         unsigned long int major = 0UL;
1274         unsigned long int minor = 0UL;
1275
1276         /*
1277          * The banner is typical:
1278          * OpenSSH_5.4
1279          * 012345678901234567890
1280          */
1281         if (strlen(openssh) > 9) {
1282             major = strtoul(openssh + 8, &tmp, 10);
1283             if ((tmp == (openssh + 8)) ||
1284                 ((errno == ERANGE) && (major == ULONG_MAX)) || <--------
1285                 ((errno != 0) && (major == 0)) || <---------------------
1286                 ((major < 1) || (major > 100))) {
1287                 /* invalid major */
1288                 goto done;
1289             }
1290
1291             minor = strtoul(openssh + 10, &tmp, 10);
1292             if ((tmp == (openssh + 10)) ||
1293                 ((errno == ERANGE) && (major == ULONG_MAX)) || <--------
1294                 ((errno != 0) && (major == 0)) || <---------------------
1295                 (minor > 100)) {
1296                 /* invalid minor */
1297                 goto done;
1298             }
1299
1300             session->openssh = SSH_VERSION_INT(((int) major), ((int) minor), 0); 
1301
1302             SSH_LOG(SSH_LOG_PROTOCOL,
1303                     "We are talking to an OpenSSH client version: %lu.%lu (%x)",
1304                     major, minor, session->openssh);
1305         }
1306     }   
1307

This is pretty low prio and can be considered a kind of a hardening.

Comment 11 errata-xmlrpc 2023-05-09 08:15:49 UTC
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory (libssh bug fix and enhancement update), and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://access.redhat.com/errata/RHBA-2023:2476


Note You need to log in before you can comment on or make changes to this bug.