PowerShell / PowerShell/Win32-OpenSSH

On remote login via ssh, sshd sets an environment variable that causes git operations over ssh to fail

Open
#2,037 9 comments 2 reactions 1 assignee View on GitHub

@tgauth is already working on this.

Since Feb 27, 2023.

Area-ssh Investigate
Dominant language
No language data
Stars
8.3k
Forks
819
PR merge metrics
No merged PRs in 30d

Description

Prerequisites
  • Write a descriptive title.
  • Make sure you are able to repro it on the latest version
  • Search the existing issues.
Steps to reproduce

If you log into a Windows host over ssh and then attempt to perform a git operation (such as pull) over ssh, it will fail. In my case it just locks up in the middle of the operation and never completes.

Expected behavior

It is expected that the git operation completes successfully.

Actual behavior

The git operation never completes.

Error details

The issue is this code related to POSIX_FD_STATE in this file:

https://github.com/PowerShell/openssh-portable/blob/latestw_all/contrib/win32/win32compat/w32fd.c

This code causes the environment variable c28fc6f98a2c44abbbd89d6a3037d0d9_POSIX_FD_STATE to appear in the shell environments created by sshd upon login. It appears to be used by sshd to transfer some file descriptor state from the sshd service exe to child processes during login.

Unfortunately, ssh client is affected by this same environment variable. It interprets it and sets file descriptor flags on it which interferes with its own operation (such as being the transport for a git operation).

The author of this code was aware of the potential for this as they wrote this comment:

		/*TODO - validate parent process - to accomodate these scenarios -
		* A posix parent process launches a regular process that inturn launches a posix child process
		* In this case the posix child process may misinterpret POSIX_FD_STATE set by grand parent
		*/

That is precisely what is going on.

The workaround is to unset the c28fc6f98a2c44abbbd89d6a3037d0d9_POSIX_FD_STATE environment variable after login and before running any git commands.

Environment data
Name                           Value
----                           -----
PSVersion                      5.1.22621.963
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.22621.963
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
Version

OpenSSH_for_Windows_9.2p1, LibreSSL 3.6.1

Visuals

No response

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.