From patchwork Thu May 11 15:07:12 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Simon Horman X-Patchwork-Id: 13238124 X-Patchwork-Delegate: kuba@kernel.org Received: from smtp.kernel.org (aws-us-west-2-korg-mail-1.web.codeaurora.org [10.30.226.201]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 520FD629 for ; Thu, 11 May 2023 15:07:16 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 80F0CC433D2; Thu, 11 May 2023 15:07:14 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1683817636; bh=VRMniVLBTOi5ZQYefU/ECsSzJJiSsUxbGragDiwwd8w=; h=From:Date:Subject:To:Cc:From; b=q/Bep2eSjNhBtoyYnB99q2b5tw9u5PufZptSJB55NZeIyqOslzgi8pyEUB8OwHdW4 gywDazu7RaBf5P8lNWn27iuyNOsVzkCQjtRHDmHCnaMIiXM3HSKhi+NkEQXNf/cfAk r1ukb0TzU3tNIQtZLvsBQEFvq12FYqYpocAAvbT50A1Eb3d5gjWrq5y0RDLv8AjH6B 5C0onJAWXdFF9mHKQct74fzEEBrT6W3vwL++StayWvU/V+oeQNtRFmDZmD1vfY8D+Z 5WwPXV2MQ4IW5IB3JsMvusm5IP6fizXBD0xPsdkZj31IatAFvnQmQt/taRpBIs3JXw jKPwjP4GhhlEg== From: Simon Horman Date: Thu, 11 May 2023 17:07:12 +0200 Subject: [PATCH net-next v2] bonding: Always assign be16 value to vlan_proto Precedence: bulk X-Mailing-List: netdev@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Message-Id: <20230420-bonding-be-vlan-proto-v2-1-9f594fabdbd9@kernel.org> X-B4-Tracking: v=1; b=H4sIAJ8EXWQC/4WOQQ6CMBBFr0Jm7Zi2gIgr72FYtDBAI5mStjYYw t1tuIDL939+3t8hkLcU4FHs4CnZYB1nUJcC+lnzRGiHzKCEKkWlBBrHg+UJDWFaNOPqXXRYlz2 pmyLR0B3y1uhAaLzmfs5r/ixLDldPo91O2QuYIjJtEbrczDZE57/niyTP/o8wSZTY1FXZtmMtB yGfb/JMy9X5CbrjOH7rWcXm2gAAAA== To: Jakub Kicinski , "David S. Miller" , Eric Dumazet , Paolo Abeni Cc: Jay Vosburgh , Andy Gospodarek , Vladimir Oltean , netdev@vger.kernel.org X-Mailer: b4 0.12.2 X-Patchwork-Delegate: kuba@kernel.org The type of the vlan_proto field is __be16. And most users of the field use it as such. In the case of setting or testing the field for the special VLAN_N_VID value, host byte order is used. Which seems incorrect. It also seems somewhat odd to store a VLAN ID value in a field that is otherwise used to store Ether types. Address this issue by defining BOND_VLAN_PROTO_NONE, a big endian value. 0xffff was chosen somewhat arbitrarily. What is important is that it doesn't overlap with any valid VLAN Ether types. I don't believe the problems described above are a bug because VLAN_N_VID in both little-endian and big-endian byte order does not conflict with any supported VLAN Ether types in big-endian byte order. Reported by sparse as: .../bond_main.c:2857:26: warning: restricted __be16 degrades to integer .../bond_main.c:2863:20: warning: restricted __be16 degrades to integer .../bond_main.c:2939:40: warning: incorrect type in assignment (different base types) .../bond_main.c:2939:40: expected restricted __be16 [usertype] vlan_proto .../bond_main.c:2939:40: got int No functional changes intended. Compile tested only. Signed-off-by: Simon Horman Acked-by: Jay Vosburgh --- Changes in v2: - Decribe Ether Type aspect of problem in patch description - Use an Ether Type rather than VID valie as sential - Link to v1: https://lore.kernel.org/r/20230420-bonding-be-vlan-proto-v1-1-754399f51d01@kernel.org --- drivers/net/bonding/bond_main.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c index 3fed888629f7..ebf61c19dcef 100644 --- a/drivers/net/bonding/bond_main.c +++ b/drivers/net/bonding/bond_main.c @@ -2871,6 +2871,8 @@ static bool bond_has_this_ip(struct bonding *bond, __be32 ip) return ret; } +#define BOND_VLAN_PROTO_NONE cpu_to_be16(0xffff) + static bool bond_handle_vlan(struct slave *slave, struct bond_vlan_tag *tags, struct sk_buff *skb) { @@ -2878,13 +2880,13 @@ static bool bond_handle_vlan(struct slave *slave, struct bond_vlan_tag *tags, struct net_device *slave_dev = slave->dev; struct bond_vlan_tag *outer_tag = tags; - if (!tags || tags->vlan_proto == VLAN_N_VID) + if (!tags || tags->vlan_proto == BOND_VLAN_PROTO_NONE) return true; tags++; /* Go through all the tags backwards and add them to the packet */ - while (tags->vlan_proto != VLAN_N_VID) { + while (tags->vlan_proto != BOND_VLAN_PROTO_NONE) { if (!tags->vlan_id) { tags++; continue; @@ -2960,7 +2962,7 @@ struct bond_vlan_tag *bond_verify_device_path(struct net_device *start_dev, tags = kcalloc(level + 1, sizeof(*tags), GFP_ATOMIC); if (!tags) return ERR_PTR(-ENOMEM); - tags[level].vlan_proto = VLAN_N_VID; + tags[level].vlan_proto = BOND_VLAN_PROTO_NONE; return tags; }