SDL-Hercules-390 / hyperion

The SDL Hercules 4.x Hyperion version of the System/370, ESA/390, and z/Architecture Emulator
Other
242 stars 90 forks source link

Segmentation fault in hercifc #236

Closed mcisho closed 5 years ago

mcisho commented 5 years ago

My host is:  Fedora 30 x86_64.

I have two Hercules on the system, Hercules 3.13 which in installed from an rpm and which I never (knowingly) use, and SDL Hercules 4.n (currently commit de63b92cf82e35233f47361c61283237b912c358) which I make from source and use regularly. Since pre-configured interfaces became available, I have run Hercules 4.n without privileges, and as a result regularly see message HHC00166E issued by hercifc.

In the process of attempting to reproduce #230, I discovered that the 4.3 hercifc was experiencing a Segmentation fault when issuing message HHC00166E. It appears that all of those regularly seen HHC00166E messages had been issued by the 3.13 hercifc!

The simplest way to demonstrate the problem is to execute hercifc from the command line, the results of which are shown in the following gdb back trace:

 

> Program received signal SIGSEGV, Segmentation fault.

0x00007ffff7f9ef1d in hthreads_get_ILOCK (addr=0x7ffff7fb9740 , name=0x7ffff7fad25d "&captctl_lock") at hthreads.c:190
190         if (ilk->addr == addr)

> (gdb) where

#0  0x00007ffff7f9ef1d in hthreads_get_ILOCK (addr=0x7ffff7fb9740 , name=0x7ffff7fad25d "&captctl_lock")
    at hthreads.c:190

#1  0x00007ffff7f9f05b in hthread_initialize_lock (plk=0x7ffff7fb9740 , name=0x7ffff7fad25d "&captctl_lock", 
    location=0x7ffff7fad250 "logmsg.c:117") at hthreads.c:227

#2  0x00007ffff7fa2856 in InitCAPTCTL () at logmsg.c:117

#3  0x00007ffff7fa2c15 in flog_write (panel=3, f=0x7ffff73d86a0 <_IO_2_1_stderr_>, 
    msg=0x405700 "HHC00162E /home/irs/Hercules.run/bin/hercifc: Must be called from within Hercules.\n") at logmsg.c:297

#4  0x00007ffff7fa3093 in vfwritemsg (panel=3 '\003', f=0x7ffff73d86a0 <_IO_2_1_stderr_>, filename=0x40204d "hercifc.c", line=59, 
    func=0x402348 <__FUNCTION__.34379> "main", fmt=0x402018 "HHC00162%s %s: Must be called from within Hercules.\n", vl=0x7fffffffd318)
    at logmsg.c:397

#5  0x00007ffff7fa33ec in fwritemsg (filename=0x40204d "hercifc.c", line=59, func=0x402348 <__FUNCTION__.34379> "main", 
    panel=3 '\003', f=0x7ffff73d86a0 <_IO_2_1_stderr_>, fmt=0x402018 "HHC00162%s %s: Must be called from within Hercules.\n")
    at logmsg.c:469

#6  0x0000000000401279 in main (argc=1, argv=0x7fffffffd5e8) at hercifc.c:59

> (gdb) where full

#0  0x00007ffff7f9ef1d in hthreads_get_ILOCK (addr=0x7ffff7fb9740 , name=0x7ffff7fad25d "&captctl_lock")
    at hthreads.c:190
        ilk = 0x0
        ple = 0x0

#1  0x00007ffff7f9f05b in hthread_initialize_lock (plk=0x7ffff7fb9740 , name=0x7ffff7fad25d "&captctl_lock", 
    location=0x7ffff7fad250 "logmsg.c:117") at hthreads.c:227
        rc = 0
        attr = {__size = "\000\000\000", __align = 0}
        ilk = 0x7ffff7fcc510

#2  0x00007ffff7fa2856 in InitCAPTCTL () at logmsg.c:117
        didthis = 1 '\001'

#3  0x00007ffff7fa2c15 in flog_write (panel=3, f=0x7ffff73d86a0 <_IO_2_1_stderr_>, 
    msg=0x405700 "HHC00162E /home/irs/Hercules.run/bin/hercifc: Must be called from within Hercules.\n") at logmsg.c:297
        pCAPTCTL = 0x0

#4  0x00007ffff7fa3093 in vfwritemsg (panel=3 '\003', f=0x7ffff73d86a0 <_IO_2_1_stderr_>, filename=0x40204d "hercifc.c", line=59, 
    func=0x402348 <__FUNCTION__.34379> "main", fmt=0x402018 "HHC00162%s %s: Must be called from within Hercules.\n", vl=0x7fffffffd318)
    at logmsg.c:397
        prefix = '\000' 
        bfr = 0x4056a0 "HHC00162E /home/irs/Hercules.run/bin/hercifc: Must be called from within Hercules.\n"
        rc = 83
        siz = 1024
        msgbuf = 0x405700 "HHC00162E /home/irs/Hercules.run/bin/hercifc: Must be called from within Hercules.\n"
        msglen = 85
        bufsiz = 85
        __FUNCTION__ = "vfwritemsg"

#5  0x00007ffff7fa33ec in fwritemsg (filename=0x40204d "hercifc.c", line=59, func=0x402348 <__FUNCTION__.34379> "main", 
    panel=3 '\003', f=0x7ffff73d86a0 <_IO_2_1_stderr_>, fmt=0x402018 "HHC00162%s %s: Must be called from within Hercules.\n")
    at logmsg.c:469
        vl = {{gp_offset = 48, fp_offset = 48, overflow_arg_area = 0x7fffffffd400, reg_save_area = 0x7fffffffd330}}

