public inbox for astral-devel@lists.astral-os.org
 help / color / mirror / Atom feed
* [PATCH] iovec: reject iovecs whose total size overflows
@ 2026-11-19 18:39 Marvin Friedrich
  2026-11-19 18:53 ` Marvin Friedrich
  2026-11-19 20:33 ` Matheus
  0 siblings, 2 replies; 3+ messages in thread
From: Marvin Friedrich @ 2026-11-19 18:39 UTC (permalink / raw)
  To: astral-devel; +Cc: Marvin Friedrich

diff --git a/kernel-src/include/kernel/iovec.h b/kernel-src/include/kernel/iovec.h
index ad3e8e96..b7ad0a0d 100644
--- a/kernel-src/include/kernel/iovec.h
+++ b/kernel-src/include/kernel/iovec.h
@@ -21,7 +21,7 @@ typedef struct {
 	size_t total_size;
 } iovec_iterator_t;
 
-// checks if all iovec[x].addr is an userspace address
+// checks if all iovec[x].addr is an userspace address and that the total size fits in an ssize_t
 bool iovec_user_check(iovec_t *iovec, size_t count);
 
 // returns the sum of the size of all iovecs
diff --git a/kernel-src/io/iovec.c b/kernel-src/io/iovec.c
index ff8e638c..840dfba3 100644
--- a/kernel-src/io/iovec.c
+++ b/kernel-src/io/iovec.c
@@ -1,17 +1,23 @@
 #include <kernel/iovec.h>
 #include <kernel/mm.h>
 #include <kernel/usercopy.h>
+#include <stdint.h>
 
 static inline bool iovec_iterator_finished(iovec_iterator_t *iovec_iterator) {
 	return iovec_iterator->total_size == iovec_iterator->total_offset;
 }
 
 bool iovec_user_check(iovec_t *iovec, size_t count) {
-	// TODO add size overflow check
+	size_t total = 0;
+
 	for (int i = 0; i < count; ++i) {
 		// POSIX says that when len is zero, the addr can be an invalid buffer
 		if (iovec[i].len && IS_USER_ADDRESS(iovec[i].addr) == false)
 			return false;
+
+		// The total size has to fit in the ssize_t returned to userspace
+		if (__builtin_add_overflow(total, iovec[i].len, &total) || total > SIZE_MAX / 2)
+			return false;
 	}
 
 	return true;
-- 
2.56.0


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

* Re: [PATCH] iovec: reject iovecs whose total size overflows
  2026-11-19 18:39 [PATCH] iovec: reject iovecs whose total size overflows Marvin Friedrich
@ 2026-11-19 18:53 ` Marvin Friedrich
  2026-11-19 20:33 ` Matheus
  1 sibling, 0 replies; 3+ messages in thread
From: Marvin Friedrich @ 2026-11-19 18:53 UTC (permalink / raw)
  To: astral-devel

Any objections?

On 11/19/26 19:39, Marvin Friedrich wrote:
> diff --git a/kernel-src/include/kernel/iovec.h b/kernel-src/include/kernel/iovec.h
> index ad3e8e96..b7ad0a0d 100644
> --- a/kernel-src/include/kernel/iovec.h
> +++ b/kernel-src/include/kernel/iovec.h
> @@ -21,7 +21,7 @@ typedef struct {
>   	size_t total_size;
>   } iovec_iterator_t;
>   
> -// checks if all iovec[x].addr is an userspace address
> +// checks if all iovec[x].addr is an userspace address and that the total size fits in an ssize_t
>   bool iovec_user_check(iovec_t *iovec, size_t count);
>   
>   // returns the sum of the size of all iovecs
> diff --git a/kernel-src/io/iovec.c b/kernel-src/io/iovec.c
> index ff8e638c..840dfba3 100644
> --- a/kernel-src/io/iovec.c
> +++ b/kernel-src/io/iovec.c
> @@ -1,17 +1,23 @@
>   #include <kernel/iovec.h>
>   #include <kernel/mm.h>
>   #include <kernel/usercopy.h>
> +#include <stdint.h>
>   
>   static inline bool iovec_iterator_finished(iovec_iterator_t *iovec_iterator) {
>   	return iovec_iterator->total_size == iovec_iterator->total_offset;
>   }
>   
>   bool iovec_user_check(iovec_t *iovec, size_t count) {
> -	// TODO add size overflow check
> +	size_t total = 0;
> +
>   	for (int i = 0; i < count; ++i) {
>   		// POSIX says that when len is zero, the addr can be an invalid buffer
>   		if (iovec[i].len && IS_USER_ADDRESS(iovec[i].addr) == false)
>   			return false;
> +
> +		// The total size has to fit in the ssize_t returned to userspace
> +		if (__builtin_add_overflow(total, iovec[i].len, &total) || total > SIZE_MAX / 2)
> +			return false;
>   	}
>   
>   	return true;


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

* Re: [PATCH] iovec: reject iovecs whose total size overflows
  2026-11-19 18:39 [PATCH] iovec: reject iovecs whose total size overflows Marvin Friedrich
  2026-11-19 18:53 ` Marvin Friedrich
@ 2026-11-19 20:33 ` Matheus
  1 sibling, 0 replies; 3+ messages in thread
From: Matheus @ 2026-11-19 20:33 UTC (permalink / raw)
  To: astral-devel, Marvin Friedrich



Em 19 de novembro de 2026 15:39:26 BRT, Marvin Friedrich <contact@marvinf.com> escreveu:
>diff --git a/kernel-src/include/kernel/iovec.h b/kernel-src/include/kernel/iovec.h
>index ad3e8e96..b7ad0a0d 100644
>--- a/kernel-src/include/kernel/iovec.h
>+++ b/kernel-src/include/kernel/iovec.h
>@@ -21,7 +21,7 @@ typedef struct {
> 	size_t total_size;
> } iovec_iterator_t;
> 
>-// checks if all iovec[x].addr is an userspace address
>+// checks if all iovec[x].addr is an userspace address and that the total size fits in an ssize_t
> bool iovec_user_check(iovec_t *iovec, size_t count);
> 
> // returns the sum of the size of all iovecs
>diff --git a/kernel-src/io/iovec.c b/kernel-src/io/iovec.c
>index ff8e638c..840dfba3 100644
>--- a/kernel-src/io/iovec.c
>+++ b/kernel-src/io/iovec.c
>@@ -1,17 +1,23 @@
> #include <kernel/iovec.h>
> #include <kernel/mm.h>
> #include <kernel/usercopy.h>
>+#include <stdint.h>
> 
> static inline bool iovec_iterator_finished(iovec_iterator_t *iovec_iterator) {
> 	return iovec_iterator->total_size == iovec_iterator->total_offset;
> }
> 
> bool iovec_user_check(iovec_t *iovec, size_t count) {
>-	// TODO add size overflow check
>+	size_t total = 0;
>+
> 	for (int i = 0; i < count; ++i) {
> 		// POSIX says that when len is zero, the addr can be an invalid buffer
> 		if (iovec[i].len && IS_USER_ADDRESS(iovec[i].addr) == false)
> 			return false;
>+
>+		// The total size has to fit in the ssize_t returned to userspace
>+		if (__builtin_add_overflow(total, iovec[i].len, &total) || total > SIZE_MAX / 2)
>+			return false;
> 	}
> 
> 	return true;

Applied.

Thanks,
Matheus

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

end of thread, other threads:[~2026-11-19 20:33 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2026-11-19 18:39 [PATCH] iovec: reject iovecs whose total size overflows Marvin Friedrich
2026-11-19 18:53 ` Marvin Friedrich
2026-11-19 20:33 ` Matheus

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