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

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: 90017accff61 ("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>

authored by

Dmitry Antipov and committed by
Jakub Kicinski
4e45170d e5b2e810

+10 -4
+10 -4
net/sctp/inqueue.c
··· 38 38 INIT_WORK(&queue->immediate, NULL); 39 39 } 40 40 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 + 41 49 /* Release the memory associated with an SCTP inqueue. */ 42 50 void sctp_inq_free(struct sctp_inq *queue) 43 51 { ··· 61 53 * free it as well. 62 54 */ 63 55 if (queue->in_progress) { 64 - sctp_chunk_free(queue->in_progress); 56 + sctp_inq_chunk_free(queue->in_progress); 65 57 queue->in_progress = NULL; 66 58 } 67 59 } ··· 138 130 goto new_skb; 139 131 } 140 132 141 - if (chunk->head_skb) 142 - chunk->skb = chunk->head_skb; 143 - sctp_chunk_free(chunk); 133 + sctp_inq_chunk_free(chunk); 144 134 chunk = queue->in_progress = NULL; 145 135 } else { 146 136 /* Nothing to do. Next chunk in the packet, please. */