Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5632893pxb; Tue, 16 Feb 2021 03:47:23 -0800 (PST) X-Google-Smtp-Source: ABdhPJxQ8VzqKh63izrVtN9nJ2Aqul8+FZBjjdA/huUFaGYDM0vYsa/v44hyJIA+OzwtfdwucKHn X-Received: by 2002:a17:906:1d44:: with SMTP id o4mr17305335ejh.130.1613476043139; Tue, 16 Feb 2021 03:47:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613476043; cv=none; d=google.com; s=arc-20160816; b=jxogi7x8OuK97LsQxfooXfD7d9N74eKvX2Z7w9hrxH5HLTWfM5iPmdZKfNtjtmIo7D it8wKDuKUJ3QfUc1WiH9wGWdvwTo/YIbuGvv2m/vEYLVrWxQhZAh80bDL9l2lbqULgZf 99+L8GfG++bGnPZ+9q9Xs2G1+lytxWXILiyO1Ql1rDYjSpXKr8BRQWy/n3fXzbSVjebs Oyu2JsshjCrc1E3ZJE6mWkjwIaHCZ/pT2Zjx5YtdSeoMGwxfT32yFojyfLUxDjBBn5zH m83/Yw2WG26wZnKtH6Q1QpuQ3wX0scgGJs8IbI8xdDYzr7bEGv2jI5ZMSJ5vl3tNmsqG Fszw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:reply-to:cc:from:to :dkim-signature:date; bh=jIXE5w2oQPgxeatOYIJ5XGHcdrWadlvRgtBHKR6uEoQ=; b=lrkwTG5NJPkLWTykNA6T17LpJPE0NBEPOh2aBlhhODlF0cn+98jS5cTJv3FWdsQra9 R6S6q+X7+JRL4skk45BKVf3npnsL2rXoSstT5WUcCzjODpS10/Obrf0BIdskxDaQNCEz OF56isaH2LMwp5VS0I6ECfIQ9JEYeEF+/nVEstEEgVvdCocdy1Xy2NmBZkF40Qs3kzDm UPZ2PCaLmMtewITuoXAbprbc86tb9iahYlI5T1TqDAPoNdJTDxxrpJn7kpDyz2QZH/cW nvJpqIVtA+g+qdoWHOp+bNsnDkUWumHGfPuDh1KEVIw5UefY9ggIm6em47UJQMepnPRs fX6g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=eCD3ZSnb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id y15si14616558edc.57.2021.02.16.03.47.00; Tue, 16 Feb 2021 03:47:23 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=eCD3ZSnb; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=pm.me Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230473AbhBPLou (ORCPT + 99 others); Tue, 16 Feb 2021 06:44:50 -0500 Received: from mail1.protonmail.ch ([185.70.40.18]:30565 "EHLO mail1.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230382AbhBPLjV (ORCPT ); Tue, 16 Feb 2021 06:39:21 -0500 Date: Tue, 16 Feb 2021 11:38:34 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1613475517; bh=jIXE5w2oQPgxeatOYIJ5XGHcdrWadlvRgtBHKR6uEoQ=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=eCD3ZSnbkwKQyQq0up6qK7z7UaKEYi7BoHgnRwTAw4Vd97kq6d4nEDxuPHhDxpiDa 10DMZmFyys6Szx3vP18bi/1uz9BxalzlqlJ7or6ea2mNMK6L+wqKkx3eQb5e5P56+W MuT96ukeDQMfwZ7gsgoAU2BcPrkLh7q3j8iYLUuVvZVQJjb5zdohoNWjtvrSOXZqUs GaG03SKxC3DVXXCe15NMyLpZxOquah9zdLVG/kbpUZv4g3sGP3UIqzAg7tkijQL3J2 HhTcO0ZUnlhuYgCIQMuWTT6qu8x1/pErc0wa5/VGCW2aMslSR3Ts4BojA6yBNdXQ25 bjlchsfqBgbcg== To: Magnus Karlsson , =?utf-8?Q?Bj=C3=B6rn_T=C3=B6pel?= From: Alexander Lobakin Cc: "Michael S. Tsirkin" , Jason Wang , "David S. Miller" , Jakub Kicinski , Jonathan Lemon , Alexei Starovoitov , Daniel Borkmann , Jesper Dangaard Brouer , John Fastabend , Andrii Nakryiko , Martin KaFai Lau , Song Liu , Yonghong Song , KP Singh , Paolo Abeni , Eric Dumazet , Xuan Zhuo , Dust Li , Alexander Lobakin , virtualization@lists.linux-foundation.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org, bpf@vger.kernel.org Reply-To: Alexander Lobakin Subject: [PATCH v4 bpf-next 2/6] netdevice: check for net_device::priv_flags bitfield overflow Message-ID: <20210216113740.62041-3-alobakin@pm.me> In-Reply-To: <20210216113740.62041-1-alobakin@pm.me> References: <20210216113740.62041-1-alobakin@pm.me> MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable X-Spam-Status: No, score=-0.4 required=10.0 tests=ALL_TRUSTED,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,UPPERCASE_50_75 shortcircuit=no autolearn=disabled version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on mailout.protonmail.ch Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org We almost ran out of unsigned int bitwidth. Define priv flags and check for potential overflow in the fashion of netdev_features_t. Defined this way, priv_flags can be easily expanded later with just changing its typedef. Signed-off-by: Alexander Lobakin --- include/linux/netdevice.h | 135 ++++++++++++++++++++------------------ 1 file changed, 72 insertions(+), 63 deletions(-) diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h index b895973390ee..fa4ab77ce81e 100644 --- a/include/linux/netdevice.h +++ b/include/linux/netdevice.h @@ -1527,70 +1527,79 @@ struct net_device_ops { * @IFF_LIVE_RENAME_OK: rename is allowed while device is up and running */ enum netdev_priv_flags { -=09IFF_802_1Q_VLAN=09=09=09=3D 1<<0, -=09IFF_EBRIDGE=09=09=09=3D 1<<1, -=09IFF_BONDING=09=09=09=3D 1<<2, -=09IFF_ISATAP=09=09=09=3D 1<<3, -=09IFF_WAN_HDLC=09=09=09=3D 1<<4, -=09IFF_XMIT_DST_RELEASE=09=09=3D 1<<5, -=09IFF_DONT_BRIDGE=09=09=09=3D 1<<6, -=09IFF_DISABLE_NETPOLL=09=09=3D 1<<7, -=09IFF_MACVLAN_PORT=09=09=3D 1<<8, -=09IFF_BRIDGE_PORT=09=09=09=3D 1<<9, -=09IFF_OVS_DATAPATH=09=09=3D 1<<10, -=09IFF_TX_SKB_SHARING=09=09=3D 1<<11, -=09IFF_UNICAST_FLT=09=09=09=3D 1<<12, -=09IFF_TEAM_PORT=09=09=09=3D 1<<13, -=09IFF_SUPP_NOFCS=09=09=09=3D 1<<14, -=09IFF_LIVE_ADDR_CHANGE=09=09=3D 1<<15, -=09IFF_MACVLAN=09=09=09=3D 1<<16, -=09IFF_XMIT_DST_RELEASE_PERM=09=3D 1<<17, -=09IFF_L3MDEV_MASTER=09=09=3D 1<<18, -=09IFF_NO_QUEUE=09=09=09=3D 1<<19, -=09IFF_OPENVSWITCH=09=09=09=3D 1<<20, -=09IFF_L3MDEV_SLAVE=09=09=3D 1<<21, -=09IFF_TEAM=09=09=09=3D 1<<22, -=09IFF_RXFH_CONFIGURED=09=09=3D 1<<23, -=09IFF_PHONY_HEADROOM=09=09=3D 1<<24, -=09IFF_MACSEC=09=09=09=3D 1<<25, -=09IFF_NO_RX_HANDLER=09=09=3D 1<<26, -=09IFF_FAILOVER=09=09=09=3D 1<<27, -=09IFF_FAILOVER_SLAVE=09=09=3D 1<<28, -=09IFF_L3MDEV_RX_HANDLER=09=09=3D 1<<29, -=09IFF_LIVE_RENAME_OK=09=09=3D 1<<30, +=09IFF_802_1Q_VLAN_BIT, +=09IFF_EBRIDGE_BIT, +=09IFF_BONDING_BIT, +=09IFF_ISATAP_BIT, +=09IFF_WAN_HDLC_BIT, +=09IFF_XMIT_DST_RELEASE_BIT, +=09IFF_DONT_BRIDGE_BIT, +=09IFF_DISABLE_NETPOLL_BIT, +=09IFF_MACVLAN_PORT_BIT, +=09IFF_BRIDGE_PORT_BIT, +=09IFF_OVS_DATAPATH_BIT, +=09IFF_TX_SKB_SHARING_BIT, +=09IFF_UNICAST_FLT_BIT, +=09IFF_TEAM_PORT_BIT, +=09IFF_SUPP_NOFCS_BIT, +=09IFF_LIVE_ADDR_CHANGE_BIT, +=09IFF_MACVLAN_BIT, +=09IFF_XMIT_DST_RELEASE_PERM_BIT, +=09IFF_L3MDEV_MASTER_BIT, +=09IFF_NO_QUEUE_BIT, +=09IFF_OPENVSWITCH_BIT, +=09IFF_L3MDEV_SLAVE_BIT, +=09IFF_TEAM_BIT, +=09IFF_RXFH_CONFIGURED_BIT, +=09IFF_PHONY_HEADROOM_BIT, +=09IFF_MACSEC_BIT, +=09IFF_NO_RX_HANDLER_BIT, +=09IFF_FAILOVER_BIT, +=09IFF_FAILOVER_SLAVE_BIT, +=09IFF_L3MDEV_RX_HANDLER_BIT, +=09IFF_LIVE_RENAME_OK_BIT, + +=09NETDEV_PRIV_FLAG_COUNT, }; =20 -#define IFF_802_1Q_VLAN=09=09=09IFF_802_1Q_VLAN -#define IFF_EBRIDGE=09=09=09IFF_EBRIDGE -#define IFF_BONDING=09=09=09IFF_BONDING -#define IFF_ISATAP=09=09=09IFF_ISATAP -#define IFF_WAN_HDLC=09=09=09IFF_WAN_HDLC -#define IFF_XMIT_DST_RELEASE=09=09IFF_XMIT_DST_RELEASE -#define IFF_DONT_BRIDGE=09=09=09IFF_DONT_BRIDGE -#define IFF_DISABLE_NETPOLL=09=09IFF_DISABLE_NETPOLL -#define IFF_MACVLAN_PORT=09=09IFF_MACVLAN_PORT -#define IFF_BRIDGE_PORT=09=09=09IFF_BRIDGE_PORT -#define IFF_OVS_DATAPATH=09=09IFF_OVS_DATAPATH -#define IFF_TX_SKB_SHARING=09=09IFF_TX_SKB_SHARING -#define IFF_UNICAST_FLT=09=09=09IFF_UNICAST_FLT -#define IFF_TEAM_PORT=09=09=09IFF_TEAM_PORT -#define IFF_SUPP_NOFCS=09=09=09IFF_SUPP_NOFCS -#define IFF_LIVE_ADDR_CHANGE=09=09IFF_LIVE_ADDR_CHANGE -#define IFF_MACVLAN=09=09=09IFF_MACVLAN -#define IFF_XMIT_DST_RELEASE_PERM=09IFF_XMIT_DST_RELEASE_PERM -#define IFF_L3MDEV_MASTER=09=09IFF_L3MDEV_MASTER -#define IFF_NO_QUEUE=09=09=09IFF_NO_QUEUE -#define IFF_OPENVSWITCH=09=09=09IFF_OPENVSWITCH -#define IFF_L3MDEV_SLAVE=09=09IFF_L3MDEV_SLAVE -#define IFF_TEAM=09=09=09IFF_TEAM -#define IFF_RXFH_CONFIGURED=09=09IFF_RXFH_CONFIGURED -#define IFF_PHONY_HEADROOM=09=09IFF_PHONY_HEADROOM -#define IFF_MACSEC=09=09=09IFF_MACSEC -#define IFF_NO_RX_HANDLER=09=09IFF_NO_RX_HANDLER -#define IFF_FAILOVER=09=09=09IFF_FAILOVER -#define IFF_FAILOVER_SLAVE=09=09IFF_FAILOVER_SLAVE -#define IFF_L3MDEV_RX_HANDLER=09=09IFF_L3MDEV_RX_HANDLER -#define IFF_LIVE_RENAME_OK=09=09IFF_LIVE_RENAME_OK +typedef u32 netdev_priv_flags_t; +static_assert(sizeof(netdev_priv_flags_t) * BITS_PER_BYTE <=3D +=09 NETDEV_PRIV_FLAG_COUNT); + +#define __IFF_BIT(bit)=09=09=09((netdev_priv_flags_t)1 << (bit)) +#define __IFF(name)=09=09=09__IFF_BIT(IFF_##name##_BIT) + +#define IFF_802_1Q_VLAN=09=09=09__IFF(802_1Q_VLAN) +#define IFF_EBRIDGE=09=09=09__IFF(EBRIDGE) +#define IFF_BONDING=09=09=09__IFF(BONDING) +#define IFF_ISATAP=09=09=09__IFF(ISATAP) +#define IFF_WAN_HDLC=09=09=09__IFF(WAN_HDLC) +#define IFF_XMIT_DST_RELEASE=09=09__IFF(XMIT_DST_RELEASE) +#define IFF_DONT_BRIDGE=09=09=09__IFF(DONT_BRIDGE) +#define IFF_DISABLE_NETPOLL=09=09__IFF(DISABLE_NETPOLL) +#define IFF_MACVLAN_PORT=09=09__IFF(MACVLAN_PORT) +#define IFF_BRIDGE_PORT=09=09=09__IFF(BRIDGE_PORT) +#define IFF_OVS_DATAPATH=09=09__IFF(OVS_DATAPATH) +#define IFF_TX_SKB_SHARING=09=09__IFF(TX_SKB_SHARING) +#define IFF_UNICAST_FLT=09=09=09__IFF(UNICAST_FLT) +#define IFF_TEAM_PORT=09=09=09__IFF(TEAM_PORT) +#define IFF_SUPP_NOFCS=09=09=09__IFF(SUPP_NOFCS) +#define IFF_LIVE_ADDR_CHANGE=09=09__IFF(LIVE_ADDR_CHANGE) +#define IFF_MACVLAN=09=09=09__IFF(MACVLAN) +#define IFF_XMIT_DST_RELEASE_PERM=09__IFF(XMIT_DST_RELEASE_PERM) +#define IFF_L3MDEV_MASTER=09=09__IFF(L3MDEV_MASTER) +#define IFF_NO_QUEUE=09=09=09__IFF(NO_QUEUE) +#define IFF_OPENVSWITCH=09=09=09__IFF(OPENVSWITCH) +#define IFF_L3MDEV_SLAVE=09=09__IFF(L3MDEV_SLAVE) +#define IFF_TEAM=09=09=09__IFF(TEAM) +#define IFF_RXFH_CONFIGURED=09=09__IFF(RXFH_CONFIGURED) +#define IFF_PHONY_HEADROOM=09=09__IFF(PHONY_HEADROOM) +#define IFF_MACSEC=09=09=09__IFF(MACSEC) +#define IFF_NO_RX_HANDLER=09=09__IFF(NO_RX_HANDLER) +#define IFF_FAILOVER=09=09=09__IFF(FAILOVER) +#define IFF_FAILOVER_SLAVE=09=09__IFF(FAILOVER_SLAVE) +#define IFF_L3MDEV_RX_HANDLER=09=09__IFF(L3MDEV_RX_HANDLER) +#define IFF_LIVE_RENAME_OK=09=09__IFF(LIVE_RENAME_OK) =20 /** *=09struct net_device - The DEVICE structure. @@ -1925,7 +1934,7 @@ struct net_device { =09const struct header_ops *header_ops; =20 =09unsigned int=09=09flags; -=09unsigned int=09=09priv_flags; +=09netdev_priv_flags_t=09priv_flags; =20 =09unsigned short=09=09gflags; =09unsigned short=09=09padded; --=20 2.30.1