Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

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>

authored by

Vlad Yasevich and committed by
David S. Miller
deb85a6e 0b8f9e25

+14 -6
+14 -6
net/sctp/endpointola.c
··· 325 325 struct sctp_transport **transport) 326 326 { 327 327 struct sctp_association *asoc = NULL; 328 + struct sctp_association *tmp; 328 329 struct sctp_transport *t = NULL; 329 330 struct sctp_hashbucket *head; 330 331 struct sctp_ep_common *epb; ··· 334 333 int rport; 335 334 336 335 *transport = NULL; 336 + 337 + /* If the local port is not set, there can't be any associations 338 + * on this endpoint. 339 + */ 340 + if (!ep->base.bind_addr.port) 341 + goto out; 342 + 337 343 rport = ntohs(paddr->v4.sin_port); 338 344 339 345 hash = sctp_assoc_hashfn(ep->base.bind_addr.port, rport); 340 346 head = &sctp_assoc_hashtable[hash]; 341 347 read_lock(&head->lock); 342 348 sctp_for_each_hentry(epb, node, &head->chain) { 343 - asoc = sctp_assoc(epb); 344 - if (asoc->ep != ep || rport != asoc->peer.port) 345 - goto next; 349 + tmp = sctp_assoc(epb); 350 + if (tmp->ep != ep || rport != tmp->peer.port) 351 + continue; 346 352 347 - t = sctp_assoc_lookup_paddr(asoc, paddr); 353 + t = sctp_assoc_lookup_paddr(tmp, paddr); 348 354 if (t) { 355 + asoc = tmp; 349 356 *transport = t; 350 357 break; 351 358 } 352 - next: 353 - asoc = NULL; 354 359 } 355 360 read_unlock(&head->lock); 361 + out: 356 362 return asoc; 357 363 } 358 364