diff options
Diffstat (limited to 'net/sctp/sm_statefuns.c')
-rw-r--r-- | net/sctp/sm_statefuns.c | 59 |
1 files changed, 44 insertions, 15 deletions
diff --git a/net/sctp/sm_statefuns.c b/net/sctp/sm_statefuns.c index 2b9a832b29a7..8cdba51ec076 100644 --- a/net/sctp/sm_statefuns.c +++ b/net/sctp/sm_statefuns.c | |||
@@ -636,8 +636,9 @@ sctp_disposition_t sctp_sf_do_5_1D_ce(const struct sctp_endpoint *ep, | |||
636 | */ | 636 | */ |
637 | chunk->subh.cookie_hdr = | 637 | chunk->subh.cookie_hdr = |
638 | (struct sctp_signed_cookie *)chunk->skb->data; | 638 | (struct sctp_signed_cookie *)chunk->skb->data; |
639 | skb_pull(chunk->skb, | 639 | if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) - |
640 | ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t)); | 640 | sizeof(sctp_chunkhdr_t))) |
641 | goto nomem; | ||
641 | 642 | ||
642 | /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint | 643 | /* 5.1 D) Upon reception of the COOKIE ECHO chunk, Endpoint |
643 | * "Z" will reply with a COOKIE ACK chunk after building a TCB | 644 | * "Z" will reply with a COOKIE ACK chunk after building a TCB |
@@ -965,7 +966,8 @@ sctp_disposition_t sctp_sf_beat_8_3(const struct sctp_endpoint *ep, | |||
965 | */ | 966 | */ |
966 | chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data; | 967 | chunk->subh.hb_hdr = (sctp_heartbeathdr_t *) chunk->skb->data; |
967 | paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t); | 968 | paylen = ntohs(chunk->chunk_hdr->length) - sizeof(sctp_chunkhdr_t); |
968 | skb_pull(chunk->skb, paylen); | 969 | if (!pskb_pull(chunk->skb, paylen)) |
970 | goto nomem; | ||
969 | 971 | ||
970 | reply = sctp_make_heartbeat_ack(asoc, chunk, | 972 | reply = sctp_make_heartbeat_ack(asoc, chunk, |
971 | chunk->subh.hb_hdr, paylen); | 973 | chunk->subh.hb_hdr, paylen); |
@@ -1860,8 +1862,9 @@ sctp_disposition_t sctp_sf_do_5_2_4_dupcook(const struct sctp_endpoint *ep, | |||
1860 | * are in good shape. | 1862 | * are in good shape. |
1861 | */ | 1863 | */ |
1862 | chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data; | 1864 | chunk->subh.cookie_hdr = (struct sctp_signed_cookie *)chunk->skb->data; |
1863 | skb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) - | 1865 | if (!pskb_pull(chunk->skb, ntohs(chunk->chunk_hdr->length) - |
1864 | sizeof(sctp_chunkhdr_t)); | 1866 | sizeof(sctp_chunkhdr_t))) |
1867 | goto nomem; | ||
1865 | 1868 | ||
1866 | /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie | 1869 | /* In RFC 2960 5.2.4 3, if both Verification Tags in the State Cookie |
1867 | * of a duplicate COOKIE ECHO match the Verification Tags of the | 1870 | * of a duplicate COOKIE ECHO match the Verification Tags of the |
@@ -5151,7 +5154,9 @@ static int sctp_eat_data(const struct sctp_association *asoc, | |||
5151 | int tmp; | 5154 | int tmp; |
5152 | __u32 tsn; | 5155 | __u32 tsn; |
5153 | int account_value; | 5156 | int account_value; |
5157 | struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map; | ||
5154 | struct sock *sk = asoc->base.sk; | 5158 | struct sock *sk = asoc->base.sk; |
5159 | int rcvbuf_over = 0; | ||
5155 | 5160 | ||
5156 | data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data; | 5161 | data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data; |
5157 | skb_pull(chunk->skb, sizeof(sctp_datahdr_t)); | 5162 | skb_pull(chunk->skb, sizeof(sctp_datahdr_t)); |
@@ -5162,10 +5167,16 @@ static int sctp_eat_data(const struct sctp_association *asoc, | |||
5162 | /* ASSERT: Now skb->data is really the user data. */ | 5167 | /* ASSERT: Now skb->data is really the user data. */ |
5163 | 5168 | ||
5164 | /* | 5169 | /* |
5165 | * if we are established, and we have used up our receive | 5170 | * If we are established, and we have used up our receive buffer |
5166 | * buffer memory, drop the frame | 5171 | * memory, think about droping the frame. |
5167 | */ | 5172 | * Note that we have an opportunity to improve performance here. |
5168 | if (asoc->state == SCTP_STATE_ESTABLISHED) { | 5173 | * If we accept one chunk from an skbuff, we have to keep all the |
5174 | * memory of that skbuff around until the chunk is read into user | ||
5175 | * space. Therefore, once we accept 1 chunk we may as well accept all | ||
5176 | * remaining chunks in the skbuff. The data_accepted flag helps us do | ||
5177 | * that. | ||
5178 | */ | ||
5179 | if ((asoc->state == SCTP_STATE_ESTABLISHED) && (!chunk->data_accepted)) { | ||
5169 | /* | 5180 | /* |
5170 | * If the receive buffer policy is 1, then each | 5181 | * If the receive buffer policy is 1, then each |
5171 | * association can allocate up to sk_rcvbuf bytes | 5182 | * association can allocate up to sk_rcvbuf bytes |
@@ -5176,9 +5187,25 @@ static int sctp_eat_data(const struct sctp_association *asoc, | |||
5176 | account_value = atomic_read(&asoc->rmem_alloc); | 5187 | account_value = atomic_read(&asoc->rmem_alloc); |
5177 | else | 5188 | else |
5178 | account_value = atomic_read(&sk->sk_rmem_alloc); | 5189 | account_value = atomic_read(&sk->sk_rmem_alloc); |
5179 | 5190 | if (account_value > sk->sk_rcvbuf) { | |
5180 | if (account_value > sk->sk_rcvbuf) | 5191 | /* |
5181 | return SCTP_IERROR_IGNORE_TSN; | 5192 | * We need to make forward progress, even when we are |
5193 | * under memory pressure, so we always allow the | ||
5194 | * next tsn after the ctsn ack point to be accepted. | ||
5195 | * This lets us avoid deadlocks in which we have to | ||
5196 | * drop frames that would otherwise let us drain the | ||
5197 | * receive queue. | ||
5198 | */ | ||
5199 | if ((sctp_tsnmap_get_ctsn(map) + 1) != tsn) | ||
5200 | return SCTP_IERROR_IGNORE_TSN; | ||
5201 | |||
5202 | /* | ||
5203 | * We're going to accept the frame but we should renege | ||
5204 | * to make space for it. This will send us down that | ||
5205 | * path later in this function. | ||
5206 | */ | ||
5207 | rcvbuf_over = 1; | ||
5208 | } | ||
5182 | } | 5209 | } |
5183 | 5210 | ||
5184 | /* Process ECN based congestion. | 5211 | /* Process ECN based congestion. |
@@ -5226,6 +5253,7 @@ static int sctp_eat_data(const struct sctp_association *asoc, | |||
5226 | datalen -= sizeof(sctp_data_chunk_t); | 5253 | datalen -= sizeof(sctp_data_chunk_t); |
5227 | 5254 | ||
5228 | deliver = SCTP_CMD_CHUNK_ULP; | 5255 | deliver = SCTP_CMD_CHUNK_ULP; |
5256 | chunk->data_accepted = 1; | ||
5229 | 5257 | ||
5230 | /* Think about partial delivery. */ | 5258 | /* Think about partial delivery. */ |
5231 | if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) { | 5259 | if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) { |
@@ -5242,7 +5270,8 @@ static int sctp_eat_data(const struct sctp_association *asoc, | |||
5242 | * large spill over. | 5270 | * large spill over. |
5243 | */ | 5271 | */ |
5244 | if (!asoc->rwnd || asoc->rwnd_over || | 5272 | if (!asoc->rwnd || asoc->rwnd_over || |
5245 | (datalen > asoc->rwnd + asoc->frag_point)) { | 5273 | (datalen > asoc->rwnd + asoc->frag_point) || |
5274 | rcvbuf_over) { | ||
5246 | 5275 | ||
5247 | /* If this is the next TSN, consider reneging to make | 5276 | /* If this is the next TSN, consider reneging to make |
5248 | * room. Note: Playing nice with a confused sender. A | 5277 | * room. Note: Playing nice with a confused sender. A |
@@ -5250,8 +5279,8 @@ static int sctp_eat_data(const struct sctp_association *asoc, | |||
5250 | * space and in the future we may want to detect and | 5279 | * space and in the future we may want to detect and |
5251 | * do more drastic reneging. | 5280 | * do more drastic reneging. |
5252 | */ | 5281 | */ |
5253 | if (sctp_tsnmap_has_gap(&asoc->peer.tsn_map) && | 5282 | if (sctp_tsnmap_has_gap(map) && |
5254 | (sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + 1) == tsn) { | 5283 | (sctp_tsnmap_get_ctsn(map) + 1) == tsn) { |
5255 | SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn); | 5284 | SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn); |
5256 | deliver = SCTP_CMD_RENEGE; | 5285 | deliver = SCTP_CMD_RENEGE; |
5257 | } else { | 5286 | } else { |