* [PATCH net-next] neighbor: Use nda_policy for validating attributes in adds and dump requests
@ 2018-12-20 4:02 David Ahern
2018-12-20 7:55 ` David Miller
0 siblings, 1 reply; 2+ messages in thread
From: David Ahern @ 2018-12-20 4:02 UTC (permalink / raw)
To: netdev; +Cc: davem, David Ahern
From: David Ahern <dsahern@gmail.com>
Add NDA_PROTOCOL to nda_policy and use the policy for attribute parsing and
validation for adding neighbors and in dump requests. Remove the now duplicate
checks on nla_len.
Signed-off-by: David Ahern <dsahern@gmail.com>
---
net/core/neighbour.c | 22 +++++-----------------
1 file changed, 5 insertions(+), 17 deletions(-)
diff --git a/net/core/neighbour.c b/net/core/neighbour.c
index d9fa101b0e41..8baa9ab01db6 100644
--- a/net/core/neighbour.c
+++ b/net/core/neighbour.c
@@ -1762,6 +1762,7 @@ const struct nla_policy nda_policy[NDA_MAX+1] = {
[NDA_VNI] = { .type = NLA_U32 },
[NDA_IFINDEX] = { .type = NLA_U32 },
[NDA_MASTER] = { .type = NLA_U32 },
+ [NDA_PROTOCOL] = { .type = NLA_U8 },
};
static int neigh_delete(struct sk_buff *skb, struct nlmsghdr *nlh,
@@ -1845,7 +1846,7 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
int err;
ASSERT_RTNL();
- err = nlmsg_parse(nlh, sizeof(*ndm), tb, NDA_MAX, NULL, extack);
+ err = nlmsg_parse(nlh, sizeof(*ndm), tb, NDA_MAX, nda_policy, extack);
if (err < 0)
goto out;
@@ -1881,13 +1882,8 @@ static int neigh_add(struct sk_buff *skb, struct nlmsghdr *nlh,
dst = nla_data(tb[NDA_DST]);
lladdr = tb[NDA_LLADDR] ? nla_data(tb[NDA_LLADDR]) : NULL;
- if (tb[NDA_PROTOCOL]) {
- if (nla_len(tb[NDA_PROTOCOL]) != sizeof(u8)) {
- NL_SET_ERR_MSG(extack, "Invalid protocol attribute");
- goto out;
- }
+ if (tb[NDA_PROTOCOL])
protocol = nla_get_u8(tb[NDA_PROTOCOL]);
- }
if (ndm->ndm_flags & NTF_PROXY) {
struct pneigh_entry *pn;
@@ -2639,10 +2635,10 @@ static int neigh_valid_dump_req(const struct nlmsghdr *nlh,
}
err = nlmsg_parse_strict(nlh, sizeof(struct ndmsg), tb, NDA_MAX,
- NULL, extack);
+ nda_policy, extack);
} else {
err = nlmsg_parse(nlh, sizeof(struct ndmsg), tb, NDA_MAX,
- NULL, extack);
+ nda_policy, extack);
}
if (err < 0)
return err;
@@ -2654,17 +2650,9 @@ static int neigh_valid_dump_req(const struct nlmsghdr *nlh,
/* all new attributes should require strict_check */
switch (i) {
case NDA_IFINDEX:
- if (nla_len(tb[i]) != sizeof(u32)) {
- NL_SET_ERR_MSG(extack, "Invalid IFINDEX attribute in neighbor dump request");
- return -EINVAL;
- }
filter->dev_idx = nla_get_u32(tb[i]);
break;
case NDA_MASTER:
- if (nla_len(tb[i]) != sizeof(u32)) {
- NL_SET_ERR_MSG(extack, "Invalid MASTER attribute in neighbor dump request");
- return -EINVAL;
- }
filter->master_idx = nla_get_u32(tb[i]);
break;
default:
--
2.11.0
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH net-next] neighbor: Use nda_policy for validating attributes in adds and dump requests
2018-12-20 4:02 [PATCH net-next] neighbor: Use nda_policy for validating attributes in adds and dump requests David Ahern
@ 2018-12-20 7:55 ` David Miller
0 siblings, 0 replies; 2+ messages in thread
From: David Miller @ 2018-12-20 7:55 UTC (permalink / raw)
To: dsahern; +Cc: netdev, dsahern
From: David Ahern <dsahern@kernel.org>
Date: Wed, 19 Dec 2018 20:02:36 -0800
> From: David Ahern <dsahern@gmail.com>
>
> Add NDA_PROTOCOL to nda_policy and use the policy for attribute parsing and
> validation for adding neighbors and in dump requests. Remove the now duplicate
> checks on nla_len.
>
> Signed-off-by: David Ahern <dsahern@gmail.com>
Applied, thanks.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2018-12-20 7:55 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2018-12-20 4:02 [PATCH net-next] neighbor: Use nda_policy for validating attributes in adds and dump requests David Ahern
2018-12-20 7:55 ` David Miller
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).