mirror_ubuntu-kernels/drivers/net/ethernet/microchip/vcap
Jinjie Ruan 281f65d29d net: microchip: vcap api: Fix possible memory leak for vcap_dup_rule()
Inject fault When select CONFIG_VCAP_KUNIT_TEST, the below memory leak
occurs. If kzalloc() for duprule succeeds, but the following
kmemdup() fails, the duprule, ckf and caf memory will be leaked. So kfree
them in the error path.

unreferenced object 0xffff122744c50600 (size 192):
  comm "kunit_try_catch", pid 346, jiffies 4294896122 (age 911.812s)
  hex dump (first 32 bytes):
    10 27 00 00 04 00 00 00 1e 00 00 00 2c 01 00 00  .'..........,...
    00 00 00 00 00 00 00 00 18 06 c5 44 27 12 ff ff  ...........D'...
  backtrace:
    [<00000000394b0db8>] __kmem_cache_alloc_node+0x274/0x2f8
    [<0000000001bedc67>] kmalloc_trace+0x38/0x88
    [<00000000b0612f98>] vcap_dup_rule+0x50/0x460
    [<000000005d2d3aca>] vcap_add_rule+0x8cc/0x1038
    [<00000000eef9d0f8>] test_vcap_xn_rule_creator.constprop.0.isra.0+0x238/0x494
    [<00000000cbda607b>] vcap_api_rule_remove_in_front_test+0x1ac/0x698
    [<00000000c8766299>] kunit_try_run_case+0xe0/0x20c
    [<00000000c4fe9186>] kunit_generic_run_threadfn_adapter+0x50/0x94
    [<00000000f6864acf>] kthread+0x2e8/0x374
    [<0000000022e639b3>] ret_from_fork+0x10/0x20

Fixes: 814e769320 ("net: microchip: vcap api: Add a storage state to a VCAP rule")
Signed-off-by: Jinjie Ruan <ruanjinjie@huawei.com>
Reviewed-by: Simon Horman <horms@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
2023-09-10 18:51:42 +01:00
..
Kconfig net: microchip: sparx5: Add VCAP debugfs KUNIT test 2022-11-21 11:33:02 +00:00
Makefile net: microchip: vcap: Add tc flower keys for lan966x 2023-02-10 08:03:09 +00:00
vcap_ag_api.h net: lan966x: Add ES0 VCAP model 2023-05-10 09:51:10 +01:00
vcap_api_client.h net: microchip: Remove unused declarations 2023-08-22 10:31:47 -07:00
vcap_api_debugfs_kunit.c net: lan966x: Add IS1 VCAP model 2023-03-10 16:44:24 -08:00
vcap_api_debugfs.c net: microchip: sparx5: Add ingress information to VCAP instance 2023-01-30 07:36:22 +00:00
vcap_api_debugfs.h net: microchip: sparx5: Add VCAP debugFS support 2022-11-21 11:33:02 +00:00
vcap_api_kunit.c net: microchip: sparx5: reduce stack usage 2023-02-20 10:50:47 +00:00
vcap_api_private.h net: microchip: sparx5: Add VCAP admin locking in debugFS 2023-01-18 14:31:43 +00:00
vcap_api.c net: microchip: vcap api: Fix possible memory leak for vcap_dup_rule() 2023-09-10 18:51:42 +01:00
vcap_api.h net: microchip: Remove unused declarations 2023-08-22 10:31:47 -07:00
vcap_model_kunit.c net: microchip: sparx5: Add ES0 VCAP model and updated KUNIT VCAP model 2023-02-16 08:59:48 +01:00
vcap_model_kunit.h net: microchip: sparx5: Add ES0 VCAP model and updated KUNIT VCAP model 2023-02-16 08:59:48 +01:00
vcap_tc.c net: flow_dissector: Use 64bits for used_keys 2023-07-31 09:11:24 +01:00
vcap_tc.h net: flow_dissector: Use 64bits for used_keys 2023-07-31 09:11:24 +01:00