Skip to content

Commit 7c3ceb4

Browse files
nhormandavem330
authored andcommitted
[SCTP]: Allow spillover of receive buffer to avoid deadlock.
This patch fixes a deadlock situation in the receive path by allowing temporary spillover of the receive buffer. - If the chunk we receive has a tsn that immediately follows the ctsn, accept it even if we run out of receive buffer space and renege data with higher TSNs. - Once we accept one chunk in a packet, accept all the remaining chunks even if we run out of receive buffer space. Signed-off-by: Neil Horman <nhorman@tuxdriver.com> Acked-by: Mark Butler <butlerm@middle.net> Acked-by: Vlad Yasevich <vladislav.yasevich@hp.com> Signed-off-by: Sridhar Samudrala <sri@us.ibm.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 91ef5d2 commit 7c3ceb4

3 files changed

Lines changed: 38 additions & 10 deletions

File tree

‎include/net/sctp/structs.h‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -712,6 +712,7 @@ struct sctp_chunk {
712712
__u8 tsn_gap_acked; /* Is this chunk acked by a GAP ACK? */
713713
__s8 fast_retransmit; /* Is this chunk fast retransmitted? */
714714
__u8 tsn_missing_report; /* Data chunk missing counter. */
715+
__u8 data_accepted; /* At least 1 chunk in this packet accepted */
715716
};
716717

717718
void sctp_chunk_hold(struct sctp_chunk *);

‎net/sctp/inqueue.c‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ struct sctp_chunk *sctp_inq_pop(struct sctp_inq *queue)
149149
/* This is the first chunk in the packet. */
150150
chunk->singleton = 1;
151151
ch = (sctp_chunkhdr_t *) chunk->skb->data;
152+
chunk->data_accepted = 0;
152153
}
153154

154155
chunk->chunk_hdr = ch;

‎net/sctp/sm_statefuns.c‎

Lines changed: 36 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5151,7 +5151,9 @@ static int sctp_eat_data(const struct sctp_association *asoc,
51515151
int tmp;
51525152
__u32 tsn;
51535153
int account_value;
5154+
struct sctp_tsnmap *map = (struct sctp_tsnmap *)&asoc->peer.tsn_map;
51545155
struct sock *sk = asoc->base.sk;
5156+
int rcvbuf_over = 0;
51555157

51565158
data_hdr = chunk->subh.data_hdr = (sctp_datahdr_t *)chunk->skb->data;
51575159
skb_pull(chunk->skb, sizeof(sctp_datahdr_t));
@@ -5162,10 +5164,16 @@ static int sctp_eat_data(const struct sctp_association *asoc,
51625164
/* ASSERT: Now skb->data is really the user data. */
51635165

51645166
/*
5165-
* if we are established, and we have used up our receive
5166-
* buffer memory, drop the frame
5167-
*/
5168-
if (asoc->state == SCTP_STATE_ESTABLISHED) {
5167+
* If we are established, and we have used up our receive buffer
5168+
* memory, think about droping the frame.
5169+
* Note that we have an opportunity to improve performance here.
5170+
* If we accept one chunk from an skbuff, we have to keep all the
5171+
* memory of that skbuff around until the chunk is read into user
5172+
* space. Therefore, once we accept 1 chunk we may as well accept all
5173+
* remaining chunks in the skbuff. The data_accepted flag helps us do
5174+
* that.
5175+
*/
5176+
if ((asoc->state == SCTP_STATE_ESTABLISHED) && (!chunk->data_accepted)) {
51695177
/*
51705178
* If the receive buffer policy is 1, then each
51715179
* association can allocate up to sk_rcvbuf bytes
@@ -5176,9 +5184,25 @@ static int sctp_eat_data(const struct sctp_association *asoc,
51765184
account_value = atomic_read(&asoc->rmem_alloc);
51775185
else
51785186
account_value = atomic_read(&sk->sk_rmem_alloc);
5179-
5180-
if (account_value > sk->sk_rcvbuf)
5181-
return SCTP_IERROR_IGNORE_TSN;
5187+
if (account_value > sk->sk_rcvbuf) {
5188+
/*
5189+
* We need to make forward progress, even when we are
5190+
* under memory pressure, so we always allow the
5191+
* next tsn after the ctsn ack point to be accepted.
5192+
* This lets us avoid deadlocks in which we have to
5193+
* drop frames that would otherwise let us drain the
5194+
* receive queue.
5195+
*/
5196+
if ((sctp_tsnmap_get_ctsn(map) + 1) != tsn)
5197+
return SCTP_IERROR_IGNORE_TSN;
5198+
5199+
/*
5200+
* We're going to accept the frame but we should renege
5201+
* to make space for it. This will send us down that
5202+
* path later in this function.
5203+
*/
5204+
rcvbuf_over = 1;
5205+
}
51825206
}
51835207

51845208
/* Process ECN based congestion.
@@ -5226,6 +5250,7 @@ static int sctp_eat_data(const struct sctp_association *asoc,
52265250
datalen -= sizeof(sctp_data_chunk_t);
52275251

52285252
deliver = SCTP_CMD_CHUNK_ULP;
5253+
chunk->data_accepted = 1;
52295254

52305255
/* Think about partial delivery. */
52315256
if ((datalen >= asoc->rwnd) && (!asoc->ulpq.pd_mode)) {
@@ -5242,16 +5267,17 @@ static int sctp_eat_data(const struct sctp_association *asoc,
52425267
* large spill over.
52435268
*/
52445269
if (!asoc->rwnd || asoc->rwnd_over ||
5245-
(datalen > asoc->rwnd + asoc->frag_point)) {
5270+
(datalen > asoc->rwnd + asoc->frag_point) ||
5271+
rcvbuf_over) {
52465272

52475273
/* If this is the next TSN, consider reneging to make
52485274
* room. Note: Playing nice with a confused sender. A
52495275
* malicious sender can still eat up all our buffer
52505276
* space and in the future we may want to detect and
52515277
* do more drastic reneging.
52525278
*/
5253-
if (sctp_tsnmap_has_gap(&asoc->peer.tsn_map) &&
5254-
(sctp_tsnmap_get_ctsn(&asoc->peer.tsn_map) + 1) == tsn) {
5279+
if (sctp_tsnmap_has_gap(map) &&
5280+
(sctp_tsnmap_get_ctsn(map) + 1) == tsn) {
52555281
SCTP_DEBUG_PRINTK("Reneging for tsn:%u\n", tsn);
52565282
deliver = SCTP_CMD_RENEGE;
52575283
} else {

0 commit comments

Comments
 (0)