Skip to content

Commit

Permalink
net: fix iteration for sctp transport seq_files
Browse files Browse the repository at this point in the history
The sctp transport seq_file iterators take a reference to the transport
in the ->start and ->next functions and releases the reference in the
->show function.  The preferred handling for such resources is to
release them in the subsequent ->next or ->stop function call.

Since Commit 1f4aace ("fs/seq_file.c: simplify seq_file iteration
code and interface") there is no guarantee that ->show will be called
after ->next, so this function can now leak references.

So move the sctp_transport_put() call to ->next and ->stop.

Fixes: 1f4aace ("fs/seq_file.c: simplify seq_file iteration code and interface")
Reported-by: Xin Long <[email protected]>
Signed-off-by: NeilBrown <[email protected]>
Acked-by: Marcelo Ricardo Leitner <[email protected]>
Signed-off-by: Jakub Kicinski <[email protected]>
  • Loading branch information
neilbrown authored and kuba-moo committed Feb 8, 2021
1 parent 225353c commit af8085f
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions net/sctp/proc.c
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,25 @@ static void sctp_transport_seq_stop(struct seq_file *seq, void *v)
{
struct sctp_ht_iter *iter = seq->private;

if (v && v != SEQ_START_TOKEN) {
struct sctp_transport *transport = v;

sctp_transport_put(transport);
}

sctp_transport_walk_stop(&iter->hti);
}

static void *sctp_transport_seq_next(struct seq_file *seq, void *v, loff_t *pos)
{
struct sctp_ht_iter *iter = seq->private;

if (v && v != SEQ_START_TOKEN) {
struct sctp_transport *transport = v;

sctp_transport_put(transport);
}

++*pos;

return sctp_transport_get_next(seq_file_net(seq), &iter->hti);
Expand Down Expand Up @@ -277,8 +289,6 @@ static int sctp_assocs_seq_show(struct seq_file *seq, void *v)
sk->sk_rcvbuf);
seq_printf(seq, "\n");

sctp_transport_put(transport);

return 0;
}

Expand Down Expand Up @@ -354,8 +364,6 @@ static int sctp_remaddr_seq_show(struct seq_file *seq, void *v)
seq_printf(seq, "\n");
}

sctp_transport_put(transport);

return 0;
}

Expand Down

0 comments on commit af8085f

Please sign in to comment.