|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2016-11-01 21:16 UTC] ben at indietorrent dot org
Description:
------------
Summary
Prior to PHP 7 (ssh2 version 0.13), disconnections were performed implicitly by calling unset() on the associated resource. And while it was nice to see an explicit ssh2_disconnect() method added in PHP 7 (ssh2 version 1.0), calling it seems to result in a segfault.
Note: Passing a disconnect callback function to ssh2_connect() seems still to be supported, but this approach results in a segfault, too.
This crashing makes it impossible to terminate SSH connections gracefully. As such, when ssh2_connect() is wrapped in any sort of loop, every connection persists on the remote server until the PHP script has finished executing completely. This can exhaust resources on the remote server very quickly and result in a DoS scenario, in effect.
PHP Version
$ php -v
PHP 7.0.12-1+deb.sury.org~xenial+1 (cli) ( NTS )
Copyright (c) 1997-2016 The PHP Group
Zend Engine v3.0.0, Copyright (c) 1998-2016 Zend Technologies
with Zend OPcache v7.0.12-1+deb.sury.org~xenial+1, Copyright (c) 1999-2016, by Zend Technologies
PECL ssh2 Version
$ pecl info ssh2
About pecl.php.net/ssh2-1.0
===========================
Release Type PECL-style PHP extension (source code)
Name ssh2
Channel pecl.php.net
Summary Bindings for the libssh2 library
Description Provides bindings to the functions of libssh2
which implements the SSH2 protocol.
libssh2 is available from http://libssh2.org/
ssh2 1.0 and above is PHP 7 only. To install a
version that is PHP 5 compatible you can run
'pecl install ssh2-0.13'
Note that reaching version 1.0 does NOT
indicate we've reached a stable release.
Maintainers Casper Langemeijer <langemeijer@php.net> (lead)
Pierre Joye <pierre@php.net> (lead)
Mike Sullivan <mikesul@php.net> (lead, inactive)
Sara Golemon <pollita@php.net> (lead, inactive)
Release Date 2016-06-12 15:05:45
Release Version 1.0 (alpha)
API Version 1.0 (beta)
License PHP License (http://www.php.net/license)
Release Notes - Release for PHP 7 (Sean DuBois)
- Made win32 builds depend on zlib and openssl
extensions (Credomane Evonguard)
- Add blocking call to php_ssh2_direct_tcpip
(Credomane Evonguard)
- Added explicit ssh2_disconnect function
(Credomane Evonguard)
- Fixed bug #72150 - Fixing segfault when
passing env variables (Krakjoe)
Required Dependencies PHP version 7.0.0-8.0.0
PEAR installer version 1.4.0 or newer
package.xml version 2.0
Last Modified 2016-07-16 18:57
Previous Installed - None -
Version
Installed modules:
$ php -m
[PHP Modules]
calendar
Core
ctype
curl
date
dom
exif
fileinfo
filter
ftp
gd
gettext
hash
iconv
imagick
imap
intl
json
libxml
mbstring
mcrypt
memcache
mysqli
mysqlnd
openssl
pcntl
pcre
PDO
pdo_mysql
pdo_sqlite
Phar
posix
pspell
readline
recode
Reflection
session
shmop
SimpleXML
soap
sockets
SPL
sqlite3
ssh2
standard
sysvmsg
sysvsem
sysvshm
tidy
tokenizer
wddx
xml
xmlreader
xmlrpc
xmlwriter
xsl
Zend OPcache
zip
zlib
[Zend Modules]
Zend OPcache
php.ini Changes
[None]
Test script:
---------------
https://gist.github.com/cbj4074/7b8b3509150d35a786a51dce395bf9c6
This example uses public-key authentication to connect to the remote server. I don't know whether or not the segfault occurs in the same way when using password authentication.
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 07:00:01 2025 UTC |
I found a few minutes in which to reproduce the issue with the most basic example possible, and PHP still segfaults: <?php $ssh = ssh2_connect('localhost', 22, array('hostkey'=>'ssh-rsa,ssh-dss')); // The segfault happens with both password and public-key authentication. #ssh2_auth_pubkey_file($ssh, 'root', '/root/.ssh/php-ssh2-test.pub', '/root/.ssh/php-ssh2-test'); ssh2_auth_password($ssh, 'root', 'password'); $sftp = ssh2_sftp($ssh); ssh2_disconnect($ssh); exit; P.S. The ssh_disconnect() function isn't documented in the PHP manual. I do realize that ssh2-1.0 is still considered to be non-stable, but given that ssh-0.13 isn't API-compatible with PHP 5, it seems prudent to add it to the manual and note its requirement to be PECL ssh2 >= 1.0.