bridge: make buffer larger in br_setlink()
Subsystems (4)
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
@@ -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);
Quoted 14 lines · Dan Carpenter
__IFLA_BRPORT_MAXis one larger thanIFLA_BRPORT_MAX. We passIFLA_BRPORT_MAXtonla_parse_nested()so we needIFLA_BRPORT_MAX+ 1 elements. Also Smatch complains that we read past the end of the array when inbr_set_port_flag()when it's called withIFLA_BRPORT_FAST_LEAVE.Signed-off-by Dan Carpenter <[email protected]>---
Only needed in linux-next.net/bridge/br_netlink.c +0
-0
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?
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
@@ -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);
Am 07.12.2012 12:10, schrieb Dan Carpenter:
Quoted 5 lines
We pass
IFLA_BRPORT_MAXtonla_parse_nested()so we needIFLA_BRPORT_MAX+ 1 elements. Also Smatch complains that we read past the end of the array when inbr_set_port_flag()when it's called withIFLA_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
Signed-off-by Dan Carpenter <[email protected]>---
v2: Style tweak.Only needed in linux-next.
net/bridge/br_netlink.c +1
-2@@ -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
Quoted 11 lines · walter harms
Am 07.12.2012 12:10, schrieb Dan Carpenter:
Quoted 5 lines
We pass
IFLA_BRPORT_MAXtonla_parse_nested()so we needIFLA_BRPORT_MAX+ 1 elements. Also Smatch complains that we read past the end of the array when inbr_set_port_flag()when it's called withIFLA_BRPORT_FAST_LEAVE.
Quoted 9 lines
I have no clue why
nla_parse_nested()needIFLA_BRPORT_MAXelements. 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 isnla_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
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_MAXtonla_parse_nested()so we needIFLA_BRPORT_MAX+ 1 elements. Also Smatch complains that we read past the end of the array when inbr_set_port_flag()when it's called withIFLA_BRPORT_FAST_LEAVE.Quoted 9 lines
I have no clue why
nla_parse_nested()needIFLA_BRPORT_MAXelements. 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 isnla_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
----- Original Message -----
Quoted 25 lines
We pass
IFLA_BRPORT_MAXtonla_parse_nested()so we needIFLA_BRPORT_MAX+ 1 elements. Also Smatch complains that we read past
the end of the array when inbr_set_port_flag()when it's called withIFLA_BRPORT_FAST_LEAVE.Signed-off-by Dan Carpenter <[email protected]>---
v2: Style tweak.Only needed in linux-next.
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 +1 ];int err;
Quoted 3 lines
ifm =
nlmsg_data(nlh);
From: Dan Carpenter <[email protected]>
Date: Fri, 7 Dec 2012 14:10:46 +0300
Quoted 6 lines
We pass
IFLA_BRPORT_MAXtonla_parse_nested()so we needIFLA_BRPORT_MAX+ 1 elements. Also Smatch complains that we read past the end of the array when inbr_set_port_flag()when it's called withIFLA_BRPORT_FAST_LEAVE.Signed-off-by Dan Carpenter <[email protected]>
Applied.