From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.remote-ip=100.103.45.18 ARC-Seal: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; cv=none; t=1796075056; b=G5cnhaF6DHm/8nHo+T0jyv6GmPl4WDheCKiYvGT/kckwl9zWqyuPGjTVT0pF2ekPtscl 5Qxg6gSKFkSrjfm/YXeFdq441VytCRyjOZHiD63xFEsFKKKRYtBXLbspGCe+MdNmbNvdR dnJQfHIgxcY4uIclikJu2r7pBPb6RRK8inZ3JQ614V6iDycM5tf04Ddfpcp5Eu5sQ0JBi RoWKZcWDwaHZfvEXxGelORmEIvq1ye/hqlS92EcsCURQqv5FTNWfg/WkthO4l1rhKPKoM XeuFizWQuQmngeKEHtTiGfphIpYhok9HyfIinDejF+lfaW9/dr16arIm466lZVKyzPQ== ARC-Message-Signature: i=1; d=subspace.kernel.org; s=arc20261015; a=rsa-sha256; c=relaxed/relaxed; t=1796075056; h=Received:DKIM-Signature:Message-ID:From:Subject:Reply-To:To:Cc: In-Reply-To:References:Content-Type:Content-Transfer-Encoding:Date; bh=zbXzvqnSdchxWjoBi9SRsWMvCZQv0bbQEVZpJ+DzjcM=; b=RPiM9qGItsjB80gUPAWXNcEcIoRR8wFgTTUCG6z1DBTagW5VOsXXCe/F3027wrY77XgD oErAe4i9W8CfKTYer3ru9zcsjqwQCX8HXzRfQm8sEekLMud08o5IDs5j19Uf35C1oUUUa JqUdobRdIX1ReD92xtaGhWdRxePy0cCDSsdAkJf8bSoIXRoi6sPQuqPmzmOVWeHthSp/U M7v5R5AYaRJZBOr5XQhvUcCcoQHW5F7ZbAhAprorfWPLvnRxlrqXTDIVpMKBTqm/kIg2m H4adoV9+AED9quYkSfOuoqNw9k+W3fibPEzm2iz4wZGCQPE4oUWu/jqW8dBl8Zax98A== ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dkim=pass header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=icyvDhJo; arc=none smtp.remote-ip=100.103.45.18 Received: from smtp.kernel.org (quasi.space.kernel.org [100.103.45.18]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (prime256v1)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 488D4606A31A for ; Mon, 30 Nov 2026 21:44:16 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=kernel.org header.i=@kernel.org header.a=rsa-sha256 header.s=k20260515 header.b=icyvDhJo Received: by smtp.kernel.org (Postfix) with ESMTPSA id 101E01F00897; Mon, 30 Nov 2026 21:44:16 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=kernel.org; s=k20260515; t=1796075056; bh=zbXzvqnSdchxWjoBi9SRsWMvCZQv0bbQEVZpJ+DzjcM=; h=From:Subject:Reply-To:To:Cc:In-Reply-To:References:Date; b=icyvDhJoA9zd1Q/JXo/jrz0o5NVnh36Y1VrZ4przAmy8umLh7gwhJtW3vsfuoZBiy R1P39z7MDbDg8MMmmT/+DokCIWytm6thLHpXkdgGJqvllaOb8rz1oIS97QDavhoJ0Q p74fedKE7BvOs+HiY6ofXejBoGaDInumRU5UKAomotB+hmTkcRhhFwi4bZMjNNBHKA DxKqJj6grlsV1hXLRS9pC6xHQGkdf2GmXtzaAZ5fNDM4st6bLDRlAT8biMdam3UtjG HrCyFCf6f6ecWIlpyj6fysJkFkerECsLKL2DLqW6qT0rPOgllrW7wwD4TyBbvhq744 0r+d9XtDLziHA== Message-ID: From: sashiko-bot@kernel.org Subject: Re: [PATCH] usb: gadget: configfs: fix OOB read on ext_prop type toggle Reply-To: sashiko-reviews@lists.linux.dev To: "Tanuj Sharma" Cc: linux-usb@vger.kernel.org In-Reply-To: <20261130212459.85640-1-ertanuj96@gmail.com> References: <20261130212459.85640-1-ertanuj96@gmail.com> Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable Date: Mon, 30 Nov 2026 21:44:15 +0000 X-Mailing-List: linux-usb@vger.kernel.org List-Id: List-Post: List-Help: List-Subscribe: List-Unsubscribe: List-Owner: Precedence: list Thank you for your contribution! Sashiko AI review found 3 potential issues to consider: - [High] usb: gadget: configfs: OOB read and page overflow in ext_prop_type_store() - [Medium] usb: gadget: configfs: zero-size krealloc() in ext_prop_type_store() - [Medium] usb: gadget: configfs: race and UAF on data buffer in ext_prop_type_store() -- commit 369cb44f3d37f1e467b4fc47f9afd4f859e6fcdf Author: Tanuj Sharma usb: gadget: configfs: fix OOB read on ext_prop type toggle This commit reallocates and zero-fills ext_prop->data in ext_prop_type_store() when toggling an extended property from a binary or 32-bit type to a Unicode type. > diff --git a/drivers/usb/gadget/configfs.c b/drivers/usb/gadget/configfs.c > index 568b2a0a6df81..5ba45da8e6b89 100644 > --- a/drivers/usb/gadget/configfs.c > +++ b/drivers/usb/gadget/configfs.c > @@ -1311,9 +1311,24 @@ static ssize_t ext_prop_type_store(struct config_i= tem *item, > ext_prop->type =3D=3D USB_EXT_PROP_BE32) && > (type =3D=3D USB_EXT_PROP_UNICODE || > type =3D=3D USB_EXT_PROP_UNICODE_ENV || > - type =3D=3D USB_EXT_PROP_UNICODE_LINK)) > + type =3D=3D USB_EXT_PROP_UNICODE_LINK)) { > + if (ext_prop->data) { > + char *new_data; > + size_t new_len =3D ext_prop->data_len << 1; > + > + new_data =3D krealloc(ext_prop->data, new_len, > + GFP_KERNEL); [Severity: Medium] What happens if ext_prop->data is non-NULL while ext_prop->data_len is 0? Writing a single newline or NUL byte in ext_prop_data_store() while the type is USB_EXT_PROP_BINARY decrements len to 0, allocates a 1-byte buffer for ext_prop->data, and sets ext_prop->data_len to 0. Toggling the type to USB_EXT_PROP_UNICODE then calls krealloc(ext_prop->data, 0, GFP_KERNEL), which frees ext_prop->data and returns ZERO_SIZE_PTR. Because ZERO_SIZE_PTR is non-NULL, ext_prop->data is set to ZERO_SIZE_PTR with ext_prop->data_len still 0, and fill_ext_prop() -> usb_ext_prop_put_unicode() later writes the 2-byte UTF-16LE terminator at offset data_len - 2 (-2), corrupting dwPropertyDataLength in the descriptor buffer. > + if (!new_data) { > + if (desc->opts_mutex) > + mutex_unlock(desc->opts_mutex); > + return -ENOMEM; > + } > + memset(new_data + ext_prop->data_len, 0, > + ext_prop->data_len); > + ext_prop->data =3D new_data; > + } > ext_prop->data_len <<=3D 1; [Severity: Medium] Can reallocating ext_prop->data here race with ext_prop_data_show()? ext_prop_data_show() reads ext_prop->data_len, ext_prop->type, and ext_prop->data without taking desc->opts_mutex: CPU0 CPU1 ext_prop_type_store() ext_prop_data_show() mutex_lock(desc->opts_mutex) new_data =3D krealloc(ext_prop->data, new_len, ...) /* frees old ext_prop->data */ memcpy(page, ext_prop->data, len) <-- use-after-free ext_prop->data =3D new_data Even if krealloc() does not move the buffer, updating ext_prop->data_len before ext_prop->type lets a concurrent ext_prop_data_show() see the doubled ext_prop->data_len with the old binary ext_prop->type, skipping len >>=3D 1 and reading past the allocation. In addition, both in-tree callers of usb_os_desc_prepare_interf_dir() (ncm_alloc_inst() and rndis_alloc_inst()) leave desc->opts_mutex as NULL, allowing two concurrent ext_prop_type_store() calls to pass the same ext_prop->data pointer to krealloc(). > - else if ((ext_prop->type =3D=3D USB_EXT_PROP_UNICODE || > + } else if ((ext_prop->type =3D=3D USB_EXT_PROP_UNICODE || > ext_prop->type =3D=3D USB_EXT_PROP_UNICODE_ENV || > ext_prop->type =3D=3D USB_EXT_PROP_UNICODE_LINK) && > (type =3D=3D USB_EXT_PROP_BINARY || [Severity: High] Does this still allow an out-of-bounds read and page overflow when transitioning through USB_EXT_PROP_UNICODE_MULTI? When ext_prop->type is already USB_EXT_PROP_UNICODE, ext_prop_data_store() allocates only len + 1 bytes for ext_prop->data while setting ext_prop->data_len to (len << 1) + 2: drivers/usb/gadget/configfs.c:ext_prop_data_store() { ... new_data =3D kzalloc(len + 1, GFP_KERNEL); if (!new_data) return -ENOMEM; memcpy(new_data, page, len); ... if (ext_prop->type =3D=3D USB_EXT_PROP_UNICODE || ext_prop->type =3D=3D USB_EXT_PROP_UNICODE_ENV || ext_prop->type =3D=3D USB_EXT_PROP_UNICODE_LINK) ext_prop->data_len =3D (len << 1) + 2; ... } If userspace writes len bytes while the type is USB_EXT_PROP_UNICODE and then changes the type to USB_EXT_PROP_UNICODE_MULTI (or cycles 1 -> 7 -> 3), neither branch in ext_prop_type_store() runs. ext_prop->data remains len + 1 bytes while ext_prop->data_len remains (len << 1) + 2, so ext_prop_data_show() does not halve len and copies (len << 1) + 2 bytes from a (len + 1)-byte slab buffer. If userspace then transitions 1 -> 7 -> 3 -> 1, krealloc() grows the (len + 1)-byte buffer to (len << 2) + 4 bytes, but memset() only zeroes the upper half starting at (len << 1) + 2, leaving bytes [len + 1 .. (len << 1) + 1] uninitialized when ext_prop_data_show() reads them. Repeating the cycle (or writing more than 2048 bytes before toggling 3 -> 1 -> 7) also grows ext_prop->data_len past PAGE_SIZE, causing memcpy(page, ext_prop->data, len) in ext_prop_data_show() to overflow the configfs page buffer. --=20 Sashiko AI review =C2=B7 https://sashiko.dev/#/patchset/20261130212459.8564= 0-1-ertanuj96@gmail.com?part=3D1