Return-Path: Received: from mail-bn3nam01on0111.outbound.protection.outlook.com ([104.47.33.111]:51356 "EHLO NAM01-BN3-obe.outbound.protection.outlook.com" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1032596AbeCAPkN (ORCPT ); Thu, 1 Mar 2018 10:40:13 -0500 From: Sasha Levin To: "stable@vger.kernel.org" , "stable-commits@vger.kernel.org" CC: Jack Pham , Mayank Rana , Felipe Balbi , Sasha Levin Subject: [added to the 4.1 stable tree] usb: gadget: f_fs: Process all descriptors during bind Date: Thu, 1 Mar 2018 15:28:00 +0000 Message-ID: <20180301152116.1486-517-alexander.levin@microsoft.com> References: <20180301152116.1486-1-alexander.levin@microsoft.com> In-Reply-To: <20180301152116.1486-1-alexander.levin@microsoft.com> Content-Language: en-US Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable MIME-Version: 1.0 Sender: stable-owner@vger.kernel.org List-ID: From: Jack Pham This patch has been added to the 4.1 stable tree. If you have any objections, please let us know. =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D [ Upstream commit 6cf439e0d37463e42784271179c8a308fd7493c6 ] During _ffs_func_bind(), the received descriptors are evaluated to prepare for binding with the gadget in order to allocate endpoints and optionally set up OS descriptors. However, the high- and super-speed descriptors are only parsed based on whether the gadget_is_dualspeed() and gadget_is_superspeed() calls are true, respectively. This is a problem in case a userspace program always provides all of the {full,high,super,OS} descriptors when configuring a function. Then, for example if a gadget device is not capable of SuperSpeed, the call to ffs_do_descs() for the SS descriptors is skipped, resulting in an incorrect offset calculation for the vla_ptr when moving on to the OS descriptors that follow. This causes ffs_do_os_descs() to fail as it is now looking at the SS descriptors' offset within the raw_descs buffer instead. _ffs_func_bind() should evaluate the descriptors unconditionally, so remove the checks for gadget speed. Fixes: f0175ab51993 ("usb: gadget: f_fs: OS descriptors support") Cc: stable@vger.kernel.org Co-Developed-by: Mayank Rana Signed-off-by: Mayank Rana Signed-off-by: Jack Pham Signed-off-by: Felipe Balbi Signed-off-by: Sasha Levin --- drivers/usb/gadget/function/f_fs.c | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/drivers/usb/gadget/function/f_fs.c b/drivers/usb/gadget/functi= on/f_fs.c index d3fb7bd8e10d..6b62bb5c021c 100644 --- a/drivers/usb/gadget/function/f_fs.c +++ b/drivers/usb/gadget/function/f_fs.c @@ -2756,10 +2756,8 @@ static int _ffs_func_bind(struct usb_configuration *= c, struct ffs_data *ffs =3D func->ffs; =20 const int full =3D !!func->ffs->fs_descs_count; - const int high =3D gadget_is_dualspeed(func->gadget) && - func->ffs->hs_descs_count; - const int super =3D gadget_is_superspeed(func->gadget) && - func->ffs->ss_descs_count; + const int high =3D !!func->ffs->hs_descs_count; + const int super =3D !!func->ffs->ss_descs_count; =20 int fs_len, hs_len, ss_len, ret, i; =20 --=20 2.14.1