Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp28597298rwd; Tue, 4 Jul 2023 23:10:48 -0700 (PDT) X-Google-Smtp-Source: APBJJlGqAe1Zlb4dMjwRwKFCWhj0FIZONoWgqfxXw34E93BDQVbnczE2zg0yWnWKpw1nEDsgfnzU X-Received: by 2002:a17:90b:4ac5:b0:263:ba18:3bcc with SMTP id mh5-20020a17090b4ac500b00263ba183bccmr7454945pjb.46.1688537448054; Tue, 04 Jul 2023 23:10:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688537448; cv=none; d=google.com; s=arc-20160816; b=VqPFByIb4JVIPoqYtvp9DDRF4yuJN6kSzt+Pou/3eaKm8hntZ8Zwk6hN65/mrsY9l3 TafghOLCEDgZzJ9Or49u8pbvCTMmqGytNF801ZtCYYgBBcsRV+tzCxZb+oDrh9SsPFMV rBXNI/9LdapVBD/hOmNsqdKDp1zgoBgOxpLA2fIopQwAzcZppgLEDKKgm6mr7/dPXAA3 gzaoi5xE2fvVMoucB/oJNMzVvoSCHJSsL9kuN9VcNFE5X8F+q+59RJ+/OIWZkx2nQIXU ffLqdB4/V/EhzgIL8gYYm7yHGlPZJkQuJc1ke+naVjUXrjSDJ0n8YUTYOPUzECmNg/qG x5jg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :organization:references:in-reply-to:message-id:subject:cc:to:from :date:dkim-signature; bh=O0C66mVI1nkOIpn+KxsHOUvDqjbprbMxbnSqsj7WItk=; fh=Zhsjdys0h/kFuusKUFFb2Y00SbPmbnhhZ0JxIFId4e4=; b=iD18wTwJKriLwmrWejSiAxG0VExseo3q2KWkZT3q6gp2G/5h2CVgWq/921IrAtUAA3 t8eVTACbDWbwFJW9hJUQsG/11buaQRfDYCb4EzgO4wZzxQ8j8/h9xW2/CwiC4uHYIuju cZqaBrINcXmVuLg1u/tyfv8ssBwHq4Mh3ijdZ3NtYOqcw6GYU1v0f4j5xQiZBJ5J0UoI QcUS97Nf49Pd8UCEiUytA1N18KT+Uxl+rQSTLD42026EOMlyXcAh0fhg6nx05JflnOTW iIkYWSDJVgY9IqkQtV9TLZpth1kiEsk4Rvw6GKniu2UyOexopjiPDQpaDlEIRVywopCm B2nQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=HMzIJ0wI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id i3-20020a17090a7e0300b00262e9461e36si917085pjl.143.2023.07.04.23.10.32; Tue, 04 Jul 2023 23:10:48 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@bootlin.com header.s=gm1 header.b=HMzIJ0wI; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=REJECT sp=REJECT dis=NONE) header.from=bootlin.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231305AbjGEGGj (ORCPT + 99 others); Wed, 5 Jul 2023 02:06:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33622 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229998AbjGEGGh (ORCPT ); Wed, 5 Jul 2023 02:06:37 -0400 Received: from relay1-d.mail.gandi.net (relay1-d.mail.gandi.net [IPv6:2001:4b98:dc4:8::221]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D4921700; Tue, 4 Jul 2023 23:06:27 -0700 (PDT) X-GND-Sasl: herve.codina@bootlin.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=bootlin.com; s=gm1; t=1688537186; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=O0C66mVI1nkOIpn+KxsHOUvDqjbprbMxbnSqsj7WItk=; b=HMzIJ0wIJQCx++SRoTVQ8bottUooWGrkC8U7ZbdBDWg4B+tUqyPdud6JH9otkTYx2SY5fR t1NQSyOEzJPRQQZvqLzSHQMzV+R/uoM4OOVbiiKYOkZ/nGpqrrmZVCcj4fbt4TjJ1AnkvT IrqpE/3YkiwUoF1JTiKaeXmwNTXWWbT0bIbEihf02ULF0r0KLhbj264ppLD/bndnr2ZLTR M4k/4p2K+3qLySn9vZ8R2zqGUElPkVybtLGVxq6YpF1ppekDo8CePFROKUoz5/SgrN3VnL pCnV4fnpHLFG4+CF5XYs+C8FMJdP4mepqUQJL1K5TwJf8dW+aTf7pPrk9vPIyw== X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com X-GND-Sasl: herve.codina@bootlin.com Received: by mail.gandi.net (Postfix) with ESMTPSA id C88C824000A; Wed, 5 Jul 2023 06:06:25 +0000 (UTC) Date: Wed, 5 Jul 2023 08:06:25 +0200 From: Herve Codina To: Yu Hao Cc: chunfeng.yun@mediatek.com, gregkh@linuxfoundation.org, linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-mediatek@lists.infradead.org, linux-kernel Subject: Re: [PATCH] usb: mtu3: Fix possible use-before-initialization bug Message-ID: <20230705080625.02b2bac5@bootlin.com> In-Reply-To: References: Organization: Bootlin X-Mailer: Claws Mail 4.1.1 (GTK 3.24.38; x86_64-redhat-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW,SPF_HELO_PASS, SPF_PASS,T_SCC_BODY_TEXT_LINE,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Yu, On Tue, 4 Jul 2023 16:25:50 -0700 Yu Hao wrote: > The struct usb_ctrlrequest setup should be initialized in the function > ep0_read_setup(mtu, &setup). However, inside that function, > the variable count could be 0 and the struct usb_ctrlrequest setup > is not initialized. But there is a read for setup.bRequestType. > > Signed-off-by: Yu Hao > --- > drivers/usb/mtu3/mtu3_gadget_ep0.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/drivers/usb/mtu3/mtu3_gadget_ep0.c > b/drivers/usb/mtu3/mtu3_gadget_ep0.c > index e4fd1bb14a55..67034fa515d0 100644 > --- a/drivers/usb/mtu3/mtu3_gadget_ep0.c > +++ b/drivers/usb/mtu3/mtu3_gadget_ep0.c > @@ -638,7 +638,7 @@ static int ep0_handle_setup(struct mtu3 *mtu) > __releases(mtu->lock) > __acquires(mtu->lock) > { > - struct usb_ctrlrequest setup; > + struct usb_ctrlrequest setup = {}; > struct mtu3_request *mreq; > int handled = 0; > Looks strange to me because, if ep0_read_setup() cannot read the setup data why don't we simply abort the operation ? With setup = {}, the following test is true: if ((setup.bRequestType & USB_TYPE_MASK) == USB_TYPE_STANDARD) handled = handle_standard_request(mtu, &setup); handle_standard_request() is called and supposes an USB_REQ_GET_STATUS (0x00) request: case USB_REQ_GET_STATUS: handled = ep0_get_status(mtu, setup); break; Then ep0_get_status() supposes USB_RECIP_DEVICE (0x00) and performs some operation sending the data related to the GET_STATUS. All of these are not correct as the setup data that triggered this sequence was never received. Aborting the operation if ep0_read_setup() cannot read the setup data seems better to me. Best regards, Hervé -- Hervé Codina, Bootlin Embedded Linux and Kernel engineering https://bootlin.com