Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp7616755rwi; Mon, 24 Oct 2022 17:44:05 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5U1ORlwjmtxLKUGhQ88vuP7nWpYqUD4a+azxPlcagF2AkKHmcrFrL+5ZH5G+r2n7bf70Ly X-Received: by 2002:aa7:d80b:0:b0:45f:b9ed:6e3c with SMTP id v11-20020aa7d80b000000b0045fb9ed6e3cmr25301510edq.22.1666658645230; Mon, 24 Oct 2022 17:44:05 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666658645; cv=none; d=google.com; s=arc-20160816; b=w+1hoStOgJLaZzXThnjsKOFZB6LiqsJOYn7VX32+qcImZbFwBMJDK1NpizT3R9zuL/ /u/VgcLIP8dvnSRJTs0Z/Fo+JH+CF71hvFUzFs5UVND1el9EOT43IbStbkPLpilSJeOs F11PX9aB/CqVFVUXKLK0phpVThgbjDBDlAO/7Ybmk65LKsIhHOwzWMayc8T4DlqccJes GWp9gC+ZneLCrwDr4UWxV1in9hJ1FxCNJZtGgl6yNTgNHA0KPvazS9HvY16suArbtC0e W27gg1421vya9ztxyFTYk0+ZBqJ6Fnins2Rs5uix/lgr+0biNkSRK5W/+DYxNyIW38ne la8w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:mime-version:user-agent :content-transfer-encoding:references:in-reply-to:date:to:from :subject:message-id; bh=TfHFOgTLbFmPt+EiBeyK9sMFVCxrRgIbUbskwugNppQ=; b=NP07cbLtyFXePIVpS0+fPDevzOnkGoQgogY0zxw5nxjbbeWZRytjHe6kCID/HbOw5W gdmkPDsidh1dBkMlUF1iJPjt8dVvlokALorzXsxPLaW5xMw0uf3RtJoyu7mCL+i6HpJl oWLJu3eCSNVfoJDprx4I3Pnjb5Zarh5B4XN0FbVYr7CtRGta7kYDJ0oMIwVVZieHO7DX ejFL7Fa4bIUPL0BP6JJSK41Xedci2bLV98Rtppb7bZA3mskq7sU/ALX0EKyZTqBh1UWE 8bTSmLog2/IOzJICRV5AfJWiew01oZs/VDqMnGsDcEJyNz0SM/XTKi9IkPTRXhxHcPeL cUZw== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id go7-20020a1709070d8700b00788a70eed08si1460704ejc.610.2022.10.24.17.43.40; Mon, 24 Oct 2022 17:44:05 -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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230403AbiJYAcK convert rfc822-to-8bit (ORCPT + 99 others); Mon, 24 Oct 2022 20:32:10 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229667AbiJYAbx (ORCPT ); Mon, 24 Oct 2022 20:31:53 -0400 Received: from gate.crashing.org (gate.crashing.org [63.228.1.57]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9D5D4814EE; Mon, 24 Oct 2022 15:55:35 -0700 (PDT) Received: from [IPv6:::1] (localhost.localdomain [127.0.0.1]) by gate.crashing.org (8.14.1/8.14.1) with ESMTP id 29OLxHwv016050; Mon, 24 Oct 2022 16:59:18 -0500 Message-ID: <661b43881b7f8764919847f29c0daf1866441090.camel@kernel.crashing.org> Subject: Re: [PATCH] usb: gadget: aspeed: fix buffer overflow From: Benjamin Herrenschmidt To: Lei YU , Felipe Balbi , Greg Kroah-Hartman , Joel Stanley , Andrew Jeffery , Henry Tian , Jakob Koschel , linux-usb@vger.kernel.org, linux-arm-kernel@lists.infradead.org, linux-aspeed@lists.ozlabs.org, linux-kernel@vger.kernel.org Date: Tue, 25 Oct 2022 08:59:17 +1100 In-Reply-To: <20221024094853.2877441-1-yulei.sh@bytedance.com> References: <20221024094853.2877441-1-yulei.sh@bytedance.com> Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 8BIT User-Agent: Evolution 3.44.4-0ubuntu1 MIME-Version: 1.0 X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS 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 On Mon, 2022-10-24 at 09:48 +0000, Lei YU wrote: > From: Henry Tian I wrote that driver, please CC me on further patches to it (thanks Joel for the heads up). > In ast_vhub_epn_handle_ack() when the received data length exceeds the > buffer, it does not check the case and just copies to req.buf and cause > a buffer overflow, kernel oops on this case. .../... Thanks ! Seems like a legit bug, however: > diff --git a/drivers/usb/gadget/udc/aspeed-vhub/epn.c b/drivers/usb/gadget/udc/aspeed-vhub/epn.c > index b5252880b389..56e55472daa1 100644 > --- a/drivers/usb/gadget/udc/aspeed-vhub/epn.c > +++ b/drivers/usb/gadget/udc/aspeed-vhub/epn.c > @@ -84,6 +84,7 @@ static void ast_vhub_epn_handle_ack(struct ast_vhub_ep *ep) >  { >         struct ast_vhub_req *req; >         unsigned int len; > +       int status = 0; >         u32 stat; >   >         /* Read EP status */ > @@ -119,9 +120,15 @@ static void ast_vhub_epn_handle_ack(struct ast_vhub_ep *ep) >         len = VHUB_EP_DMA_TX_SIZE(stat); >   >         /* If not using DMA, copy data out if needed */ > -       if (!req->req.dma && !ep->epn.is_in && len) > -               memcpy(req->req.buf + req->req.actual, ep->buf, len); > - > +       if (!req->req.dma && !ep->epn.is_in && len) { > +               if (req->req.actual + len > req->req.length) { > +                       req->last_desc = 1; > +                       status = -EOVERFLOW; > +                       goto done; Should we stall as well ? Should we continue receiving and just dropping the data until we have a small packet ? Otherwise the EP could get out of sync for subsequent ones... Additionally, I'm curious, why in this specific case is the device sending more data than the buffer can hold ? The MTU change should have resulted in buffers being re-allocated no ? Or did you change the MTU on the remote and not on the local device ? Cheers, Ben.