Basin Ilya | 1 Oct 11:52 2015

improve cygwin_attach_handle_to_fd()

Hi All.
There's undocumented function cygwin_attach_handle_to_fd() , which is
similar to Visual C _open_osfhandle() for wrapping Windows file handles.

I wanted to wrap a handle returned by CreateNamedPipe() using a custom
tool running in background and then dup the fd to parent shell using
exec 4</proc/$!/fd/4

I knew Cygwin internally used CreateNamedPipe() instead of CreatePipe()
and hoped the idea would work. Unfortunately it didn't, mainly because
cygwin_attach_handle_to_fd() calls some other windows functions on the
handle, which is fine for normal files, but makes a connected pipe unusable.

Also for stealing a pipe handle via procfs, the fd should have a special
name like "pipe:[652]". You cannot freely choose the name with

Do you think it is possible to add another function for wrapping native
pipes and sockets? It could be less destructive for a hanlde, if it took
all the needed info from its parameters instead of querying the hanlde.

Yaakov Selkowitz | 1 Sep 23:41 2015

[PATCH] Allow direct access to dlmalloc

This allows programs to override malloc/free/etc. while still being able
to access the internally provided implementation.

* common.din (__libc_calloc): Export.
(__libc_free): Export.
(__libc_mallinfo): Export.
(__libc_malloc): Export.
(__libc_mallopt): Export.
(__libc_memalign): Export.
(__libc_realloc): Export.
(__libc_valloc): Export.
* (__libc_free, free): Split out builtin dlmalloc
implementation into separate function.
(__libc_malloc, malloc): Ditto.
(__libc_realloc, realloc): Ditto.
(__libc_calloc, calloc): Ditto.
(__libc_memalign, posix_memalign, memalign): Ditto.
(__libc_valloc, valloc): Ditto.
(__libc_mallopt, mallopt): Ditto.
(__libc_mallinfo, mallinfo): Ditto.
This came to my attention due to:

Although this will likely be changed due to it being unable to link
on anything not using glibc.

The one question I have about this patch is that I see in a couple other
places that malloc-overriding code tries to override the __libc_* variants
(Continue reading)

Jon TURNEY | 24 Aug 16:20 2015

Investigating a fork failure

I'm not very happy with the assumption that this is SEP, so I did a bit 
more investigation into the problem in [1]

Installing "Lavasoft Ad-Aware Web Companion" into a W7 x86_64 VM, I'm 
able to reproduce that problem.

Running 'XWin -multiwindow' under WinDbg, with "Debug child processes 
also" enabled, a 2nd chance exception occurs in bash, with the following 
call stack:

>  # Child-SP          RetAddr           Call Site
> 00 00000000`0022e2e0 00000000`7755f37a ntdll!KiUserCallbackDispatcher+0x1b
> 01 00000000`0022e338 00000000`7755f3af USER32!NtUserRegisterWindowMessage+0xa
> 02 00000000`0022e340 000007fe`fe2f80f2 USER32!RegisterWindowMessageW+0x2b
> 03 00000000`0022e390 000007fe`fe2f8014 OLEAUT32!_RegisterClipFormat+0xc2
> 04 00000000`0022e470 000007fe`fe2f33c1 OLEAUT32!_typesDllMain+0x4c
> 05 00000000`0022e4a0 000007fe`fe2f3356 OLEAUT32!DllMain+0x21
> 06 00000000`0022e4d0 00000000`7768b108 OLEAUT32!CRT_INIT+0x2af
> 07 00000000`0022e630 00000000`7767787a ntdll!LdrpRunInitializeRoutines+0x1fe
> 08 00000000`0022e800 00000000`77677b5e ntdll!LdrpLoadDll+0x231
> 09 00000000`0022ea10 000007fe`fd439059 ntdll!LdrLoadDll+0x9a
> 0a 00000000`0022ea80 000007fe`ff917d66 KERNELBASE!LoadLibraryExW+0x22e
> 0b 00000000`0022eaf0 000007fe`ff915d22 ws2_32!DPROVIDER::Initialize+0x156
> 0c 00000000`0022f090 000007fe`ff933a90 ws2_32!DCATALOG::LoadProvider+0x7e
> 0d 00000000`0022f0c0 000007fe`ff920b9b ws2_32!DCATALOG::GetCountedCatalogItemFromCatalogEntryId+0x70
> 0e 00000000`0022f100 00000001`800ab085 ws2_32!_chkstk+0x362a
> 0f 00000000`0022f1a0 00000001`8006d8b7 cygwin1!feinitialise+0x33f95
> 10 00000000`0022f1f0 00000001`800469d0 cygwin1!dlfork+0x3ac7
> 11 00000000`0022f250 00000001`8004897c cygwin1!setprogname+0x3ed0
(Continue reading)

