Skip to content

Commit 7c1e092

Browse files
kuba-moodavem330
authored andcommitted
taskstats: move specifying netlink policy back to ops
commit 3b0f31f ("genetlink: make policy common to family") had to work around removal of policy from ops by parsing in the pre_doit callback. Now that policy is back in full ops we can switch again. Set maxattr to actual size of the policies - both commands set GENL_DONT_VALIDATE_STRICT so out of range attributes will be silently ignored, anyway. v2: - remove stale comment Suggested-by: Johannes Berg <[email protected]> Signed-off-by: Jakub Kicinski <[email protected]> Reviewed-by: Johannes Berg <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 48526a0 commit 7c1e092

File tree

1 file changed

+10
-36
lines changed

1 file changed

+10
-36
lines changed

kernel/taskstats.c

Lines changed: 10 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -34,17 +34,13 @@ struct kmem_cache *taskstats_cache;
3434

3535
static struct genl_family family;
3636

37-
static const struct nla_policy taskstats_cmd_get_policy[TASKSTATS_CMD_ATTR_MAX+1] = {
37+
static const struct nla_policy taskstats_cmd_get_policy[] = {
3838
[TASKSTATS_CMD_ATTR_PID] = { .type = NLA_U32 },
3939
[TASKSTATS_CMD_ATTR_TGID] = { .type = NLA_U32 },
4040
[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK] = { .type = NLA_STRING },
4141
[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK] = { .type = NLA_STRING },};
4242

43-
/*
44-
* We have to use TASKSTATS_CMD_ATTR_MAX here, it is the maxattr in the family.
45-
* Make sure they are always aligned.
46-
*/
47-
static const struct nla_policy cgroupstats_cmd_get_policy[TASKSTATS_CMD_ATTR_MAX+1] = {
43+
static const struct nla_policy cgroupstats_cmd_get_policy[] = {
4844
[CGROUPSTATS_CMD_ATTR_FD] = { .type = NLA_U32 },
4945
};
5046

@@ -644,52 +640,30 @@ void taskstats_exit(struct task_struct *tsk, int group_dead)
644640
nlmsg_free(rep_skb);
645641
}
646642

647-
static const struct genl_small_ops taskstats_ops[] = {
643+
static const struct genl_ops taskstats_ops[] = {
648644
{
649645
.cmd = TASKSTATS_CMD_GET,
650646
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
651647
.doit = taskstats_user_cmd,
652-
/* policy enforced later */
653-
.flags = GENL_ADMIN_PERM | GENL_CMD_CAP_HASPOL,
648+
.policy = taskstats_cmd_get_policy,
649+
.maxattr = ARRAY_SIZE(taskstats_cmd_get_policy) - 1,
650+
.flags = GENL_ADMIN_PERM,
654651
},
655652
{
656653
.cmd = CGROUPSTATS_CMD_GET,
657654
.validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
658655
.doit = cgroupstats_user_cmd,
659-
/* policy enforced later */
660-
.flags = GENL_CMD_CAP_HASPOL,
656+
.policy = cgroupstats_cmd_get_policy,
657+
.maxattr = ARRAY_SIZE(cgroupstats_cmd_get_policy) - 1,
661658
},
662659
};
663660

664-
static int taskstats_pre_doit(const struct genl_ops *ops, struct sk_buff *skb,
665-
struct genl_info *info)
666-
{
667-
const struct nla_policy *policy = NULL;
668-
669-
switch (ops->cmd) {
670-
case TASKSTATS_CMD_GET:
671-
policy = taskstats_cmd_get_policy;
672-
break;
673-
case CGROUPSTATS_CMD_GET:
674-
policy = cgroupstats_cmd_get_policy;
675-
break;
676-
default:
677-
return -EINVAL;
678-
}
679-
680-
return nlmsg_validate_deprecated(info->nlhdr, GENL_HDRLEN,
681-
TASKSTATS_CMD_ATTR_MAX, policy,
682-
info->extack);
683-
}
684-
685661
static struct genl_family family __ro_after_init = {
686662
.name = TASKSTATS_GENL_NAME,
687663
.version = TASKSTATS_GENL_VERSION,
688-
.maxattr = TASKSTATS_CMD_ATTR_MAX,
689664
.module = THIS_MODULE,
690-
.small_ops = taskstats_ops,
691-
.n_small_ops = ARRAY_SIZE(taskstats_ops),
692-
.pre_doit = taskstats_pre_doit,
665+
.ops = taskstats_ops,
666+
.n_ops = ARRAY_SIZE(taskstats_ops),
693667
};
694668

695669
/* Needed early in initialization */

0 commit comments

Comments
 (0)