* [PATCH net-next v2] net: vlan: Avoid using BUG() in vlan_proto_idx()
@ 2020-09-25 0:27 Florian Fainelli
2020-09-25 21:12 ` David Miller
0 siblings, 1 reply; 4+ messages in thread
From: Florian Fainelli @ 2020-09-25 0:27 UTC (permalink / raw)
To: netdev
Cc: olteanv, vladimir.oltean, Florian Fainelli, David S. Miller,
Jakub Kicinski, Taehee Yoo, Eric Dumazet, open list
While we should always make sure that we specify a valid VLAN protocol
to vlan_proto_idx(), killing the machine when an invalid value is
specified is too harsh and not helpful for debugging. All callers are
capable of dealing with an error returned by vlan_proto_idx() so check
the index value and propagate it accordingly.
Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
---
Changes in v2:
- changed signature to return int
- changed message to use ntohs()
- renamed an index variable to 'pidx' instead of 'pdix'
net/8021q/vlan.c | 3 +++
net/8021q/vlan.h | 19 +++++++++++++------
2 files changed, 16 insertions(+), 6 deletions(-)
diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index d4bcfd8f95bf..6c08de1116c1 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -57,6 +57,9 @@ static int vlan_group_prealloc_vid(struct vlan_group *vg,
ASSERT_RTNL();
pidx = vlan_proto_idx(vlan_proto);
+ if (pidx < 0)
+ return -EINVAL;
+
vidx = vlan_id / VLAN_GROUP_ARRAY_PART_LEN;
array = vg->vlan_devices_arrays[pidx][vidx];
if (array != NULL)
diff --git a/net/8021q/vlan.h b/net/8021q/vlan.h
index bb7ec1a3915d..953405362795 100644
--- a/net/8021q/vlan.h
+++ b/net/8021q/vlan.h
@@ -36,7 +36,7 @@ struct vlan_info {
struct rcu_head rcu;
};
-static inline unsigned int vlan_proto_idx(__be16 proto)
+static inline int vlan_proto_idx(__be16 proto)
{
switch (proto) {
case htons(ETH_P_8021Q):
@@ -44,8 +44,8 @@ static inline unsigned int vlan_proto_idx(__be16 proto)
case htons(ETH_P_8021AD):
return VLAN_PROTO_8021AD;
default:
- BUG();
- return 0;
+ WARN(1, "invalid VLAN protocol: 0x%04x\n", ntohs(proto));
+ return -EINVAL;
}
}
@@ -64,17 +64,24 @@ static inline struct net_device *vlan_group_get_device(struct vlan_group *vg,
__be16 vlan_proto,
u16 vlan_id)
{
- return __vlan_group_get_device(vg, vlan_proto_idx(vlan_proto), vlan_id);
+ int pidx = vlan_proto_idx(vlan_proto);
+
+ if (pidx < 0)
+ return NULL;
+
+ return __vlan_group_get_device(vg, pidx, vlan_id);
}
static inline void vlan_group_set_device(struct vlan_group *vg,
__be16 vlan_proto, u16 vlan_id,
struct net_device *dev)
{
+ int pidx = vlan_proto_idx(vlan_proto);
struct net_device **array;
- if (!vg)
+
+ if (!vg || pidx < 0)
return;
- array = vg->vlan_devices_arrays[vlan_proto_idx(vlan_proto)]
+ array = vg->vlan_devices_arrays[pidx]
[vlan_id / VLAN_GROUP_ARRAY_PART_LEN];
array[vlan_id % VLAN_GROUP_ARRAY_PART_LEN] = dev;
}
--
2.25.1
^ permalink raw reply related [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v2] net: vlan: Avoid using BUG() in vlan_proto_idx()
2020-09-25 0:27 [PATCH net-next v2] net: vlan: Avoid using BUG() in vlan_proto_idx() Florian Fainelli
@ 2020-09-25 21:12 ` David Miller
2020-09-25 21:20 ` Vladimir Oltean
0 siblings, 1 reply; 4+ messages in thread
From: David Miller @ 2020-09-25 21:12 UTC (permalink / raw)
To: f.fainelli
Cc: netdev, olteanv, vladimir.oltean, kuba, ap420073, edumazet, linux-kernel
From: Florian Fainelli <f.fainelli@gmail.com>
Date: Thu, 24 Sep 2020 17:27:44 -0700
> While we should always make sure that we specify a valid VLAN protocol
> to vlan_proto_idx(), killing the machine when an invalid value is
> specified is too harsh and not helpful for debugging. All callers are
> capable of dealing with an error returned by vlan_proto_idx() so check
> the index value and propagate it accordingly.
>
> Signed-off-by: Florian Fainelli <f.fainelli@gmail.com>
> ---
> Changes in v2:
> - changed signature to return int
> - changed message to use ntohs()
> - renamed an index variable to 'pidx' instead of 'pdix'
Applied, thanks Florian.
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v2] net: vlan: Avoid using BUG() in vlan_proto_idx()
2020-09-25 21:12 ` David Miller
@ 2020-09-25 21:20 ` Vladimir Oltean
2020-09-28 2:14 ` Florian Fainelli
0 siblings, 1 reply; 4+ messages in thread
From: Vladimir Oltean @ 2020-09-25 21:20 UTC (permalink / raw)
To: David Miller
Cc: f.fainelli, netdev, olteanv, kuba, ap420073, edumazet, linux-kernel
On Fri, Sep 25, 2020 at 02:12:34PM -0700, David Miller wrote:
> From: Florian Fainelli <f.fainelli@gmail.com>
> Date: Thu, 24 Sep 2020 17:27:44 -0700
>
> Applied, thanks Florian.
Uh-oh, that 'negative value stored in unsigned variable' issue that the
build bot reported was on v2, wasn't it?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: [PATCH net-next v2] net: vlan: Avoid using BUG() in vlan_proto_idx()
2020-09-25 21:20 ` Vladimir Oltean
@ 2020-09-28 2:14 ` Florian Fainelli
0 siblings, 0 replies; 4+ messages in thread
From: Florian Fainelli @ 2020-09-28 2:14 UTC (permalink / raw)
To: Vladimir Oltean, David Miller
Cc: netdev, olteanv, kuba, ap420073, edumazet, linux-kernel
On 9/25/2020 2:20 PM, Vladimir Oltean wrote:
> On Fri, Sep 25, 2020 at 02:12:34PM -0700, David Miller wrote:
>> From: Florian Fainelli <f.fainelli@gmail.com>
>> Date: Thu, 24 Sep 2020 17:27:44 -0700
>>
>> Applied, thanks Florian.
>
> Uh-oh, that 'negative value stored in unsigned variable' issue that the
> build bot reported was on v2, wasn't it?
Yes, I will be sending a fixup now.
--
Florian
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2020-09-28 2:14 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-25 0:27 [PATCH net-next v2] net: vlan: Avoid using BUG() in vlan_proto_idx() Florian Fainelli
2020-09-25 21:12 ` David Miller
2020-09-25 21:20 ` Vladimir Oltean
2020-09-28 2:14 ` Florian Fainelli
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).