-
Notifications
You must be signed in to change notification settings - Fork 153
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SSH server comparison the channel id from INT_MAX for a signed value. #786
Conversation
Hi @asingh1508, Can you provide more details as to what problem this is solving? Thanks, |
We're describing a bug in OpenSSH where the OpenSSH daemon (sshd) incorrectly handles sender channel IDs due to an issue with signed vs. unsigned integer comparisons. Understanding the Issue: In SSH, each side of a connection assigns a sender channel ID, which is an unsigned integer (typically a random number). However, in the affected versions, sshd mistakenly compares the sender channel ID using INT_MAX (which is for signed integers). Impact: OpenSSH server code:
} |
Its not specific SSH server. This issue will happend all SSH to servers that are running OpenSSH daemon. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @asingh1508,
Thank you for providing information on how OpenSSH rejects channels with an id that exceeds INT_MAX.
I think a cleaner fix would be something like this: can you confirm and if so, adjust this PR?
diff --git a/src/main/java/com/jcraft/jsch/Channel.java b/src/main/java/com/jcraft/jsch/Channel.java
index 6fb79a7..467d591 100644
--- a/src/main/java/com/jcraft/jsch/Channel.java
+++ b/src/main/java/com/jcraft/jsch/Channel.java
@@ -139,6 +139,8 @@ public abstract class Channel {
Channel() {
synchronized (pool) {
id = index++;
+ // OpenSSH rejects channels with an id that exceeds INT_MAX
+ index &= Integer.MAX_VALUE;
pool.addElement(this);
}
}
Thanks,
Jeremy
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
@norrisjeremy Who will this pull request merged in master branch ? |
We will need to wait for @mwiede. |
Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actually, I am reviewing OpenSSH code more closely and more changes may be required.
I will respond back once I have completed a more thorough review.
sure |
Hi @asingh1508, Actually, after reviewing further, I'm not sure if I believe any changes are actually needed. All SSH channels consist of two channel id values: one assigned by the client and one assigned by the server (see RFC-4254 Section 5.1). The code you cited in OpenSSH appears to be related to handling of it's locally assigned id value that it associates with the channel and not the id value that JSch associates with the channel. Have you actually experienced a failure that can somehow be traced back to JSch channel id values exceeding Thanks, |
I had experienced a failure in customer machine where JSch channel id values exceeding
@norrisjeremy |
Can you share more details as to how you arrived at the conclusion that the failure you experienced is related to a JSch channel id exceeding 0x7fffffff (INT_MAX)? |
@norrisjeremy @norrisjeremy Jsch library is sending the channel id (signed value) In packet SSH_MSG_CHANNEL_OPEN to openssh server. Server code where channel id parsed from packet (get unsigend value of channed id) and comapre from INT_MAX. /* -- protocol input */ /* Parse a channel ID from the current packet */
|
Hi @asingh1508, But I do not believe the code you cited is actually the code that is used to parse the Thanks, |
static int
@norrisjeremy rchan is u_int type variable but it is comparing with if (rchan > INT_MAX). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @asingh1508,
Ok, I now see that this was a bug that existed until OpenSSH 8.2, when it was fixed in openssh/openssh-portable@0ecd20b.
I would encourage you in the future when opening issues or PRs with us, to include as many details as possible, to help us understand the conditions in which you were encountering as issue.
For example, pinpointing the fact that this impacted older OpenSSH releases was crucial in me understanding why this workaround is needed.
Thanks,
Jeremy
|
@norrisjeremy Buid with all tests passed succesfully. Please verify and approved.. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for you patience.
I think this looks good now.
The problem is related to the checking of what is called a sender channel ID (which is set to a unsigned INT random number by the originator of the connection). However, in the versions mentioned above the daemon is making a comparison using INT_MAX for a signed value. This means that valid channel numbers are being rejected and the connection is not established.