From: Foster Snowhill <forst@pen.gy>
To: Oliver Neukum <oneukum@suse.com>,
"David S. Miller" <davem@davemloft.net>,
Eric Dumazet <edumazet@google.com>,
Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: Georgi Valkov <gvalkov@gmail.com>,
Simon Horman <horms@kernel.org>,
netdev@vger.kernel.org, linux-usb@vger.kernel.org
Subject: Re: [PATCH net-next] usbnet: ipheth: prevent OoB reads of NDP16
Date: Mon, 9 Sep 2024 15:39:02 +0200 [thread overview]
Message-ID: <3d5a69be-2527-41cd-b3f2-28ae86084ee7@pen.gy> (raw)
In-Reply-To: <d15bc43b-f130-4fd1-a758-b19b2dc99d46@suse.com>
Hi,
I think you already got the idea, but just in case, a more concise
explanation for Apple's tethering implementation would be "they just
happened to use NCM encapsulation for RX, everything else about it
has nothing to do with CDC NCM".
On 2024-09-09 13:04, Oliver Neukum wrote:
> May I suggest a reformulation of the
> commit message. It reads like this patch is intended for generic CDC-NCM.
No problem, does the commit message below read better? Suggestions are
absolutely welcome.
For one, I added a paragraph closer to the beginning that's explicit
about the intentions of this driver: it doesn't aim to be and can't be
a generic spec-compliant implementation. I can't avoid naming "CDC NCM"
completely, but I only use it in the first paragraph to clarify the
difference. There was one subsequent mention of it, and I replaced it
with a more generic "NCM mode".
If this is good, I'll give v1 a day or two more for any more feedback,
and then resubmit v2 with the updated commit message.
Cheers,
Foster
---
usbnet: ipheth: prevent OoB reads of NDP16
In "NCM mode", the iOS device encapsulates RX (phone->computer) traffic
in NCM Transfer Blocks (similarly to CDC NCM). However, unlike reverse
tethering (handled by the `cdc_ncm` driver), regular tethering is not
compliant with the CDC NCM spec, as the device is missing the necessary
descriptors, and TX (computer->phone) traffic is not encapsulated
at all. Thus `ipheth` implements a very limited subset of the spec with
the sole purpose of parsing RX URBs.
In the first iteration of the NCM mode implementation, there were a few
potential out of bounds reads when processing malformed URBs received
from a connected device:
* Only the start of NDP16 (wNdpIndex) was checked to fit in the URB
buffer.
* Datagram length check as part of DPEs could overflow.
* DPEs could be read past the end of NDP16 and even end of URB buffer
if a trailer DPE wasn't encountered.
The above is not expected to happen in normal device operation.
To address the above issues for iOS devices in NCM mode, rely on
and check for a specific fixed format of incoming URBs expected from
an iOS device:
* 12-byte NTH16
* 96-byte NDP16, allowing up to 22 DPEs (up to 21 datagrams + trailer)
On iOS, NDP16 directly follows NTH16, and its length is constant
regardless of the DPE count.
The format above was observed on all iOS versions starting with iOS 16,
where NCM mode was introduced, up until the latest stable iOS release,
which is iOS 17.6.1 at the moment of writing.
Adapt the driver to use the fixed URB format. Set an upper bound for
the DPE count based on the expected header size. Always expect a null
trailer DPE.
The minimal URB length of 108 bytes (IPHETH_NCM_HEADER_SIZE) in NCM mode
is already enforced in ipheth since introduction of NCM mode support.
next prev parent reply other threads:[~2024-09-09 13:39 UTC|newest]
Thread overview: 6+ messages / expand[flat|nested] mbox.gz Atom feed top
2024-09-07 23:01 [PATCH net-next] usbnet: ipheth: prevent OoB reads of NDP16 Foster Snowhill
2024-09-09 8:47 ` Oliver Neukum
2024-09-09 9:04 ` Foster Snowhill
2024-09-09 11:04 ` Oliver Neukum
2024-09-09 13:39 ` Foster Snowhill [this message]
2024-09-09 14:12 ` Oliver Neukum
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=3d5a69be-2527-41cd-b3f2-28ae86084ee7@pen.gy \
--to=forst@pen.gy \
--cc=davem@davemloft.net \
--cc=edumazet@google.com \
--cc=gvalkov@gmail.com \
--cc=horms@kernel.org \
--cc=kuba@kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=netdev@vger.kernel.org \
--cc=oneukum@suse.com \
--cc=pabeni@redhat.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