Visitar URL original
ossfuzz: test #1953 on master by vszakats · Pull Request #2509 · libssh2/libssh2 · GitHub
Skip to content

ossfuzz: test #1953 on master - #2509

Draft
vszakats wants to merge 16 commits into
libssh2:masterfrom
vszakats:morefuzz
Draft

vszakats wants to merge 16 commits into
libssh2:masterfrom
vszakats:morefuzz

Conversation

@vszakats

@vszakats vszakats commented Aug 4, 2026 •

Copy link
Copy Markdown
Member

Also:

  • tidy up code and LLM comments.

@vszakats

vszakats commented Aug 4, 2026 •

Copy link
Copy Markdown
Member Author

the hang again... nice.

what may be the reason of this?

edit: in ssh2_knownhost_fuzzer.

@vszakats
vszakats marked this pull request as draft August 4, 2026 11:52
@vszakats vszakats changed the title ossfuzz: test 1953 ossfuzz: test #1953 on master Aug 4, 2026
@vszakats
vszakats requested a lite review from Copilot August 4, 2026 21:03

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Adds two new OSS-Fuzz harnesses to broaden libssh2’s fuzz coverage beyond the existing handshake fuzzer, and wires them into the Autotools/CMake OSS-Fuzz build and packaging scripts.

Changes:

  • Add ssh2_sftp_packet_fuzzer to drive banner reception and SSH binary packet parsing/dispatch using a synthetic server banner + wrapped fuzz payload.
  • Add ssh2_knownhost_fuzzer to exercise libssh2_knownhost_readline() and the writeline path.
  • Update OSS-Fuzz build scripts (Autotools + CMake + ossfuzz.sh) to build and export the new fuzz targets.

Reviewed changes

Copilot reviewed 5 out of 5 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
tests/ossfuzz/ssh2_sftp_packet_fuzzer.cc New fuzzer harness for SSH transport packet parsing/dispatch (with fixed server banner).
tests/ossfuzz/ssh2_knownhost_fuzzer.cc New fuzzer harness for known_hosts line parsing and serialization.
tests/ossfuzz/ossfuzz.sh Copy the additional fuzz binaries into $OUT.
tests/ossfuzz/Makefile.am Build the two new fuzzers when OSS-Fuzz targets are enabled.
tests/ossfuzz/CMakeLists.txt Generalize fuzzer target creation/linking via a loop for all fuzzers.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

vszakats added a commit to vszakats/libssh2 that referenced this pull request Aug 5, 2026
"MAX_PAYLOAD_SIZE is larger than LIBSSH2_PACKET_MAXPAYLOAD (40000). For
inputs >~39995 bytes, packet_length exceeds libssh2's inbound limit and
_libssh2_transport_read() returns OUT_OF_BOUNDARY early, which reduces
the harness's ability to reach deeper parsing/dispatch code."

libssh2#2509 (comment)
vszakats added a commit to vszakats/libssh2 that referenced this pull request Aug 5, 2026
"MAX_PAYLOAD_SIZE is larger than LIBSSH2_PACKET_MAXPAYLOAD (40000). For
inputs >~39995 bytes, packet_length exceeds libssh2's inbound limit and
_libssh2_transport_read() returns OUT_OF_BOUNDARY early, which reduces
the harness's ability to reach deeper parsing/dispatch code."

libssh2#2509 (comment)
@vszakats

vszakats commented Aug 5, 2026 •

Copy link
Copy Markdown
Member Author

After making the knownhost fuzzer a no-op, it still hangs the same way:

2026-08-05 12:09:41,178 - root - WARNING - Failed to download corpus for ssh2_knownhost_fuzzer.
2026-08-05 12:09:41,178 - root - INFO - Starting fuzzing
#include "libssh2.h"

extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size)
{
    return 0;
}

XananasX7 and others added 16 commits August 7, 2026 21:14
## Summary

Adds two new libFuzzer harnesses targeting previously uncovered parsing paths in libssh2.

### New harness: `tests/ossfuzz/ssh2_sftp_packet_fuzzer.cc`

