]> git.baikalelectronics.ru Git - kernel.git/commit
net: mpls: fix stale pointer if allocation fails during device rename
authorJakub Kicinski <kuba@kernel.org>
Tue, 14 Feb 2023 06:53:55 +0000 (22:53 -0800)
committerGreg Kroah-Hartman <gregkh@linuxfoundation.org>
Wed, 22 Feb 2023 11:50:41 +0000 (12:50 +0100)
commitca7793945c5a982e62f810b9bfe3ece4fa969512
tree1dd07c1c83843afaba1d0aa0b57f4f36a6f29b09
parenta6a49a523adc94d4a6864dd0b36c017fe96f09c0
net: mpls: fix stale pointer if allocation fails during device rename

commit fda6c89fe3d9aca073495a664e1d5aea28cd4377 upstream.

lianhui reports that when MPLS fails to register the sysctl table
under new location (during device rename) the old pointers won't
get overwritten and may be freed again (double free).

Handle this gracefully. The best option would be unregistering
the MPLS from the device completely on failure, but unfortunately
mpls_ifdown() can fail. So failing fully is also unreliable.

Another option is to register the new table first then only
remove old one if the new one succeeds. That requires more
code, changes order of notifications and two tables may be
visible at the same time.

sysctl point is not used in the rest of the code - set to NULL
on failures and skip unregister if already NULL.

Reported-by: lianhui tang <bluetlh@gmail.com>
Fixes: 03ccbe9b3f80 ("mpls: handle device renames for per-device sysctls")
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
net/mpls/af_mpls.c