From: Yingjie Wang <x-professor@outlook.com>
To: Neill Kapron <nkapron@google.com>,
"linux-usb@vger.kernel.org" <linux-usb@vger.kernel.org>
Cc: Greg Kroah-Hartman <gregkh@linuxfoundation.org>,
Bingquan Chen <patzilla007@gmail.com>,
Andrzej Pietrasiewicz <andrzej.p@collabora.com>,
Felipe Balbi <balbi@kernel.org>,
"linux-kernel@vger.kernel.org" <linux-kernel@vger.kernel.org>
Subject: [PATCH v2 0/2] usb: gadget: configfs: fix extended property length handling
Date: Sat, 31 Oct 2026 18:13:57 +0000 [thread overview]
Message-ID: <cover.1793470427.git.x-professor@outlook.com> (raw)
In-Reply-To: <179338899796.2590875.15337207674245295434.b4-review@b4>
The configfs implementation of Microsoft OS Extended Properties keeps the
raw property payload in memory while data_len records the descriptor wire
length. The Unicode wire length includes a two-byte terminator, but the
stored allocation did not. Configfs readback and descriptor conversion
could consequently read one byte past the allocation.
Type changes also updated data_len with shifts that omitted the Unicode
terminator and left the aggregate descriptor length unchanged. This could
truncate a property value, report a stale dwLength, or make configfs
readback use a length larger than the allocation.
Patch 1 allocates the source terminator, guards empty writes and introduces
the raw-to-wire length helper. Patch 2 keeps the raw data length separately,
derives Unicode wire lengths from the actual UTF-16 conversion, uses both
lengths for type changes and readback, and updates the aggregate descriptor
length. Configfs now returns the raw payload, while the host-visible Unicode
descriptor retains its UTF-16 terminator.
Changes since v1:
- use separate raw and wire lengths instead of inferring UTF-8 bytes from
a UTF-16 wire length;
- derive Unicode wire lengths from UTF-16 code units, including the
terminator, so non-ASCII values are not padded with extra zero units;
- return only the raw payload through configfs readback;
- keep data_len and the aggregate descriptor length consistent across type
changes;
- calculate the type-dependent length and publish the new data under
opts_mutex;
- guard empty data writes before checking the trailing byte;
- preserve the FunctionFS Unicode conversion input length while adapting the
shared serializer;
- reject malformed UTF-8 without replacing the existing property data or
changing its descriptor lengths;
- include the related type-change fix as patch 2/2.
Tested on x86-64 with KASAN using an RNDIS configfs gadget on dummy_hcd.
The base kernel reported out-of-bounds reads in configfs readback and host
descriptor generation. Patch 1 removed the direct Unicode-data reports;
the full series also removed the type-change report, with no KASAN, BUG or
WARNING. Binary-to-Unicode, Unicode-to-binary, data-before-type, property
removal and type 7 configfs readback were exercised. ASCII, U+00E9 and
U+1F600 values produced exact UTF-16 data lengths and terminators, including
through a binary-to-Unicode transition. Every host descriptor length
matched the returned response, and configfs returned the raw bytes. An
invalid UTF-8 write failed without changing the old data, type or host
descriptor. A separate FunctionFS run returned the complete "abc\0" Unicode
property and preserved a four-byte Binary property containing an embedded
NUL. Both commits also built with W=1 for x86-64 and i386.
Yingjie Wang (2):
usb: gadget: configfs: NUL-terminate extended property data
usb: gadget: configfs: keep extended property lengths consistent
drivers/usb/gadget/composite.c | 1 +
drivers/usb/gadget/configfs.c | 100 +++++++++++++++++++----------
drivers/usb/gadget/function/f_fs.c | 1 +
drivers/usb/gadget/u_os_desc.h | 8 +--
include/linux/usb/composite.h | 4 +-
5 files changed, 76 insertions(+), 38 deletions(-)
base-commit: e971f4f365bad51d01bc90db55b56fdb3124f963
--
2.43.0
next prev parent reply other threads:[~2026-10-31 18:13 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-10-29 3:06 [PATCH] usb: gadget: configfs: NUL-terminate extended property data Yingjie Wang
2026-10-30 19:36 ` Neill Kapron
2026-10-31 18:13 ` Yingjie Wang [this message]
2026-10-31 18:13 ` [PATCH v2 1/2] " Yingjie Wang
2026-10-31 18:13 ` [PATCH v2 2/2] usb: gadget: configfs: keep extended property lengths consistent Yingjie Wang
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=cover.1793470427.git.x-professor@outlook.com \
--to=x-professor@outlook.com \
--cc=andrzej.p@collabora.com \
--cc=balbi@kernel.org \
--cc=gregkh@linuxfoundation.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-usb@vger.kernel.org \
--cc=nkapron@google.com \
--cc=patzilla007@gmail.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
all inboxes | Powered by JetHome®