delorie.com/archives/browse.cgi   search  
Mail Archives: cygwin/2014/09/15/10:36:21

X-Recipient: archive-cygwin AT delorie DOT com
DomainKey-Signature: a=rsa-sha1; c=nofws; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:message-id:date:from:mime-version:to:subject
:references:in-reply-to:content-type:content-transfer-encoding;
q=dns; s=default; b=wDQmFxrdrQuLDWr7dWb1/Zbriaj+/D59rQCPu9vTIk6
znIbOLMDfhUjVVi+b3bWMYSSXbljYK8yrFGU3iHXwq3a2wPCMFAIxja5cAth3mCR
kYTQxWaOoHDATW0sSMaPlKktxT9t3/SBN6XjagIjHUO7u8UDbTPiJD/L4nfJUHDA
=
DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=sourceware.org; h=list-id
:list-unsubscribe:list-subscribe:list-archive:list-post
:list-help:sender:message-id:date:from:mime-version:to:subject
:references:in-reply-to:content-type:content-transfer-encoding;
s=default; bh=ge1aySgGU+05XUqvUIdc7esGDvs=; b=tGwd7P5TsAkv10S+1
AzUK0FBz/553NhitzKwOYLCqOdocBASpLThMFl9lADjZPM1oWw22l7dNBUA5wlSU
n8+miDWvGyXmlXTFCoFlQDtWE5Tcq7UmAoBh01IT5Yev+VplDngSqt4pAkiNMzfH
ggBdSlbf3MipRojA/5W65iYTTk=
Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm
List-Id: <cygwin.cygwin.com>
List-Subscribe: <mailto:cygwin-subscribe AT cygwin DOT com>
List-Archive: <http://sourceware.org/ml/cygwin/>
List-Post: <mailto:cygwin AT cygwin DOT com>
List-Help: <mailto:cygwin-help AT cygwin DOT com>, <http://sourceware.org/ml/#faqs>
Sender: cygwin-owner AT cygwin DOT com
Mail-Followup-To: cygwin AT cygwin DOT com
Delivered-To: mailing list cygwin AT cygwin DOT com
Authentication-Results: sourceware.org; auth=none
X-Virus-Found: No
X-Spam-SWARE-Status: No, score=-2.3 required=5.0 tests=AWL,BAYES_00,RCVD_IN_DNSWL_NONE,RP_MATCHES_RCVD autolearn=ham version=3.3.2
X-HELO: mailout05.t-online.de
Message-ID: <5416F946.7010905@t-online.de>
Date: Mon, 15 Sep 2014 16:35:50 +0200
From: Christian Franke <Christian DOT Franke AT t-online DOT de>
User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64; rv:29.0) Gecko/20100101 Firefox/29.0 SeaMonkey/2.26.1
MIME-Version: 1.0
To: cygwin AT cygwin DOT com
Subject: Re: Cannot exec() program outside of /bin if PATH is unset
References: <5413271B DOT 1010109 AT t-online DOT de> <54134A83 DOT 80107 AT redhat DOT com> <54135451 DOT 3060902 AT t-online DOT de> <601154762 DOT 20140913012935 AT yandex DOT ru> <541378C4 DOT 6030705 AT t-online DOT de> <54137BDE DOT 6040907 AT redhat DOT com> <54137C7F DOT 1040507 AT redhat DOT com> <541415B1 DOT 8090500 AT t-online DOT de> <541698CC DOT 7090802 AT lysator DOT liu DOT se>
In-Reply-To: <541698CC.7090802@lysator.liu.se>
X-IsSubscribed: yes

Peter Rosin wrote:
> On 2014-09-13 12:00, Christian Franke wrote:
>> Note that setting PATH=/bin on Cygwin does not fix the security problem in the DLL search order. Even with "SafeDllSearchMode" enabled, the current directory is always checked before PATH. Running some Cygwin program from /usr/sbin, /usr/local/bin, /usr/libexec, ... would load a possible malicious cyg*.dll from current directory regardless of PATH setting. Only programs in /bin are safe.
>>
>> Using SetDllDirectory("c:\\cygwin\\bin") somewhere in cygwin1.dll would fix this also.
> How could a call inside a DLL fix the library search order used
> to find that same DLL? Yes, it is possible (or likely) that
> SetDllDirectory fixes the immediate problem for processes that
> are started *by* cygwin1.dll, but it is not effective for Cygwin
> processes that are started by some direct use of the Win32 API.

Of course, and the same is true for any non-Cygwin program. The security 
fix is effective only for any CreateProcess()/LoadLibrary() call within 
the process which called SetDllDirectory(DIR_OF_SUBSYSTEM_DLLs).


> Also, SetDllDirectory will kill all attempts to run 32-bit
> Cygwin programs from 64-bit Cygwin (and vice versa).

For programs in /bin directory, there is no problem because the EXE's 
directory is always searched first for required DLLs. SetDllDirectory() 
then has no effect for cyg*.dll search order.

For other programs it also works because Windows (at least 7) apparently 
skips 32-bit DLLs when searching for 64-bit ones (and vice versa). It is 
then required that PATH contains the other Cygwin's /bin directory.

Testcase for calling 64-bit from 32-bit:

exe in /bin:

   SetDllDirectory("c:\\cygwin\\bin");
   unsetenv("PATH");
   execl("/cygdrive/c/cygwin64/bin/uname", "uname", "-a", (const char*)0);

exe not in /bin:

   SetDllDirectory("c:\\cygwin\\bin");
   setenv("PATH", "/cygdrive/c/cygwin64/bin", 1);
   execl("/cygdrive/c/cygwin64/usr/sbin/alternatives", "alternatives", 
(const char*)0);

In both cases, the SetDllDirectory() call does not break anything.

Cheers,
Christian


--
Problem reports:       http://cygwin.com/problems.html
FAQ:                   http://cygwin.com/faq/
Documentation:         http://cygwin.com/docs.html
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019