Skip to content

Commit 53fa103

Browse files
lxindavem330
authored andcommitted
sctp: fix some rhashtable functions using in sctp proc/diag
When rhashtable_walk_init return err, no release function should be called, and when rhashtable_walk_start return err, we should only invoke rhashtable_walk_exit to release the source. But now when sctp_transport_walk_start return err, we just call rhashtable_walk_stop/exit, and never care about if rhashtable_walk_init or start return err, which is so bad. We will fix it by calling rhashtable_walk_exit if rhashtable_walk_start return err in sctp_transport_walk_start, and if sctp_transport_walk_start return err, we do not need to call sctp_transport_walk_stop any more. For sctp proc, we will use 'iter->start_fail' to decide if we will call rhashtable_walk_stop/exit. Signed-off-by: Xin Long <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent b5e2f4e commit 53fa103

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

net/sctp/proc.c

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -280,15 +280,18 @@ void sctp_eps_proc_exit(struct net *net)
280280
struct sctp_ht_iter {
281281
struct seq_net_private p;
282282
struct rhashtable_iter hti;
283+
int start_fail;
283284
};
284285

285286
static void *sctp_transport_seq_start(struct seq_file *seq, loff_t *pos)
286287
{
287288
struct sctp_ht_iter *iter = seq->private;
288289
int err = sctp_transport_walk_start(&iter->hti);
289290

290-
if (err)
291+
if (err) {
292+
iter->start_fail = 1;
291293
return ERR_PTR(err);
294+
}
292295

293296
return sctp_transport_get_idx(seq_file_net(seq), &iter->hti, *pos);
294297
}
@@ -297,6 +300,8 @@ static void sctp_transport_seq_stop(struct seq_file *seq, void *v)
297300
{
298301
struct sctp_ht_iter *iter = seq->private;
299302

303+
if (iter->start_fail)
304+
return;
300305
sctp_transport_walk_stop(&iter->hti);
301306
}
302307

net/sctp/socket.c

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4299,8 +4299,12 @@ int sctp_transport_walk_start(struct rhashtable_iter *iter)
42994299
return err;
43004300

43014301
err = rhashtable_walk_start(iter);
4302+
if (err && err != -EAGAIN) {
4303+
rhashtable_walk_exit(iter);
4304+
return err;
4305+
}
43024306

4303-
return err == -EAGAIN ? 0 : err;
4307+
return 0;
43044308
}
43054309

43064310
void sctp_transport_walk_stop(struct rhashtable_iter *iter)
@@ -4389,11 +4393,12 @@ EXPORT_SYMBOL_GPL(sctp_transport_lookup_process);
43894393
int sctp_for_each_transport(int (*cb)(struct sctp_transport *, void *),
43904394
struct net *net, int pos, void *p) {
43914395
struct rhashtable_iter hti;
4392-
int err = 0;
43934396
void *obj;
4397+
int err;
43944398

4395-
if (sctp_transport_walk_start(&hti))
4396-
goto out;
4399+
err = sctp_transport_walk_start(&hti);
4400+
if (err)
4401+
return err;
43974402

43984403
sctp_transport_get_idx(net, &hti, pos);
43994404
obj = sctp_transport_get_next(net, &hti);
@@ -4407,8 +4412,8 @@ int sctp_for_each_transport(int (*cb)(struct sctp_transport *, void *),
44074412
if (err)
44084413
break;
44094414
}
4410-
out:
44114415
sctp_transport_walk_stop(&hti);
4416+
44124417
return err;
44134418
}
44144419
EXPORT_SYMBOL_GPL(sctp_for_each_transport);

0 commit comments

Comments
 (0)