diff mbox series

[v2] net: sctp: fix skb leak in sctp_inq_free()

Message ID 20240212082202.17927-1-dmantipov@yandex.ru (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series [v2] net: sctp: fix skb leak in sctp_inq_free() | expand

Checks

Context Check Description
netdev/series_format warning Single patches do not need cover letters; Target tree name not specified in the subject
netdev/tree_selection success Guessed tree name to be net-next
netdev/ynl success Generated files up to date; no warnings/errors; no diff in generated;
netdev/fixes_present success Fixes tag not required for -next series
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 989 this patch: 989
netdev/build_tools success No tools touched, skip
netdev/cc_maintainers warning 2 maintainers not CCed: pabeni@redhat.com edumazet@google.com
netdev/build_clang success Errors and warnings before: 1006 this patch: 1006
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/deprecated_api success None detected
netdev/check_selftest success No net selftest shell script
netdev/verify_fixes success Fixes tag looks correct
netdev/build_allmodconfig_warn success Errors and warnings before: 1006 this patch: 1006
netdev/checkpatch success total: 0 errors, 0 warnings, 0 checks, 32 lines checked
netdev/build_clang_rust success No Rust files in patch. Skipping build
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline fail Was 0 now: 1
netdev/contest success net-next-2024-02-13--00-00 (tests: 1436)

Commit Message

Dmitry Antipov Feb. 12, 2024, 8:22 a.m. UTC
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_chunk_release()' 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>
---
v2: factor the fix out to helper function (Jakub Kicinski)
---
 net/sctp/inqueue.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

Comments

Jakub Kicinski Feb. 13, 2024, 12:25 a.m. UTC | #1
On Mon, 12 Feb 2024 11:22:02 +0300 Dmitry Antipov wrote:
> 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_chunk_release()' 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.

Please repost this as a separate thread, per:
https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#resending-after-review
Xin Long is probably out for New Year celebrations, anyway.
Xin Long Feb. 13, 2024, 3:21 p.m. UTC | #2
On Mon, Feb 12, 2024 at 7:25 PM Jakub Kicinski <kuba@kernel.org> wrote:
>
> On Mon, 12 Feb 2024 11:22:02 +0300 Dmitry Antipov wrote:
> > 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_chunk_release()' 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.
>
> Please repost this as a separate thread, per:
> https://www.kernel.org/doc/html/next/process/maintainer-netdev.html#resending-after-review
and instead of sctp_chunk_release(), please use a better name like
"sctp_inq_chunk_free()" when you repost.

Thanks.

> Xin Long is probably out for New Year celebrations, anyway.
> --
> pw-bot: cr
diff mbox series

Patch

diff --git a/net/sctp/inqueue.c b/net/sctp/inqueue.c
index 7182c5a450fb..9ec172405ff4 100644
--- a/net/sctp/inqueue.c
+++ b/net/sctp/inqueue.c
@@ -38,6 +38,14 @@  void sctp_inq_init(struct sctp_inq *queue)
 	INIT_WORK(&queue->immediate, NULL);
 }
 
+/* Properly release the chunk which is being worked on. */
+static inline void sctp_chunk_release(struct sctp_chunk *chunk)
+{
+	if (chunk->head_skb)
+		chunk->skb = chunk->head_skb;
+	sctp_chunk_free(chunk);
+}
+
 /* Release the memory associated with an SCTP inqueue.  */
 void sctp_inq_free(struct sctp_inq *queue)
 {
@@ -53,7 +61,7 @@  void sctp_inq_free(struct sctp_inq *queue)
 	 * free it as well.
 	 */
 	if (queue->in_progress) {
-		sctp_chunk_free(queue->in_progress);
+		sctp_chunk_release(queue->in_progress);
 		queue->in_progress = NULL;
 	}
 }
@@ -130,9 +138,7 @@  struct sctp_chunk *sctp_inq_pop(struct sctp_inq *queue)
 				goto new_skb;
 			}
 
-			if (chunk->head_skb)
-				chunk->skb = chunk->head_skb;
-			sctp_chunk_free(chunk);
+			sctp_chunk_release(chunk);
 			chunk = queue->in_progress = NULL;
 		} else {
 			/* Nothing to do. Next chunk in the packet, please. */