Re: [PATCH v1] net/ipv4/nexthop: check the return value of nexthop_find_by_id()

From: Nikolay Aleksandrov
Date: Sat Sep 17 2022 - 04:29:59 EST


On 17/09/2022 05:30, Li Zhong wrote:
> 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 <floridsleeves@xxxxxxxxx>
> ---
> net/ipv4/nexthop.c | 4 ++++
> 1 file changed, 4 insertions(+)
>
> diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c
> index 853a75a8fbaf..9f91bb78eed5 100644
> --- a/net/ipv4/nexthop.c
> +++ b/net/ipv4/nexthop.c
> @@ -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?