Skip to content

Commit 4e45170

Browse files
dmantipovkuba-moo
authored andcommitted
net: sctp: fix skb leak in sctp_inq_free()
In case of GSO, 'chunk->skb' pointer may point to an entry from fraglist created in 'sctp_packet_gso_append()'. To avoid freeing random fraglist entry (and so undefined behavior and/or memory leak), introduce 'sctp_inq_chunk_free()' helper to ensure that 'chunk->skb' is set to 'chunk->head_skb' (i.e. fraglist head) before calling 'sctp_chunk_free()', and use the aforementioned helper in 'sctp_inq_pop()' as well. Reported-by: syzbot+8bb053b5d63595ab47db@syzkaller.appspotmail.com Closes: https://syzkaller.appspot.com/bug?id=0d8351bbe54fd04a492c2daab0164138db008042 Fixes: 90017ac ("sctp: Add GSO support") Suggested-by: Xin Long <lucien.xin@gmail.com> Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru> Acked-by: Xin Long <lucien.xin@gmail.com> Link: https://lore.kernel.org/r/20240214082224.10168-1-dmantipov@yandex.ru Signed-off-by: Jakub Kicinski <kuba@kernel.org>
1 parent e5b2e81 commit 4e45170

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

net/sctp/inqueue.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,14 @@ void sctp_inq_init(struct sctp_inq *queue)
3838
INIT_WORK(&queue->immediate, NULL);
3939
}
4040

41+
/* Properly release the chunk which is being worked on. */
42+
static inline void sctp_inq_chunk_free(struct sctp_chunk *chunk)
43+
{
44+
if (chunk->head_skb)
45+
chunk->skb = chunk->head_skb;
46+
sctp_chunk_free(chunk);
47+
}
48+
4149
/* Release the memory associated with an SCTP inqueue. */
4250
void sctp_inq_free(struct sctp_inq *queue)
4351
{
@@ -53,7 +61,7 @@ void sctp_inq_free(struct sctp_inq *queue)
5361
* free it as well.
5462
*/
5563
if (queue->in_progress) {
56-
sctp_chunk_free(queue->in_progress);
64+
sctp_inq_chunk_free(queue->in_progress);
5765
queue->in_progress = NULL;
5866
}
5967
}
@@ -130,9 +138,7 @@ struct sctp_chunk *sctp_inq_pop(struct sctp_inq *queue)
130138
goto new_skb;
131139
}
132140

133-
if (chunk->head_skb)
134-
chunk->skb = chunk->head_skb;
135-
sctp_chunk_free(chunk);
141+
sctp_inq_chunk_free(chunk);
136142
chunk = queue->in_progress = NULL;
137143
} else {
138144
/* Nothing to do. Next chunk in the packet, please. */

0 commit comments

Comments
 (0)