linux/drivers/net/ethernet/mellanox/mlxsw
Ido Schimmel 12ae97c531 mlxsw: spectrum_ipip: Fix memory leak when changing remote IPv6 address
The device stores IPv6 addresses that are used for encapsulation in
linear memory that is managed by the driver.

Changing the remote address of an ip6gre net device never worked
properly, but since cited commit the following reproducer [1] would
result in a warning [2] and a memory leak [3]. The problem is that the
new remote address is never added by the driver to its hash table (and
therefore the device) and the old address is never removed from it.

Fix by programming the new address when the configuration of the ip6gre
net device changes and removing the old one. If the address did not
change, then the above would result in increasing the reference count of
the address and then decreasing it.

[1]
 # ip link add name bla up type ip6gre local 2001:db8:1::1 remote 2001:db8:2::1 tos inherit ttl inherit
 # ip link set dev bla type ip6gre remote 2001:db8:3::1
 # ip link del dev bla
 # devlink dev reload pci/0000:01:00.0

[2]
WARNING: CPU: 0 PID: 1682 at drivers/net/ethernet/mellanox/mlxsw/spectrum.c:3002 mlxsw_sp_ipv6_addr_put+0x140/0x1d0
Modules linked in:
CPU: 0 UID: 0 PID: 1682 Comm: ip Not tainted 6.12.0-rc3-custom-g86b5b55bc835 #151
Hardware name: Nvidia SN5600/VMOD0013, BIOS 5.13 05/31/2023
RIP: 0010:mlxsw_sp_ipv6_addr_put+0x140/0x1d0
[...]
Call Trace:
 <TASK>
 mlxsw_sp_router_netdevice_event+0x55f/0x1240
 notifier_call_chain+0x5a/0xd0
 call_netdevice_notifiers_info+0x39/0x90
 unregister_netdevice_many_notify+0x63e/0x9d0
 rtnl_dellink+0x16b/0x3a0
 rtnetlink_rcv_msg+0x142/0x3f0
 netlink_rcv_skb+0x50/0x100
 netlink_unicast+0x242/0x390
 netlink_sendmsg+0x1de/0x420
 ____sys_sendmsg+0x2bd/0x320
 ___sys_sendmsg+0x9a/0xe0
 __sys_sendmsg+0x7a/0xd0
 do_syscall_64+0x9e/0x1a0
 entry_SYSCALL_64_after_hwframe+0x77/0x7f

[3]
unreferenced object 0xffff898081f597a0 (size 32):
  comm "ip", pid 1626, jiffies 4294719324
  hex dump (first 32 bytes):
    20 01 0d b8 00 02 00 00 00 00 00 00 00 00 00 01   ...............
    21 49 61 83 80 89 ff ff 00 00 00 00 01 00 00 00  !Ia.............
  backtrace (crc fd9be911):
    [<00000000df89c55d>] __kmalloc_cache_noprof+0x1da/0x260
    [<00000000ff2a1ddb>] mlxsw_sp_ipv6_addr_kvdl_index_get+0x281/0x340
    [<000000009ddd445d>] mlxsw_sp_router_netdevice_event+0x47b/0x1240
    [<00000000743e7757>] notifier_call_chain+0x5a/0xd0
    [<000000007c7b9e13>] call_netdevice_notifiers_info+0x39/0x90
    [<000000002509645d>] register_netdevice+0x5f7/0x7a0
    [<00000000c2e7d2a9>] ip6gre_newlink_common.isra.0+0x65/0x130
    [<0000000087cd6d8d>] ip6gre_newlink+0x72/0x120
    [<000000004df7c7cc>] rtnl_newlink+0x471/0xa20
    [<0000000057ed632a>] rtnetlink_rcv_msg+0x142/0x3f0
    [<0000000032e0d5b5>] netlink_rcv_skb+0x50/0x100
    [<00000000908bca63>] netlink_unicast+0x242/0x390
    [<00000000cdbe1c87>] netlink_sendmsg+0x1de/0x420
    [<0000000011db153e>] ____sys_sendmsg+0x2bd/0x320
    [<000000003b6d53eb>] ___sys_sendmsg+0x9a/0xe0
    [<00000000cae27c62>] __sys_sendmsg+0x7a/0xd0

