From: Petr Machata <petrm@nvidia.com>
To: Petr Machata <petrm@nvidia.com>
Cc: "Ziyang Xuan (William)" <william.xuanziyang@huawei.com>,
Jakub Kicinski <kuba@kernel.org>, <davem@davemloft.net>,
<jgg@nvidia.com>, <netdev@vger.kernel.org>,
<linux-kernel@vger.kernel.org>
Subject: Re: [PATCH net v2] net: vlan: fix a UAF in vlan_dev_real_dev()
Date: Thu, 25 Nov 2021 12:33:11 +0100 [thread overview]
Message-ID: <87v90gqxl4.fsf@nvidia.com> (raw)
In-Reply-To: <87k0gzrqw8.fsf@nvidia.com>
Petr Machata <petrm@nvidia.com> writes:
> Ziyang Xuan (William) <william.xuanziyang@huawei.com> writes:
>
>>>
>>> Ziyang Xuan (William) <william.xuanziyang@huawei.com> writes:
>>>
>>>> I need some time to test my some ideas. And anyone has good ideas, please
>>>> do not be stingy.
>>>
>>> Jakub Kicinski <kuba@kernel.org> writes:
>>>
>>>> I think we should move the dev_hold() to ndo_init(), otherwise it's
>>>> hard to reason if destructor was invoked or not if
>>>> register_netdevice() errors out.
>>>
>>> That makes sense to me. We always put real_dev in the destructor, so we
>>> should always hold it in the constructor...
>>
>> Inject error before dev_hold(real_dev) in register_vlan_dev(), and execute
>> the following testcase:
>>
>> ip link add dev dummy1 type dummy
>> ip link add name dummy1.100 link dummy1 type vlan id 100 // failed for error injection
>> ip link del dev dummy1
>>
>> Make the problem repro. The problem is solved using the following fix
>> according to the Jakub's suggestion:
>>
>> diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
>> index a3a0a5e994f5..abaa5d96ded2 100644
>> --- a/net/8021q/vlan.c
>> +++ b/net/8021q/vlan.c
>> @@ -184,9 +184,6 @@ int register_vlan_dev(struct net_device *dev, struct netlink_ext_ack *extack)
>> if (err)
>> goto out_unregister_netdev;
>>
>> - /* Account for reference in struct vlan_dev_priv */
>> - dev_hold(real_dev);
>> -
>> vlan_stacked_transfer_operstate(real_dev, dev, vlan);
>> linkwatch_fire_event(dev); /* _MUST_ call rfc2863_policy() */
>>
>> diff --git a/net/8021q/vlan_dev.c b/net/8021q/vlan_dev.c
>> index ab6dee28536d..a54535cbcf4c 100644
>> --- a/net/8021q/vlan_dev.c
>> +++ b/net/8021q/vlan_dev.c
>> @@ -615,6 +615,9 @@ static int vlan_dev_init(struct net_device *dev)
>> if (!vlan->vlan_pcpu_stats)
>> return -ENOMEM;
>>
>> + /* Get vlan's reference to real_dev */
>> + dev_hold(real_dev);
>>
>>
>> If there is not any other idea and objection, I will send the fix patch later.
>>
>> Thank you!
>
> This fixes the issue in my repro, and does not seems to break anything.
> We'll take it to full regression overnight, I'll report back tomorrow
> about the result.
Sorry, was AFK yesterday. It does look good.
next prev parent reply other threads:[~2021-11-25 11:35 UTC|newest]
Thread overview: 18+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-11-02 2:12 [PATCH net v2] net: vlan: fix a UAF in vlan_dev_real_dev() Ziyang Xuan
2021-11-03 13:50 ` Jason Gunthorpe
2021-11-03 15:47 ` Jakub Kicinski
2021-11-03 16:11 ` Jason Gunthorpe
2021-11-03 14:30 ` patchwork-bot+netdevbpf
2021-11-15 17:04 ` Petr Machata
2021-11-15 17:49 ` Jakub Kicinski
2021-11-16 14:20 ` Petr Machata
2021-11-17 11:50 ` Petr Machata
2021-11-18 1:46 ` Ziyang Xuan (William)
2021-11-18 14:17 ` Jakub Kicinski
2021-11-19 3:29 ` Ziyang Xuan (William)
2021-11-19 10:07 ` Petr Machata
2021-11-23 9:01 ` Ziyang Xuan (William)
2021-11-23 12:35 ` Petr Machata
2021-11-25 11:33 ` Petr Machata [this message]
2021-11-26 1:48 ` Ziyang Xuan (William)
2021-11-19 3:04 ` Ziyang Xuan (William)
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=87v90gqxl4.fsf@nvidia.com \
--to=petrm@nvidia.com \
--cc=davem@davemloft.net \
--cc=jgg@nvidia.com \
--cc=kuba@kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=william.xuanziyang@huawei.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox