Received: by 2002:a05:6a10:8c0a:0:0:0:0 with SMTP id go10csp5871839pxb; Tue, 16 Feb 2021 09:31:48 -0800 (PST) X-Google-Smtp-Source: ABdhPJz8eM6ZHUPvaPvpshEmj7N0Sn4KIFcR9Oi7ChqUa9SQtSye3RrUxQVbKD/9pcAsdF+q/YI6 X-Received: by 2002:aa7:d857:: with SMTP id f23mr12317571eds.356.1613496707834; Tue, 16 Feb 2021 09:31:47 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1613496707; cv=none; d=google.com; s=arc-20160816; b=Y2y+XgChwv/Px5jKMoktmiPwSdYUURdjZD5WqZRKTn4aRPjoW5805bgp1sh2kP3d+p iINF+DKEAsevLSQb9VFM0pY+Zw/BWSf1lfxsRDw1ToCo9ysvxJZxsCYxLn0jlwa45nTg VCrKCTKZKyx4pGJuiEdn48bOslNeaZJfFDUWI3QhP3HLb+70PVpiuT14sUnj6LzTEve/ MUsHWleKosfbF6mKAs+kZW2U4sJcB+9cgexgu/dS9pt6H9V6zcqRDPzd+cmQUjGluxvJ +Y1ZN379+yZ0Zvg2/p8coGf9/K1IN3t3ojzHHNcDQxuzSPNplAOpReYBU0tbrxiwET5v vzHw== 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=PHmuJq9cOWYNoHZxYQCeI5xDyiS1tfH8wP2q82Nb0h0EsjInR3G6mrytpfdX4LxBaM dO3n0j39Vszg+/lAD47r9nuv6jH2sLLMblxL/BR5nUk3ZUaArui3Iu0/cyhFI3vN4QTz PWMvUHfuWm9+ffVIgVbPNUewXf7s/bwiY7NEabrD5/iKJ/Sm5fP3+uSj5KZLYjpziVAr rGvTyVPMmvS20EXjF2P8T7GoNegF6v64t4Ed5FR11MWhgVs26evIgHKHqXjfGrT6Kli+ D+zsqS/N5mtgSnpaDPyKRcpiWqCwwbsA3Ja034SJHsx/AbAwSX21Szm3UQKWyyQV/yxx bSSA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@pm.me header.s=protonmail header.b=U+AaaHNZ; 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 h2si14497814ejy.284.2021.02.16.09.31.24; Tue, 16 Feb 2021 09:31:47 -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=U+AaaHNZ; 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 S231124AbhBPR22 (ORCPT + 99 others); Tue, 16 Feb 2021 12:28:28 -0500 Received: from mail2.protonmail.ch ([185.70.40.22]:48642 "EHLO mail2.protonmail.ch" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230514AbhBPR2K (ORCPT ); Tue, 16 Feb 2021 12:28:10 -0500 Date: Tue, 16 Feb 2021 17:27:18 +0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pm.me; s=protonmail; t=1613496445; bh=F79GxxLFgGar0uDA252Y0utA5OPZJ+zP9u/t7cIgBJg=; h=Date:To:From:Cc:Reply-To:Subject:In-Reply-To:References:From; b=U+AaaHNZclbjjTg3cviprd1ajTaCAzE9tfmK+uBpazvaAC6dCVKE7V+DFrjp3pgQG DUXGnRCFmonFsD2zI9rJHpGbALxWCRVESI85N7H9z+3Eb2XvB2Tx4IsvcqQgBxo/pz BpOQQgSKxi1KzRkNqk/XrOTG8qXGd1r++gBc/0XtAMr5ApgjXwe1xKJ/wBIBiTYPo0 tukpi/Y9HRAn7kmMxkh5DpKvq8pneMPYKVlIcbPYj9umMGEYH1GeynZatSZUkvVj1+ 5uOcCo9B2TwSrZ4E1l0r2a47ri7Dpwg04X94U5Jvp1lxGa2Ep4WIBdyWIKSOyf7omZ iphQDi/miS+4w== 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 v6 bpf-next 2/6] netdevice: check for net_device::priv_flags bitfield overflow Message-ID: <20210216172640.374487-3-alobakin@pm.me> In-Reply-To: <20210216172640.374487-1-alobakin@pm.me> References: <20210216172640.374487-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