memif: crash on slave mode 04/8604/2
authorSteven <sluong@cisco.com>
Sat, 30 Sep 2017 17:50:20 +0000 (10:50 -0700)
committerDamjan Marion <dmarion.lists@gmail.com>
Wed, 4 Oct 2017 09:46:26 +0000 (09:46 +0000)
commit9fefa9a697daf0e949ea7a2700ecaf2ba4d1d2cb
tree578ab9118d7094dc6f223159dabad79e5bad46ab
parent62549fec3bb3b466fbca91e995a5dc6e77fe4ce1
memif: crash on slave mode

Crash was seen on recent image with this BT on top of the stack

(gdb) bt full
    (mif=0x7fffb6226568) at
    /vpp/build-data/../src/plugins/memif/memif.c:297
        ring = 0x0 <<<<<<<<<<
        i = 0
        j = 0
        buffer_offset = 65792
        r = 0x7fffb5e59f80
        alloc = {flags = 1, name = 0x7fffb449f965 "memif region",
          size = 4260096, numa_node = 0, addr = 0x7fff41dac000,
          fd = 11,
          log2_page_size = 12, n_pages = 1041}
        err = 0x0
        __FUNCTION__ = "memif_init_regions_and_queues"

The crash happened at this line.
      ring = memif_get_ring (mif, MEMIF_RING_S2M, i);
      ring=>head = ring->tail = 0; <=====

Please note that the crash is caused by dereferencing NULL rinng.
Put breakpoint into the function. I notice that
mif->regions[0].shm is not initialized.

(gdb) p mif->regions[0].shm
$8 = (void *) 0x0

It looks like we forgot to set shm after clib_mem_vm_ext_alloc().
Add the missing cide and the crash is fixed.

Change-Id: Ib722a6c241c77acfa8e33962106b57faa50e1ea7
Signed-off-by: Steven <sluong@cisco.com>
src/plugins/memif/memif.c