public inbox for astral-devel@lists.astral-os.org
 help / color / mirror / Atom feed
From: Marvin Friedrich <contact@marvinf.com>
To: astral-devel@lists.astral-os.org
Cc: Marvin Friedrich <contact@marvinf.com>
Subject: [PATCH] iovec: reject iovecs whose total size overflows
Date: Thu, 19 Nov 2026 19:39:26 +0100	[thread overview]
Message-ID: <20261119183926.81087-1-contact@marvinf.com> (raw)

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


             reply	other threads:[~2026-11-19 18:39 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-11-19 18:39 Marvin Friedrich [this message]
2026-11-19 18:53 ` Marvin Friedrich
2026-11-19 20:33 ` Matheus

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20261119183926.81087-1-contact@marvinf.com \
    --to=contact@marvinf.com \
    --cc=astral-devel@lists.astral-os.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox