Skip to content

Commit 899b07c

Browse files
jmberg-inteldavem330
authored andcommitted
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: Johannes Berg <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 678cdd4 commit 899b07c

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

net/netlink/policy.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,8 @@ static int add_policy(struct netlink_policy_dump_state **statep,
3535
return 0;
3636

3737
for (i = 0; i < state->n_alloc; i++) {
38-
if (state->policies[i].policy == policy)
38+
if (state->policies[i].policy == policy &&
39+
state->policies[i].maxtype == maxtype)
3940
return 0;
4041

4142
if (!state->policies[i].policy) {
@@ -63,12 +64,14 @@ static int add_policy(struct netlink_policy_dump_state **statep,
6364
}
6465

6566
static unsigned int get_policy_idx(struct netlink_policy_dump_state *state,
66-
const struct nla_policy *policy)
67+
const struct nla_policy *policy,
68+
unsigned int maxtype)
6769
{
6870
unsigned int i;
6971

7072
for (i = 0; i < state->n_alloc; i++) {
71-
if (state->policies[i].policy == policy)
73+
if (state->policies[i].policy == policy &&
74+
state->policies[i].maxtype == maxtype)
7275
return i;
7376
}
7477

@@ -182,7 +185,8 @@ int netlink_policy_dump_write(struct sk_buff *skb,
182185
type = NL_ATTR_TYPE_NESTED_ARRAY;
183186
if (pt->nested_policy && pt->len &&
184187
(nla_put_u32(skb, NL_POLICY_TYPE_ATTR_POLICY_IDX,
185-
get_policy_idx(state, pt->nested_policy)) ||
188+
get_policy_idx(state, pt->nested_policy,
189+
pt->len)) ||
186190
nla_put_u32(skb, NL_POLICY_TYPE_ATTR_POLICY_MAXTYPE,
187191
pt->len)))
188192
goto nla_put_failure;

0 commit comments

Comments
 (0)