]> xenbits.xensource.com Git - libvirt.git/commitdiff
rpc: avoid ssh interpreting malicious hostname as arguments
authorDaniel P. Berrange <berrange@redhat.com>
Fri, 11 Aug 2017 16:19:53 +0000 (17:19 +0100)
committerDaniel P. Berrange <berrange@redhat.com>
Tue, 29 Aug 2017 17:02:03 +0000 (18:02 +0100)
Inspired by the recent GIT / Mercurial security flaws
(http://blog.recurity-labs.com/2017-08-10/scm-vulns),
consider someone/something manages to feed libvirt a bogus
URI such as:

  virsh -c qemu+ssh://-oProxyCommand=gnome-calculator/system

In this case, the hosname "-oProxyCommand=gnome-calculator"
will get interpreted as an argument to ssh, not a hostname.
Fortunately, due to the set of args we have following the
hostname, SSH will then interpret our bit of shell script
that runs 'nc' on the remote host as a cipher name, which is
clearly invalid. This makes ssh exit during argv parsing and
so it never tries to run gnome-calculator.

We are lucky this time, but lets be more paranoid, by using
'--' to explicitly tell SSH when it has finished seeing
command line options. This forces it to interpret
"-oProxyCommand=gnome-calculator" as a hostname, and thus
see a fail from hostname lookup.

Signed-off-by: Daniel P. Berrange <berrange@redhat.com>
src/rpc/virnetsocket.c

index d228c8a8c879164e5c474eaa6d75bea39ad585e4..23089afef47284cf55836b418fa37fb6f7dc86d4 100644 (file)
@@ -868,7 +868,7 @@ int virNetSocketNewConnectSSH(const char *nodename,
     if (!netcat)
         netcat = "nc";
 
-    virCommandAddArgList(cmd, nodename, "sh", "-c", NULL);
+    virCommandAddArgList(cmd, "--", nodename, "sh", "-c", NULL);
 
     virBufferEscapeShell(&buf, netcat);
     if (virBufferCheckError(&buf) < 0) {