# Re: \[PATCH net\] net, neigh: clear whole pneigh\_entry at alloc time

- From: Eric Dumazet \<hidden\>
- Date: 2021-12-08 18:36:43 
- List: netdev
- Page: https://ratatoskr.run/netdev/2021/12/11218345
- Thread: https://ratatoskr.run/netdev/2021/12/11217989/t.md

```text
On Wed, Dec 8, 2021 at 7:54 AM David Ahern [ref] wrote:
>
> On 12/6/21 9:53 AM, Eric Dumazet wrote:
> > From: Eric Dumazet <redacted>
> >
> > Commit 2c611ad97a82 ("net, neigh: Extend neigh->flags to 32 bit
> > to allow for extensions") enables a new KMSAM warning [1]
> >
> > I think the bug is actually older, because the following intruction
> > only occurred if ndm->ndm_flags had NTF_PROXY set.
> >
> >       pn->flags = ndm->ndm_flags;
> >
> > Let's clear all pneigh_entry fields at alloc time.
> >
>
> All of the fields - except the new flags field - are initialized after
> the alloc. Why do you think the bug is older?

Because the flags field was added earlier, in the commit I pointed in Fixes: tag

For some reason, syzbot found the issue only after Roopa patch went in.
But we need to backport to older versions I think, or risk a kernel-info-leak

>
> ...
>
> > Fixes: 62dd93181aaa ("[IPV6] NDISC: Set per-entry is_router flag in Proxy NA.")
> > Signed-off-by: Eric Dumazet <redacted>
> > Cc: Roopa Prabhu <redacted>
> > ---
> >  net/core/neighbour.c | 3 +--
> >  1 file changed, 1 insertion(+), 2 deletions(-)
> >
> > diff --git a/net/core/neighbour.c b/net/core/neighbour.c
> > index 72ba027c34cfea6f38a9e78927c35048ebfe7a7f..dda12fbd177ba6ad2798ea2b07733fa3f03441ab 100644
> > --- a/net/core/neighbour.c
> > +++ b/net/core/neighbour.c
> > @@ -763,11 +763,10 @@ struct pneigh_entry * pneigh_lookup(struct neigh_table *tbl,
> >
> >       ASSERT_RTNL();
> >
> > -     n = kmalloc(sizeof(*n) + key_len, GFP_KERNEL);
> > +     n = kzalloc(sizeof(*n) + key_len, GFP_KERNEL);
> >       if (!n)
> >               goto out;
> >
> > -     n->protocol = 0;
> >       write_pnet(&n->net, net);
> >       memcpy(n->key, pkey, key_len);
> >       n->dev = dev;
> >
>
> Reviewed-by: David Ahern <dsahern@kernel.org>
```
