Skip to contentSkip to conversation

bridge: per vlan dst_metadata netlink support

PATCH Applied Colin Ian King 5 participants 5 messages Feb 7, 2017

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

Hi,

Static analysis with CoverityScan on net/bridge/br_netlink_tunnel.c has picked up and issue where tb[] is being referenced but contains uninitialized data.

222 int br_parse_vlan_tunnel_info(struct nlattr *attr,
223 struct vtunnel_info *tinfo)
224 {

1. var_decl: Declaring variable tb without initializer.

225         struct nlattr *tb[IFLA_BRIDGE_VLAN_TUNNEL_MAX + 1];
226         u32 tun_id;
227         u16 vid, flags = 0;
228         int err;

229
230 memset(tinfo, 0, sizeof(*tinfo));
231

    CID 1400055 (#1 of 1): Uninitialized pointer read (UNINIT)2.

uninit_use: Using uninitialized value tb[IFLA_BRIDGE_VLAN_TUNNEL_ID].

232 if (!tb[IFLA_BRIDGE_VLAN_TUNNEL_ID] ||
233 !tb[IFLA_BRIDGE_VLAN_TUNNEL_VID])
234 return -EINVAL;

Colin

#1 lore raw
Quoted 20 lines · Colin Ian King

Hi,

Static analysis with CoverityScan on net/bridge/br_netlink_tunnel.c has picked up and issue where tb[] is being referenced but contains uninitialized data.

222 int br_parse_vlan_tunnel_info(struct nlattr *attr,
223 struct vtunnel_info *tinfo)
224 {

1. var_decl: Declaring variable tb without initializer.

225         struct nlattr *tb[IFLA_BRIDGE_VLAN_TUNNEL_MAX + 1];
226         u32 tun_id;
227         u16 vid, flags = 0;
228         int err;

229
230 memset(tinfo, 0, sizeof(*tinfo));
231

Quoted 9 lines
    CID 1400055 (#1 of 1): Uninitialized pointer read (UNINIT)2.

uninit_use: Using uninitialized value tb[IFLA_BRIDGE_VLAN_TUNNEL_ID].

232 if (!tb[IFLA_BRIDGE_VLAN_TUNNEL_ID] ||
233 !tb[IFLA_BRIDGE_VLAN_TUNNEL_VID])
234 return -EINVAL;

Colin

Good catch, these should go after the parsing.

#2 lore raw

PATCH 1/1 bridge: tunnel: fix attribute checks in br_parse_vlan_tunnel_info

These checks should go after the attributes have been parsed otherwise we're using tb uninitialized.

Fixes efa5356b0d97 ("bridge: per vlan dst_metadata netlink support")
---
 net/bridge/br_netlink_tunnel.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
net/bridge/br_netlink_tunnel.c +4 -4
index 99c68012c9d4..62eaf750bd9e 100644
@@ -229,15 +229,15 @@ int br_parse_vlan_tunnel_info(struct nlattr *attr,
 
 	memset(tinfo, 0, sizeof(*tinfo));
 
-	if (!tb[IFLA_BRIDGE_VLAN_TUNNEL_ID] ||
-	    !tb[IFLA_BRIDGE_VLAN_TUNNEL_VID])
-		return -EINVAL;
-
 	err = nla_parse_nested(tb, IFLA_BRIDGE_VLAN_TUNNEL_MAX,
 			       attr, vlan_tunnel_policy);
 	if (err < 0)
 		return err;
 
+	if (!tb[IFLA_BRIDGE_VLAN_TUNNEL_ID] ||
+	    !tb[IFLA_BRIDGE_VLAN_TUNNEL_VID])
+		return -EINVAL;
+
 	tun_id = nla_get_u32(tb[IFLA_BRIDGE_VLAN_TUNNEL_ID]);
 	vid = nla_get_u16(tb[IFLA_BRIDGE_VLAN_TUNNEL_VID]);
 	if (vid >= VLAN_VID_MASK)
Signature · 1 line
2.1.4
#3 lore raw

Re: [PATCH net-next] bridge: tunnel: fix attribute checks in br_parse_vlan_tunnel_info

Quoted 8 lines · Nikolay Aleksandrov

These checks should go after the attributes have been parsed otherwise we're using tb uninitialized.

Fixes efa5356b0d97 ("bridge: per vlan dst_metadata netlink support")

---

ouch, am surprised i did not catch this. Thanks Colin and Nikolay.

maintainer Applied
#4 lore raw

Re: [PATCH net-next] bridge: tunnel: fix attribute checks in br_parse_vlan_tunnel_info

In reply to Nikolay Aleksandrov

From: Nikolay Aleksandrov <[email protected]>
Date: Tue, 7 Feb 2017 12:46:46 +0100

Quoted 6 lines

These checks should go after the attributes have been parsed otherwise we're using tb uninitialized.

Fixes efa5356b0d97 ("bridge: per vlan dst_metadata netlink support")

Applied.