Skip to content

os400qc3: validate DH public value - #2402

Closed
monnerat wants to merge 5 commits into
libssh2:masterfrom
monnerat:dh-validate
Closed

monnerat wants to merge 5 commits into
libssh2:masterfrom
monnerat:dh-validate

Conversation

@monnerat

@monnerat monnerat commented Jul 23, 2026 •

Copy link
Copy Markdown
Contributor

We consider parameters as valid if 2 <= f <= p-2 and if f has at least 4 bits set.

I had to undo some tidy-up that broke compilation on os400:

((ptr)->connect)(...) instead of (ptr)->connect(...) is intentional since connect() is a macro and extra-parentheses avoid its expansion. The same applies to send() and recv().

OS400 has no uintptr_t.

Ref: GHSA-m9rg-h9jv-9gvh
Follow-up to fcf8307 #2239

Comment thread src/os400qc3.c Resolved
Comment thread src/os400qc3.c Resolved
Comment thread src/os400qc3.c Resolved

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 stricter Diffie–Hellman public value validation for the OS/400 QC3 backend and restores OS/400-safe calling patterns where system macros like connect(), send(), and recv() would otherwise expand unexpectedly.

Changes:

  • Add DH public value validation (range check 2 <= f <= p-2 and minimum bit population) in the OS/400 QC3 backend.
  • Introduce local big-number subtraction helper for the OS/400 backend and adjust QC3 HMAC key-context creation to use an int algorithm variable.
  • Prevent macro expansion of connect(), send(), and recv() by wrapping function-pointer calls in extra parentheses; adjust SSH2_UNCONST for OS/400 where uintptr_t is unavailable.

Reviewed changes

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

File Description
src/os400qc3.c Adds DH public value validation, a BN subtraction helper, and a minor QC3 HMAC init tweak.
src/libssh2_priv.h Adjusts SSH2_UNCONST for OS/400 and wraps send/recv function-pointer calls to avoid macro expansion.
src/agent.c Wraps the backend connect call to avoid macro expansion on OS/400.

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

Comment thread src/os400qc3.c Resolved
Comment thread src/os400qc3.c Resolved
Comment thread src/os400qc3.c Resolved
@monnerat

Copy link
Copy Markdown
Contributor Author
The following tests FAILED:
	 26 - test_sshd (Failed)

I don't feel it is os400qc3-related. Any hint, or test not reliable ?

@vszakats

Copy link
Copy Markdown
Member
The following tests FAILED:
	 26 - test_sshd (Failed)

I don't feel it is os400qc3-related. Any hint, or test not reliable ?

It isn't, no, my guess is it's an ML-KEM-related flaky regression:
#1644 (comment)

vszakats added a commit to vszakats/libssh2 that referenced this pull request Jul 23, 2026
To reflect that the return value is not a boolean.

Reported-by: Patrick Monnerat
Bug: libssh2#2402 (comment)
Follow-up to fcf8307 libssh2#2239
vszakats added a commit that referenced this pull request Jul 23, 2026
To reflect that the return value is not a boolean.

Reported-by: Patrick Monnerat
Bug: #2402 (comment)
Follow-up to fcf8307 #2239

Closes #2406
We consider parameters as valid if 2 <= f <= p-2 and if f has at least 4
bits set.

Also apply some changes that make libssh2 compilable on os400 again.
Comment thread src/os400qc3.c Resolved
Comment thread src/os400qc3.c Resolved
Comment thread src/os400qc3.c Resolved
Comment thread src/os400qc3.c Resolved
@vszakats vszakats changed the title os400 qc3: validate DH public value. os400qc3: validate DH public value Jul 27, 2026
@vszakats
vszakats requested a review from Copilot July 27, 2026 11:52

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

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

Comment thread src/os400qc3.c Resolved
vszakats added a commit that referenced this pull request Jul 27, 2026
@vszakats vszakats closed this in d0ca946 Jul 27, 2026
@vszakats

Copy link
Copy Markdown
Member

Thanks!

@monnerat
monnerat deleted the dh-validate branch July 27, 2026 12:23
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