Skip to content

Commit 8f5c5fc

Browse files
congwangdavem330
authored andcommitted
tipc: call start and done ops directly in __tipc_nl_compat_dumpit()
__tipc_nl_compat_dumpit() uses a netlink_callback on stack, so the only way to align it with other ->dumpit() call path is calling tipc_dump_start() and tipc_dump_done() directly inside it. Otherwise ->dumpit() would always get NULL from cb->args[]. But tipc_dump_start() uses sock_net(cb->skb->sk) to retrieve net pointer, the cb->skb here doesn't set skb->sk, the net pointer is saved in msg->net instead, so introduce a helper function __tipc_dump_start() to pass in msg->net. Ying pointed out cb->args[0...3] are already used by other callbacks on this call path, so we can't use cb->args[0] any more, use cb->args[4] instead. Fixes: 9a07efa ("tipc: switch to rhashtable iterator") Reported-and-tested-by: [email protected] Cc: Jon Maloy <[email protected]> Cc: Ying Xue <[email protected]> Signed-off-by: Cong Wang <[email protected]> Acked-by: Ying Xue <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent 6da410d commit 8f5c5fc

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

net/tipc/netlink_compat.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -185,6 +185,7 @@ static int __tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd,
185185
return -ENOMEM;
186186

187187
buf->sk = msg->dst_sk;
188+
__tipc_dump_start(&cb, msg->net);
188189

189190
do {
190191
int rem;
@@ -216,6 +217,7 @@ static int __tipc_nl_compat_dumpit(struct tipc_nl_compat_cmd_dump *cmd,
216217
err = 0;
217218

218219
err_out:
220+
tipc_dump_done(&cb);
219221
kfree_skb(buf);
220222

221223
if (err == -EMSGSIZE) {

net/tipc/socket.c

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3230,7 +3230,7 @@ int tipc_nl_sk_walk(struct sk_buff *skb, struct netlink_callback *cb,
32303230
struct netlink_callback *cb,
32313231
struct tipc_sock *tsk))
32323232
{
3233-
struct rhashtable_iter *iter = (void *)cb->args[0];
3233+
struct rhashtable_iter *iter = (void *)cb->args[4];
32343234
struct tipc_sock *tsk;
32353235
int err;
32363236

@@ -3266,26 +3266,31 @@ EXPORT_SYMBOL(tipc_nl_sk_walk);
32663266

32673267
int tipc_dump_start(struct netlink_callback *cb)
32683268
{
3269-
struct rhashtable_iter *iter = (void *)cb->args[0];
3270-
struct net *net = sock_net(cb->skb->sk);
3269+
return __tipc_dump_start(cb, sock_net(cb->skb->sk));
3270+
}
3271+
EXPORT_SYMBOL(tipc_dump_start);
3272+
3273+
int __tipc_dump_start(struct netlink_callback *cb, struct net *net)
3274+
{
3275+
/* tipc_nl_name_table_dump() uses cb->args[0...3]. */
3276+
struct rhashtable_iter *iter = (void *)cb->args[4];
32713277
struct tipc_net *tn = tipc_net(net);
32723278

32733279
if (!iter) {
32743280
iter = kmalloc(sizeof(*iter), GFP_KERNEL);
32753281
if (!iter)
32763282
return -ENOMEM;
32773283

3278-
cb->args[0] = (long)iter;
3284+
cb->args[4] = (long)iter;
32793285
}
32803286

32813287
rhashtable_walk_enter(&tn->sk_rht, iter);
32823288
return 0;
32833289
}
3284-
EXPORT_SYMBOL(tipc_dump_start);
32853290

32863291
int tipc_dump_done(struct netlink_callback *cb)
32873292
{
3288-
struct rhashtable_iter *hti = (void *)cb->args[0];
3293+
struct rhashtable_iter *hti = (void *)cb->args[4];
32893294

32903295
rhashtable_walk_exit(hti);
32913296
kfree(hti);

net/tipc/socket.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,5 +69,6 @@ int tipc_nl_sk_walk(struct sk_buff *skb, struct netlink_callback *cb,
6969
struct netlink_callback *cb,
7070
struct tipc_sock *tsk));
7171
int tipc_dump_start(struct netlink_callback *cb);
72+
int __tipc_dump_start(struct netlink_callback *cb, struct net *net);
7273
int tipc_dump_done(struct netlink_callback *cb);
7374
#endif

0 commit comments

Comments
 (0)