Skip to contentSkip to conversation

net: bridge: fix potential NULL pointer dereference

PATCH In review Gustavo A. R. Silva 4 participants 6 messages Jun 5, 2017 – Jun 6, 2017

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

PATCH 1/1 net: bridge: fix potential NULL pointer dereference

Add NULL check before dereferencing pointer _p_ inside br_afspec().

Addresses-Coverity-ID: 1401872

---
 net/bridge/br_netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/br_netlink.c +1 -1
index 1e63ec4..ad85a9c 100644
@@ -776,7 +776,7 @@ int br_setlink(struct net_device *dev, struct nlmsghdr *nlh, u16 flags)
 			goto out;
 	}
 
-	if (afspec) {
+	if (p && afspec) {
 		err = br_afspec((struct net_bridge *)netdev_priv(dev), p,
 				afspec, RTM_SETLINK);
 	}
Signature · 1 line
2.5.0
#1 lore raw
Quoted 14 lines · Gustavo A. R. Silva

Add NULL check before dereferencing pointer _p_ inside br_afspec().

Addresses-Coverity-ID: 1401872

---
 net/bridge/br_netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/br_netlink.c +0 -0
index 1e63ec4..ad85a9c 100644

net/bridge/br_netlink.c int br_setlink(struct net_device *dev, struct nlmsghdr *nlh, u16 flags) · line 782

Quoted 8 lines
net/bridge/br_netlink.c +1 -1
@@ -776,7 +776,7 @@ int br_setlink(struct net_device *dev, struct nlmsghdr *nlh, u16 flags)
 			goto out;
 	}
 
-	if (afspec) {
+	if (p && afspec) {
 		err = br_afspec((struct net_bridge *)netdev_priv(dev), p,
 				afspec, RTM_SETLINK);
 	}

While I see a possible issue with the new bridge tunnel code (+CC Roopa), this is the wrong fix because there are legitimate use cases where p is null and br_afspec is called.
We need to change the p->flags check in br_afspec()'s IFLA_BRIDGE_VLAN_TUNNEL_INFO case to check for a NULL p first.

Thanks for the report!

#2 lore raw

PATCH 1/1 net: bridge: fix a null pointer dereference in br_afspec

We might call br_afspec() with p == NULL which is a valid use case if the action is on the bridge device itself, but the bridge tunnel code dereferences the p pointer without checking, so check if p is null first.

Fixes efa5356b0d97 ("bridge: per vlan dst_metadata netlink support")
---
 net/bridge/br_netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/br_netlink.c +1 -1
index 1e63ec466d7c..3bcda556971e 100644
@@ -595,7 +595,7 @@ static int br_afspec(struct net_bridge *br,
 		err = 0;
 		switch (nla_type(attr)) {
 		case IFLA_BRIDGE_VLAN_TUNNEL_INFO:
-			if (!(p->flags & BR_VLAN_TUNNEL))
+			if (!p || !(p->flags & BR_VLAN_TUNNEL))
 				return -EINVAL;
 			err = br_parse_vlan_tunnel_info(attr, &tinfo_curr);
 			if (err)
Signature · 1 line
2.1.4
Acked-by on v1 1/1
#3 lore raw

Re: [PATCH net] net: bridge: fix a null pointer dereference in br_afspec

Quoted 8 lines · Nikolay Aleksandrov

We might call br_afspec() with p == NULL which is a valid use case if the action is on the bridge device itself, but the bridge tunnel code dereferences the p pointer without checking, so check if p is null first.

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

Thanks Nikolay.

maintainer
#4 lore raw

Re: [PATCH net] net: bridge: fix a null pointer dereference in br_afspec

In reply to Nikolay Aleksandrov

From: Nikolay Aleksandrov <[email protected]>
Date: Tue, 6 Jun 2017 01:26:24 +0300

Quoted 8 lines

We might call br_afspec() with p == NULL which is a valid use case if the action is on the bridge device itself, but the bridge tunnel code dereferences the p pointer without checking, so check if p is null first.

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

Applied and queued up for -stable, thanks Nikolay.

#5 lore raw
In reply to Nikolay Aleksandrov

Hi Nikolay,

Quoting Nikolay Aleksandrov <[email protected]>:

Quoted 18 lines · Gustavo A. R. Silva
Quoted 17 lines

Add NULL check before dereferencing pointer _p_ inside br_afspec().

Addresses-Coverity-ID: 1401872

---
 net/bridge/br_netlink.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
net/bridge/br_netlink.c +0 -0
index 1e63ec4..ad85a9c 100644
@@ -776,7 +776,7 @@ int br_setlink(struct net_device *dev, struct  
 nlmsghdr *nlh, u16 flags)
 			goto out;
 	}
 
Quoted 13 lines
Quoted 6 lines
net/bridge/br_netlink.c +1 -1
-	if (afspec) {
+	if (p && afspec) {
 		err = br_afspec((struct net_bridge *)netdev_priv(dev), p,
 				afspec, RTM_SETLINK);

}

While I see a possible issue with the new bridge tunnel code (+CC Roopa), this is the wrong fix because there are legitimate use cases where p is null and br_afspec is called.
We need to change the p->flags check in br_afspec()'s IFLA_BRIDGE_VLAN_TUNNEL_INFO case to check for a NULL p first.

You're right. I got it.

Quoted 1 line

Thanks for the report!

Sure thing, glad to help.

Thank you!
--
Gustavo A. R. Silva