All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH] [v3] net: sctp: fix skb leak in sctp_inq_free()
@ 2024-02-14  8:22 Dmitry Antipov
  2024-02-14 19:14 ` Xin Long
  2024-02-15 16:00 ` patchwork-bot+netdevbpf
  0 siblings, 2 replies; 3+ messages in thread
From: Dmitry Antipov @ 2024-02-14  8:22 UTC (permalink / raw)
  To: Xin Long
  Cc: Jakub Kicinski, Marcelo Ricardo Leitner, linux-sctp, netdev,
	lvc-project, Dmitry Antipov, syzbot+8bb053b5d63595ab47db

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>
---
v3: https://lore.kernel.org/netdev/CADvbK_cjg7kd7uFWxPBpwMAxwsuCki791zQ7D01y+vk0R5wTSQ@mail.gmail.com
    - rename helper to 'sctp_inq_chunk_free()' (Xin Long)
v2: https://lore.kernel.org/netdev/20240209134703.63a9167b@kernel.org
    - factor the fix out to helper function (Jakub Kicinski)
---
 net/sctp/inqueue.c | 14 ++++++++++----
 1 file changed, 10 insertions(+), 4 deletions(-)

diff --git a/net/sctp/inqueue.c b/net/sctp/inqueue.c
index 7182c5a450fb..5c1652181805 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_inq_chunk_free(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_inq_chunk_free(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_inq_chunk_free(chunk);
 			chunk = queue->in_progress = NULL;
 		} else {
 			/* Nothing to do. Next chunk in the packet, please. */
-- 
2.43.0


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

* Re: [PATCH] [v3] net: sctp: fix skb leak in sctp_inq_free()
  2024-02-14  8:22 [PATCH] [v3] net: sctp: fix skb leak in sctp_inq_free() Dmitry Antipov
@ 2024-02-14 19:14 ` Xin Long
  2024-02-15 16:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: Xin Long @ 2024-02-14 19:14 UTC (permalink / raw)
  To: Dmitry Antipov
  Cc: Jakub Kicinski, Marcelo Ricardo Leitner, linux-sctp, netdev,
	lvc-project, syzbot+8bb053b5d63595ab47db

On Wed, Feb 14, 2024 at 3:23 AM Dmitry Antipov <dmantipov@yandex.ru> 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_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>
> ---
> v3: https://lore.kernel.org/netdev/CADvbK_cjg7kd7uFWxPBpwMAxwsuCki791zQ7D01y+vk0R5wTSQ@mail.gmail.com
>     - rename helper to 'sctp_inq_chunk_free()' (Xin Long)
> v2: https://lore.kernel.org/netdev/20240209134703.63a9167b@kernel.org
>     - factor the fix out to helper function (Jakub Kicinski)
> ---
>  net/sctp/inqueue.c | 14 ++++++++++----
>  1 file changed, 10 insertions(+), 4 deletions(-)
>
> diff --git a/net/sctp/inqueue.c b/net/sctp/inqueue.c
> index 7182c5a450fb..5c1652181805 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_inq_chunk_free(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_inq_chunk_free(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_inq_chunk_free(chunk);
>                         chunk = queue->in_progress = NULL;
>                 } else {
>                         /* Nothing to do. Next chunk in the packet, please. */
> --
> 2.43.0
>

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

* Re: [PATCH] [v3] net: sctp: fix skb leak in sctp_inq_free()
  2024-02-14  8:22 [PATCH] [v3] net: sctp: fix skb leak in sctp_inq_free() Dmitry Antipov
  2024-02-14 19:14 ` Xin Long
@ 2024-02-15 16:00 ` patchwork-bot+netdevbpf
  1 sibling, 0 replies; 3+ messages in thread
From: patchwork-bot+netdevbpf @ 2024-02-15 16:00 UTC (permalink / raw)
  To: Dmitry Antipov
  Cc: lucien.xin, kuba, marcelo.leitner, linux-sctp, netdev,
	lvc-project, syzbot+8bb053b5d63595ab47db

Hello:

This patch was applied to netdev/net.git (main)
by Jakub Kicinski <kuba@kernel.org>:

On Wed, 14 Feb 2024 11:22:24 +0300 you 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_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.
> 
> [...]

Here is the summary with links:
  - [v3] net: sctp: fix skb leak in sctp_inq_free()
    https://git.kernel.org/netdev/net/c/4e45170d9acc

You are awesome, thank you!
-- 
Deet-doot-dot, I am a bot.
https://korg.docs.kernel.org/patchwork/pwbot.html



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

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

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2024-02-14  8:22 [PATCH] [v3] net: sctp: fix skb leak in sctp_inq_free() Dmitry Antipov
2024-02-14 19:14 ` Xin Long
2024-02-15 16:00 ` patchwork-bot+netdevbpf

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.