[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <20221018230728.1039524-6-kuba@kernel.org>
Date: Tue, 18 Oct 2022 16:07:20 -0700
From: Jakub Kicinski <kuba@...nel.org>
To: davem@...emloft.net, johannes@...solutions.net
Cc: netdev@...r.kernel.org, edumazet@...gle.com, pabeni@...hat.com,
jiri@...nulli.us, razor@...ckwall.org, nicolas.dichtel@...nd.com,
gnault@...hat.com, jacob.e.keller@...el.com, fw@...len.de,
Jakub Kicinski <kuba@...nel.org>
Subject: [PATCH net-next 05/13] genetlink: check for callback type at op load time
Now that genl_get_cmd_split() is informed what type of callback
user is trying to access (do or dump) we can check that this
callback is indeed available and return an error early.
Signed-off-by: Jakub Kicinski <kuba@...nel.org>
---
net/netlink/genetlink.c | 20 ++++++++++----------
1 file changed, 10 insertions(+), 10 deletions(-)
diff --git a/net/netlink/genetlink.c b/net/netlink/genetlink.c
index 26ddbd23549d..9dfb3cf89b97 100644
--- a/net/netlink/genetlink.c
+++ b/net/netlink/genetlink.c
@@ -166,11 +166,17 @@ static int genl_get_cmd(u32 cmd, const struct genl_family *family,
return genl_get_cmd_small(cmd, family, op);
}
-static void
+static int
genl_cmd_full_to_split(struct genl_split_ops *op,
const struct genl_family *family,
const struct genl_ops *full, u8 flags)
{
+ if ((flags & GENL_CMD_CAP_DO && !full->doit) ||
+ (flags & GENL_CMD_CAP_DUMP && !full->dumpit)) {
+ memset(op, 0, sizeof(*op));
+ return -ENOENT;
+ }
+
if (flags & GENL_CMD_CAP_DUMP) {
op->start = full->start;
op->dumpit = full->dumpit;
@@ -196,6 +202,8 @@ genl_cmd_full_to_split(struct genl_split_ops *op,
op->validate = full->validate;
op->flags |= flags;
+
+ return 0;
}
static int
@@ -211,9 +219,7 @@ genl_get_cmd_split(u32 cmd, u8 flags, const struct genl_family *family,
return err;
}
- genl_cmd_full_to_split(op, family, &full, flags);
-
- return 0;
+ return genl_cmd_full_to_split(op, family, &full, flags);
}
static void genl_get_cmd_by_index(unsigned int i,
@@ -704,9 +710,6 @@ static int genl_family_rcv_msg_dumpit(const struct genl_family *family,
struct genl_start_context ctx;
int err;
- if (!ops->dumpit)
- return -EOPNOTSUPP;
-
ctx.family = family;
ctx.nlh = nlh;
ctx.extack = extack;
@@ -751,9 +754,6 @@ static int genl_family_rcv_msg_doit(const struct genl_family *family,
struct genl_info info;
int err;
- if (!ops->doit)
- return -EOPNOTSUPP;
-
attrbuf = genl_family_rcv_msg_attrs_parse(family, nlh, extack,
ops, hdrlen,
GENL_DONT_VALIDATE_STRICT);
--
2.37.3
Powered by blists - more mailing lists