Re: [PATCH net] macvlan: inherit needed_headroom and needed_tailroom from lowerdev

Hangbin Liu <[email protected]>
Newsgroups gmane.linux.network
Message-ID <anV5Cu3V6UF2Ilqe@fedora>
On 06.08.2026 14:19, Eric Dumazet wrote:
>macvlan devices inherit hard_header_len from lowerdev during macvlan_init(),
>but leave needed_headroom and needed_tailroom set to 0.
>
>When the underlying lowerdev requires extra headroom or tailroom for
>headers/trailers (e.g. macsec, ipsec, wireguard, tunnels, or veth with rx
>headroom), upper layers calculating packet headroom and tailroom fail to
>reserve sufficient space.
>
>This can result in reallocation overhead, skb headroom underflows, or KASAN
>slab-use-after-free crashes when dev_hard_header() / macvlan_hard_header()
>prepends header data or when lower devices append tailroom.
>
>Fix this by:
>1. Inheriting needed_headroom and needed_tailroom from lowerdev in macvlan_init().
>2. Propagating needed_headroom and needed_tailroom updates to attached macvlans
>   in macvlan_device_event() when receiving NETDEV_FEAT_CHANGE events.
>
>Fixes: b863ceb7ddce ("[NET]: Add macvlan driver")
>Reported-by: Tangxin Xie <[email protected]>
>Closes: https://lore.kernel.org/netdev/CANn89i+1EW-sFNK8xoq98gMbPCeLS7e=+rs9gHfLg5Wj+4x0sw@mail.gmail.com/T/#m16adf0ff972cbfd8066c3a8e656e75eaeb12d021
>Signed-off-by: Eric Dumazet <[email protected]>
>---
> drivers/net/macvlan.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
>diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
>index c40fa331836bb2395267914807542ae5094e1a3c..ff2f4bb651b74cdb054f245ea0f4e8cfe2297193 100644
>--- a/drivers/net/macvlan.c
>+++ b/drivers/net/macvlan.c
>@@ -950,6 +950,8 @@ static int macvlan_init(struct net_device *dev)
> 	dev->lltx		= true;
> 	netif_inherit_tso_max(dev, lowerdev);
> 	dev->hard_header_len	= lowerdev->hard_header_len;
>+	dev->needed_headroom	= lowerdev->needed_headroom;
>+	dev->needed_tailroom	= lowerdev->needed_tailroom;
> 	macvlan_set_lockdep_class(dev);
>
> 	vlan->pcpu_stats = netdev_alloc_pcpu_stats(struct vlan_pcpu_stats);
>@@ -1824,6 +1826,8 @@ static int macvlan_device_event(struct notifier_block *unused,
> 	case NETDEV_FEAT_CHANGE:
> 		list_for_each_entry(vlan, &port->vlans, list) {
> 			netif_inherit_tso_max(vlan->dev, dev);
>+			vlan->dev->needed_headroom = dev->needed_headroom;
>+			vlan->dev->needed_tailroom = dev->needed_tailroom;
> 			netdev_update_features(vlan->dev);
> 		}
> 		break;
>-- 
>2.55.0.629.g250fe7f194-goog
>

Reviewed-by: Hangbin Liu <[email protected]>
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.