From: "Bjørn Mork" <bjorn@mork.no>
To: Alan Stern <stern@rowland.harvard.edu>
Cc: Hans Petter Selasky <hps@selasky.org>,
Oliver Neukum <oneukum@suse.com>,
linux-usb@vger.kernel.org, netdev@vger.kernel.org
Subject: Re: [RFC] CDC-NCM: avoid overflow in sanity checking
Date: Fri, 11 Feb 2022 08:17:37 +0100 [thread overview]
Message-ID: <87k0e1oory.fsf@miraculix.mork.no> (raw)
In-Reply-To: <YgXByzVayvl3KJTS@rowland.harvard.edu> (Alan Stern's message of "Thu, 10 Feb 2022 20:54:19 -0500")
Alan Stern <stern@rowland.harvard.edu> writes:
> First, since offset and len are initialized by converting 16- or 32-bit
> unsigned values from little-endian to cpu-endian, they should be
> unsigned themselves.
>
> Second, once they are unsigned there is obviously no point in testing
> whether they are < 0.
>
> Third, if you want to make sure that skb_in's buffer contains the entire
> interval from offset to offset + len, the proper tests are:
>
> if (offset <= skb_in->len && len <= skb_in->len - offset) ...
>
> The first test demonstrates that the start of the interval is in range
> and the second test demonstrates that the end of the interval is in
> range. Furthermore, success of the first test proves that the
> computation in the second test can't overflow to a negative value.
Thanks. That detailed explanation makes perfect sense even to me.
Adding the additional offset <= skb_in->len test to Oliver's patch
is sufficient and the best solution.
Only is that the existing code wants the inverted result:
if (offset > skb_in->len || len > skb_in->len - offset) ...
with all values unsigned.
> IMO, working with unsigned values is simpler than working with
> signed values. But it does require some discipline to ensure that
> intermediate computations don't overflow or yield negative values.
And there you point out my problem: discipline :-)
Bjørn
next prev parent reply other threads:[~2022-02-11 7:17 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-02-10 15:54 [RFC] CDC-NCM: avoid overflow in sanity checking Oliver Neukum
2022-02-10 16:38 ` Hans Petter Selasky
2022-02-10 17:27 ` Bjørn Mork
2022-02-10 22:50 ` Hans Petter Selasky
2022-02-11 1:54 ` Alan Stern
2022-02-11 7:17 ` Bjørn Mork [this message]
2022-02-14 19:30 ` Oliver Neukum
2022-02-14 19:41 ` Bjørn Mork
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=87k0e1oory.fsf@miraculix.mork.no \
--to=bjorn@mork.no \
--cc=hps@selasky.org \
--cc=linux-usb@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oneukum@suse.com \
--cc=stern@rowland.harvard.edu \
/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