Skip to content

Commit

Permalink
genetlink: check for callback type at op load time
Browse files Browse the repository at this point in the history
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@kernel.org>
Reviewed-by: Jacob Keller <jacob.e.keller@intel.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jakub Kicinski authored and David S. Miller committed Nov 7, 2022
1 parent 7747eb7 commit e1a2489
Showing 1 changed file with 10 additions and 10 deletions.
20 changes: 10 additions & 10 deletions net/netlink/genetlink.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,11 +189,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;
Expand All @@ -220,6 +226,8 @@ genl_cmd_full_to_split(struct genl_split_ops *op,

/* Make sure flags include the GENL_CMD_CAP_DO / GENL_CMD_CAP_DUMP */
op->flags |= flags;

return 0;
}

static int
Expand All @@ -235,9 +243,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,
Expand Down Expand Up @@ -730,9 +736,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;
Expand Down Expand Up @@ -777,9 +780,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);
Expand Down

0 comments on commit e1a2489

Please sign in to comment.