Skip to content

Commit 9453faa

Browse files
committed
net, neigh: Reject creating NUD_PERMANENT with NTF_MANAGED entries
Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=2193175 commit 30fc7ef Author: Daniel Borkmann <daniel@iogearbox.net> Date: Wed Oct 13 15:21:40 2021 +0200 net, neigh: Reject creating NUD_PERMANENT with NTF_MANAGED entries The combination of NUD_PERMANENT + NTF_MANAGED is not supported and does not make sense either given the former indicates a static/fixed neighbor entry whereas the latter a dynamically resolved one. While it is possible to transition from one over to the other, we should however reject such creation attempts. Fixes: 7482e38 ("net, neigh: Add NTF_MANAGED flag for managed neighbor entries") 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 45ee5d9 commit 9453faa

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

net/core/neighbour.c

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2002,15 +2002,20 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
20022002

20032003
neigh = neigh_lookup(tbl, dst, dev);
20042004
if (neigh == NULL) {
2005-
bool exempt_from_gc;
2005+
bool ndm_permanent = ndm->ndm_state & NUD_PERMANENT;
2006+
bool exempt_from_gc = ndm_permanent ||
2007+
ndm_flags & NTF_EXT_LEARNED;
20062008

20072009
if (!(nlh->nlmsg_flags & NLM_F_CREATE)) {
20082010
err = -ENOENT;
20092011
goto out;
20102012
}
2013+
if (ndm_permanent && (ndm_flags & NTF_MANAGED)) {
2014+
NL_SET_ERR_MSG(extack, "Invalid NTF_* flag for permanent entry");
2015+
err = -EINVAL;
2016+
goto out;
2017+
}
20112018

2012-
exempt_from_gc = ndm->ndm_state & NUD_PERMANENT ||
2013-
ndm_flags & NTF_EXT_LEARNED;
20142019
neigh = ___neigh_create(tbl, dst, dev,
20152020
ndm_flags &
20162021
(NTF_EXT_LEARNED | NTF_MANAGED),

0 commit comments

Comments
 (0)