Skip to content

Commit 45ee5d9

Browse files
committed
net, neigh: Add build-time assertion to avoid neigh->flags overflow
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2193175 commit 507c2f1 Author: Daniel Borkmann <daniel@iogearbox.net> Date: Wed Oct 13 15:21:38 2021 +0200 net, neigh: Add build-time assertion to avoid neigh->flags overflow 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 2c611ad ("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@kernel.org> Signed-off-by: Daniel Borkmann <daniel@iogearbox.net> Reviewed-by: David Ahern <dsahern@kernel.org> Signed-off-by: Jakub Kicinski <kuba@kernel.org> Signed-off-by: Ivan Vecera <ivecera@redhat.com>
1 parent d7d7807 commit 45ee5d9

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

net/core/neighbour.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1939,6 +1939,9 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
19391939
NL_SET_ERR_MSG(extack, "Invalid extended flags");
19401940
goto out;
19411941
}
1942+
BUILD_BUG_ON(sizeof(neigh->flags) * BITS_PER_BYTE <
1943+
(sizeof(ndm->ndm_flags) * BITS_PER_BYTE +
1944+
hweight32(NTF_EXT_MASK)));
19421945
ndm_flags |= (ext << NTF_EXT_SHIFT);
19431946
}
19441947
if (ndm->ndm_ifindex) {

0 commit comments

Comments
 (0)