Skip to content

Commit 30fc7ef

Browse files
borkmannkuba-moo
authored andcommitted
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>
1 parent c8e80c1 commit 30fc7ef

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
@@ -1999,15 +1999,20 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
19991999

20002000
neigh = neigh_lookup(tbl, dst, dev);
20012001
if (neigh == NULL) {
2002-
bool exempt_from_gc;
2002+
bool ndm_permanent = ndm->ndm_state & NUD_PERMANENT;
2003+
bool exempt_from_gc = ndm_permanent ||
2004+
ndm_flags & NTF_EXT_LEARNED;
20032005

20042006
if (!(nlh->nlmsg_flags & NLM_F_CREATE)) {
20052007
err = -ENOENT;
20062008
goto out;
20072009
}
2010+
if (ndm_permanent && (ndm_flags & NTF_MANAGED)) {
2011+
NL_SET_ERR_MSG(extack, "Invalid NTF_* flag for permanent entry");
2012+
err = -EINVAL;
2013+
goto out;
2014+
}
20082015

2009-
exempt_from_gc = ndm->ndm_state & NUD_PERMANENT ||
2010-
ndm_flags & NTF_EXT_LEARNED;
20112016
neigh = ___neigh_create(tbl, dst, dev,
20122017
ndm_flags &
20132018
(NTF_EXT_LEARNED | NTF_MANAGED),

0 commit comments

Comments
 (0)