From: Stefano Brivio <sbrivio@redhat.com>
To: passt-dev@passt.top
Cc: David Gibson <david@gibson.dropbear.id.au>
Subject: [PATCH] tcp: Explicit bound check on options length field
Date: Fri, 18 Nov 2022 01:26:13 +0100 [thread overview]
Message-ID: <20221118002613.2656578-1-sbrivio@redhat.com> (raw)
For some reason, Coverity only reports this (harmless) warning after
David's series unifying IPv4 and IPv6 sockets for TCP: an untrusted
loop bound (CWE-606) in tcp_opt_get(), coming from the fact that we
use indeed the value of a TCP header field as loop bound.
Note, though, that the loop already checks we're not exceeding the
length of the option field, and this field is used as 8-bit unsigned
value, so we can't really look for options past the end of the
header.
In any case, make Coverity happy with an explicit check.
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
---
tcp.c | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)
diff --git a/tcp.c b/tcp.c
index 8044617..8874789 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1146,7 +1146,11 @@ static int tcp_opt_get(const char *opts, size_t len, uint8_t type_find,
break;
default:
type = *(opts++);
- optlen = *(opts++) - 2;
+
+ if (*opts < 2 || *(uint8_t *)opts > len)
+ return -1;
+
+ optlen = *((uint8_t *)opts++) - 2;
len -= 2;
if (type != type_find)
--
@@ -1146,7 +1146,11 @@ static int tcp_opt_get(const char *opts, size_t len, uint8_t type_find,
break;
default:
type = *(opts++);
- optlen = *(opts++) - 2;
+
+ if (*opts < 2 || *(uint8_t *)opts > len)
+ return -1;
+
+ optlen = *((uint8_t *)opts++) - 2;
len -= 2;
if (type != type_find)
--
2.35.1
reply other threads:[~2022-11-18 0:26 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
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=20221118002613.2656578-1-sbrivio@redhat.com \
--to=sbrivio@redhat.com \
--cc=david@gibson.dropbear.id.au \
--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).