Received: by 2002:a05:6358:1087:b0:cb:c9d3:cd90 with SMTP id j7csp6739438rwi; Mon, 24 Oct 2022 05:38:02 -0700 (PDT) X-Google-Smtp-Source: AMsMyM5gQI0bQoI9/p+SrrIr94T/l43zYqBaGHwQmxwsk4SH18JOaILAkbDtI/GircY1NoJdlJVu X-Received: by 2002:a17:902:cec2:b0:186:7e63:d35b with SMTP id d2-20020a170902cec200b001867e63d35bmr16202403plg.83.1666615081850; Mon, 24 Oct 2022 05:38:01 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1666615081; cv=none; d=google.com; s=arc-20160816; b=eQFgEN+0urDsBST30CBGiJti7MdiegPdjXPEDTa4eBHmdTitmO3a/Fll1E4H9rw/4H 7kQvOv6psEA1MpuH/Uow5/maaJjLka0ucfr19uhvQViT2ZwPOsjlFQECiEE6zzK22sZl alb8X6AwvOfvad6/RrR0C5jb/vF9BL6+jP3UoFk2kj+jnGKH47En6cRzNVJcAjkT0pRj BJf0bgB/f/rNfdzGSE1hug2efQ6xCe1PykkiI1RnYMKNAPRh9SCI7+zreaag/rEvRtCi 8lDPWaeq1s3mUnePtJvbIGR5YTv4bXmVOyrkUzP9ahkynPC94lqH2G8TD7Mfovsu6qr1 dYIg== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=oalOrpyosbir6jPMiBqj2HaU6sqdyvuiQeVCe6HiCnI=; b=jUJUu8mRjOinU+EML8Wsxta0TXa+3A5NGGY2E/M3gcZZHJ9v8ER66h04tbbEC5kaI5 IVGL5LVSMOl1k+pv4Ud58YEOj805blPpy9FAFzwDYGi8K3eKjLHyTtl/dD0XBrgSup1b nCl6z304IZoi8BkG5I9oeRDiKVWuyjyyjL0zb2R443X/C2kbZQVdbwvZDBIzWlmJQNVI G9chttnznmQ/3waPilkk4rZfOvmDyuUp6bd6gmPza8uiSQN+LkTByOBV5H5vRh05eC6v rhvN/k6xrsucHo/SrPgAMomD+fWXLg4zQ/zoVt2djCE3rC3T606X6y2bXeTTahH0o+Vt QqIg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=EPqg7JzD; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id h7-20020a635307000000b00450200a1078si36346905pgb.853.2022.10.24.05.37.50; Mon, 24 Oct 2022 05:38:01 -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=@linuxfoundation.org header.s=korg header.b=EPqg7JzD; 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=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232331AbiJXL5I (ORCPT + 99 others); Mon, 24 Oct 2022 07:57:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54222 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232086AbiJXLz2 (ORCPT ); Mon, 24 Oct 2022 07:55:28 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 99BBB74CE1; Mon, 24 Oct 2022 04:46:43 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 76A5EB810F5; Mon, 24 Oct 2022 11:45:21 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id CE5FDC43148; Mon, 24 Oct 2022 11:45:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1666611920; bh=bhDouuUflupWGGnjEU3vG613jCzS1Gy6Wbou3SeQ8uk=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=EPqg7JzDya3b98rA+aPcRkDIGMHJLRTvudZ1aMHHohvlNpAQnx6nnaFDpv98AdHct rbpEtZ3xxxjvsLwcEmhzw0cluc1p1UC1/FUz2pyN9oGSx8FKm3ToFX2qaSzR/K5u+z z3hoiWVSw6n1bROrDm/ewAo2An1WReCivcIUazi8= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Robin Guo , Sasha Levin Subject: [PATCH 4.9 150/159] usb: musb: Fix musb_gadget.c rxstate overflow bug Date: Mon, 24 Oct 2022 13:31:44 +0200 Message-Id: <20221024112954.898484057@linuxfoundation.org> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221024112949.358278806@linuxfoundation.org> References: <20221024112949.358278806@linuxfoundation.org> User-Agent: quilt/0.67 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,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 From: Robin Guo [ Upstream commit eea4c860c3b366369eff0489d94ee4f0571d467d ] The usb function device call musb_gadget_queue() adds the passed request to musb_ep::req_list,If the (request->length > musb_ep->packet_sz) and (is_buffer_mapped(req) return false),the rxstate() will copy all data in fifo to request->buf which may cause request->buf out of bounds. Fix it by add the length check : fifocnt = min_t(unsigned, request->length - request->actual, fifocnt); Signed-off-by: Robin Guo Link: https://lore.kernel.org/r/20220906102119.1b071d07a8391ff115e6d1ef@inspur.com Signed-off-by: Greg Kroah-Hartman Signed-off-by: Sasha Levin --- drivers/usb/musb/musb_gadget.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/drivers/usb/musb/musb_gadget.c b/drivers/usb/musb/musb_gadget.c index 8eb3a291ca9d..02ec84ce5ab9 100644 --- a/drivers/usb/musb/musb_gadget.c +++ b/drivers/usb/musb/musb_gadget.c @@ -785,6 +785,9 @@ static void rxstate(struct musb *musb, struct musb_request *req) musb_writew(epio, MUSB_RXCSR, csr); buffer_aint_mapped: + fifo_count = min_t(unsigned int, + request->length - request->actual, + (unsigned int)fifo_count); musb_read_fifo(musb_ep->hw_ep, fifo_count, (u8 *) (request->buf + request->actual)); request->actual += fifo_count; -- 2.35.1