Commit 154ba79c authored by Jakub Kicinski's avatar Jakub Kicinski

genetlink: correctly begin the iteration over policies

The return value from genl_op_iter_init() only tells us if
there are any policies but to begin the iteration (and therefore
load the first entry) we need to call genl_op_iter_next().
Note that it's safe to call genl_op_iter_next() on a family
with no ops, it will just return false.

This may lead to various crashes, a warning in
netlink_policy_dump_get_policy_idx() when policy is not found
or.. no problem at all if the kmalloc'ed memory happens to be
zeroed.

Fixes: b502b318 ("genetlink: use iterator in the op to policy map dumping")
Link: https://lore.kernel.org/r/20221108204128.330287-1-kuba@kernel.orgSigned-off-by: default avatarJakub Kicinski <kuba@kernel.org>
parent 3ca6c3b4
...@@ -1437,7 +1437,9 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb) ...@@ -1437,7 +1437,9 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb)
ctx->op_iter = kmalloc(sizeof(*ctx->op_iter), GFP_KERNEL); ctx->op_iter = kmalloc(sizeof(*ctx->op_iter), GFP_KERNEL);
if (!ctx->op_iter) if (!ctx->op_iter)
return -ENOMEM; return -ENOMEM;
ctx->dump_map = genl_op_iter_init(rt, ctx->op_iter);
genl_op_iter_init(rt, ctx->op_iter);
ctx->dump_map = genl_op_iter_next(ctx->op_iter);
for (genl_op_iter_init(rt, &i); genl_op_iter_next(&i); ) { for (genl_op_iter_init(rt, &i); genl_op_iter_next(&i); ) {
if (i.doit.policy) { if (i.doit.policy) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment