[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e5eed61b-94d3-aa1a-1966-84242785f5dc@gmail.com>
Date: Wed, 13 Oct 2021 21:10:49 -0600
From: David Ahern <dsahern@...il.com>
To: Daniel Borkmann <daniel@...earbox.net>, davem@...emloft.net,
kuba@...nel.org
Cc: roopa@...dia.com, dsahern@...nel.org, m@...bda.lt,
john.fastabend@...il.com, netdev@...r.kernel.org,
bpf@...r.kernel.org
Subject: Re: [PATCH net-next 1/3] net, neigh: Add build-time assertion to
avoid neigh->flags overflow
On 10/13/21 7:21 AM, Daniel Borkmann wrote:
> Currently, NDA_FLAGS_EXT flags allow a maximum of 24 bits to be used for
> extended neighbor flags. These are eventually fed into neigh->flags by
> shifting with NTF_EXT_SHIFT as per commit 2c611ad97a82 ("net, neigh:
> Extend neigh->flags to 32 bit to allow for extensions").
>
> If really ever needed in future, the full 32 bits from NDA_FLAGS_EXT can
> be used, it would only require to move neigh->flags from u32 to u64 inside
> the kernel.
>
> Add a build-time assertion such that when extending the NTF_EXT_MASK with
> new bits, we'll trigger an error once we surpass the 24th bit. This assumes
> that no bit holes in new NTF_EXT_* flags will slip in from UAPI, but I
> think this is reasonable to assume.
>
> Suggested-by: David Ahern <dsahern@...nel.org>
> Signed-off-by: Daniel Borkmann <daniel@...earbox.net>
> ---
> net/core/neighbour.c | 3 +++
> 1 file changed, 3 insertions(+)
>
> diff --git a/net/core/neighbour.c b/net/core/neighbour.c
> index eae73efa9245..4fc601f9cd06 100644
> --- a/net/core/neighbour.c
> +++ b/net/core/neighbour.c
> @@ -1940,6 +1940,9 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
> NL_SET_ERR_MSG(extack, "Invalid extended flags");
> goto out;
> }
> + BUILD_BUG_ON(sizeof(neigh->flags) * BITS_PER_BYTE <
> + (sizeof(ndm->ndm_flags) * BITS_PER_BYTE +
> + hweight32(NTF_EXT_MASK)));
> ndm_flags |= (ext << NTF_EXT_SHIFT);
> }
> if (ndm->ndm_ifindex) {
>
Reviewed-by: David Ahern <dsahern@...nel.org>
Powered by blists - more mailing lists