Skip to content

Commit f5046fb

Browse files
q2venkuba-moo
authored andcommitted
neighbour: Move two validations from neigh_get() to neigh_valid_get_req().
We will remove RTNL for neigh_get() and run it under RCU instead. neigh_get() returns -EINVAL in the following cases: * NDA_DST is not specified * Both ndm->ndm_ifindex and NTF_PROXY are not specified These validations do not require RCU. Let's move them to neigh_valid_get_req(). While at it, the extack string for the first case is replaced with NL_SET_ERR_ATTR_MISS(). Signed-off-by: Kuniyuki Iwashima <[email protected]> Link: https://patch.msgid.link/[email protected] Signed-off-by: Jakub Kicinski <[email protected]>
1 parent caf0a75 commit f5046fb

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

net/core/neighbour.c

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -2935,6 +2935,11 @@ static struct ndmsg *neigh_valid_get_req(const struct nlmsghdr *nlh,
29352935
return ERR_PTR(-EINVAL);
29362936
}
29372937

2938+
if (!(ndm->ndm_flags & NTF_PROXY) && !ndm->ndm_ifindex) {
2939+
NL_SET_ERR_MSG(extack, "No device specified");
2940+
return ERR_PTR(-EINVAL);
2941+
}
2942+
29382943
err = nlmsg_parse_deprecated_strict(nlh, sizeof(struct ndmsg), tb,
29392944
NDA_MAX, nda_policy, extack);
29402945
if (err < 0)
@@ -2947,18 +2952,23 @@ static struct ndmsg *neigh_valid_get_req(const struct nlmsghdr *nlh,
29472952
}
29482953

29492954
for (i = 0; i <= NDA_MAX; ++i) {
2950-
if (!tb[i])
2951-
continue;
2952-
29532955
switch (i) {
29542956
case NDA_DST:
2957+
if (!tb[i]) {
2958+
NL_SET_ERR_ATTR_MISS(extack, NULL, NDA_DST);
2959+
return ERR_PTR(-EINVAL);
2960+
}
2961+
29552962
if (nla_len(tb[i]) != (int)(*tbl)->key_len) {
29562963
NL_SET_ERR_MSG(extack, "Invalid network address in neighbor get request");
29572964
return ERR_PTR(-EINVAL);
29582965
}
29592966
*dst = nla_data(tb[i]);
29602967
break;
29612968
default:
2969+
if (!tb[i])
2970+
continue;
2971+
29622972
NL_SET_ERR_MSG(extack, "Unsupported attribute in neighbor get request");
29632973
return ERR_PTR(-EINVAL);
29642974
}
@@ -3051,11 +3061,6 @@ static int neigh_get(struct sk_buff *in_skb, struct nlmsghdr *nlh,
30513061
}
30523062
}
30533063

3054-
if (!dst) {
3055-
NL_SET_ERR_MSG(extack, "Network address not specified");
3056-
return -EINVAL;
3057-
}
3058-
30593064
if (ndm->ndm_flags & NTF_PROXY) {
30603065
struct pneigh_entry *pn;
30613066

@@ -3068,11 +3073,6 @@ static int neigh_get(struct sk_buff *in_skb, struct nlmsghdr *nlh,
30683073
nlh->nlmsg_seq, tbl);
30693074
}
30703075

3071-
if (!dev) {
3072-
NL_SET_ERR_MSG(extack, "No device specified");
3073-
return -EINVAL;
3074-
}
3075-
30763076
neigh = neigh_lookup(tbl, dst, dev);
30773077
if (!neigh) {
30783078
NL_SET_ERR_MSG(extack, "Neighbour entry not found");

0 commit comments

Comments
 (0)