hc
2023-12-11 d2ccde1c8e90d38cee87a1b0309ad2827f3fd30d
kernel/kernel/taskstats.c
....@@ -1,19 +1,9 @@
1
+// SPDX-License-Identifier: GPL-2.0-or-later
12 /*
23 * taskstats.c - Export per-task statistics to userland
34 *
45 * Copyright (C) Shailabh Nagar, IBM Corp. 2006
56 * (C) Balbir Singh, IBM Corp. 2006
6
- *
7
- * This program is free software; you can redistribute it and/or modify
8
- * it under the terms of the GNU General Public License as published by
9
- * the Free Software Foundation; either version 2 of the License, or
10
- * (at your option) any later version.
11
- *
12
- * This program is distributed in the hope that it will be useful,
13
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15
- * GNU General Public License for more details.
16
- *
177 */
188
199 #include <linux/kernel.h>
....@@ -44,17 +34,13 @@
4434
4535 static struct genl_family family;
4636
47
-static const struct nla_policy taskstats_cmd_get_policy[TASKSTATS_CMD_ATTR_MAX+1] = {
37
+static const struct nla_policy taskstats_cmd_get_policy[] = {
4838 [TASKSTATS_CMD_ATTR_PID] = { .type = NLA_U32 },
4939 [TASKSTATS_CMD_ATTR_TGID] = { .type = NLA_U32 },
5040 [TASKSTATS_CMD_ATTR_REGISTER_CPUMASK] = { .type = NLA_STRING },
5141 [TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK] = { .type = NLA_STRING },};
5242
53
-/*
54
- * We have to use TASKSTATS_CMD_ATTR_MAX here, it is the maxattr in the family.
55
- * Make sure they are always aligned.
56
- */
57
-static const struct nla_policy cgroupstats_cmd_get_policy[TASKSTATS_CMD_ATTR_MAX+1] = {
43
+static const struct nla_policy cgroupstats_cmd_get_policy[] = {
5844 [CGROUPSTATS_CMD_ATTR_FD] = { .type = NLA_U32 },
5945 };
6046
....@@ -375,7 +361,7 @@
375361 ? TASKSTATS_TYPE_AGGR_PID
376362 : TASKSTATS_TYPE_AGGR_TGID;
377363
378
- na = nla_nest_start(skb, aggr);
364
+ na = nla_nest_start_noflag(skb, aggr);
379365 if (!na)
380366 goto err;
381367
....@@ -657,21 +643,24 @@
657643 static const struct genl_ops taskstats_ops[] = {
658644 {
659645 .cmd = TASKSTATS_CMD_GET,
646
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
660647 .doit = taskstats_user_cmd,
661648 .policy = taskstats_cmd_get_policy,
649
+ .maxattr = ARRAY_SIZE(taskstats_cmd_get_policy) - 1,
662650 .flags = GENL_ADMIN_PERM,
663651 },
664652 {
665653 .cmd = CGROUPSTATS_CMD_GET,
654
+ .validate = GENL_DONT_VALIDATE_STRICT | GENL_DONT_VALIDATE_DUMP,
666655 .doit = cgroupstats_user_cmd,
667656 .policy = cgroupstats_cmd_get_policy,
657
+ .maxattr = ARRAY_SIZE(cgroupstats_cmd_get_policy) - 1,
668658 },
669659 };
670660
671661 static struct genl_family family __ro_after_init = {
672662 .name = TASKSTATS_GENL_NAME,
673663 .version = TASKSTATS_GENL_VERSION,
674
- .maxattr = TASKSTATS_CMD_ATTR_MAX,
675664 .module = THIS_MODULE,
676665 .ops = taskstats_ops,
677666 .n_ops = ARRAY_SIZE(taskstats_ops),