Skip to content

Commit

Permalink
sctp: Fix SKB list traversal in sctp_intl_store_ordered().
Browse files Browse the repository at this point in the history
Same change as made to sctp_intl_store_reasm().

To be fully correct, an iterator has an undefined value when something
like skb_queue_walk() naturally terminates.

This will actually matter when SKB queues are converted over to
list_head.

Formalize what this code ends up doing with the current
implementation.

Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David S. Miller committed Nov 11, 2018
1 parent 348bbc2 commit e15e067
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions net/sctp/stream_interleave.c
Original file line number Diff line number Diff line change
Expand Up @@ -390,7 +390,7 @@ static void sctp_intl_store_ordered(struct sctp_ulpq *ulpq,
struct sctp_ulpevent *event)
{
struct sctp_ulpevent *cevent;
struct sk_buff *pos;
struct sk_buff *pos, *loc;

pos = skb_peek_tail(&ulpq->lobby);
if (!pos) {
Expand All @@ -410,18 +410,25 @@ static void sctp_intl_store_ordered(struct sctp_ulpq *ulpq,
return;
}

loc = NULL;
skb_queue_walk(&ulpq->lobby, pos) {
cevent = (struct sctp_ulpevent *)pos->cb;

if (cevent->stream > event->stream)
if (cevent->stream > event->stream) {
loc = pos;
break;

}
if (cevent->stream == event->stream &&
MID_lt(event->mid, cevent->mid))
MID_lt(event->mid, cevent->mid)) {
loc = pos;
break;
}
}

__skb_queue_before(&ulpq->lobby, pos, sctp_event2skb(event));
if (!loc)
__skb_queue_tail(&ulpq->lobby, sctp_event2skb(event));
else
__skb_queue_before(&ulpq->lobby, loc, sctp_event2skb(event));
}

static void sctp_intl_retrieve_ordered(struct sctp_ulpq *ulpq,
Expand Down

0 comments on commit e15e067

Please sign in to comment.