David Stacey | 29 Apr 19:58 2015

Coverity: Update to version 7.6.0

If there are no objections, I'd like to update our weekly Coverity scan 
to use Coverity Analysis 7.6.0 (presently we're using 7.5.0). There 
should be fewer false positives this week, but there might be some new 
coding defects picked up also.


Bryan Berns | 17 Apr 20:11 2015

Potential Enhancement Of 'noacl'?

Wasn't sure which mailing list I should throw this on so I apologize
if this is the wrong one -- just let me know for future purposes.

At least for my internal use, I plan to create a patch that will allow
me to conditionally force a permission set for a particular mount
point -- like an enhanced "noacl".  I was thinking about adding an
option after noacl[=XXX] where XXX would force XXX as the returned
permissions for any file on that mount point.

Why would someone want to do this crazy thing?  In short, I continue
to struggle with the current Cygwin permissions handling for certain
drives where programs do sanity checks on group readability (e.g.,
ssh).  Our drives have ACEs for various admin groups.  Regardless of
various philosophical viewpoints on file system administration, that's
how it is for us and it's not going to change.  I believe a select
group of others might be in this same boat.

The only other alternative that would work for us to would be read a
custom list of SIDS to ignore in group permission calculations but I
already know Corinna is not a fan of that.

Would this (the noacl thing) be something that we'd be potentially
willing to incorporate into the codebase?  If I know ahead of time,
I'll make sure I address some other artifacts (user guide
documentation, etc).



(Continue reading)

Bryan Berns | 17 Apr 04:50 2015

"Unknown" Groups Not Caching - Debugging

Posting here because that's what Corinna told me to do.

So I was looking into the issue I found with Cygwin not caching
orphaned / unknown groups.  At least for my test case, this appears to
be rooted in the RID getting striped from the end of the SID just
prior to the line being outputted (line 2464 from the exert below)
within fetch_account_from_windows(). 2460: /* Check if we know the domain.  If so, create a passwd/group 2461:    entry with domain prefix and RID as username. */ 2462: PDS_DOMAIN_TRUSTSW td = NULL; 2463: 2464: sid_sub_auth_count (sid) = sid_sub_auth_count (sid) - 1;

It's not clear to me, in general, why we're interested in creating a
"passwd/group entry with domain prefix and RID as username".  There
are quite a few nuances and special cases in this function so I feel
like any attempt on my part to produce a patch on this will likely be
completely errant.  Might someone familiar with check weigh-in on
these findings thus far?

I've attached my test script (Windows Batch).
 <at> ECHO OFF
IF EXIST C:\LocalGroupTestDir RD /S /Q C:\LocalGroupTestDir 
MKDIR C:\LocalGroupTestDir
FOR /L %%X IN (1,1,1000) DO ECHO TestFile > C:\LocalGroupTestDir\Test.%%X
FOR /L %%X IN (1,1,1000) DO ICACLS C:\LocalGroupTestDir\Test.%%X /grant LocalGroupTest:M > NUL
(Continue reading)

David Stacey | 15 Mar 20:51 2015

backtrace(3) in Cygwin

Following on from my thread on the main list [1], I have made an initial 
attempt at implementing backtrace(3) and backtrace_symbols(3). This 
still needs a little work - at the moment, the paths in the strings will 
be DOS-style rather than POSIX. However, I wanted to submit an early 
version to make sure you were happy with my approach before I spend more 
time on it.

I've also documented (in the code) the issues surrounding 
backtrace_symbols_fd(3) on Cygwin.

This is my first real submission to the programme - be kind :-)


[1] -

Attachment (exec_info.c): text/x-csrc, 7786 bytes
Corinna Vinschen | 5 Mar 16:12 2015

Evil deed: Switching development repository to git

Hi folks,

next week, I'm planning to move the combined newlib/libgloss and cygwin
repository from CVS to git.  The basic stuff is quickly done, but hooks,
mailing list handling, and changes to the websites are to be done, so I
expect the switch to take about two days.

I'll set up a commit moratorium starting next Monday at about 10:00 UTC.

When the git repo is up and working I'll throw the lever and inform the
mailing lists.  Afterwards you can expect to access the new combined
newlib/cygwin git repository via either

  git clone git://

or, if you have write permissions on the repo

  git clone

or, for the web view:



Corinna Vinschen                  Please, send mails regarding Cygwin to
Cygwin Maintainer                 cygwin AT cygwin DOT com
Red Hat
(Continue reading)

Jon TURNEY | 17 Feb 19:24 2015

Fwd: A small issue with _GNU_SOURCE

Consider the following:

$ cat test.c
#include <string.h>
#include <stdlib.h>

int main()
  long long i = random();
  return ffsll(i);

ffsll() is a GNU extension and should be prototyped when _GNU_SOURCE is 

random() is in SUSv2 and requires _XOPEN_SOURCE=500

$ gcc test.c -Wall -ansi -D_XOPEN_SOURCE=700
test.c: In function ‘main’:
test.c:8:2: warning: implicit declaration of function ‘ffsll’

This is correct

$ gcc test.c -Wall -ansi -D_XOPEN_SOURCE=700 -D_GNU_SOURCE
test.c: In function ‘main’:
test.c:8:2: warning: implicit declaration of function ‘ffsll’

This looks like a problem with newlib's sys/cdefs.h.  _XOPEN_SOURCE 
causes _POSIX_C_SOURCE to be defined, which prevents _GNU_SOURCE from 
(Continue reading)

George Prekas | 12 Nov 11:35 2014

Unexpected behavior using arrow keys on the terminal

Using Cygwin 1.7.32, mintty 1.1.3 and OpenSSH_6.7p1 I am getting unexpected behavior regarding the use of
arrow keys on the terminal. You can reproduce the behavior by doing the following:

ssh linux
cd /usr/src/linux/tools/perf
cd ~
/usr/src/linux/tools/perf/perf record echo 42
/usr/src/linux/tools/perf/perf report

Pressing UP or DOWN should highlight one of the rows displayed. You can verify expected behavior by using
either PuTTY or native Linux.

Observation #1: You can fix perf's behavior by applying perf.patch (attached).

Observation #2: Using Wireshark, I've observed that when I ssh to a host and press UP or DOWN on my terminal 3
packets are transmitted from the client. PuTTY on the other hand transmits only 1 packet (larger in size).

Observation #3: I wrote the program test.c (attached). If I run it and press UP or DOWN:
* on Windows from cmd.exe it says "Read 3 bytes. First is 27."
* on Linux it says "Read 3 bytes. First is 27."
* on Linux via PuTTY it says "Read 3 bytes. First is 27."
* on Windows from mintty.exe it says "Read 1 bytes. First is 27. Read 1 bytes. First is 91. Read 1 bytes. First
is 65."

My understanding is that the unexpected behavior occurs because Cygwin sends the UP/DOWN sequence one
byte at a time. Specifically:

* winsup\cygwin\  <at>  fhandler_pty_master::write
    This is the function called by the write system call invoked by mintty. Here len = 3. line_edit is invoked 3 times.
(Continue reading)

Christian Franke | 16 Oct 23:34 2014

Cygwin AF_UNIX emulation

Hi Corinna,

Corinna Vinschen wrote:
> On Oct 13 07:37, Christian Franke wrote:
>>> I
>>> also added a comment to explain why we do this and a FIXME comment so we
>>> don't forget we're still looking for a more generic solution for the
>>> SO_PEERCRED exchange.
>> Definitely, at least because the current AF_LOCAL emulation has some
>> security issues.
> -v?

With the secret+cred exchange, the current implementation is IMO 
reasonably safe. The client cannot connect without access to the socket 

Nasty detail: At least postfix sets the all AF_UNIX sockets to rw-rw-rw- 
and relies only on directory permissions (private: rwx------, public: 
rwx--x---) for access control. This is not effective on Cygwin. Due to 
the rw-rw-rw-, the 'secret' is world readable on Cygwin and another 
Cygwin specific patch is required :-)

After new setsockopt(sd, ., SO_PEERCRED, .), AF_UNIX sockets are 
definitely vulnerable. Any local process could "guess" the TCP port and 
connect to any emulated AF_UNIX server regardless of user account.

Two draft ideas for a new AF_UNIX emulation:

Keep the current secret+cred exchange, but handle accept() and connect() 
(Continue reading)