Re: [PATCH net] net: prevent NULL pointer dereference in rt_fibinfo_free() and rt_fibinfo_free_cpus()

From: Eric Dumazet
Date: Tue Sep 10 2024 - 02:00:46 EST


On Tue, Sep 10, 2024 at 5:23 AM Jeongjun Park <aha310510@xxxxxxxxx> wrote:
>
>
> > Eric Dumazet <edumazet@xxxxxxxxxx> wrote:
> > On Mon, Sep 9, 2024 at 8:48 PM Jeongjun Park <aha310510@xxxxxxxxx> wrote:
> >>
> >> rt_fibinfo_free() and rt_fibinfo_free_cpus() only check for rt and do not
> >> verify rt->dst and use it, which will result in NULL pointer dereference.
> >>
> >> Therefore, to prevent this, we need to add a check for rt->dst.
> >>
> >> Fixes: 0830106c5390 ("ipv4: take dst->__refcnt when caching dst in fib")
> >> Fixes: c5038a8327b9 ("ipv4: Cache routes in nexthop exception entries.")
> >> Signed-off-by: Jeongjun Park <aha310510@xxxxxxxxx>
> >> ---
> >
> > As far as I can tell, your patch is a NOP, and these Fixes: tags seem
> > random to me.
>
> I somewhat agree with the opinion that the fixes tag is random.
> However, I think it is absolutely necessary to add a check for
> &rt->dst , because the existence of rt does not guarantee that
> &rt->dst will not be NULL.

dst is the first field of 'struct rtable'.

Always has been.

Unless your compiler is buggy, (void *)rt == (void *)&rt->dst