net/ipv4/nexthop: check the return value of nexthop_find_by_id()
Subsystems (3)
PATCH 1/1 net/ipv4/nexthop: check the return value of nexthop_find_by_id()
Check the return value of nexthop_find_by_id(), which could be NULL on when not found. So we check to avoid null pointer dereference.
--- net/ipv4/nexthop.c | 4 ++++ 1 file changed, 4 insertions(+)
net/ipv4/nexthop.c +4 -0
@@ -2445,6 +2445,10 @@ static struct nexthop *nexthop_create_group(struct net *net,struct nh_info *nhi; nhe =nexthop_find_by_id (net, entry[i].id); +if (!nhe) { + err = -EINVAL ; + goto out_no_nh; + }if (!nexthop_get (nhe)) { err = -ENOENT ; goto out_no_nh;
Signature · 1 line
2.25.1
Quoted 13 lines · Li Zhong
Check the return value of
nexthop_find_by_id(), which could be NULL on when not found. So we check to avoid null pointer dereference.Signed-off-by Li Zhong <[email protected]>--- net/ipv4/nexthop.c | 4 ++++ 1 file changed, 4 insertions(+)net/ipv4/nexthop.c +0
-0
net/ipv4/nexthop.c static struct nexthop *nexthop_create_group(struct net *net, · line 2454
Quoted 10 lines
net/ipv4/nexthop.c +4
-0@@ -2445,6 +2445,10 @@ static struct nexthop *nexthop_create_group(struct net *net,struct nh_info *nhi; nhe =nexthop_find_by_id (net, entry[i].id); +if (!nhe) { + err = -EINVAL ; + goto out_no_nh; + }if (!nexthop_get (nhe)) { err = -ENOENT ; goto out_no_nh;
These are validated in nh_check_attr_group() and should exist at this point. Since remove_nexthop() should run under rtnl I don't see a way for a nexthop to disappear after nh_check_attr_group() and before nexthop_create_group().
Did you notice a problem or have a stack dump?
David Ahern
maintainerQuoted 16 lines · Nikolay Aleksandrov
Quoted 15 lines · Li Zhong
Check the return value of
nexthop_find_by_id(), which could be NULL on when not found. So we check to avoid null pointer dereference.Signed-off-by Li Zhong <[email protected]>--- net/ipv4/nexthop.c | 4 ++++ 1 file changed, 4 insertions(+)net/ipv4/nexthop.c +0
-0@@ -2445,6 +2445,10 @@ static struct nexthop *nexthop_create_group(struct net *net,struct nh_info *nhi;
Quoted 13 lines
net/ipv4/nexthop.c static struct nexthop *nexthop_create_group(struct net *net, · line 2454
Quoted 8 lines
net/ipv4/nexthop.c +4
-0nhe =nexthop_find_by_id (net, entry[i].id); +if (!nhe) { + err = -EINVAL ; + goto out_no_nh; + }if (!nexthop_get (nhe)) { err = -ENOENT ; goto out_no_nh;These are validated in
nh_check_attr_group()and should exist at this point. Sinceremove_nexthop()should run under rtnl I don't see a way for a nexthop to disappear afternh_check_attr_group()and beforenexthop_create_group().
exactly. That lookup can't fail because the ids have been validated and all of this is under rtnl preventing nexthop removes.
Quoted 32 lines · David Ahern
Quoted 16 lines · Nikolay Aleksandrov
Quoted 15 lines · Li Zhong
Check the return value of
nexthop_find_by_id(), which could be NULL on when not found. So we check to avoid null pointer dereference.Signed-off-by Li Zhong <[email protected]>--- net/ipv4/nexthop.c | 4 ++++ 1 file changed, 4 insertions(+)net/ipv4/nexthop.c +0
-0@@ -2445,6 +2445,10 @@ static struct nexthop *nexthop_create_group(struct net *net,struct nh_info *nhi;Quoted 13 lines
net/ipv4/nexthop.c static struct nexthop *nexthop_create_group(struct net *net, · line 2454
Quoted 8 lines
net/ipv4/nexthop.c +4
-0nhe =nexthop_find_by_id (net, entry[i].id); +if (!nhe) { + err = -EINVAL ; + goto out_no_nh; + }if (!nexthop_get (nhe)) { err = -ENOENT ; goto out_no_nh;These are validated in
nh_check_attr_group()and should exist at this point. Sinceremove_nexthop()should run under rtnl I don't see a way for a nexthop to disappear afternh_check_attr_group()and beforenexthop_create_group().
Quoted 3 lines
exactly. That lookup can't fail because the ids have been validated and all of this is under rtnl preventing nexthop removes.
Thanks for all your replies. That makes sense to me.