Skip to content

Commit 70fc69b

Browse files
Lee A. Robertsdavem330
authored andcommitted
sctp: fix association hangs due to off-by-one errors in sctp_tsnmap_grow()
In sctp_tsnmap_mark(), correct off-by-one error when calculating size value for sctp_tsnmap_grow(). In sctp_tsnmap_grow(), correct off-by-one error when copying and resizing the tsnmap. If max_tsn_seen is in the LSB of the word, this bit can be lost, causing the corresponding packet to be transmitted again and to be entered as a duplicate into the SCTP reassembly/ordering queues. Change parameter name from "gap" (zero-based index) to "size" (one-based) to enhance code readability. Signed-off-by: Lee A. Roberts <lee.roberts@hp.com> Acked-by: Vlad Yasevich <vyasevich@gmail.com> Acked-by: Neil Horman <nhorman@tuxdriver.com>
1 parent 726bc6b commit 70fc69b

1 file changed

Lines changed: 7 additions & 6 deletions

File tree

net/sctp/tsnmap.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@
5151
static void sctp_tsnmap_update(struct sctp_tsnmap *map);
5252
static void sctp_tsnmap_find_gap_ack(unsigned long *map, __u16 off,
5353
__u16 len, __u16 *start, __u16 *end);
54-
static int sctp_tsnmap_grow(struct sctp_tsnmap *map, u16 gap);
54+
static int sctp_tsnmap_grow(struct sctp_tsnmap *map, u16 size);
5555

5656
/* Initialize a block of memory as a tsnmap. */
5757
struct sctp_tsnmap *sctp_tsnmap_init(struct sctp_tsnmap *map, __u16 len,
@@ -124,7 +124,7 @@ int sctp_tsnmap_mark(struct sctp_tsnmap *map, __u32 tsn,
124124

125125
gap = tsn - map->base_tsn;
126126

127-
if (gap >= map->len && !sctp_tsnmap_grow(map, gap))
127+
if (gap >= map->len && !sctp_tsnmap_grow(map, gap + 1))
128128
return -ENOMEM;
129129

130130
if (!sctp_tsnmap_has_gap(map) && gap == 0) {
@@ -360,23 +360,24 @@ __u16 sctp_tsnmap_num_gabs(struct sctp_tsnmap *map,
360360
return ngaps;
361361
}
362362

363-
static int sctp_tsnmap_grow(struct sctp_tsnmap *map, u16 gap)
363+
static int sctp_tsnmap_grow(struct sctp_tsnmap *map, u16 size)
364364
{
365365
unsigned long *new;
366366
unsigned long inc;
367367
u16 len;
368368

369-
if (gap >= SCTP_TSN_MAP_SIZE)
369+
if (size > SCTP_TSN_MAP_SIZE)
370370
return 0;
371371

372-
inc = ALIGN((gap - map->len),BITS_PER_LONG) + SCTP_TSN_MAP_INCREMENT;
372+
inc = ALIGN((size - map->len), BITS_PER_LONG) + SCTP_TSN_MAP_INCREMENT;
373373
len = min_t(u16, map->len + inc, SCTP_TSN_MAP_SIZE);
374374

375375
new = kzalloc(len>>3, GFP_ATOMIC);
376376
if (!new)
377377
return 0;
378378

379-
bitmap_copy(new, map->tsn_map, map->max_tsn_seen - map->base_tsn);
379+
bitmap_copy(new, map->tsn_map,
380+
map->max_tsn_seen - map->cumulative_tsn_ack_point);
380381
kfree(map->tsn_map);
381382
map->tsn_map = new;
382383
map->len = len;

0 commit comments

Comments
 (0)