• Jinjie Ruan's avatar
    net: microchip: sparx5: Fix memory leak for vcap_api_rule_add_keyvalue_test() · f037fc99
    Jinjie Ruan authored
    Inject fault while probing kunit-example-test.ko, the field which
    is allocated by kzalloc in vcap_rule_add_key() of
    vcap_rule_add_key_bit/u32/u128() is not freed, and it cause
    the memory leaks below.
    
    unreferenced object 0xffff0276c14b7240 (size 64):
      comm "kunit_try_catch", pid 284, jiffies 4294894220 (age 920.072s)
      hex dump (first 32 bytes):
        28 3c 61 82 00 80 ff ff 28 3c 61 82 00 80 ff ff  (<a.....(<a.....
        67 00 00 00 00 00 00 00 00 01 37 2b af ab ff ff  g.........7+....
      backtrace:
        [<0000000028f08898>] slab_post_alloc_hook+0xb8/0x368
        [<00000000514b9b37>] __kmem_cache_alloc_node+0x174/0x290
        [<000000004620684a>] kmalloc_trace+0x40/0x164
        [<0000000059ad6bcd>] vcap_rule_add_key+0x104/0x180
        [<00000000ff8002d3>] vcap_api_rule_add_keyvalue_test+0x100/0xba8
        [<00000000fcc5326c>] kunit_try_run_case+0x50/0xac
        [<00000000f5f45b20>] kunit_generic_run_threadfn_adapter+0x20/0x2c
        [<0000000026284079>] kthread+0x124/0x130
        [<0000000024d4a996>] ret_from_fork+0x10/0x20
    unreferenced object 0xffff0276c14b7280 (size 64):
      comm "kunit_try_catch", pid 284, jiffies 4294894221 (age 920.068s)
      hex dump (first 32 bytes):
        28 3c 61 82 00 80 ff ff 28 3c 61 82 00 80 ff ff  (<a.....(<a.....
        67 00 00 00 00 00 00 00 01 01 37 2b af ab ff ff  g.........7+....
      backtrace:
        [<0000000028f08898>] slab_post_alloc_hook+0xb8/0x368
        [<00000000514b9b37>] __kmem_cache_alloc_node+0x174/0x290
        [<000000004620684a>] kmalloc_trace+0x40/0x164
        [<0000000059ad6bcd>] vcap_rule_add_key+0x104/0x180
        [<00000000f5ac9dc7>] vcap_api_rule_add_keyvalue_test+0x168/0xba8
        [<00000000fcc5326c>] kunit_try_run_case+0x50/0xac
        [<00000000f5f45b20>] kunit_generic_run_threadfn_adapter+0x20/0x2c
        [<0000000026284079>] kthread+0x124/0x130
        [<0000000024d4a996>] ret_from_fork+0x10/0x20
    unreferenced object 0xffff0276c14b72c0 (size 64):
      comm "kunit_try_catch", pid 284, jiffies 4294894221 (age 920.068s)
      hex dump (first 32 bytes):
        28 3c 61 82 00 80 ff ff 28 3c 61 82 00 80 ff ff  (<a.....(<a.....
        67 00 00 00 00 00 00 00 00 00 37 2b af ab ff ff  g.........7+....
      backtrace:
        [<0000000028f08898>] slab_post_alloc_hook+0xb8/0x368
        [<00000000514b9b37>] __kmem_cache_alloc_node+0x174/0x290
        [<000000004620684a>] kmalloc_trace+0x40/0x164
        [<0000000059ad6bcd>] vcap_rule_add_key+0x104/0x180
        [<00000000c918ae7f>] vcap_api_rule_add_keyvalue_test+0x1d0/0xba8
        [<00000000fcc5326c>] kunit_try_run_case+0x50/0xac
        [<00000000f5f45b20>] kunit_generic_run_threadfn_adapter+0x20/0x2c
        [<0000000026284079>] kthread+0x124/0x130
        [<0000000024d4a996>] ret_from_fork+0x10/0x20
    unreferenced object 0xffff0276c14b7300 (size 64):
      comm "kunit_try_catch", pid 284, jiffies 4294894221 (age 920.084s)
      hex dump (first 32 bytes):
        28 3c 61 82 00 80 ff ff 28 3c 61 82 00 80 ff ff  (<a.....(<a.....
        7d 00 00 00 01 00 00 00 32 54 76 98 ab ff 00 ff  }.......2Tv.....
      backtrace:
        [<0000000028f08898>] slab_post_alloc_hook+0xb8/0x368
        [<00000000514b9b37>] __kmem_cache_alloc_node+0x174/0x290
        [<000000004620684a>] kmalloc_trace+0x40/0x164
        [<0000000059ad6bcd>] vcap_rule_add_key+0x104/0x180
        [<0000000003352814>] vcap_api_rule_add_keyvalue_test+0x240/0xba8
        [<00000000fcc5326c>] kunit_try_run_case+0x50/0xac
        [<00000000f5f45b20>] kunit_generic_run_threadfn_adapter+0x20/0x2c
        [<0000000026284079>] kthread+0x124/0x130
        [<0000000024d4a996>] ret_from_fork+0x10/0x20
    unreferenced object 0xffff0276c14b7340 (size 64):
      comm "kunit_try_catch", pid 284, jiffies 4294894221 (age 920.084s)
      hex dump (first 32 bytes):
        28 3c 61 82 00 80 ff ff 28 3c 61 82 00 80 ff ff  (<a.....(<a.....
        51 00 00 00 07 00 00 00 17 26 35 44 63 62 71 00  Q........&5Dcbq.
      backtrace:
        [<0000000028f08898>] slab_post_alloc_hook+0xb8/0x368
        [<00000000514b9b37>] __kmem_cache_alloc_node+0x174/0x290
        [<000000004620684a>] kmalloc_trace+0x40/0x164
        [<0000000059ad6bcd>] vcap_rule_add_key+0x104/0x180
        [<000000001516f109>] vcap_api_rule_add_keyvalue_test+0x2cc/0xba8
        [<00000000fcc5326c>] kunit_try_run_case+0x50/0xac
        [<00000000f5f45b20>] kunit_generic_run_threadfn_adapter+0x20/0x2c
        [<0000000026284079>] kthread+0x124/0x130
        [<0000000024d4a996>] ret_from_fork+0x10/0x20
    
    Fixes: c956b9b3 ("net: microchip: sparx5: Adding KUNIT tests of key/action values in VCAP API")
    Signed-off-by: default avatarJinjie Ruan <ruanjinjie@huawei.com>
    Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
    f037fc99
vcap_api_kunit.c 67 KB