From: Ziyang Xuan <hidden> Date: 2022-03-18 01:39:33
Add the reference operation to phy_dev of ipvlan to avoid
the potential UAF problem under the following known scenario:
Someone module puts the NETDEV_UNREGISTER event handler to a
work, and phy_dev is accessed in the work handler. But when
the work is excuted, phy_dev has been destroyed because upper
ipvlan did not get reference to phy_dev correctly.
In addition, add net device refcount tracker to ipvlan and
fix some error comments for ipvtap module.
------
v1->v2:
- Add "Fixes: tag" for fix patches.
Ziyang Xuan (3):
net: ipvlan: fix potential UAF problem for phy_dev
net: ipvlan: add net device refcount tracker
net: ipvtap: fix error comments
drivers/net/ipvlan/ipvlan.h | 1 +
drivers/net/ipvlan/ipvlan_main.c | 13 +++++++++++++
drivers/net/ipvlan/ipvtap.c | 4 ++--
3 files changed, 16 insertions(+), 2 deletions(-)
--
2.25.1
From: Ziyang Xuan <hidden> Date: 2022-03-18 01:40:32
Add the reference operation to phy_dev of ipvlan to avoid
the potential UAF problem under the following known scenario:
Someone module puts the NETDEV_UNREGISTER event handler to a
work, and phy_dev is accessed in the work handler. But when
the work is excuted, phy_dev has been destroyed because upper
ipvlan did not get reference to phy_dev correctly.
That likes as the scenario occurred by
commit 563bcbae3ba2 ("net: vlan: fix a UAF in vlan_dev_real_dev()").
Fixes: 2ad7bf363841 ("ipvlan: Initial check-in of the IPVLAN driver.")
Signed-off-by: Ziyang Xuan <redacted>
---
drivers/net/ipvlan/ipvlan_main.c | 13 +++++++++++++
1 file changed, 13 insertions(+)
@@ -158,6 +158,10 @@ static int ipvlan_init(struct net_device *dev)}port=ipvlan_port_get_rtnl(phy_dev);port->count+=1;++/* Get ipvlan's reference to phy_dev */+dev_hold(phy_dev);+return0;}
@@ -665,6 +669,14 @@ void ipvlan_link_delete(struct net_device *dev, struct list_head *head)}EXPORT_SYMBOL_GPL(ipvlan_link_delete);+staticvoidipvlan_dev_free(structnet_device*dev)+{+structipvl_dev*ipvlan=netdev_priv(dev);++/* Get rid of the ipvlan's reference to phy_dev */+dev_put(ipvlan->phy_dev);+}+voidipvlan_link_setup(structnet_device*dev){ether_setup(dev);
@@ -160,7 +160,7 @@ static int ipvlan_init(struct net_device *dev)port->count+=1;/* Get ipvlan's reference to phy_dev */-dev_hold(phy_dev);+dev_hold_track(phy_dev,&ipvlan->dev_tracker,GFP_KERNEL);return0;}
@@ -674,7 +674,7 @@ static void ipvlan_dev_free(struct net_device *dev)structipvl_dev*ipvlan=netdev_priv(dev);/* Get rid of the ipvlan's reference to phy_dev */-dev_put(ipvlan->phy_dev);+dev_put_track(ipvlan->phy_dev,&ipvlan->dev_tracker);}voidipvlan_link_setup(structnet_device*dev)
From: Ziyang Xuan <hidden> Date: 2022-03-18 01:42:14
Use "macvlan" comment inappropriately in ipvtap module.
Fix them with "ipvlan" comment.
Fixes: 235a9d89da97 ("ipvtap: IP-VLAN based tap driver")
Signed-off-by: Ziyang Xuan <redacted>
---
drivers/net/ipvlan/ipvtap.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
@@ -83,7 +83,7 @@ static int ipvtap_newlink(struct net *src_net, struct net_device *dev,INIT_LIST_HEAD(&vlantap->tap.queue_list);-/* Since macvlan supports all offloads by default, make+/* Since ipvlan supports all offloads by default, make*tapsupportalloffloadsalso.*/vlantap->tap.tap_features=TUN_OFFLOADS;
@@ -95,7 +95,7 @@ static int ipvtap_newlink(struct net *src_net, struct net_device *dev,if(err)returnerr;-/* Don't put anything that may fail after macvlan_common_newlink+/* Don't put anything that may fail after ipvlan_link_new*becausewecan'tundowhatitdoes.*/err=ipvlan_link_new(src_net,dev,tb,data,extack);
From: Jakub Kicinski <kuba@kernel.org> Date: 2022-03-18 17:53:21
On Fri, 18 Mar 2022 09:57:47 +0800 Ziyang Xuan wrote:
Add the reference operation to phy_dev of ipvlan to avoid
the potential UAF problem under the following known scenario:
Someone module puts the NETDEV_UNREGISTER event handler to a
work, and phy_dev is accessed in the work handler. But when
the work is excuted, phy_dev has been destroyed because upper
ipvlan did not get reference to phy_dev correctly.
That likes as the scenario occurred by
commit 563bcbae3ba2 ("net: vlan: fix a UAF in vlan_dev_real_dev()").
There is no equivalent of vlan_dev_real_dev() for ipvlan, AFAICT.
The definition of struct ipvl_dev is private to the driver. I don't
see how a UAF can happen here.
You should either clearly explain how the bug could happen or clearly
state that there is no possibility of the bug for this driver, and the
patch is just future proofing.
If the latter is the case we should drop the Fixes tag and prevent this
patch from getting backported into stable.
Fixes: 2ad7bf363841 ("ipvlan: Initial check-in of the IPVLAN driver.")
Signed-off-by: Ziyang Xuan <redacted>
From: Ziyang Xuan (William) <hidden> Date: 2022-03-19 03:39:07
On Fri, 18 Mar 2022 09:57:47 +0800 Ziyang Xuan wrote:
quoted
Add the reference operation to phy_dev of ipvlan to avoid
the potential UAF problem under the following known scenario:
Someone module puts the NETDEV_UNREGISTER event handler to a
work, and phy_dev is accessed in the work handler. But when
the work is excuted, phy_dev has been destroyed because upper
ipvlan did not get reference to phy_dev correctly.
That likes as the scenario occurred by
commit 563bcbae3ba2 ("net: vlan: fix a UAF in vlan_dev_real_dev()").
There is no equivalent of vlan_dev_real_dev() for ipvlan, AFAICT.
The definition of struct ipvl_dev is private to the driver. I don't
see how a UAF can happen here.
You should either clearly explain how the bug could happen or clearly
state that there is no possibility of the bug for this driver, and the
patch is just future proofing.
If the latter is the case we should drop the Fixes tag and prevent this
patch from getting backported into stable.
It is to prevent ipvlan from occurring the similar problem in the future.
For now, there is not way to access phy_dev outside ipvlan module as vlan
real_dev using vlan_dev_real_dev(). I will make this clear.
I think it is necessary to protect lower netdevice using the feature of
netdevice refcnt. So I do it.
Thank you for your valuable opinions! I believe I can do more and more better
with your help.
quoted
Fixes: 2ad7bf363841 ("ipvlan: Initial check-in of the IPVLAN driver.")
Signed-off-by: Ziyang Xuan <redacted>