Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5744377pxb; Tue, 16 Feb 2021 06:39:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5WJ6SSRJOW89QPcrvfHIOgT8J0Tcr+SHFQdn6FOrILyM3u7ZZrmWdc8hQcn68pnWMtAx/ X-Received: by 2002:a17:906:168e:: with SMTP id s14mr21169152ejd.515.1613486370476; Tue, 16 Feb 2021 06:39:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613486370; cv=none; d=google.com; s=arc-20160816; b=ewScoYrQm0bOX+POyo1cqhoFZEa2oa0CY9dRNhG41M/K+x3SvSRSkT23JbCFKcKuQV CzCaxVd8JB9keXUdOMJTEQmxDvjH9myuwngruSdupuBJtnU/5hcg97P0z5P38VHsHnFx cyTZGvABUBsociQ2zz88px+XqSeeTVtrZbozRjPsmt+5GlcjdkTXyKxnRgqoQxvejH3I sjDUL0JGuoIkDflSHkYbqfECZpc5GNRfsECloBi6SNgWxdeX/yaCFzkMzgk5+Jd6g29Q O9WYusLE4c5OGMFyTPsCKy4gHwWSjg2mVbO+BtbBKuODLIkXVZo0Gpb03OuOMMO1MHCR LHBw== 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=F79GxxLFgGar0uDA252Y0utA5OPZJ+zP9u/t7cIgBJg=; b=FQ5w2iEbJ0qfv0n59Xmn7HjMc3tcpzV6F01f8w1Fi2HgHEtGBcimsLWw/xmHo6LKDZ r/rMkhol1+DouiUwQxmuU/SRCQVHwxyOYB0/UrIq0/YaMazK2Y4fP6nQtTw22idDCaI3 0Nxzxwr5Po4L5kD5FlHJr0GTcueTuMRMO6EW0yCjhSIgDpwlgD9c5aGeYH8HrzYI7r1e Rudw95fZo56EGTUpQhaEqGRGSInbS32QPGpCJwlMRRLAoreulHUBTnpd9qRtEczmkMmg vTzAAccfWNjxrxFwKM4MIrN+4ThqkikdsIrSHRgaWIq90mNmpCfl5v43F06jDzcCQcSt lpZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=eEMOhQ21; 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 f8si14267509ejf.3.2021.02.16.06.39.07; Tue, 16 Feb 2021 06:39:30 -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=eEMOhQ21; 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 S230282AbhBPOfY (ORCPT + 99 others); Tue, 16 Feb 2021 09:35:24 -0500 Received: from mail-40133.protonmail.ch ([185.70.40.133]:46340 "EHLO mail-40133.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230361AbhBPOfG (ORCPT ); Tue, 16 Feb 2021 09:35:06 -0500 Date: Tue, 16 Feb 2021 14:34:16 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1613486061; bh=F79GxxLFgGar0uDA252Y0utA5OPZJ+zP9u/t7cIgBJg=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=eEMOhQ21Ih63jKmwgdrqH1NtMqjuglv/W9LhnJEinSZ0dPZFYSG/ovDV5+oLVPLmP IG9j65SkR2g28LhuC/+9EL/ydrPau2j9cKzAWGCblPK6nObfu53yJxFSSf7i/7cmbZ EBgINC+pO7KgOrqE9scTOz6xK5hflJfklQ/Btcm4qhn/nGQxtRwdMj9ZW3jYlLjF2X 0nzQAFeXtDHBC02GgAO/knfwCo5v+e4WceiB6S45p2/gBXC2CSCiX0IP1qlSKYbpOr R6fLaE3A/x1HZsrk/yqfhnoBVjHbUgBGRIfB6sDeFKIRxDZt0KH/Dm0zMv4VbLlf6X NGxRtnLIZDddw== 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, kernel test robot Reply-To: Alexander Lobakin Subject: [PATCH v5 bpf-next 2/6] netdevice: check for net_device::priv_flags bitfield overflow Message-ID: <20210216143333.5861-3-alobakin@pm.me> In-Reply-To: <20210216143333.5861-1-alobakin@pm.me> References: <20210216143333.5861-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 Reported-by: kernel test robot # Inverted assert condition --- 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..0a9b2b31f411 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