Skip to content

Commit fda6c89

Browse files
kuba-moodavem330
authored andcommitted
net: mpls: fix stale pointer if allocation fails during device rename
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 <[email protected]> Fixes: 0fae3bf ("mpls: handle device renames for per-device sysctls") Signed-off-by: Jakub Kicinski <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 42018a3 commit fda6c89

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

net/mpls/af_mpls.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1428,6 +1428,7 @@ static int mpls_dev_sysctl_register(struct net_device *dev,
14281428
free:
14291429
kfree(table);
14301430
out:
1431+
mdev->sysctl = NULL;
14311432
return -ENOBUFS;
14321433
}
14331434

@@ -1437,6 +1438,9 @@ static void mpls_dev_sysctl_unregister(struct net_device *dev,
14371438
struct net *net = dev_net(dev);
14381439
struct ctl_table *table;
14391440

1441+
if (!mdev->sysctl)
1442+
return;
1443+
14401444
table = mdev->sysctl->ctl_table_arg;
14411445
unregister_net_sysctl_table(mdev->sysctl);
14421446
kfree(table);

0 commit comments

Comments
 (0)