Subject: Re: [libssh2] #213: segfault while calling some API in multithreads

Re: [libssh2] #213: segfault while calling some API in multithreads

From: libssh2 Trac <trac_at_libssh2.stuge.se>
Date: Thu, 24 Feb 2011 03:57:35 -0000

#213: segfault while calling some API in multithreads
---------------------------------------------------------------------------------------+
  Reporter: www.google.com/accounts/o8/id?id=aitoawm7w0npnppytaxsfxvbcdtodu9fots4nnu | Owner:
      Type: defect | Status: closed
  Priority: normal | Milestone: 1.2.8
 Component: crypto | Version: 1.2.7
Resolution: invalid | Keywords:
    Blocks: | Blocked By:
---------------------------------------------------------------------------------------+
Changes (by stuge):

  * status: new => closed
  * resolution: => invalid

Old description:

> I don't know if libssh2 is thread safe.but I think it should be that.
> when I call
> libssh2_session_startup(),libssh2_userauth_publickey_fromfile().... it
> will cause a segfault sometimes
>

> #0 0x0000000000000000 in ?? ()
> (gdb) where
> #0 0x0000000000000000 in ?? ()
> #1 0x00002b1b9b176951 in _libssh2_cipher_crypt (ctx=0x17707510,
> algo=<value optimized out>, encrypt=<value optimized out>,
> block=0x17b603f8
> "耇0\021M\232侵\a楗.蘒\224}\017餹鱘227\b赲210V^鱘222@]穃204贵\024Qu=\032酬{馶231)U‐004?2\214悯\022U]肻214\030綠1nk鱟kXrL死燶002\025\213胤T\205\235V<\234b郐轡0037205玕177!b5黒031\227|0(>v驤邀Z\035酆A(玟CTD\032\006\023芋\230k鸤237圉続\234wA`H\004\032}f覾213K醝|\221\206醆237sF矛妪\231)W騄\031鳏籺\"鋡"...)
> at openssl.c:197
> #2 0x00002b1b9b173e3d in decrypt (session=0x17b601e0,
> source=0x17b603f8
> "耇0\021M\232侵\a楗.蘒\224}\017餹鱘227\b赲210V^鱘222@]穃204贵\024Qu=\032酬{馶231)U‐004?2\214悯\022U]肻214\030綠1nk鱟kXrL死燶002\025\213胤T\205\235V<\234b郐轡0037205玕177!b5黒031\227|0(>v驤邀Z\035酆A(玟CTD\032\006\023芋\230k鸤237圉続\234wA`H\004\032}f覾213K醝|\221\206醆237sF矛妪\231)W騄\031鳏籺\"鋡"...,
> dest=0x2aaab407e63b "椽*", len=<value optimized out>) at transport.c:138
> #3 0x00002b1b9b1740dd in _libssh2_transport_read (session=0x17b601e0) at
> transport.c:538
> #4 0x00002b1b9b168345 in _libssh2_packet_requirev (session=0x17b601e0,
> packet_types=0x2b1b9b177906 "cd", data=0x4f5fbe48, data_len=0x4f5fbe40,
> match_ofs=1, match_buf=0x17b41ed8 "", match_len=4, state=0x17b41ee0)
> at packet.c:1146
> #5 0x00002b1b9b16236c in _libssh2_channel_process_startup
> (channel=0x17b41db0, request=0x40650d "exec", request_len=4,
> message=<value optimized out>,
> message_len=63) at channel.c:1295
> #6 0x00002b1b9b162475 in libssh2_channel_process_startup
> (channel=0x17b41db0, req=0x40650d "exec", req_len=4,
> msg=0x1770af90 "cd /home/work/opbin/medusa/ && ./medusaStat
> --time=201102241108", msg_len=63) at channel.c:1334
> #7 0x00000000004050f0 in ssh_exec (user=0x40654c "work", h=0x17b0bd10
> "jx-cm-as22.jx",
> cmd=0x1770af90 "cd /home/work/opbin/medusa/ && ./medusaStat
> --time=201102241108", output=0x17716790 "") at mds_crond.c:194
> #8 0x00000000004052c6 in cronworker (a=0x7fff0f95cbf0) at
> mds_crond.c:261
> #9 0x0000003356806367 in start_thread () from /lib64/libpthread.so.0
> #10 0x0000003355cd30ad in clone () from /lib64/libc.so.6

New description:

 I don't know if libssh2 is thread safe.but I think it should be that. when
 I call libssh2_session_startup(),libssh2_userauth_publickey_fromfile()....
 it will cause a segfault sometimes

 #0 0x0000000000000000 in ?? ()
 (gdb) where
 #0 0x0000000000000000 in ?? ()
 #1 0x00002b1b9b176951 in _libssh2_cipher_crypt (ctx=0x17707510,
 algo=<value optimized out>, encrypt=<value optimized out>,
     block=0x17b603f8
 "耇0\021M\232侵\a楗.蘒\224}\017餹鱘227\b赲210V^鱘222@]穃204贵\024Qu=\032酬{馶231)U‐004?2\214悯\022U]肻214\030綠1nk鱟kXrL死燶002\025\213胤T\205\235V<\234b郐轡0037205玕177!b5黒031\227|0(>v驤邀Z\035酆A(玟CTD\032\006\023芋\230k鸤237圉続\234wA`H\004\032}f覾213K醝|\221\206醆237sF矛妪\231)W騄\031鳏籺\"鋡"...)
 at openssl.c:197
 #2 0x00002b1b9b173e3d in decrypt (session=0x17b601e0,
     source=0x17b603f8
 "耇0\021M\232侵\a楗.蘒\224}\017餹鱘227\b赲210V^鱘222@]穃204贵\024Qu=\032酬{馶231)U‐004?2\214悯\022U]肻214\030綠1nk鱟kXrL死燶002\025\213胤T\205\235V<\234b郐轡0037205玕177!b5黒031\227|0(>v驤邀Z\035酆A(玟CTD\032\006\023芋\230k鸤237圉続\234wA`H\004\032}f覾213K醝|\221\206醆237sF矛妪\231)W騄\031鳏籺\"鋡"...,
 dest=0x2aaab407e63b "椽*", len=<value optimized out>) at transport.c:138
 #3 0x00002b1b9b1740dd in _libssh2_transport_read (session=0x17b601e0) at
 transport.c:538
 #4 0x00002b1b9b168345 in _libssh2_packet_requirev (session=0x17b601e0,
 packet_types=0x2b1b9b177906 "cd", data=0x4f5fbe48, data_len=0x4f5fbe40,
     match_ofs=1, match_buf=0x17b41ed8 "", match_len=4, state=0x17b41ee0)
 at packet.c:1146
 #5 0x00002b1b9b16236c in _libssh2_channel_process_startup
 (channel=0x17b41db0, request=0x40650d "exec", request_len=4,
 message=<value optimized out>,
     message_len=63) at channel.c:1295
 #6 0x00002b1b9b162475 in libssh2_channel_process_startup
 (channel=0x17b41db0, req=0x40650d "exec", req_len=4,
     msg=0x1770af90 "cd /home/work/opbin/medusa/ && ./medusaStat
 --time=201102241108", msg_len=63) at channel.c:1334
 #7 0x00000000004050f0 in ssh_exec (user=0x40654c "work", h=0x17b0bd10
 "jx-cm-as22.jx",
     cmd=0x1770af90 "cd /home/work/opbin/medusa/ && ./medusaStat
 --time=201102241108", output=0x17716790 "") at mds_crond.c:194
 #8 0x00000000004052c6 in cronworker (a=0x7fff0f95cbf0) at mds_crond.c:261
 #9 0x0000003356806367 in start_thread () from /lib64/libpthread.so.0
 #10 0x0000003355cd30ad in clone () from /lib64/libc.so.6

--
Comment:
 Replying to [ticket:213
 www.google.com/accounts/o8/id?id=aitoawm7w0npnppytaxsfxvbcdtodu9fots4nnu]:
 > I don't know if libssh2 is thread safe.
 It is not.
 > but I think it should be that.
 That would be great. Please come discuss it on the mailing list, or just
 send patches.
 Thanks!
-- 
Ticket URL: <http://trac.libssh2.org/ticket/213#comment:1>
libssh2 <http://trac.libssh2.org/>
C library for writing portable SSH2 clients
_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2011-02-24