Subject: Re: [PATCH net] net: mpls: fix stale pointer if allocation fails during device rename

From: Jakub Kicinski <[email-masked]>
Date: Tue, 14 Feb 2023 13:23:31 -0800

On Tue, 14 Feb 2023 17:33:36 +0800 Gong Ruiqi wrote:
> Just be curious: would this be a simpler solution?
> 
> @@ -1439,6 +1439,7 @@ static void mpls_dev_sysctl_unregister(struct
> net_device *dev,
> 
>         table = mdev->sysctl->ctl_table_arg;
>         unregister_net_sysctl_table(mdev->sysctl);
> +       mdev->sysctl = NULL;
>         kfree(table);
> 
>         mpls_netconf_notify_devconf(net, RTM_DELNETCONF, 0, mdev);
> 
> However I'm not sure if we need to preserve the old value of
> mdev->sysctl after we unregister it.

It'd work too, I decided to limit the zeroing to the exception case
because of recent discussions on the list. The argument there was that
zeroing in cases were we don't expect it to be necessary may hide bugs.
We generally try to avoid defensive programming in the kernel.