Complements the existing `ssh2_client_fuzzer` by prepending a valid `SSH-2.0` server banner so that `banner_receive()` in `session.c` always completes and the code enters the SSH binary-packet transport layer with fuzz-controlled payload bytes.

**Coverage added:**
- Server banner/version string parsing (`session.c:banner_receive`)
- SSH binary packet transport reader (`transport.c:_libssh2_transport_read`)
- SSH message type dispatch (`packet.c:_libssh2_packet_add`) including:
  - `SSH_MSG_DISCONNECT` string parsing
  - `SSH_MSG_DEBUG` and `SSH_MSG_IGNORE` handlers
  - `SSH_MSG_EXT_INFO` extension negotiation
  - `SSH_MSG_GLOBAL_REQUEST` parsing
  - `SSH_MSG_CHANNEL_*` family (DATA, EOF, CLOSE, REQUEST, OPEN, WINDOW_ADJUST)
  - `SSH_MSG_USERAUTH_BANNER` string extraction
  - `SSH_MSG_KEXINIT` algorithm name-list parser in `kex.c`

### New harness: `tests/ossfuzz/ssh2_knownhost_fuzzer.cc`

Exercises `libssh2_knownhost_readline()` which parses lines from an OpenSSH `known_hosts` file. Uses only the public API; no network access required.

**Coverage added:**
- Plain and comma-separated hostname parsing (`knownhost.c:oldstyle_hostline`)
- Hashed hostname parsing (`knownhost.c:hashed_hostline`, `|1|salt|hash` format)
- Key-type token recognition and base64 public-key blob decoding (`misc.c:_libssh2_base64_decode`)
- HMAC-SHA1 computation for hashed host verification
- `libssh2_knownhost_writeline()` round-trip for successfully parsed entries

### Why this matters

The existing `ssh2_client_fuzzer` exercises the client-side SSH handshake but:
- Does not bypass banner parsing (banner data and binary-packet data are interleaved in the same fuzz corpus, making it hard for the fuzzer to reach post-banner code)
- Does not cover the known-hosts parser (`knownhost_readline`, `hashed_hostline`, base64 decode) — reachable whenever an application calls `libssh2_knownhost_readfile()`

Both paths process attacker-controlled data and are reachable in production deployments.

### Build

Both harnesses integrate with the existing `tests/ossfuzz/ossfuzz.sh` build system and require no new dependencies. Verified to compile cleanly with OpenSSL + zlib on Debian Bookworm.

Ref 1953
"MAX_PAYLOAD_SIZE is larger than LIBSSH2_PACKET_MAXPAYLOAD (40000). For
inputs >~39995 bytes, packet_length exceeds libssh2's inbound limit and
_libssh2_transport_read() returns OUT_OF_BOUNDARY early, which reduces
the harness's ability to reach deeper parsing/dispatch code."

libssh2#2509 (comment)

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

Packet framing is usually invalid, and advertised SFTP and HMAC coverage is not implemented.

Once you've addressed the issues Copilot identified, you can request another Copilot review.

Review details
  • Files reviewed: 6/6 changed files
  • Comments generated: 4
  • Review effort level: Balanced

Comment on lines +84 to +86
const uint8_t padding_length = 4;
uint32_t packet_length = (uint32_t)(1 + payload_len + padding_length);
size_t pkt_buf_len = 4 + 1 + payload_len + padding_length;
Comment thread tests/ossfuzz/Makefile.am
Comment on lines +27 to +28
ssh2_sftp_packet_fuzzer \
ssh2_knownhost_fuzzer
Comment on lines +17 to +20
* All of these fields involve string parsing, base64 decoding, and
* (for hashed hosts) HMAC computation - paths that process
* attacker-controlled data in any deployment that calls
* libssh2_knownhost_readfile() or libssh2_knownhost_readline().
* SPDX-License-Identifier: BSD-3-Clause
*/

/* Fuzz harness for libssh2 SSH binary packet dispatch and SFTP packet parsing.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants