#295 OSX single threaded SSL client SIGPIPE.

open
nobody
None
5
2013-01-19
2013-01-19
John Chanak
No

The included file, when compiled and run against a non-listening server (connection reset) causes a near instant crash on OSX.
The same file, under linux, operates normally (Connection gets reset, but there is no crash)
The same file, on BOTH OS'es, operates fine if the server actually responds. (SSL handshake takes place, etc)

The following is the result seen on OSX, when the connection is reset: (Note the SSL Version and Libevent version are included in the output)

(gdb) run 10.80.1.100
Starting program: /Users/jchanak/src/internal/fohh/test3 10.80.1.100
Reading symbols for shared libraries ++++++............................. done
SSL version: OpenSSL 1.0.1c 10 May 2012
Libevent version: 2.0.21-stable
Starting dispatch loop

Program received signal SIGPIPE, Broken pipe.
0x00007fff93d5f4aa in write ()
(gdb) bt
#0 0x00007fff93d5f4aa in write ()
#1 0x00000001000d381c in sock_write ()
#2 0x00000001000d1b9e in BIO_write ()
#3 0x00000001000183cb in ssl3_write_pending ()
#4 0x0000000100017e59 in ssl3_write_bytes ()
#5 0x00000001000198c9 in ssl3_do_write ()
#6 0x000000010000f2de in ssl3_connect ()
#7 0x0000000100268ab7 in do_handshake (bev_ssl=0x4) at bufferevent_openssl.c:1003
#8 0x0000000100268e32 in be_openssl_handshakeeventcb (fd=4, ptr=0x10031a090) at bufferevent_openssl.c:1056
#9 0x0000000100215107 in event_base_loop (base=0x100319d60, flags=1606416752) at event.c:1350
#10 0x0000000100001a2c in main (argc=2, argv=0x7fff5fbffa88) at test3.c:158
(gdb)

The following is seen on the wire:

Justa-Laptop:~ jchanak$ sudo tcpdump -n host 10.80.1.100
tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
listening on en0, link-type EN10MB (Ethernet), capture size 65535 bytes
17:41:27.200731 IP 10.32.146.130.51777 > 10.80.1.100.443: Flags [S], seq 349217842, win 65535, options [mss 1460,nop,wscale 4,nop,nop,TS val 922020855 ecr 0,sackOK,eol], length 0
17:41:27.202252 IP 10.80.1.100.443 > 10.32.146.130.51777: Flags [R.], seq 0, ack 349217843, win 0, length 0
^C
2 packets captured

The code that I am running is included as an attachment. It is about as simple as I could make it and have it clearly fail.

Thanks.

Discussion

  • John Chanak
    John Chanak
    2013-01-19

    Test C file that crashes OSX but not Centos 6.3 Linux

     
    Attachments
  • John Chanak
    John Chanak
    2013-01-19

    Update with OSX specifics: 2012 MBPro:

    Justa-Laptop:~ jchanak$ uname -a
    Darwin Justa-Laptop.local 12.2.1 Darwin Kernel Version 12.2.1: Thu Oct 18 16:32:48 PDT 2012; root:xnu-2050.20.9~2/RELEASE_X86_64 x86_64

    Justa-Laptop:~ jchanak$ sw_vers
    ProductName: Mac OS X
    ProductVersion: 10.8.2
    BuildVersion: 12C3006

     
  • Nick Mathewson
    Nick Mathewson
    2013-02-19

    It's generally best (and almost always safe) to ignore SIGPIPE signals. Is that an option here?

     
  • John Chanak
    John Chanak
    2013-02-19

    Thanks for the response. Turning off sigpipe on sockets prevents the system crashing in OSX.

    Unfortunately, disabling sigpipe on a socket is an OSX specific feature. Furthermore, I had been letting libevent handle such system abstractions for me in order to simplify portability. If libevent requires no sigpipe errors on its sockets, I would prefer that it set this option appropriately when running OSX- particularly for sockets it creates at the user's request.

    However, I am quite happy that I can work around this issue for the time being.

    Thanks again.