netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] net: sctp: fix memory leak in sctp_chunk_destroy()
@ 2024-02-05 17:01 Dmitry Antipov
  2024-02-05 23:29 ` Xin Long
  0 siblings, 1 reply; 8+ messages in thread
From: Dmitry Antipov @ 2024-02-05 17:01 UTC (permalink / raw)
  To: Marcelo Ricardo Leitner
  Cc: Xin Long, linux-sctp, netdev, lvc-project, Dmitry Antipov,
	syzbot+8bb053b5d63595ab47db

In case of GSO, per-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), consume 'head_skb' (i.e. beginning of a fraglist) instead.

Reported-by: syzbot+8bb053b5d63595ab47db@syzkaller.appspotmail.com
Closes: https://syzkaller.appspot.com/bug?id=0d8351bbe54fd04a492c2daab0164138db008042
Signed-off-by: Dmitry Antipov <dmantipov@yandex.ru>
---
 net/sctp/sm_make_chunk.c | 5 ++++-
 1 file changed, 4 insertions(+), 1 deletion(-)

diff --git a/net/sctp/sm_make_chunk.c b/net/sctp/sm_make_chunk.c
index f80208edd6a5..30fe34743009 100644
--- a/net/sctp/sm_make_chunk.c
+++ b/net/sctp/sm_make_chunk.c
@@ -1500,7 +1500,10 @@ static void sctp_chunk_destroy(struct sctp_chunk *chunk)
 	BUG_ON(!list_empty(&chunk->list));
 	list_del_init(&chunk->transmitted_list);
 
-	consume_skb(chunk->skb);
+	/* In case of GSO, 'skb' may be a pointer to fraglist entry.
+	 * Consume the read head if so.
+	 */
+	consume_skb(chunk->head_skb ? chunk->head_skb : chunk->skb);
 	consume_skb(chunk->auth_chunk);
 
 	SCTP_DBG_OBJCNT_DEC(chunk);
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 8+ messages in thread

end of thread, other threads:[~2024-02-13 15:22 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-02-05 17:01 [PATCH] net: sctp: fix memory leak in sctp_chunk_destroy() Dmitry Antipov
2024-02-05 23:29 ` Xin Long
2024-02-06  5:15   ` [lvc-project] " Antipov, Dmitriy
2024-02-06  9:26   ` [PATCH] net: sctp: fix skb leak in sctp_inq_free() Dmitry Antipov
2024-02-09 21:47     ` Jakub Kicinski
2024-02-12  8:22       ` [PATCH] [v2] " Dmitry Antipov
2024-02-13  0:25         ` Jakub Kicinski
2024-02-13 15:21           ` Xin Long

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).