Skip to contentSkip to conversation

bridge: make buffer larger in br_setlink()

PATCH Superseded Dan Carpenter 5 participants 8 messages Dec 7, 2012

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

PATCH 1/1 bridge: make buffer larger in br_setlink()

__IFLA_BRPORT_MAX is one larger than IFLA_BRPORT_MAX. We pass IFLA_BRPORT_MAX to nla_parse_nested() so we need IFLA_BRPORT_MAX + 1 elements. Also Smatch complains that we read past the end of the array when in br_set_port_flag() when it's called with IFLA_BRPORT_FAST_LEAVE.

---
Only needed in linux-next.

net/bridge/br_netlink.c +1 -1
index 850b7d1..cfc5cfe 100644
@@ -239,7 +239,7 @@ int br_setlink(struct net_device *dev, struct nlmsghdr *nlh)
 	struct ifinfomsg *ifm;
 	struct nlattr *protinfo;
 	struct net_bridge_port *p;
-	struct nlattr *tb[IFLA_BRPORT_MAX];
+	struct nlattr *tb[__IFLA_BRPORT_MAX];
 	int err;
 
 	ifm = nlmsg_data(nlh);
#1 lore raw
Quoted 14 lines · Dan Carpenter

__IFLA_BRPORT_MAX is one larger than IFLA_BRPORT_MAX. We pass IFLA_BRPORT_MAX to nla_parse_nested() so we need IFLA_BRPORT_MAX + 1 elements. Also Smatch complains that we read past the end of the array when in br_set_port_flag() when it's called with IFLA_BRPORT_FAST_LEAVE.

---
Only needed in linux-next.

net/bridge/br_netlink.c +0 -0
index 850b7d1..cfc5cfe 100644

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

Quoted 8 lines
net/bridge/br_netlink.c +1 -1
@@ -239,7 +239,7 @@ int br_setlink(struct net_device *dev, struct nlmsghdr *nlh)
 	struct ifinfomsg *ifm;
 	struct nlattr *protinfo;
 	struct net_bridge_port *p;
-	struct nlattr *tb[IFLA_BRPORT_MAX];
+	struct nlattr *tb[__IFLA_BRPORT_MAX];
 	int err;
 
 	ifm = nlmsg_data(nlh);

I know it's nitpicking but could you use IFLA_BRPORT_MAX+1 for consistency?

#2 lore raw

PATCH v2 1/1 bridge: make buffer larger in br_setlink()

We pass IFLA_BRPORT_MAX to nla_parse_nested() so we need IFLA_BRPORT_MAX + 1 elements. Also Smatch complains that we read past the end of the array when in br_set_port_flag() when it's called with IFLA_BRPORT_FAST_LEAVE.

---
v2: Style tweak.

Only needed in linux-next.

net/bridge/br_netlink.c +1 -1
index 850b7d1..cfc5cfe 100644
@@ -239,7 +239,7 @@ int br_setlink(struct net_device *dev, struct nlmsghdr *nlh)
 	struct ifinfomsg *ifm;
 	struct nlattr *protinfo;
 	struct net_bridge_port *p;
-	struct nlattr *tb[IFLA_BRPORT_MAX];
+	struct nlattr *tb[IFLA_BRPORT_MAX + 1];
 	int err;
 
 	ifm = nlmsg_data(nlh);
#3 lore raw

Am 07.12.2012 12:10, schrieb Dan Carpenter:

Quoted 5 lines

We pass IFLA_BRPORT_MAX to nla_parse_nested() so we need IFLA_BRPORT_MAX + 1 elements. Also Smatch complains that we read past the end of the array when in br_set_port_flag() when it's called with IFLA_BRPORT_FAST_LEAVE.

I have no clue why nla_parse_nested() need IFLA_BRPORT_MAX elements. but the majory of loop look like
for(i=0;i<max;++)
most programmers will think this way.
So it seems the place to fix is nla_parse_nested().
doing not so is asking for trouble (in the long run).
At least this function needs a big warning label that (max-1) is actually needed.

just my two cents,
wh

Quoted 26 lines

---
v2: Style tweak.

Only needed in linux-next.

net/bridge/br_netlink.c +1 -2
index 850b7d1..cfc5cfe 100644
@@ -239,7 +239,7 @@ int br_setlink(struct net_device *dev, struct nlmsghdr *nlh)
 	struct ifinfomsg *ifm;
 	struct nlattr *protinfo;
 	struct net_bridge_port *p;
-	struct nlattr *tb[IFLA_BRPORT_MAX];
+	struct nlattr *tb[IFLA_BRPORT_MAX + 1];
 	int err;
 
 	ifm = nlmsg_data(nlh);
 
--

To unsubscribe from this list: send the line "unsubscribe kernel-janitors" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html

Acked-by on v2 1/1
#6 lore raw
In reply to Dan Carpenter

----- Original Message -----

Quoted 25 lines

We pass IFLA_BRPORT_MAX to nla_parse_nested() so we need IFLA_BRPORT_MAX + 1 elements. Also Smatch complains that we read past
the end of the array when in br_set_port_flag() when it's called with IFLA_BRPORT_FAST_LEAVE.

---
v2: Style tweak.

Only needed in linux-next.

net/bridge/br_netlink.c +1 -1
index 850b7d1..cfc5cfe 100644
@@ -239,7 +239,7 @@ int br_setlink(struct net_device *dev, struct
 nlmsghdr *nlh)
 	struct ifinfomsg *ifm;
 	struct nlattr *protinfo;
 	struct net_bridge_port *p;
-	struct nlattr *tb[IFLA_BRPORT_MAX];
+	struct nlattr *tb[IFLA_BRPORT_MAX + 1];
 	int err;
 
Quoted 3 lines

ifm = nlmsg_data(nlh);

#4 lore raw
In reply to walter harms
Quoted 11 lines · walter harms

Am 07.12.2012 12:10, schrieb Dan Carpenter:

Quoted 5 lines

We pass IFLA_BRPORT_MAX to nla_parse_nested() so we need IFLA_BRPORT_MAX + 1 elements. Also Smatch complains that we read past the end of the array when in br_set_port_flag() when it's called with IFLA_BRPORT_FAST_LEAVE.

Quoted 9 lines

I have no clue why nla_parse_nested() need IFLA_BRPORT_MAX elements. but the majory of loop look like
for(i=0;i<max;++)
most programmers will think this way.
So it seems the place to fix is nla_parse_nested().
doing not so is asking for trouble (in the long run).
At least this function needs a big warning label that (max-1) is actually needed.

Yeah, nla_parse_nested() is actually documented already.

regards,
dan carpenter

#5 lore raw

Am 07.12.2012 19:53, schrieb Dan Carpenter:

Quoted 22 lines · walter harms
Quoted 11 lines

Am 07.12.2012 12:10, schrieb Dan Carpenter:

Quoted 5 lines

We pass IFLA_BRPORT_MAX to nla_parse_nested() so we need IFLA_BRPORT_MAX + 1 elements. Also Smatch complains that we read past the end of the array when in br_set_port_flag() when it's called with IFLA_BRPORT_FAST_LEAVE.

Quoted 9 lines

I have no clue why nla_parse_nested() need IFLA_BRPORT_MAX elements. but the majory of loop look like
for(i=0;i<max;++)
most programmers will think this way.
So it seems the place to fix is nla_parse_nested().
doing not so is asking for trouble (in the long run).
At least this function needs a big warning label that (max-1) is actually needed.

Quoted 2 lines

Yeah, nla_parse_nested() is actually documented already.

documenting unexspected behavier is not as much helpfull as changing it.

just my 2 cents,
wh