From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Subject: [PATCH] tcp: Explicitly check option length field values in tcp_opt_get()
Date: Wed, 4 Jan 2023 18:44:21 +0100 [thread overview]
Message-ID: <20230104174421.633847-1-sbrivio@redhat.com> (raw)
Reported by Coverity (CWE-606, Untrusted loop bound), and actually
harmless because we'll exit the option-scanning loop if the remaining
length is not enough for a new option, instead of reading past the
header.
In any case, it looks like a good idea to explicitly check for
reasonable values of option lengths.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
tcp.c | 4 ++++
1 file changed, 4 insertions(+)
diff --git a/tcp.c b/tcp.c
index 26037b3..1e0a338 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1117,6 +1117,10 @@ static int tcp_opt_get(const char *opts, size_t len, uint8_t type_find,
break;
default:
type = *(opts++);
+
+ if (*(uint8_t *)opts < 2 || *(uint8_t *)opts > len)
+ return -1;
+
optlen = *(opts++) - 2;
len -= 2;
--
@@ -1117,6 +1117,10 @@ static int tcp_opt_get(const char *opts, size_t len, uint8_t type_find,
break;
default:
type = *(opts++);
+
+ if (*(uint8_t *)opts < 2 || *(uint8_t *)opts > len)
+ return -1;
+
optlen = *(opts++) - 2;
len -= 2;
--
2.35.1
next reply other threads:[~2023-01-04 17:44 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-01-04 17:44 Stefano Brivio [this message]
2023-01-05 4:34 ` [PATCH] tcp: Explicitly check option length field values in tcp_opt_get() David Gibson
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=20230104174421.633847-1-sbrivio@redhat.com \
--to=sbrivio@redhat.com \
--cc=passt-dev@passt.top \
/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.
Code repositories for project(s) associated with this public inbox
https://passt.top/passt
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for IMAP folder(s).