Message ID | 4b1e5d244476e8c442e1b42ac5e25667f26af30d.1611156111.git.petrm@nvidia.com (mailing list archive) |
---|---|
State | Accepted |
Commit | 60f5ad5e19c0996df7ca4ce7ef5fd4596cb13f01 |
Delegated to: | Netdev Maintainers |
Headers | show |
Series | nexthop: More fine-grained policies for netlink message validation | expand |
Context | Check | Description |
---|---|---|
netdev/cover_letter | success | Link |
netdev/fixes_present | success | Link |
netdev/patch_count | success | Link |
netdev/tree_selection | success | Clearly marked for net-next |
netdev/subject_prefix | success | Link |
netdev/cc_maintainers | warning | 1 maintainers not CCed: yoshfuji@linux-ipv6.org |
netdev/source_inline | success | Was 0 now: 0 |
netdev/verify_signedoff | success | Link |
netdev/module_param | success | Was 0 now: 0 |
netdev/build_32bit | success | Errors and warnings before: 2 this patch: 2 |
netdev/kdoc | success | Errors and warnings before: 0 this patch: 0 |
netdev/verify_fixes | success | Link |
netdev/checkpatch | success | total: 0 errors, 0 warnings, 0 checks, 43 lines checked |
netdev/build_allmodconfig_warn | success | Errors and warnings before: 2 this patch: 2 |
netdev/header_inline | success | Link |
netdev/stable | success | Stable not CCed |
On 1/20/21 8:44 AM, Petr Machata wrote: > This function uses the global nexthop policy only to then bounce all > arguments except for NHA_ID. Instead, just create a new policy that > only includes the one allowed attribute. > > Signed-off-by: Petr Machata <petrm@nvidia.com> > --- > > Notes: > v2: > - Do not specify size of the policy array. Use ARRAY_SIZE instead > of NHA_MAX > > net/ipv4/nexthop.c | 26 +++++++++----------------- > 1 file changed, 9 insertions(+), 17 deletions(-) Reviewed-by: David Ahern <dsahern@kernel.org>
diff --git a/net/ipv4/nexthop.c b/net/ipv4/nexthop.c index e53e43aef785..391079ff1bb5 100644 --- a/net/ipv4/nexthop.c +++ b/net/ipv4/nexthop.c @@ -36,6 +36,10 @@ static const struct nla_policy rtm_nh_policy[NHA_MAX + 1] = { [NHA_FDB] = { .type = NLA_FLAG }, }; +static const struct nla_policy rtm_nh_policy_get[] = { + [NHA_ID] = { .type = NLA_U32 }, +}; + static bool nexthop_notifiers_is_empty(struct net *net) { return !net->nexthop.notifier_chain.head; @@ -1842,28 +1846,16 @@ static int nh_valid_get_del_req(struct nlmsghdr *nlh, u32 *id, struct netlink_ext_ack *extack) { struct nhmsg *nhm = nlmsg_data(nlh); - struct nlattr *tb[NHA_MAX + 1]; - int err, i; + struct nlattr *tb[ARRAY_SIZE(rtm_nh_policy_get)]; + int err; - err = nlmsg_parse(nlh, sizeof(*nhm), tb, NHA_MAX, rtm_nh_policy, - extack); + err = nlmsg_parse(nlh, sizeof(*nhm), tb, + ARRAY_SIZE(rtm_nh_policy_get) - 1, + rtm_nh_policy_get, extack); if (err < 0) return err; err = -EINVAL; - for (i = 0; i < __NHA_MAX; ++i) { - if (!tb[i]) - continue; - - switch (i) { - case NHA_ID: - break; - default: - NL_SET_ERR_MSG_ATTR(extack, tb[i], - "Unexpected attribute in request"); - goto out; - } - } if (nhm->nh_protocol || nhm->resvd || nhm->nh_scope || nhm->nh_flags) { NL_SET_ERR_MSG(extack, "Invalid values in header"); goto out;
This function uses the global nexthop policy only to then bounce all arguments except for NHA_ID. Instead, just create a new policy that only includes the one allowed attribute. Signed-off-by: Petr Machata <petrm@nvidia.com> --- Notes: v2: - Do not specify size of the policy array. Use ARRAY_SIZE instead of NHA_MAX net/ipv4/nexthop.c | 26 +++++++++----------------- 1 file changed, 9 insertions(+), 17 deletions(-)