Fixes: cf42911523 ("mlxsw: spectrum_ipip: Use common hash table for IPv6 address mapping")
Reported-by: Maksym Yaremchuk <maksymy@nvidia.com>
Signed-off-by: Ido Schimmel <idosch@nvidia.com>
Reviewed-by: Petr Machata <petrm@nvidia.com>
Signed-off-by: Petr Machata <petrm@nvidia.com>
Link: https://patch.msgid.link/e91012edc5a6cb9df37b78fd377f669381facfcb.1729866134.git.petrm@nvidia.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
2024-10-30 18:24:39 -07:00
..
cmd.h mlxsw: cmd: Add MLXSW_CMD_MBOX_CONFIG_PROFILE_FLOOD_MODE_CFF 2023-11-21 14:53:08 -08:00
core_acl_flex_actions.c mlxsw: Use refcount_t for reference counting 2024-01-30 15:47:36 +01:00
core_acl_flex_actions.h mlxsw: core_acl_flex_actions: Add IGNORE_ACTION 2023-08-14 08:11:14 +01:00
core_acl_flex_keys.c mlxsw: Use refcount_t for reference counting 2024-01-30 15:47:36 +01:00
core_acl_flex_keys.h mlxsw: Mark high entropy key blocks 2023-10-06 11:08:06 +01:00
core_env.c mlxsw: Implement ethtool operation to write to a transceiver module EEPROM 2024-06-28 10:48:22 +01:00
core_env.h mlxsw: Implement ethtool operation to write to a transceiver module EEPROM 2024-06-28 10:48:22 +01:00
core_hwmon.c mlxsw: reg: Limit MTBR register payload to a single data record 2023-10-02 08:07:12 +01:00
core_linecard_dev.c devlink: convert linecard nested devlink to new rel infrastructure 2023-09-17 14:01:47 +01:00
core_linecards.c mlxsw: core_linecards: Fix double memory deallocation in case of invalid INI file 2024-07-04 07:34:42 -07:00
core_thermal.c Thermal control updates for 6.12-rc1 2024-09-16 08:05:54 +02:00
core.c mlxsw: core: Unregister EMAD trap using FORWARD action 2024-04-19 20:43:15 -07:00
core.h mlxsw: pci: Permit enabling CFF mode 2023-11-21 14:53:09 -08:00
emad.h
i2c.c mlxsw: i2c: Utilize standard macros for dividing buffer into chunks 2023-10-02 08:07:12 +01:00
i2c.h
item.h mlxsw: Warn about invalid accesses to array fields 2024-07-09 18:46:44 -07:00
Kconfig mlxsw: pci: Initialize page pool per CQ 2024-06-19 17:38:10 -07:00
Makefile mlxsw: spectrum_port_range: Add port range core 2023-07-12 16:57:18 -07:00
minimal.c mlxsw: Implement ethtool operation to write to a transceiver module EEPROM 2024-06-28 10:48:22 +01:00
pci_hw.h mlxsw: pci: Use only one event queue 2024-04-03 19:50:40 -07:00
pci.c mlxsw: pci: Sync Rx buffers for device 2024-10-30 18:24:39 -07:00
pci.h
port.h mlxsw: Adjust MTU value to hardware check 2024-06-14 19:30:34 -07:00
reg.h mlxsw: pci: Fix driver initialization with Spectrum-4 2024-06-21 14:30:32 +01:00
resources.h mlxsw: resources: Add max_cap_nve_flood_prf 2023-11-21 14:53:08 -08:00
spectrum1_acl_tcam.c mlxsw: spectrum_acl: Pass main driver structure to mlxsw_sp_acl_rulei_destroy() 2023-07-12 16:57:18 -07:00
spectrum1_kvdl.c
spectrum1_mr_tcam.c
spectrum2_acl_tcam.c
spectrum2_kvdl.c
spectrum2_mr_tcam.c mlxsw: Edit IPv6 key blocks to use one less block for multicast forwarding 2023-09-22 08:26:30 +01:00
spectrum_acl_atcam.c mlxsw: spectrum_acl: Fix ACL scale regression and firmware errors 2024-06-10 11:14:52 +01:00
spectrum_acl_bloom_filter.c mlxsw: spectrum_acl: Fix ACL scale regression and firmware errors 2024-06-10 11:14:52 +01:00
spectrum_acl_ctcam.c
spectrum_acl_erp.c mlxsw: spectrum_acl_erp: Fix object nesting warning 2024-06-10 11:14:52 +01:00
spectrum_acl_flex_actions.c
spectrum_acl_flex_actions.h
spectrum_acl_flex_keys.c mlxsw: Mark high entropy key blocks 2023-10-06 11:08:06 +01:00
spectrum_acl_tcam.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2024-04-25 12:41:37 -07:00
spectrum_acl_tcam.h mlxsw: spectrum_acl: Fix ACL scale regression and firmware errors 2024-06-10 11:14:52 +01:00
spectrum_acl.c mlxsw: spectrum: Allow fetch-and-clear of flow counters 2024-03-11 14:14:08 -07:00
spectrum_buffers.c Merge git://git.kernel.org/pub/scm/linux/kernel/git/netdev/net 2024-06-27 12:14:11 -07:00
spectrum_cnt.c mlxsw: spectrum: Annotate struct mlxsw_sp_counter_pool with __counted_by 2023-10-02 11:27:12 -07:00
spectrum_cnt.h
spectrum_dcb.c
spectrum_dpipe.c mlxsw: spectrum_router: Constify struct devlink_dpipe_table_ops 2024-06-05 10:24:57 +01:00
spectrum_dpipe.h
spectrum_ethtool.c net: Add struct kernel_ethtool_ts_info 2024-07-15 08:02:26 -07:00
spectrum_fid.c mlxsw: spectrum_fid: Set NVE flood profile as part of FID configuration 2023-12-15 10:58:00 +00:00
spectrum_flow.c
spectrum_flower.c mlxsw: spectrum_flower: validate control flags 2024-04-18 17:02:37 -07:00
spectrum_ipip.c mlxsw: spectrum_ipip: Fix memory leak when changing remote IPv6 address 2024-10-30 18:24:39 -07:00
spectrum_ipip.h ip_tunnel: use a separate struct to store tunnel params in the kernel 2024-04-01 10:49:28 +01:00
spectrum_kvdl.c
spectrum_matchall.c
spectrum_mr_tcam.c mlxsw: spectrum: Allow fetch-and-clear of flow counters 2024-03-11 14:14:08 -07:00
spectrum_mr_tcam.h
spectrum_mr.c mlxsw: Convert does-RIF-have-this-netdev queries to a dedicated helper 2023-06-12 09:49:30 +01:00
spectrum_mr.h
spectrum_nve_vxlan.c mlxsw: fix mlxsw_sp2_nve_vxlan_learning_set() return type 2023-10-08 13:51:39 +01:00
spectrum_nve.c mlxsw: spectrum_nve: Do not take reference when looking up netdevice 2023-07-28 13:38:45 -07:00
spectrum_nve.h
spectrum_pgt.c mlxsw: spectrum_pgt: Generalize PGT allocation 2023-10-20 11:47:50 +01:00
spectrum_policer.c
spectrum_port_range.c mlxsw: spectrum_port_range: Add devlink resource support 2023-07-12 16:57:18 -07:00
spectrum_ptp.c mlxsw: spectrum_ptp: Add missing verification before pushing Tx header 2024-10-30 18:24:39 -07:00
spectrum_ptp.h mlxsw: spectrum: Remove setting of RX software timestamp 2024-09-06 09:34:17 +01:00
spectrum_qdisc.c
spectrum_router.c mlxsw: spectrum_router: fix xa_store() error checking 2024-10-22 13:01:55 +02:00
spectrum_router.h mlxsw: spectrum_router: Have mlxsw_sp_nexthop_counter_enable() return int 2024-03-11 14:14:07 -07:00
spectrum_span.c ipv6: introduce dst_rt6_info() helper 2024-04-29 13:32:01 +01:00
spectrum_span.h mlxsw: spectrum: Remove unused function declarations 2023-08-04 18:03:05 -07:00
spectrum_switchdev.c mlxsw: Use refcount_t for reference counting 2024-01-30 15:47:36 +01:00
spectrum_switchdev.h
spectrum_trap.c
spectrum_trap.h
spectrum.c mlxsw: spectrum: Remove setting of RX software timestamp 2024-09-06 09:34:17 +01:00
spectrum.h net: Add struct kernel_ethtool_ts_info 2024-07-15 08:02:26 -07:00
trap.h
txheader.h