Commit 899b07c5 authored by Johannes Berg's avatar Johannes Berg Committed by David S. Miller

netlink: compare policy more accurately

The maxtype is really an integral part of the policy, and while we
haven't gotten into a situation yet where this happens, it seems
that some developer might eventually have two places pointing to
identical policies, with different maxattr to exclude some attrs
in one of the places.

Even if not, it's really the right thing to compare both since the
two data items fundamentally belong together.

v2:
 - also do the proper comparison in get_policy_idx()
Signed-off-by: default avatarJohannes Berg <johannes.berg@intel.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 678cdd49
...@@ -35,7 +35,8 @@ static int add_policy(struct netlink_policy_dump_state **statep, ...@@ -35,7 +35,8 @@ static int add_policy(struct netlink_policy_dump_state **statep,
return 0; return 0;
for (i = 0; i < state->n_alloc; i++) { for (i = 0; i < state->n_alloc; i++) {
if (state->policies[i].policy == policy) if (state->policies[i].policy == policy &&
state->policies[i].maxtype == maxtype)
return 0; return 0;
if (!state->policies[i].policy) { if (!state->policies[i].policy) {
...@@ -63,12 +64,14 @@ static int add_policy(struct netlink_policy_dump_state **statep, ...@@ -63,12 +64,14 @@ static int add_policy(struct netlink_policy_dump_state **statep,
} }
static unsigned int get_policy_idx(struct netlink_policy_dump_state *state, static unsigned int get_policy_idx(struct netlink_policy_dump_state *state,
const struct nla_policy *policy) const struct nla_policy *policy,
unsigned int maxtype)
{ {
unsigned int i; unsigned int i;
for (i = 0; i < state->n_alloc; i++) { for (i = 0; i < state->n_alloc; i++) {
if (state->policies[i].policy == policy) if (state->policies[i].policy == policy &&
state->policies[i].maxtype == maxtype)
return i; return i;
} }
...@@ -182,7 +185,8 @@ int netlink_policy_dump_write(struct sk_buff *skb, ...@@ -182,7 +185,8 @@ int netlink_policy_dump_write(struct sk_buff *skb,
type = NL_ATTR_TYPE_NESTED_ARRAY; type = NL_ATTR_TYPE_NESTED_ARRAY;
if (pt->nested_policy && pt->len && if (pt->nested_policy && pt->len &&
(nla_put_u32(skb, NL_POLICY_TYPE_ATTR_POLICY_IDX, (nla_put_u32(skb, NL_POLICY_TYPE_ATTR_POLICY_IDX,
get_policy_idx(state, pt->nested_policy)) || get_policy_idx(state, pt->nested_policy,
pt->len)) ||
nla_put_u32(skb, NL_POLICY_TYPE_ATTR_POLICY_MAXTYPE, nla_put_u32(skb, NL_POLICY_TYPE_ATTR_POLICY_MAXTYPE,
pt->len))) pt->len)))
goto nla_put_failure; goto nla_put_failure;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment