Skip to content

Commit deb85a6

Browse files
Vlad Yasevichdavem330
authored andcommitted
sctp: bail from sctp_endpoint_lookup_assoc() if not bound
The sctp_endpoint_lookup_assoc() function uses a port hash to lookup the association and then checks to see if any of them are on the current endpoint. However, if the current endpoint is not bound, there can't be any associations on it, thus we can bail early. Signed-off-by: Vlad Yasevich <vladislav.yasevich@hp.com> Signed-off-by: Wei Yongjun <yjwei@cn.fujitsu.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 0b8f9e2 commit deb85a6

1 file changed

Lines changed: 14 additions & 6 deletions

File tree

‎net/sctp/endpointola.c‎

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,7 @@ static struct sctp_association *__sctp_endpoint_lookup_assoc(
325325
struct sctp_transport **transport)
326326
{
327327
struct sctp_association *asoc = NULL;
328+
struct sctp_association *tmp;
328329
struct sctp_transport *t = NULL;
329330
struct sctp_hashbucket *head;
330331
struct sctp_ep_common *epb;
@@ -333,25 +334,32 @@ static struct sctp_association *__sctp_endpoint_lookup_assoc(
333334
int rport;
334335

335336
*transport = NULL;
337+
338+
/* If the local port is not set, there can't be any associations
339+
* on this endpoint.
340+
*/
341+
if (!ep->base.bind_addr.port)
342+
goto out;
343+
336344
rport = ntohs(paddr->v4.sin_port);
337345

338346
hash = sctp_assoc_hashfn(ep->base.bind_addr.port, rport);
339347
head = &sctp_assoc_hashtable[hash];
340348
read_lock(&head->lock);
341349
sctp_for_each_hentry(epb, node, &head->chain) {
342-
asoc = sctp_assoc(epb);
343-
if (asoc->ep != ep || rport != asoc->peer.port)
344-
goto next;
350+
tmp = sctp_assoc(epb);
351+
if (tmp->ep != ep || rport != tmp->peer.port)
352+
continue;
345353

346-
t = sctp_assoc_lookup_paddr(asoc, paddr);
354+
t = sctp_assoc_lookup_paddr(tmp, paddr);
347355
if (t) {
356+
asoc = tmp;
348357
*transport = t;
349358
break;
350359
}
351-
next:
352-
asoc = NULL;
353360
}
354361
read_unlock(&head->lock);
362+
out:
355363
return asoc;
356364
}
357365

0 commit comments

Comments
 (0)