All of lore.kernel.org
 help / color / mirror / Atom feed
From: Gong Ruiqi <gongruiqi1@huawei.com>
To: Jakub Kicinski <kuba@kernel.org>
Cc: <davem@davemloft.net>, <netdev@vger.kernel.org>,
	<edumazet@google.com>, <pabeni@redhat.com>,
	lianhui tang <bluetlh@gmail.com>, <kuniyu@amazon.co.jp>,
	<rshearma@brocade.com>
Subject: Re: [PATCH net] net: mpls: fix stale pointer if allocation fails during device rename
Date: Wed, 15 Feb 2023 14:29:33 +0800	[thread overview]
Message-ID: <2cf28c54-866d-cfd7-499a-e5bc04bd6d19@huawei.com> (raw)
In-Reply-To: <20230214132331.526f4fb7@kernel.org>



On 2023/02/15 5:23, Jakub Kicinski wrote:
> 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.

Actually my original thought was not to do defensive programming, but to
clearly mark it as invalid after its de-registration. Nevertheless "to
avoid defensive programming in the kernel" is a good point :)

And oops, for my proposal the complete solution should be:

@@ -1437,8 +1437,12 @@ static void mpls_dev_sysctl_unregister(struct
net_device *dev,
        struct net *net = dev_net(dev);
        struct ctl_table *table;

+       if (!mdev->sysctl)
+               return;
+
        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);

to avoid NULL dereference at `table = mdev->sysctl->...` if we try to
unregister the device after a failed renaming. Then it looks really
similar with your patch xD. So yeah I'm ok with both of them.

  reply	other threads:[~2023-02-15  6:30 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-02-14  6:53 [PATCH net] net: mpls: fix stale pointer if allocation fails during device rename Jakub Kicinski
2023-02-14  9:33 ` Gong Ruiqi
2023-02-14 21:23   ` Jakub Kicinski
2023-02-15  6:29     ` Gong Ruiqi [this message]
2023-02-15 10:30 ` patchwork-bot+netdevbpf

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=2cf28c54-866d-cfd7-499a-e5bc04bd6d19@huawei.com \
    --to=gongruiqi1@huawei.com \
    --cc=bluetlh@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=kuniyu@amazon.co.jp \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    --cc=rshearma@brocade.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.