Skip to content

Commit 154ba79

Browse files
committed
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: b502b31 ("genetlink: use iterator in the op to policy map dumping") Link: https://lore.kernel.org/r/20221108204128.330287-1-kuba@kernel.org Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent 3ca6c3b commit 154ba79

1 file changed

Lines changed: 3 additions & 1 deletion

File tree

net/netlink/genetlink.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1437,7 +1437,9 @@ static int ctrl_dumppolicy_start(struct netlink_callback *cb)
14371437
ctx->op_iter = kmalloc(sizeof(*ctx->op_iter), GFP_KERNEL);
14381438
if (!ctx->op_iter)
14391439
return -ENOMEM;
1440-
ctx->dump_map = genl_op_iter_init(rt, ctx->op_iter);
1440+
1441+
genl_op_iter_init(rt, ctx->op_iter);
1442+
ctx->dump_map = genl_op_iter_next(ctx->op_iter);
14411443

14421444
for (genl_op_iter_init(rt, &i); genl_op_iter_next(&i); ) {
14431445
if (i.doit.policy) {

0 commit comments

Comments
 (0)