#6  0x0000000000401279 in main (argc=1, argv=0x7fffffffd5e8) at hercifc.c:59
        pszProgName = 0x405260 "/home/irs/Hercules.run/bin/hercifc"
        pOp = 0x0
        pIF = 0x0
        pArg = 0x0
        ctlreq = {iType = 140737354131184, iProcID = 0, iCtlOp = 140737354132096, szIFName = '\000' , iru = {hifr = {
              ifreq = {ifr_ifrn = {ifrn_name = "\000\000\000\000\000\000\000\000\377\377\377\377\000\000\000"}, ifr_ifru = {
                  ifru_addr = {sa_family = 35776, sa_data = "?\367\377\177\000\000h\022\375\367\377\177\000"}, ifru_dstaddr = {
                    sa_family = 35776, sa_data = "?\367\377\177\000\000h\022\375\367\377\177\000"}, ifru_broadaddr = {
                    sa_family = 35776, sa_data = "?\367\377\177\000\000h\022\375\367\377\177\000"}, ifru_netmask = {sa_family = 35776, 
                    sa_data = "?\367\377\177\000\000h\022\375\367\377\177\000"}, ifru_hwaddr = {sa_family = 35776, 
                    sa_data = "?\367\377\177\000\000h\022\375\367\377\177\000"}, ifru_flags = -29760, ifru_ivalue = -146830400, 
                  ifru_mtu = -146830400, ifru_map = {mem_start = 140737341524928, mem_end = 140737353945704, base_addr = 59120, 
                    irq = 255 '\377', dma = 247 '\367', port = 255 '\377'}, 
                  ifru_slave = "\300\213?\367\377\177\000\000h\022\375\367\377\177\000", 
                  ifru_newname = "\300\213?\367\377\177\000\000h\022\375\367\377\177\000", 
                  ifru_data = 0x7ffff73f8bc0  ""}}, in6_ifreq = {ifr6_addr = {__in6_u = {
                    __u6_addr8 = "\370\325\377\377d\000\000\000\000\304\341>\037jpk", __u6_addr16 = {54776, 65535, 100, 0, 50176, 
                      16097, 27167, 27504}, __u6_addr32 = {4294956536, 100, 1054983168, 1802529311}}}, ifr6_prefixlen = 4294967295, 
                ifr6_ifindex = 0}, hifr_afamily = -146914947}, rtentry = {rt_pad1 = 0, rt_dst = {sa_family = 65535, 
                sa_data = "\377\377\000\000\000\000\300\213?\367\377\177\000"}, rt_gateway = {sa_family = 4712, 
                sa_data = "\375\367\377\177\000\000\360\346\377\367\377\177\000"}, rt_genmask = {sa_family = 54776, 
                sa_data = "\377\377d\000\000\000\000\304\341>\037jpk"}, rt_flags = 65535, rt_pad2 = -1, rt_pad3 = 140737341440381, 
              rt_tos = 0 '\000', rt_class = 0 '\000', rt_pad4 = {0, 0, 0}, rt_metric = 64, 
              rt_dev = 0x800000 , rt_mtu = 15774463, rt_window = 194, 
              rt_irtt = 54487}}}
        fd_inet = 32767
        fd_inet6 = 0
        fd = 0
        rc = 32767
        ppid = -148131899
        answer = 0
        __FUNCTION__ = "main"
Fish-Git commented 5 years ago

I think I might know what's going on...   Let me look into it and I'll get back to you.

Fish-Git commented 5 years ago

@mcisho

Ian,

I of course cannot be 100% certain (since I've mentioned many times before that in all the years I've been working with Hercules I have personally never been able to get Hercules networking working on Linux), BUT ...

... I believe the following patch should fix your problem:

--- hyperion-1/hercifc.c    2019-08-03 15:41:15.075313300 -0700
+++ hyperion-0/hercifc.c    2019-08-15 14:33:47.195041500 -0700
@@ -26,6 +26,9 @@
 #include "hercules.h"
 #include "hercifc.h"

+#define UTILITY_NAME    "hercifc"
+#define UTILITY_DESC    "Hercules Network Interface Configuration Program"
+
 // --------------------------------------------------------------------
 // HERCIFC program entry point
 // --------------------------------------------------------------------
@@ -48,6 +51,8 @@

     UNREFERENCED( argc );

+    INITIALIZE_UTILITY( UTILITY_NAME, UTILITY_DESC, &pszProgName );
+
     DROP_PRIVILEGES(CAP_NET_ADMIN);

     pszProgName = strdup( argv[0] );
--- hyperion-1/hthreads.c   2019-08-03 15:41:15.106513400 -0700
+++ hyperion-0/hthreads.c   2019-08-15 13:58:04.315000600 -0700
@@ -191,7 +191,7 @@
             break;
     }

-    /* If needed, alloacte a new ILOCK structure for this lock */
+    /* If needed, allocate a new ILOCK structure for this lock */

     if (&locklist == ple)
     {

The problem (the cause of the crash) was that hthreads was never getting initialized. The above code (which you should see in every Hercules utility) performs standard utility initialization, which includes initializing hthreads.

Please let me know whether the above patch fixes your problem or not. If it does, I'll go ahead and commit the change and then close this issue. Otherwise I'm going to need to scratch my head some more.

Thanks.

(and sorry about that! I completely forgot about hercifc!)

mcisho commented 5 years ago

Problem fixed. Thanks.

mcisho commented 5 years ago

Next time you need to do something with Linux networking let me know and we'll see if we can get it working.

Fish-Git commented 5 years ago

Fixed by commit 1f8fa07f3b3dab695620b5dbeabbca5e4c3ada45. Closing.