From: Matheus <matheus@astral-os.org>
To: astral-devel@lists.astral-os.org, Marvin Friedrich <contact@marvinf.com>
Subject: Re: [PATCH] iovec: reject iovecs whose total size overflows
Date: Thu, 19 Nov 2026 17:33:51 -0300 [thread overview]
Message-ID: <CDBD55FB-69AA-4249-A6F4-D75495FAC575@astral-os.org> (raw)
In-Reply-To: <20261119183926.81087-1-contact@marvinf.com>
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
prev parent reply other threads:[~2026-11-19 20:33 UTC|newest]
Thread overview: 3+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-11-19 18:39 Marvin Friedrich
2026-11-19 18:53 ` Marvin Friedrich
2026-11-19 20:33 ` Matheus [this message]
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=CDBD55FB-69AA-4249-A6F4-D75495FAC575@astral-os.org \
--to=matheus@astral-os.org \
--cc=astral-devel@lists.astral-os.org \
--cc=contact@marvinf.com \
/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