mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
* [PATCH net v2] sctp: Prevent TOCTOU out-of-bounds write
@ 2025-10-27 10:13 Stefan Wiehler
  2025-10-27 17:51 ` Kuniyuki Iwashima
  0 siblings, 1 reply; 3+ messages in thread
From: Stefan Wiehler @ 2025-10-27 10:13 UTC (permalink / raw)
  To: Xin Long, David S . Miller ,
	Eric Dumazet, Jakub Kicinski, Paolo Abeni, Simon Horman,
	Kuniyuki Iwashima
  Cc: linux-sctp, netdev, linux-kernel, Stefan Wiehler

Make sure not to exceed bounds in case the address list has grown
between buffer allocation (time-of-check) and write (time-of-use).

Suggested-by: Kuniyuki Iwashima <kuniyu@google.com>
Fixes: 8f840e47f190 ("sctp: add the sctp_diag.c file")
Signed-off-by: Stefan Wiehler <stefan.wiehler@nokia.com>
---
V1 -> V2: Add changelog and credit
---
 net/sctp/diag.c | 3 +++
 1 file changed, 3 insertions(+)

diff --git a/net/sctp/diag.c b/net/sctp/diag.c
index 996c2018f0e6..4ee44e0111ae 100644
--- a/net/sctp/diag.c
+++ b/net/sctp/diag.c
@@ -85,6 +85,9 @@ static int inet_diag_msg_sctpladdrs_fill(struct sk_buff *skb,
 		memcpy(info, &laddr->a, sizeof(laddr->a));
 		memset(info + sizeof(laddr->a), 0, addrlen - sizeof(laddr->a));
 		info += addrlen;
+
+		if (!--addrcnt)
+			break;
 	}
 
 	return 0;
-- 
2.51.0


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

* Re: [PATCH net v2] sctp: Prevent TOCTOU out-of-bounds write
  2025-10-27 10:13 [PATCH net v2] sctp: Prevent TOCTOU out-of-bounds write Stefan Wiehler
@ 2025-10-27 17:51 ` Kuniyuki Iwashima
  2025-10-28 16:34   ` Stefan Wiehler
  0 siblings, 1 reply; 3+ messages in thread
From: Kuniyuki Iwashima @ 2025-10-27 17:51 UTC (permalink / raw)
  To: Stefan Wiehler
  Cc: Xin Long, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, linux-sctp, netdev, linux-kernel

Thanks for the patch.

On Mon, Oct 27, 2025 at 3:16 AM Stefan Wiehler <stefan.wiehler@nokia.com> wrote:
>
> Make sure not to exceed bounds in case the address list has grown
> between buffer allocation (time-of-check) and write (time-of-use).

Could you elaborate a bit more context here like which path
we don't hold lock_sock() as Xin confirmed in this thread ?

https://lore.kernel.org/netdev/CADvbK_ddE0oUPXijkFJbWF6tFTq5TntpFMzDWH+uV_kc+KB7VA@mail.gmail.com/

Also, it would be better to post the two patches as a series

git send-email --annotate --cover-letter --thread --no-chain-reply-to \
--subject-prefix "PATCH v3 net" \
--to ...


>
> Suggested-by: Kuniyuki Iwashima <kuniyu@google.com>
> Fixes: 8f840e47f190 ("sctp: add the sctp_diag.c file")
> Signed-off-by: Stefan Wiehler <stefan.wiehler@nokia.com>
> ---
> V1 -> V2: Add changelog and credit
> ---
>  net/sctp/diag.c | 3 +++
>  1 file changed, 3 insertions(+)
>
> diff --git a/net/sctp/diag.c b/net/sctp/diag.c
> index 996c2018f0e6..4ee44e0111ae 100644
> --- a/net/sctp/diag.c
> +++ b/net/sctp/diag.c
> @@ -85,6 +85,9 @@ static int inet_diag_msg_sctpladdrs_fill(struct sk_buff *skb,
>                 memcpy(info, &laddr->a, sizeof(laddr->a));
>                 memset(info + sizeof(laddr->a), 0, addrlen - sizeof(laddr->a));
>                 info += addrlen;
> +
> +               if (!--addrcnt)
> +                       break;
>         }
>
>         return 0;
> --
> 2.51.0
>

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

* Re: [PATCH net v2] sctp: Prevent TOCTOU out-of-bounds write
  2025-10-27 17:51 ` Kuniyuki Iwashima
@ 2025-10-28 16:34   ` Stefan Wiehler
  0 siblings, 0 replies; 3+ messages in thread
From: Stefan Wiehler @ 2025-10-28 16:34 UTC (permalink / raw)
  To: Kuniyuki Iwashima
  Cc: Xin Long, David S . Miller, Eric Dumazet, Jakub Kicinski,
	Paolo Abeni, Simon Horman, linux-sctp, netdev, linux-kernel

> Also, it would be better to post the two patches as a series

Ok, I thought it would be better to treat them independently. Here is a series of
all three patches:
https://patchwork.kernel.org/project/netdevbpf/cover/20251028161506.3294376-1-stefan.wiehler@nokia.com/

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

end of thread, other threads:[~2025-10-28 16:35 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2025-10-27 10:13 [PATCH net v2] sctp: Prevent TOCTOU out-of-bounds write Stefan Wiehler
2025-10-27 17:51 ` Kuniyuki Iwashima
2025-10-28 16:34   ` Stefan Wiehler

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®