* [PATCH net-next 0/2] net: macvlan: fix potential UAF problem for lowerdev
@ 2022-03-11 9:02 Ziyang Xuan
2022-03-11 9:03 ` [PATCH net-next 1/2] " Ziyang Xuan
` (2 more replies)
0 siblings, 3 replies; 4+ messages in thread
From: Ziyang Xuan @ 2022-03-11 9:02 UTC (permalink / raw)
To: davem, kuba, netdev; +Cc: linux-kernel
Add the reference operation to lowerdev of macvlan to avoid
the potential UAF problem under the following known scenario:
Someone module puts the NETDEV_UNREGISTER event handler to a
work, and lowerdev is accessed in the work handler. But when
the work is excuted, lowerdev has been destroyed because upper
macvlan did not get reference to lowerdev correctly.
In addition, add net device refcount tracker to macvlan.
Ziyang Xuan (2):
net: macvlan: fix potential UAF problem for lowerdev
net: macvlan: add net device refcount tracker
drivers/net/macvlan.c | 14 +++++++++++++-
include/linux/if_macvlan.h | 1 +
2 files changed, 14 insertions(+), 1 deletion(-)
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH net-next 1/2] net: macvlan: fix potential UAF problem for lowerdev
2022-03-11 9:02 [PATCH net-next 0/2] net: macvlan: fix potential UAF problem for lowerdev Ziyang Xuan
@ 2022-03-11 9:03 ` Ziyang Xuan
2022-03-11 9:04 ` [PATCH net-next 2/2] net: macvlan: add net device refcount tracker Ziyang Xuan
2022-03-14 10:10 ` [PATCH net-next 0/2] net: macvlan: fix potential UAF problem for lowerdev patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Ziyang Xuan @ 2022-03-11 9:03 UTC (permalink / raw)
To: davem, kuba, netdev; +Cc: linux-kernel
Add the reference operation to lowerdev of macvlan to avoid
the potential UAF problem under the following known scenario:
Someone module puts the NETDEV_UNREGISTER event handler to a
work, and lowerdev is accessed in the work handler. But when
the work is excuted, lowerdev has been destroyed because upper
macvlan did not get reference to lowerdev correctly.
That likes as the scenario occurred by
commit 563bcbae3ba2 ("net: vlan: fix a UAF in vlan_dev_real_dev()").
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
---
drivers/net/macvlan.c | 14 +++++++++++++-
1 file changed, 13 insertions(+), 1 deletion(-)
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index 33753a2fde29..d36af413e372 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -889,7 +889,7 @@ static void macvlan_set_lockdep_class(struct net_device *dev)
static int macvlan_init(struct net_device *dev)
{
struct macvlan_dev *vlan = netdev_priv(dev);
- const struct net_device *lowerdev = vlan->lowerdev;
+ struct net_device *lowerdev = vlan->lowerdev;
struct macvlan_port *port = vlan->port;
dev->state = (dev->state & ~MACVLAN_STATE_MASK) |
@@ -911,6 +911,9 @@ static int macvlan_init(struct net_device *dev)
port->count += 1;
+ /* Get macvlan's reference to lowerdev */
+ dev_hold(lowerdev);
+
return 0;
}
@@ -1173,6 +1176,14 @@ static const struct net_device_ops macvlan_netdev_ops = {
.ndo_features_check = passthru_features_check,
};
+static void macvlan_dev_free(struct net_device *dev)
+{
+ struct macvlan_dev *vlan = netdev_priv(dev);
+
+ /* Get rid of the macvlan's reference to lowerdev */
+ dev_put(vlan->lowerdev);
+}
+
void macvlan_common_setup(struct net_device *dev)
{
ether_setup(dev);
@@ -1184,6 +1195,7 @@ void macvlan_common_setup(struct net_device *dev)
dev->priv_flags |= IFF_UNICAST_FLT | IFF_CHANGE_PROTO_DOWN;
dev->netdev_ops = &macvlan_netdev_ops;
dev->needs_free_netdev = true;
+ dev->priv_destructor = macvlan_dev_free;
dev->header_ops = &macvlan_hard_header_ops;
dev->ethtool_ops = &macvlan_ethtool_ops;
}
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread* [PATCH net-next 2/2] net: macvlan: add net device refcount tracker
2022-03-11 9:02 [PATCH net-next 0/2] net: macvlan: fix potential UAF problem for lowerdev Ziyang Xuan
2022-03-11 9:03 ` [PATCH net-next 1/2] " Ziyang Xuan
@ 2022-03-11 9:04 ` Ziyang Xuan
2022-03-14 10:10 ` [PATCH net-next 0/2] net: macvlan: fix potential UAF problem for lowerdev patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: Ziyang Xuan @ 2022-03-11 9:04 UTC (permalink / raw)
To: davem, kuba, netdev; +Cc: linux-kernel
Add net device refcount tracker to macvlan.
Signed-off-by: Ziyang Xuan <william.xuanziyang@huawei.com>
---
drivers/net/macvlan.c | 4 ++--
include/linux/if_macvlan.h | 1 +
2 files changed, 3 insertions(+), 2 deletions(-)
diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
index d36af413e372..d6241ad66c0c 100644
--- a/drivers/net/macvlan.c
+++ b/drivers/net/macvlan.c
@@ -912,7 +912,7 @@ static int macvlan_init(struct net_device *dev)
port->count += 1;
/* Get macvlan's reference to lowerdev */
- dev_hold(lowerdev);
+ dev_hold_track(lowerdev, &vlan->dev_tracker, GFP_KERNEL);
return 0;
}
@@ -1181,7 +1181,7 @@ static void macvlan_dev_free(struct net_device *dev)
struct macvlan_dev *vlan = netdev_priv(dev);
/* Get rid of the macvlan's reference to lowerdev */
- dev_put(vlan->lowerdev);
+ dev_put_track(vlan->lowerdev, &vlan->dev_tracker);
}
void macvlan_common_setup(struct net_device *dev)
diff --git a/include/linux/if_macvlan.h b/include/linux/if_macvlan.h
index 10c94a3936ca..b42294739063 100644
--- a/include/linux/if_macvlan.h
+++ b/include/linux/if_macvlan.h
@@ -21,6 +21,7 @@ struct macvlan_dev {
struct hlist_node hlist;
struct macvlan_port *port;
struct net_device *lowerdev;
+ netdevice_tracker dev_tracker;
void *accel_priv;
struct vlan_pcpu_stats __percpu *pcpu_stats;
--
2.25.1
^ permalink raw reply [flat|nested] 4+ messages in thread* Re: [PATCH net-next 0/2] net: macvlan: fix potential UAF problem for lowerdev
2022-03-11 9:02 [PATCH net-next 0/2] net: macvlan: fix potential UAF problem for lowerdev Ziyang Xuan
2022-03-11 9:03 ` [PATCH net-next 1/2] " Ziyang Xuan
2022-03-11 9:04 ` [PATCH net-next 2/2] net: macvlan: add net device refcount tracker Ziyang Xuan
@ 2022-03-14 10:10 ` patchwork-bot+netdevbpf
2 siblings, 0 replies; 4+ messages in thread
From: patchwork-bot+netdevbpf @ 2022-03-14 10:10 UTC (permalink / raw)
To: Ziyang Xuan; +Cc: davem, kuba, netdev, linux-kernel
Hello:
This series was applied to netdev/net-next.git (master)
by David S. Miller <davem@davemloft.net>:
On Fri, 11 Mar 2022 17:02:41 +0800 you wrote:
> Add the reference operation to lowerdev of macvlan to avoid
> the potential UAF problem under the following known scenario:
>
> Someone module puts the NETDEV_UNREGISTER event handler to a
> work, and lowerdev is accessed in the work handler. But when
> the work is excuted, lowerdev has been destroyed because upper
> macvlan did not get reference to lowerdev correctly.
>
> [...]
Here is the summary with links:
- [net-next,1/2] net: macvlan: fix potential UAF problem for lowerdev
https://git.kernel.org/netdev/net-next/c/291ac68478d9
- [net-next,2/2] net: macvlan: add net device refcount tracker
https://git.kernel.org/netdev/net-next/c/1f4a5983d623
You are awesome, thank you!
--
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-03-14 10:10 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-03-11 9:02 [PATCH net-next 0/2] net: macvlan: fix potential UAF problem for lowerdev Ziyang Xuan
2022-03-11 9:03 ` [PATCH net-next 1/2] " Ziyang Xuan
2022-03-11 9:04 ` [PATCH net-next 2/2] net: macvlan: add net device refcount tracker Ziyang Xuan
2022-03-14 10:10 ` [PATCH net-next 0/2] net: macvlan: fix potential UAF problem for lowerdev patchwork-bot+netdevbpf
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox
all inboxes | Powered by JetHome®